fix(compression): fall back to replace_messages when archive_and_compact fails (#71097)#71115
Conversation
…act fails (NousResearch#71097) archive_and_compact can raise on contended writes or schema-migration races. Previously the broad except swallowed the error, leaving compacted_in_place=False and causing the gateway to discard the successfully-produced summary. Fixes NousResearch#71097
|
I filed the needs-info diagnosis on #71097, so I verified this fix against that root-cause trace and it lands on exactly the right branch. This correctly fixes the issue. Root cause match. On Verified locally. One non-blocking note. The fallback Nice, tightly-scoped fix with a real regression test. |
Problem
When
archive_and_compact()raises during in-place compaction (contended write, schema-migration race, etc.), the broadexcept Exceptionat the end of thecompress_contexttry block swallows the error.compacted_in_placestaysFalse, so_last_compaction_in_placeis never set. The gateway then enters theelsebranch and discards the successfully-produced summary with the "no session_db on the hygiene agent" warning.Fix
Wrap the
archive_and_compact()call in its own try/except. When it raises, fall back toreplace_messages(active_only=True)so the compressed transcript is still persisted. This is destructive relative toarchive_and_compact(loses soft-archived pre-compaction history) but is strictly better than silently dropping the compression result.Regression test
TestInPlaceArchiveFailureFallback.test_archive_and_compact_failure_falls_back_to_replace— patchesarchive_and_compactto raiseRuntimeError("database is locked"), runscompress_context, verifies:_last_compaction_in_placeisTrueFixes #71097