Skip to content

fix(compression): recover rotated session lineage - #70121

Closed
ruizanthony wants to merge 1 commit into
NousResearch:mainfrom
ruizanthony:fix/compression-lineage-recovery
Closed

fix(compression): recover rotated session lineage#70121
ruizanthony wants to merge 1 commit into
NousResearch:mainfrom
ruizanthony:fix/compression-lineage-recovery

Conversation

@ruizanthony

Copy link
Copy Markdown
Contributor

Summary

  • prevent messages from being persisted to a parent session after compression has atomically rotated it
  • recover and adopt the unique live compression child before the next turn continues
  • fail closed when competing children make the continuation ambiguous
  • keep the in-memory agent, flush cursors, cached system prompt, context engine, and durable transcript synchronized after adoption
  • preserve parent workspace, git, user, and chat metadata when publishing the child session

Problem

A gateway or WebUI worker can remain bound to the parent session after another compression path has already rotated it. The existing duplicate-rotation guard correctly skips a second rotation, but the stale worker can then continue appending messages to the closed parent. Repeated turns grow the obsolete transcript until the provider context limit is reached.

Approach

  • add an atomic persistence guard for sessions closed with end_reason=compression
  • identify a canonical direct continuation child, excluding ended sessions and non-continuation branch/tool/delegation children
  • return no candidate when more than one plausible continuation exists
  • rebind stale agents at the start of a turn and reload the compacted transcript
  • reset persistence cursors and notify context lifecycle hooks after rebinding
  • reject stale pre-lease snapshots in concurrent compression paths

Validation

  • compression/state/gateway regression matrix: 732 passed
  • protected replay against current origin/main: 82 passed
  • live protected replay smoke: 82 passed
  • Python compilation checks passed
  • git diff --check origin/main...HEAD passed

Operational evidence

The regression was reproduced from a parent session closed by compression that subsequently received hundreds of messages while its canonical child remained live. The fix is generic and contains no site-specific configuration or credentials.

@ruizanthony
ruizanthony force-pushed the fix/compression-lineage-recovery branch from d911515 to 279f023 Compare July 23, 2026 14:44
@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 comp/gateway Gateway runner, session dispatch, delivery area/compression Context compression and continuation sessions sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Jul 23, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related: #64373 hardens durable lease/atomic rotation. This PR additionally repairs stale-worker session adoption and gateway transcript rerouting after a rotation; reviewers should assess the complementary recovery path.

@egilewski

Copy link
Copy Markdown
Contributor

too large to review safely

This PR changes 583 production lines before tests and docs. Please split it or add a focused justification if it should stay together.

Signed: GPT-5.6-terra-low in Codex

@teknium1

Copy link
Copy Markdown
Contributor

Merged via #71001 with your authorship preserved — atomic child publication, closed-parent write guard, and live-child adoption all shipped. Follow-ups: publish_compression_child now inherits profile/thread/display/origin from the parent (the direct INSERT would have bypassed fork inheritance), and the pre-lease drift guard became rotation-only + length-based (content equality aborted in-place compaction and would wedge on legal in-memory mutation). Thanks for tackling the hardest subsystem in the sweep.

@teknium1 teknium1 closed this Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/compression Context compression and continuation sessions comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery 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.

4 participants