Repository navigation
fix(engine): keep Claude's tools working after background work finishes - #584
Merged
Merged
Conversation
When Claude started a command or agent in the background and ended its turn, the turn it started on its own once that work finished could not use any Clopen tool: browser automation failed within 60 ms with "The tool call was interrupted before a result was received", and permission checks, AskUserQuestion and hooks failed the same way. The prompt iterable ended after its one message, so the SDK closed the CLI's stdin at the first result. Every request the CLI makes back to Clopen travels over stdin. Reproduced with SDK 0.3.296: the in-process tool's handler never ran in the notification turn. The adapter now holds the prompt open and ClaudeInputGate closes it when the CLI reports idle with no background task left (session-state events are switched on for this), or, without those events, on a result with none left. Idle alone is not enough: the CLI reports it while background work still runs. Verified live: the tool works in the continuation turn and the stream ends 0.6 s after the last turn. Engines report background work through one output, background_work, and the stream manager shows the gap between turns as "Waiting for a background task..." on every device, via presence. Checked live per engine: Qwen holds its result and Copilot its session.idle until such work finishes, Open Code runs it in the foreground unless its experimental background sub-agents are enabled (Clopen does not), and Codex, Cursor, Pi and Cline have none - only Claude emits it today.
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.
Summary
Keep Clopen's tools, permissions and questions working in the turn Claude starts on its own after background work finishes.
Why
The SDK closed the CLI's stdin at the first
result, so every tool call in a later notification turn failed with "The tool call was interrupted". Reproduced with SDK 0.3.296.Changes
ClaudeInputGatecloses it when the CLI reports idle with no background task left (session-state events enabled)background_work; presence shows "Waiting for a background task…" between turns on every deviceNotes
Checked live per engine: Qwen and Copilot hold their completion until such work is done, OpenCode only continues on its own with experimental background sub-agents (off in Clopen), and Codex, Cursor, Pi and Cline have none.