Skip to content

fix(agent): strip _db_persisted on rotation compression assembly (#57491) - #57531

Closed
nankingjing wants to merge 1 commit into
NousResearch:mainfrom
nankingjing:fix/57491-rotation-compression-db-persisted
Closed

fix(agent): strip _db_persisted on rotation compression assembly (#57491)#57531
nankingjing wants to merge 1 commit into
NousResearch:mainfrom
nankingjing:fix/57491-rotation-compression-db-persisted

Conversation

@nankingjing

Copy link
Copy Markdown
Contributor

Summary

Rotation compression (compression.in_place: false) on long-lived cached gateway sessions lost the compacted transcript from state.db after restart. Root cause: ContextCompressor.compress() assembled the post-rotation message list with messages[i].copy(), which propagated the _db_persisted marker stamped by incremental _flush_messages_to_session_db flushes. The child-session flush then skipped every copied row.

  • agent/context_compressor.py: add _fresh_compaction_message_copy() that strips _db_persisted before head/tail assembly
  • tests/agent/test_context_compressor.py: unit regression — assembled compressed list must not carry markers
  • tests/run_agent/test_compression_persistence.py: end-to-end rotation + flush regression with all source messages pre-marked

Fixes #57491

Scope note

Follow-up to the compression cluster (#50372 marker dedup, #56391 interrupt demotion). This closes the rotation-path amnesia window without changing in-place compaction behavior.

Test plan

  • pytest tests/agent/test_context_compressor.py::TestCompress::test_compress_strips_db_persisted_from_assembled_messages -q
  • pytest tests/run_agent/test_compression_persistence.py::TestFlushAfterCompression::test_rotation_child_session_flushes_full_compressed_transcript_with_markers -q

…transcript (NousResearch#57491)

Shallow messages[i].copy() during context compression propagated the
_db_persisted marker from cached gateway incremental flushes into the
post-rotation compressed list. _flush_messages_to_session_db then skipped
every row when writing to the new child session, so gateway restarts
lost the compacted transcript (severe amnesia).

Strip the marker in _fresh_compaction_message_copy() and add regression
tests for rotation flush + compressor assembly.

Fixes NousResearch#57491
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state duplicate This issue or pull request already exists labels Jul 3, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #57508 — same file (agent/context_compressor.py), same mechanism (strip the _db_persisted marker from the shallow-copied protected head/tail so the child-session flush no longer skips those rows), same target issue #57491. #57508 (created earlier) is the canonical fix. Related: #57491 (the bug spec).

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Fixed on main — the rotation-compression _db_persisted amnesia (#57491) landed via #57574 (commits 3e204bd, e1a1dac).

#57574 salvaged this PR's fix (cherry-picked with your authorship preserved) and added a structural follow-up: rather than relying only on the two per-site strips, a single terminal sweep (_strip_persistence_markers) runs once on the fully-assembled compressed list, so the "no compacted message leaves compress() carrying _db_persisted" invariant holds regardless of copy-site order. Verified end-to-end (real compress() → rotation → child flush, both standalone-summary and merge-into-tail cases) and mutation-tested.

Thanks for the fix — closing as superseded (your commit is on main).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists P1 High — major feature broken, no workaround sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rotation compression: _db_persisted marker copied via messages[i].copy() skips bulk flush to child session (cached gateway regression since #50372)

3 participants