Skip to content

fix(compaction): resume queued work after compaction - #1574

Merged
lavaman131 merged 1 commit into
mainfrom
fix/1570-compaction-recovery
Jul 1, 2026
Merged

fix(compaction): resume queued work after compaction#1574
lavaman131 merged 1 commit into
mainfrom
fix/1570-compaction-recovery

Conversation

@flora131

@flora131 flora131 commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

Sessions could appear stuck after auto-compaction (or after a failed tool-call recovery) because post-compaction resume called agent.continue() directly and swallowed any failure, bypassing the retry/queue-draining lifecycle that a normal turn goes through. This routes post-compaction resume through the same continuation path as regular queued turns and surfaces failures instead of silently dropping them.

Closes #1570

Changes

  • Added _runAgentContinue() (agent-session-prompt.ts) which calls agent.continue(), then waitForRetry(), then drains queued messages via _continueQueuedAgentMessages() — mirroring the lifecycle _runAgentPrompt() already uses for normal turns.
  • _resumeAfterAutoCompaction() now calls _runAgentContinue() instead of a bare agent.continue().catch(() => {}), so retries and queued follow-ups are no longer dropped after compaction.
  • Added an agent_continue_error session event (source: post_compaction) emitted when post-compaction continuation fails, instead of the error being swallowed.
  • Wired the new event into interactive mode (interactive-agent-events.ts shows the error and re-renders) and the chat-session host event reducer (chat-session-host-events.ts clears busy state and surfaces the status message).
  • Documented the resume behavior in packages/coding-agent/docs/compaction.md and added a changelog entry.
  • Added regression tests covering the full continuation lifecycle (continuewaitForRetry → queue drain) and visible failure surfacing on post-compaction resume.

Validation

  • AGENT=1 bun run --cwd packages/coding-agent test -- test/agent-session-auto-compaction-queue-01.suite.ts test/agent-session-auto-compaction-queue-02.suite.ts
  • AGENT=1 bun run typecheck
  • bun run check:file-length
  • pre-push hooks: bun run lint, bun run check:file-length, bun run test:unit

@mintlify

mintlify Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
bastani 🟢 Ready View Preview Jul 1, 2026, 4:13 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@claude

claude Bot commented Jul 1, 2026

Copy link
Copy Markdown

Code Review — PR #1574 fix(compaction): resume queued work after compaction

Nice, tightly-scoped fix. Replacing the fire-and-forget agent.continue().catch(() => {}) with a real _runAgentContinue() that mirrors _runAgentPrompt() (continue → waitForRetry() → drain queued) is the right call — it reuses the established continuation lifecycle rather than reinventing it, and the failure surfacing directly addresses the "session looks dead" symptom in issue #1570. Type union, method-surface interface, agentSessionPromptMethods registration, docs, changelog, and tests are all updated consistently. 👍

Things worth a look

1. Removing .catch(() => {}) now surfaces previously-swallowed errors — confirm none are benign. In _schedulePostAutoCompactionContinuationProbe, the overflow && willRetry branch calls _resumeAfterAutoCompaction() even when hasQueuedMessages() is false. Previously any error from agent.continue() there was silently dropped; now every throw emits agent_continue_error, flips sdkBusy = false, and shows a red Post-compaction continuation failed: … to the user. Please double-check there is no edge case (e.g. "no active turn to continue", or a benign abort) where agent.continue() can reject in that path — otherwise this could turn a previously-invisible no-op into a scary user-facing error. If such benign rejections exist, consider filtering them before emitting.

2. source: "post_compaction" is defined but never read. The discriminant field on the event type is not consumed by either the interactive handler or the chat-session host (both only read errorMessage). Harmless as a forward-looking discriminator, but if it is not intended for imminent use it is dead weight; a short comment on its purpose would help.

3. Dual event handling (pre-existing, just flagging). agent_continue_error is handled in both chat-session-host-events.ts (statusMessage + clear sdkBusy) and interactive-agent-events.ts (showError). This matches how existing events like compaction_end/agent_end are dual-handled, so it is consistent with the architecture — just confirm these paths stay mutually exclusive so the error is not rendered twice in one UI. RPC forwarding is automatic via session.subscribe(... this.output(event)), and print-mode consumes assistant messages rather than granular events, so both are correctly covered without changes.

Test coverage. Good regression coverage: the two new queue-02 tests assert the full lifecycle (continue + waitForRetry + drain each called once) and that a rejected continue() produces exactly Post-compaction continuation failed: boom; the queue-01 additions assert the drain step now runs. One caveat — the tests mock out _continueQueuedAgentMessages, waitForRetry, and continue, so they verify the wiring rather than real end-to-end draining. That is reasonable for this fix, but an integration-style test that lets an actually-queued message drain through a real (stubbed-provider) continue would harden it against future refactors of the lifecycle.

Style / conventions. Matches CLAUDE.md — .ts-native, no build step touched, the Extract cast follows the existing String(event.type) switch pattern in the host file, and no any/unknown introduced. Changelog entry is descriptive and links the issue. LGTM overall pending the #1 sanity check.

@lavaman131
lavaman131 merged commit 72ce0d8 into main Jul 1, 2026
11 checks passed
@lavaman131
lavaman131 deleted the fix/1570-compaction-recovery branch July 1, 2026 07:01
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.

Crash(?) after failed toolcall

2 participants