Skip to content

fix(sidecar): end Claude turn once pending background tasks drain - #922

Merged
dohooo merged 3 commits into
mainfrom
fix/claude-background-task-turn-end
Jul 9, 2026
Merged

dohooo merged 3 commits into
mainfrom
fix/claude-background-task-turn-end

Conversation

@dohooo

@dohooo dohooo commented Jul 9, 2026 •

Copy link
Copy Markdown
Owner

Problem

Claude sessions failed to close after all background subagents/tasks finished: when a turn's completed result arrived while background tasks were still pending, the result was swallowed. The session then kept receiving task_updated drip events indefinitely and the turn never ended.

Fix

sidecar/src/claude/session-manager.ts:

  • The swallowed completed result is now replayed immediately once the pending task count reaches zero, ending the turn in one shot;
  • turnEnded is idempotent, so the turn closes exactly once.

Testing

  • Regression tests in background-resume.test.ts (10 pass);
  • Verified standalone against origin/main: full sidecar suite 415 tests green + tsc --noEmit clean;
  • End-to-end verification on a real dev build (Tauri MCP): turn ends normally after background tasks complete, with zero new sidecar events for 60s+ after teardown.

Notes

Split out of the task-visibility branch as an independent fix (PR 1 of 2); the task panel / visibility work follows in a separate PR.

Previously, when a Claude turn's completed result arrived while background
tasks were still pending, the result was swallowed and the session never
closed — task_updated events kept dripping in indefinitely after all
tasks finished.

Now the swallowed completed result is replayed as soon as the pending
task count reaches zero, and turnEnded is idempotent so the turn closes
exactly once.
@vercel

vercel Bot commented Jul 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
helmor-marketing Ignored Ignored Preview Jul 9, 2026 8:52pm

Request Review

@dohooo
dohooo enabled auto-merge (squash) July 9, 2026 20:45
@dohooo
dohooo merged commit 5d93835 into main Jul 9, 2026
14 checks passed
dohooo added a commit that referenced this pull request Jul 10, 2026
…t's continuation survives (#927)

#922 replayed the deferred `completed` (and closed the query) the instant
the pending background-task count hit zero. But the recorded CLI contract
(claude 2.1.205) is: after `task_notification` the CLI re-invokes the main
agent on the SAME query to synthesize the results and then emits a second,
genuinely terminal `completed`. Closing at drain time killed that
continuation — background tasks finished, but the summary never arrived.

Now the loop keeps draining after the drain: the continuation streams
through and its terminal result ends the turn. A continuation grace
(default 60s, HELMOR_CLAUDE_BG_CONTINUATION_GRACE_MS) falls back to
replaying the deferred `completed` when no continuation ever comes (the
task_updated-drip case #922 was written for), and the 20-minute drain
timeout remains the hard backstop.

Contract pinned by controlled experiments against the bundled binary;
tests rewritten to match the recorded event stream (one previously
asserted the continuation being dropped).
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.

1 participant