Skip to content

Keep long-session context recovery from stranding agent loops - #1042

Merged
Yeachan-Heo merged 1 commit into
Yeachan-Heo:devfrom
realitsyourman:fix/context-overflow-recovery-dev
Jun 23, 2026
Merged

Yeachan-Heo merged 1 commit into
Yeachan-Heo:devfrom
realitsyourman:fix/context-overflow-recovery-dev

Conversation

@realitsyourman

Copy link
Copy Markdown
Contributor

What

  • Harden long-session overflow recovery so post-compaction continuations do not strand the session on non-resumable assistant tails.
  • Run scheduled/direct agent.continue() paths through pre-continue context maintenance, with explicit skip flags for immediately-post-maintenance paths.
  • Reserve input budget for OpenAI remote compaction requests instead of trimming all the way up to the model context window.
  • Surface overflow maintenance completion/skip states in the TUI, including disabled non-resumable recovery.
  • Add focused regression coverage and changelog entries for the touched packages.

Why

Long sessions could enter context-full maintenance and still fail with context_length_exceeded or leave the UI looking stuck when the rebuilt tail could not be resumed with Agent.continue(). This keeps the low-level assistant-tail invariant intact while giving the session layer a deterministic fallback and clearer user-visible recovery state.

Recreated against latest dev after #1041 was closed for targeting main.

Testing

  • bun test packages/coding-agent/test/agent-session-auto-compaction-continue.test.ts
  • bun test packages/coding-agent/test/agent-session-auto-compaction-queue.test.ts
  • bun test packages/coding-agent/test/agent-session-concurrent.test.ts -t TTSR
  • bun test packages/coding-agent/test/modes/controllers/event-controller-auto-compaction.test.ts
  • bun test packages/coding-agent/test/compaction.test.ts
  • bun test packages/agent/test/compaction-estimate-cache.test.ts packages/agent/test/remote-compaction.test.ts
  • bun --cwd=packages/coding-agent run check:types
  • bun --cwd=packages/agent run check:types
  • bun --cwd=packages/coding-agent src/cli.ts --version
  • git diff --check

  • bun check passes
  • Tested locally
  • CHANGELOG updated (if user-facing)

Constraint: preserve agent-core assistant-tail continuation invariant

Rejected: changing model metadata | current source metadata already matches the observed model window

Confidence: high

Scope-risk: moderate

Directive: keep future overflow recovery tests credential-free and event-driven

Tested: bun --cwd=packages/coding-agent run check:types; bun --cwd=packages/agent run check:types; focused overflow, queue, TTSR, EventController, compaction, remote-compaction tests; source CLI version smoke

Not-tested: live OpenAI remote compaction call
@Yeachan-Heo

Copy link
Copy Markdown
Owner

MERGE_READY

Adversarial review for PR #1042 (811c7eb8de8fcf2970781fc2b7cbf4311d441a54) against dev.

Evidence checked:

  • CI is green and merge state is CLEAN.
  • GJC review session gajae-code-pr-1042-context-recovery-review inspected the exact origin/dev...pr-1042-head diff and the affected long-session recovery paths, including packages/agent/src/compaction/openai.ts, packages/coding-agent/src/session/agent-session.ts, packages/coding-agent/src/modes/controllers/event-controller.ts, and packages/coding-agent/src/extensibility/shared-events.ts.
  • The patch keeps context-full maintenance before continuation paths and adds explicit skip/status propagation for immediately-post-maintenance paths, including the non-resumable-tail disabled case.
  • Focused CI coverage passed for the changed compaction/cache/remote-compaction and coding-agent auto-compaction continue/queue/event-controller tests.

No merge-blocking regression or contract/security blocker found in the changed auto-compaction/context recovery surface.

—
[repo owner's gaebal-gajae (clawdbot) 🦞]

@Yeachan-Heo
Yeachan-Heo merged commit 13e545c into Yeachan-Heo:dev Jun 23, 2026
16 checks passed
@Yeachan-Heo

Copy link
Copy Markdown
Owner

MERGE_READY

Red-team merge-gate review focused on the changed auto-compaction/context-recovery paths only.

Evidence:

  • Inspected packages/coding-agent/src/session/agent-session.ts overflow recovery flow: failed overflow tails are stripped before retry, resumable tails use scheduled agent.continue(), non-resumable tails respect compaction.autoContinue === false, and queued post-compaction messages are resumed without relying on the synthetic auto-continue prompt.
  • Inspected packages/coding-agent/src/modes/controllers/event-controller.ts and packages/coding-agent/src/extensibility/shared-events.ts: the new continuationSkipReason is surfaced without warning spam and queue flushing still receives the correct willRetry value.
  • Inspected packages/agent/src/compaction/openai.ts: remote compaction now reserves output budget before trimming input, reducing repeat context-overflow risk for OpenAI compaction calls.
  • CI is green/CLEAN per gate context.
  • Focused local test command attempted for the changed test files, but this review worktree cannot resolve workspace aliases such as @gajae-code/agent-core / @gajae-code/utils; no PR-specific failing assertion was observed locally.

No blocker found in the changed context recovery path. Maintainer can merge.

—
[repo owner's gaebal-gajae (clawdbot) 🦞]

jason931225 pushed a commit to jason931225/gajae-code that referenced this pull request Sep 18, 2026
…n-Heo#1042)

Constraint: preserve agent-core assistant-tail continuation invariant

Rejected: changing model metadata | current source metadata already matches the observed model window

Confidence: high

Scope-risk: moderate

Directive: keep future overflow recovery tests credential-free and event-driven

Tested: bun --cwd=packages/coding-agent run check:types; bun --cwd=packages/agent run check:types; focused overflow, queue, TTSR, EventController, compaction, remote-compaction tests; source CLI version smoke

Not-tested: live OpenAI remote compaction call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants