Repository navigation
fix(sidecar): end Claude turn once pending background tasks drain - #922
Merged
Merged
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
dohooo
enabled auto-merge (squash)
July 9, 2026 20:45
This was referenced Jul 9, 2026
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_updateddrip events indefinitely and the turn never ended.Fix
sidecar/src/claude/session-manager.ts:turnEndedis idempotent, so the turn closes exactly once.Testing
background-resume.test.ts(10 pass);origin/main: full sidecar suite 415 tests green +tsc --noEmitclean;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.