Repository navigation
Conversation
A Claude turn ended, and stdin closed, at the first `result`, even while Bash or Agent work started with run_in_background was still running. When that work finished the CLI began a follow-up turn on its own, and its permission prompts failed with "Tool permission request failed: AbortError: Stream closed". A successful `result` that arrives while background work is outstanding is now held; the turn ends at the first `result` with nothing outstanding. The existing `background` set (#134) is the single record of outstanding work, now fed by every signal the CLI sends: run_in_background on any tool_use, Agent's default background, task_started/task_updated is_backgrounded, and background_tasks_changed; terminal task statuses, failed launches and leaving the CLI's background list clear it. - The wait is capped at 30 min (BACKGROUND_CAP_MS) with a warning notice, after which the CLI is stopped. - Once work drains, a 15 s idle window (BACKGROUND_IDLE_MS) re-armed by every message lets the held reply stand if no follow-up turn starts, so system/status cannot strand a turn; it never fires while a permission prompt is open or a follow-up turn (system/init) is running. - An error result ends the turn at once, with a notice when background work was still running. - Stop still kills the CLI, clears every timer and reports interrupted. Event shapes in the tests come from a live claude 2.1.289 capture. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
BunsDev
added a commit
that referenced
this pull request
Oct 8, 2026
…rns (#144) Complete reviewed desktop delivery: background-turn draining and termination, linked Sources retaining citations, Settings display polish, and persistent Space with local OpenKnowledge. Apply new-page focus during render so it cannot interrupt content typing. Canonicalize Knowledge fixture folders, await child-page selection, wait for iPhone controls and the keyboard before input, and control the Mac fixture outage through rescan cancellation and offline retry. Verified build, typecheck, 407 unit tests, 151 desktop and 7 site E2E tests with the real companion enabled, native build-for-testing, and all desktop and iPhone hosted checks. Includes reviewed delivery from #140 and #143.
This branch was successfully deployed
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.
Bug
When Claude starts work in the background (Bash or Agent with
run_in_background), Modex ended the turn and closed stdin at the firstresult. Once that work finished, the CLI started a follow-up turn by itself, and every permission prompt in it failed withTool permission request failed: AbortError: Stream closed.On
main(a79c0f3),backends/claude.tsreturns a finished turn for everyresult(L270–273), and any finished turn runschild.stdin?.end(); finish(done)(L134–138). Thebackgroundset that #134 added only drives the subagent display. It never delays the end of a turn.Fix
A successful
resultthat arrives while background work is outstanding is held. The turn ends at the firstresultwith nothing outstanding. #134'sbackgroundset is now the single record of outstanding work.How each review risk is handled:
run_in_backgroundon anytool_use, Agent's default background,task_started/task_updatedis_backgrounded, andbackground_tasks_changed. Terminal task statuses, failed launches, and tasks leaving the CLI's background list clear it.BACKGROUND_CAP_MS). When the cap fires, Modex shows a warning notice, ends the turn and stops the CLI.system/statusstranding. After work drains, a 15 s idle window (BACKGROUND_IDLE_MS) is re-armed by every message, so a turn can't wait forever for aresultthat never comes. The window never fires while a permission prompt is open or a follow-up turn is running.resultends the turn at once, with a notice if background work was still running.Evidence
claude2.1.289 capture of a background Bash run:task_startedwithis_backgrounded: true,background_tasks_changed,task_notification, and tworesults around a follow-upinit. The capture stays in the git-ignored.probes/directory.task_startedwithis_backgrounded: false. That test assumes the CLI sends it. If it doesn't, the worst case is that the turn stays open with a "still running" notice until Stop or the 30 min cap. It does not fail with "Stream closed".Tests
apps/desktop/test/claude-background.test.tswith 12 tests:run_in_backgroundon the tool call alone;statusstranding;subagents.test.ts: one test now drains its background shell before the finalresult.main: withmain'sclaude.ts, the regression test fails:AssertionError: stdin must stay open while background work is outstanding.npm run build && npm testgives core 15/15 and desktop 306/306, plus 1/1, 10/10 and 9/9 in the other suites. The new file passed 5 out of 5 runs, 12/12 each time.unit + e2e (macOS)check covers it.This replaces the uncommitted
claude-background-turnsworktree, which is left untouched.Follow-up verification and lifecycle fix:
Background termination now escalates from SIGTERM to SIGKILL after 1.5 seconds, even after the held turn settles; only child close cancels the escalation.
A regression reproduces a Claude process that ignores SIGTERM: it fails before the fix and passes afterward. Independent review found no remaining blockers in the lifecycle fix.
Status documentation records the background-turn behavior and bounds.
Full verification on 4c801e1: npm run build && npm test && npm run test:e2e passed (345 unit tests, 125 desktop E2E and 7 site E2E). The signed merge includes current main; hosted exact-head gates are pending.
Delivery reconciliation: superseded by #144, merged on main as
f5c347ba14c6691132420a7fe7086eb10109623a. The signed squash has complete tree equality with verified integration head23600b5a95d2884ef57210f1ba6e93a77c90f5e5, after all four desktop/iPhone checks passed. The original native failure and unchanged-head targeted retry are retained in the maintainer audit. This PR is closed because its application changes have landed through #144.