puffer-cli: cancel takes precedence in classify_turn_error (follow-up to #110)#112
Open
n-WN wants to merge 1 commit into
Open
puffer-cli: cancel takes precedence in classify_turn_error (follow-up to #110)#112n-WN wants to merge 1 commit into
n-WN wants to merge 1 commit into
Conversation
Follow-up to #110. When a user cancels a turn mid tool call, the runner WebSocket gets dropped and the agent loop's `?` chain bubbles up as `internal runner error: transport error`. The substring matcher in #110 classified this as `runner_unreachable` and the SSE turn-error told the user "retry, the sandbox is still warming up" — misleading, because the user just pressed cancel on purpose. Thread the spawning turn's `CancelToken` into the std::thread closure and pass `cancel.is_cancelled()` into `classify_turn_error`. The function short-circuits to `cancelled` whenever the flag is set, with the raw chain still preserved as `errorRaw` for debug. I caught this with a real wire-capture test on hv5 against a stack built off #109 + #110: the captured outbound LLM payload had a [turn-aborted] marker reading "previous turn was ended with error... Error: internal runner error: transport error" instead of the "previous turn was cancelled by user" wording that the cancel path should produce. With this change the wording reflects what the user actually did. Tests: - existing `classify_turn_error_distinguishes_runner_unreachable` updated for the new `(err, was_cancelled)` signature - new `classify_turn_error_cancel_shadows_transport_when_token_fired` exercises the precedence with the exact "internal runner error: transport error" chain we captured
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
Follow-up to #110.
When a user cancels a turn mid tool call, the runner WebSocket gets dropped and the agent loop's
?chain bubbles up asinternal runner error: transport error. The substring matcher landed in #110 classified this asrunner_unreachable, so the SSEturn-errortold the user "retry, the sandbox is still warming up" — which is wrong, because the user just pressed cancel on purpose.This PR threads the spawning turn's
CancelTokeninto the worker thread and passescancel.is_cancelled()intoclassify_turn_error. The function short-circuits tocancelledwhenever the flag is set; the raw chain is still preserved aserrorRawfor debug.How I caught this
Real wire-capture test on hv5 against a stack built off #109 + #110:
The captured
input[2]from #109's marker said:instead of the cancel-specific wording
i.e. the cancel-induced transport interruption was being classified as a transport failure rather than a user cancel. With
was_cancelledprecedence the wording reflects what the user actually did.Test plan
cargo test -p puffer-cli classify_turn_error(2 tests, both pass):classify_turn_error_distinguishes_runner_unreachable— existing, updated for the new(err, was_cancelled)signatureclassify_turn_error_cancel_shadows_transport_when_token_fired— new, exercises precedence with the exact "internal runner error: transport error" chain captured on hv5cargo build -p puffer-clicleancargo fmt -p puffer-cli -- --checkcleanBackward compatibility
The
classify_turn_errorfunction isfn-not-pub, so the signature change is internal. Downstream consumers (SSE clients) only see the externally serializedcategorystring anderrorRawchain, both of which keep their existing meaning.Related
runner_unreachableclassification in the first place