fix(gateway): sync compression splits before failed turns - #45529
Conversation
Salvages PR #25747 by preserving gateway session rotation even when a post-compression model call fails before returning final content. Co-authored-by: Hermes <127238744+teknium1@users.noreply.github.com>
🔎 Lint report:
|
| Rule | Count |
|---|---|
invalid-assignment |
1 |
unresolved-attribute |
1 |
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [invalid-assignment] invalid-assignment: Object of type `None` is not assignable to attribute `_credits_session_start_micros` of type `int`
tests/gateway/test_compression_failure_session_sync.py:124: [unresolved-attribute] unresolved-attribute: Unresolved attribute `AIAgent` on type `ModuleType`
✅ Fixed issues (4):
| Rule | Count |
|---|---|
unresolved-attribute |
2 |
invalid-argument-type |
1 |
invalid-assignment |
1 |
First entries
gateway/run.py:14660: [invalid-argument-type] invalid-argument-type: Argument to bound method `SessionDB.get_telegram_topic_binding_by_session` is incorrect: Expected `str`, found `object`
gateway/run.py:14642: [invalid-assignment] invalid-assignment: Object of type `object` is not assignable to attribute `session_id` on type `SessionEntry & ~AlwaysFalsy`
tests/run_agent/test_credits_notices_toggle.py:76: [unresolved-attribute] unresolved-attribute: Unresolved attribute `_credits_session_start_micros` on type `AIAgent`
run_agent.py:2891: [unresolved-attribute] unresolved-attribute: Object of type `Self@get_credits_spent_micros` has no attribute `_credits_session_start_micros`
Unchanged: 5708 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Gateway compression fix: syncs compression state before marking a turn as failed, ensuring the compression records the incomplete turn before cleanup. Prevents compression from losing the context of partially-completed turns.
Correctness: Makes sense — if a turn fails after partial tool execution, compression should capture that partial context before the incomplete turn is cleared. The _sync_compression call before add_failed_turn is the right ordering.
Code Quality: Focused and minimal. No tests but the logic is straightforward and the risk of regression is low.
Reviewed by Hermes Agent (cron batch)
Summary
Gateway failed turns now keep the compressed child session instead of reloading the stale oversized parent transcript.
Salvages #25747 from @justinbao19. The compressed session split already existed, but the gateway only propagated it after a successful final response; a provider timeout after compression returned early without updating the session mapping.
Changes
gateway/run.py.session_idandhistory_offset=0on failed split turns so downstream transcript persistence targets the compressed child.Validation
python3 -m py_compile gateway/run.py tests/gateway/test_compression_failure_session_sync.py scripts/release.pyscripts/run_tests.sh tests/gateway/test_compression_failure_session_sync.py tests/gateway/test_transcript_offset.py tests/gateway/test_7100_transient_failure_transcript.pyInfographic