fix(ctx_shell): stop reporting a requested background cancel as a tool error - #1248
Open
andig wants to merge 1 commit into
Open
fix(ctx_shell): stop reporting a requested background cancel as a tool error#1248andig wants to merge 1 commit into
andig wants to merge 1 commit into
Conversation
…l error
Cancelling a background job answered with the same '[background:<id>
running]' string a status poll returns, so the cancel looked like a no-op
and the natural next move was to cancel again. That second call then
surfaced the process's own SIGINT exit as the tool's exit code, tripping
the client's failure hook and instructing the agent to fix something it
had deliberately done.
A cancel now acknowledges itself distinctly, reports the terminal state
as data ('[cancelled: <id>, exit 130]') with exit 0, and is idempotent:
cancelling an already-cancelled, already-finished or already-pruned job
is equally benign. The cancelled marker in the captured output loses its
'ERROR:' prefix for the same reason - a caller-requested stop is not a
failure.
Fixes yvgude#1246
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Cancelling a background
ctx_shelljob answered with the same[background:<id> running]string thatbackground_action: "status"returns, so the cancel was indistinguishable from a no-op poll — and the obvious follow-up (cancel again) surfaced the process's own SIGINT exit as the tool's exit code. In Claude Code that fires thePostToolUseFailurehook and instructs the agent to fix a non-problem.Changes
[background:<id> cancel requested — job is stopping; poll status for the final output]instead of the status wording.[background:<id> cancelled]\n<output>\n[cancelled: <id>, exit 130]with exit 0, so exit 130 stays visible as data without tripping the failure hook.statuspoll keeps its previous exit-code semantics.ERROR: command cancelledin the captured output becomes[cancelled: command stopped on request]— the flag is only ever set by an explicit cancel, so theERROR:prefix was wrong at the source too.The formatting moved into
format_background_state(id, is_cancel, state); no tool-schema or description change.Testing
tools::registered::ctx_shell::tests::cancel_is_acknowledged_and_never_reports_a_failurecovers the ack wording, exit 0 on the cancelled state, idempotence over Completed/None, and that astatuspoll is unaffected.cargo test --lib ctx_shell::(58 passed),cargo test --lib background_shell::(9 passed),cargo clippy --all-targetsclean.Fixes #1246
🤖 Generated with Claude Code