Skip to content

Commit 8ebca97

Browse files
committed
fix(acpx-provider): classify stop reasons
1 parent d3179bc commit 8ebca97

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

src/provider.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ describe("extractAcpxJson", () => {
613613

614614
expectStopReasonError(() => extractAcpxJson(stdout), {
615615
code: "agent-cancelled",
616-
exitCode: 6,
616+
exitCode: 1,
617617
stopReason: "cancelled",
618618
});
619619
});
@@ -623,7 +623,7 @@ describe("extractAcpxJson", () => {
623623

624624
expectStopReasonError(() => extractAcpxJson(stdout), {
625625
code: "agent-refused",
626-
exitCode: 7,
626+
exitCode: 1,
627627
stopReason: "refusal",
628628
});
629629
});
@@ -641,6 +641,16 @@ describe("extractAcpxJson", () => {
641641
});
642642
});
643643

644+
it("surfaces stopReason max_turn_requests as agent-truncated", () => {
645+
const stdout = terminalEnvelope("max_turn_requests");
646+
647+
expectStopReasonError(() => extractAcpxJson(stdout), {
648+
code: "agent-truncated",
649+
exitCode: 8,
650+
stopReason: "max_turn_requests",
651+
});
652+
});
653+
644654
it("maps unknown stopReason defensively to agent-cancelled", () => {
645655
const stdout = terminalEnvelope("future_reason_xyz");
646656

src/provider.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,18 +1055,20 @@ function buildAcpxPrompt(prompt: string, schema: object, permission: "read" | "a
10551055
// Source: acpx/src/runtime/engine/manager.ts emits the terminal JSON-RPC
10561056
// response `{"jsonrpc":"2.0","id":N,"result":{"stopReason":<reason>,...}}`
10571057
// for every `session/prompt`. Known reasons in acpx 0.8.0 / claude-agent-acp
1058-
// 0.31.4 are `end_turn | cancelled | refusal | max_tokens` (plus
1059-
// `max_turns_exceeded`, surfaced for the agent-driven turn loop).
1058+
// 0.31.4 are `end_turn | cancelled | refusal | max_tokens | max_turn_requests`
1059+
// (plus the older `max_turns_exceeded` spelling seen in agent-driven turn loops).
10601060
const ACPX_STOP_REASON_CODES: Record<string, string> = {
10611061
cancelled: "agent-cancelled",
10621062
refusal: "agent-refused",
10631063
max_tokens: "agent-truncated",
1064+
max_turn_requests: "agent-truncated",
10641065
max_turns_exceeded: "agent-truncated",
10651066
};
10661067
const ACPX_STOP_EXIT_CODES: Record<string, number> = {
1067-
cancelled: 6,
1068-
refusal: 7,
1068+
cancelled: 1,
1069+
refusal: 1,
10691070
max_tokens: 8,
1071+
max_turn_requests: 8,
10701072
max_turns_exceeded: 8,
10711073
};
10721074

0 commit comments

Comments
 (0)