fix(acpx-provider): surface stopReason as typed error codes#90
Open
coletebou wants to merge 1 commit into
Open
fix(acpx-provider): surface stopReason as typed error codes#90coletebou wants to merge 1 commit into
coletebou wants to merge 1 commit into
Conversation
Read acpx's terminal JSON-RPC result envelope
(`{id, result: {stopReason, ...}}`) inside `extractAcpxJson` and map
non-`end_turn` reasons to typed `ClawpatchError` codes:
cancelled -> agent-cancelled (exit 6)
refusal -> agent-refused (exit 7)
max_tokens -> agent-truncated (exit 8)
max_turns_exceeded -> agent-truncated (exit 8)
unknown reason -> agent-cancelled (exit 8) defensively
Previously, prompts that ended in `cancelled` / `refusal` / `max_tokens`
emitted no `agent_message_chunk`, so they fell into the same
`code: "malformed-output"` bucket as a real envelope-shape regression
(see 20260517T184420-d52a72: four parser errors of three different
shapes, all opaque `malformed-output`). On-call had to read raw NDJSON
to triage.
Now `malformed-output` keeps its narrow meaning: clawpatch could not
parse a payload acpx claims is `end_turn`. The `end_turn`-with-no-chunks
path also gets a clearer diagnostic noting the parser bug vs envelope
break.
Verified live against acpx 0.8.0 + claude-agent-acp 0.31.4. Terminal
envelope shape:
{"jsonrpc":"2.0","id":2,"result":{"stopReason":"end_turn","usage":{...}}}
`ACPX_TESTED_VERSIONS` stays at `^0.8.0`; the stopReason envelope is
present in this version.
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
extractAcpxJson(src/provider.ts) currently parses concatenatedagent_message_chunktext and never inspects the JSON-RPCresult.stopReasonenvelope. So when an acpx prompt finishes withstopReason: cancelled/refusal/max_tokens(and emits no message chunk text), clawpatch reportscode: "malformed-output"— the same code as a real envelope-shape regression. Operators can't distinguish.This PR detects the terminal envelope and surfaces non-
end_turnstopReasons as typedClawpatchErrors:cancelled→code: "agent-cancelled"refusal→code: "agent-refused"max_tokens/max_turn_requests→code: "agent-truncated"code: "agent-cancelled"(defensive default)end_turnkeeps the existing chunk-parsing success path.extractAcpxJsonis byte-compatible for happy-path output.Why
Run
20260517T190759-3c9e9ehad 37malformed-outputerrors against acpx, several of which observed only[available_commands_update, usage_update]— i.e. the prompt finished without producing a message chunk at all. Today these look identical to a parse failure; after this PR they get a separate diagnostic so operators can fix the underlying cause (permission denial, refusal, timeout) instead of guessing.Envelope shape used
Verified live against
acpx@0.8.0+claude-agent-acp@0.31.4:{"jsonrpc":"2.0","id":2,"result":{"stopReason":"end_turn","usage":{...}}}acpx parses the same envelope internally via
parsePromptStopReason.Files
src/provider.ts— terminal-envelope pre-pass + 3 new error codessrc/provider.test.ts— 6 fixture-driven tests via__testing.extractAcpxJsonValidation
pnpm format:check— cleanpnpm typecheck— cleanpnpm lint— cleanpnpm build— cleanpnpm test— 547 passed, 1 skipped (+6 new)Notes
ACPX_TESTED_VERSIONSleft at^0.8.0; bump in a follow-up after this lands and runs in the wild.