fix(gateway): restore gateway sessions from JSON snapshots - #37817
konsisumer wants to merge 1 commit into
Conversation
|
Thanks for this, and for the careful tests — appreciate the work. Closing it though, because the JSON-snapshot fallback it re-adds was removed deliberately, not by oversight.
The underlying issue (#8385) is fixed on If you hit a real case where DB rows go missing while a JSON snapshot survives, that's a session-persistence bug worth its own issue with a repro — but the fix would be to stop the DB rows from going missing, not to re-add the snapshot fallback. Closing #8385 and this PR together. |
What does this PR do?
Adds a fail-open transcript replay path for gateway sessions whose SQLite history is empty or unavailable but whose opt-in
session_<id>.jsonsnapshot still contains the conversation. SQLite remains the canonical source and wins whenever it has rows, so normal DB-backed gateway history is unchanged. This lets a fresh Discord thread turn restore the intact same-session snapshot instead of starting cold when the DB replay row is missing.Related Issue
Fixes #8385
Type of Change
Changes Made
gateway/session.py: load transcripts fromstate.dbfirst, then fall back to the matchingsession_<id>.jsonsnapshot only when DB replay rows are absent or unavailable.tests/gateway/test_session.py: cover empty transcripts, DB transcript loading, DB-over-snapshot precedence, and snapshot salvage when DB history is empty.How to Test
pytest tests/gateway/test_session.py tests/gateway/test_load_transcript_db_only.py -q->77 passed.python scripts/check-windows-footguns.py gateway/session.py tests/gateway/test_session.py-> clean.git diff --check-> clean.ruff check gateway/session.py tests/gateway/test_session.py-> clean.ruff format --check gateway/session.py tests/gateway/test_session.py-> fails because both touched files have existing full-file formatting drift; I did not reformat them to avoid a broad unrelated diff.scripts/run_tests.sh-> ran via the repo wrapper and failed with27333 passed, 776 failedon this sandbox. Relevant gateway/session coverage passed under the wrapper, includingtests/gateway/test_session.py,tests/gateway/test_load_transcript_db_only.py,tests/gateway/test_discord_thread_persistence.py,tests/gateway/test_discord_free_response.py, andtests/gateway/test_discord_slash_commands.py. The failures are outside this diff and cluster around restricted$HOME/.hermeswrites, localhost socket bind permission errors, live-system guard process-signal blocks, shared-venv import timeouts, missing optional modules, DNS/network lookup failures, and/tmpversus/private/tmppath expectations.Checklist
For New Skills
Not applicable.
Screenshots / Logs
No screenshots. Local platform tested: macOS darwin-arm64 sandbox with Python 3.11.15 through
scripts/run_tests.sh.