feat(persistence): PostgreSQL assistant store, chat persist fixes, gateway scripts

- Add SQLAlchemy Core repos, pg adapter/compat, assistant_store factory, Alembic bootstrap and migration/cutover scripts.

- Harden chat_message writes (NUL scrub for PG), turn_uuid on attempt failure, WS turn_runner fallbacks and gateway executed_turn_uuid init.

- start_gateway: log paths, PS7 stderr handling via cmd, background stdout/stderr redirect; runtime assistant_runtime_log_dir export.

- Ops: clear_all_chat_sessions with PG-only --postgresql and env-gated wipe; clear_postgres_chat_sessions.ps1.

- Tests: SA repos, pg compat, persist fallback, smoke env isolation; CI and docs touch-ups.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-05-14 09:33:50 +08:00
parent 2b32d11f43
commit d14e9d3596
103 changed files with 7574 additions and 1641 deletions

View file

@ -22,3 +22,49 @@ jobs:
run: python -m pytest -q tests
- name: Offline eval sanity
run: python runtime/operations/scripts/offline_eval.py
test-postgresql:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 10
env:
AIA_ASSISTANT_DB_BACKEND: postgresql
AIA_ASSISTANT_DATABASE_URL: postgresql://postgres:postgres@127.0.0.1:5432/oclaw
AIA_TEST_PG_URL: postgresql://postgres:postgres@127.0.0.1:5432/oclaw
OPS_WORKSPACE_ROOT: ${{ github.workspace }}/.ci_workspace
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: python -m pip install -r requirements.txt
- name: Create database and apply migrations
run: |
mkdir -p "$OPS_WORKSPACE_ROOT"
python - <<'PY'
import os
import psycopg
dsn = os.environ["AIA_ASSISTANT_DATABASE_URL"]
admin = dsn.rsplit("/", 1)[0] + "/postgres"
with psycopg.connect(admin, autocommit=True) as conn:
cur = conn.execute("SELECT 1 FROM pg_database WHERE datname = %s", ("oclaw",))
if cur.fetchone() is None:
conn.execute("CREATE DATABASE oclaw")
PY
alembic upgrade head
- name: Run PostgreSQL-scoped tests
run: python -m pytest -q tests/test_database_backend.py tests/test_pg_compat.py tests/test_sa_app_settings.py tests/test_sa_auth_sessions.py tests/test_sa_chat_sessions.py tests/test_sa_chat_messages.py tests/test_sa_fork_trim_admin_sessions.py tests/test_sa_admin_user_stats_tool_health.py tests/test_sa_tool_log_trace.py tests/test_sa_prune_orphans.py tests/test_sa_ui_session_owner.py tests/test_sa_tenant_bind_code.py tests/test_sa_app_users.py tests/test_migrate_assistant_sqlite_to_pg.py