Skip to content

fix(engine): keep Claude's tools working after background work finishes - #584

Merged
ArgaFairuz merged 1 commit into
mainfrom
fix/background-work-lifecycle
Nov 18, 2026
Merged

ArgaFairuz merged 1 commit into
mainfrom
fix/background-work-lifecycle

Conversation

@ArgaFairuz

Copy link
Copy Markdown
Collaborator

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

  • Claude keeps its prompt open; ClaudeInputGate closes it when the CLI reports idle with no background task left (session-state events enabled)
  • New engine output background_work; presence shows "Waiting for a background task…" between turns on every device
  • Tests for the gate (recorded event orders), the converter and the waiting state

Notes

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.

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.
@ArgaFairuz
ArgaFairuz merged commit c0dbd09 into main Nov 18, 2026
1 check passed
@ArgaFairuz
ArgaFairuz deleted the fix/background-work-lifecycle branch November 18, 2026 02:49
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