GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(acp): refused and limit-stopped turns no longer show as completed… · pingdotgg/t3code@0351dbb

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/orchestration-v2/Adapters
    • AcpAdapterV2.test.ts
    • AcpRegistryAdapterV2.test.ts
  • packages
    • provider-acp-registry/src/server
      • claudeAcp.ts
    • provider-acp/src/server
      • adapter.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+1-6Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,12 +2456,7 @@ describe("AcpAdapterV2", () => {
24562456
},
24572457
stopReason === "error",
24582458
);
2459-
const expectedStatus =
2460-
stopReason === "error"
2461-
? "failed"
2462-
: stopReason === "cancelled"
2463-
? "cancelled"
2464-
: "completed";
2459+
const expectedStatus = stopReason === "cancelled" ? "cancelled" : "failed";
24652460
yield* reportNextPromptStopped(stopReason);
24662461
assertReinjectedInstructions(yield* runTurn("Start work.", expectedStatus), "Start work.");
24672462
assertReinjectedInstructions(
Collapse file

‎apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts
+59Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,6 +2755,65 @@ describe("AcpRegistryAdapterV2", () => {
27552755
}).pipe(Effect.provide(layerTest)),
27562756
);
27572757

2758+
it.effect.each([
2759+
{ stopReason: "refusal", childUpdate: "state_update" },
2760+
{ stopReason: "max_tokens", childUpdate: "subagent_update" },
2761+
])(
2762+
"fails Claude's turn and child and closes its running tool when they stop with $stopReason via $childUpdate",
2763+
({ stopReason, childUpdate }) =>
2764+
Effect.gen(function* () {
2765+
const { update, idle, prompt } = claudeFrames;
2766+
const session = yield* openClaudeReplaySession([
2767+
...claudeFrames.open,
2768+
...prompt(1),
2769+
...claudeChild,
2770+
update(CLAUDE_ROOT_SESSION, {
2771+
sessionUpdate: "tool_call_update",
2772+
toolCallId: "root-tool",
2773+
name: "Bash",
2774+
title: "Read package",
2775+
kind: "execute",
2776+
status: "in_progress",
2777+
rawInput: { command: "cat package.json" },
2778+
}),
2779+
update("child-1", { sessionUpdate: "state_update", state: "running" }),
2780+
childUpdate === "state_update"
2781+
? update("child-1", { sessionUpdate: "state_update", state: "idle", stopReason })
2782+
: update(CLAUDE_ROOT_SESSION, {
2783+
sessionUpdate: "subagent_update",
2784+
sessionId: "child-1",
2785+
state: { state: "idle", stopReason },
2786+
}),
2787+
idle(stopReason),
2788+
]);
2789+
yield* session.runtime.startTurn(session.turnInput(1));
2790+
const events = yield* session.until((event) => event.type === "turn.terminal");
2791+
const terminal = events.at(-1)!;
2792+
if (terminal.type !== "turn.terminal") throw new Error("Missing root terminal");
2793+
assert.equal(terminal.status, "failed");
2794+
assert.equal(terminal.failure?.code, stopReason);
2795+
const child = events.findLast((event) => event.type === "subagent.updated");
2796+
if (child?.type !== "subagent.updated") throw new Error("Missing child update");
2797+
assert.equal(child.subagent.status, "failed");
2798+
assert.isNotNull(child.subagent.result, "the child shows why it stopped");
2799+
assert.isFalse(
2800+
events.some(
2801+
(event) =>
2802+
event.type === "message.updated" &&
2803+
event.message.threadId === child.subagent.childThreadId &&
2804+
event.message.role === "assistant",
2805+
),
2806+
"the child's conversation has no reply it didn't send",
2807+
);
2808+
const tool = events.findLast(
2809+
(event) =>
2810+
event.type === "turn_item.updated" && event.turnItem.type === "command_execution",
2811+
);
2812+
if (tool?.type !== "turn_item.updated") throw new Error("Missing tool update");
2813+
assert.equal(tool.turnItem.status, "failed");
2814+
}).pipe(Effect.provide(layerTest), Effect.scoped),
2815+
);
2816+
27582817
it.effect("keeps Claude activity after a refused Stop and closes it on retry", () =>
27592818
Effect.gen(function* () {
27602819
const gate = makeProviderReplayGate(["close-response", "queued-close-response"]);
Collapse file

‎packages/provider-acp-registry/src/server/claudeAcp.ts‎

Copy file name to clipboardExpand all lines: packages/provider-acp-registry/src/server/claudeAcp.ts
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import * as Option from "effect/Option";
22
import * as Schema from "effect/Schema";
33
import type * as AcpSchema from "effect-acp/compat";
44
import type { AcpToolCallState } from "@t3tools/provider-acp/server/runtimeModel";
5-
import type {
6-
AcpAdapterV2SubagentUpdate,
7-
AcpSubagentSessionEvent,
5+
import {
6+
acpUnfinishedStopMessage,
7+
type AcpAdapterV2SubagentUpdate,
8+
type AcpSubagentSessionEvent,
89
} from "@t3tools/provider-acp/server/adapter";
910

1011
const decodeAgentInput = Schema.decodeUnknownOption(
@@ -86,19 +87,20 @@ export function extractClaudeSubagentSessionEvent(
8687
const child = decodeChildState(update.raw);
8788
if (Option.isNone(child)) return;
8889
const { sessionId, state } = child.value;
90+
const unfinishedMessage = acpUnfinishedStopMessage(state.stopReason);
8991
return {
9092
type: "state",
9193
childSessionId: sessionId,
9294
parentSessionId: notification.sessionId,
9395
status:
9496
state.state === "running" || state.state === "requires_action"
9597
? "running"
96-
: state.stopReason === "error"
98+
: state.stopReason === "error" || unfinishedMessage !== undefined
9799
? "failed"
98100
: state.stopReason === "cancelled" || state.state === "unknown"
99101
? "cancelled"
100102
: "completed",
101-
result: state.error?.message ?? null,
103+
result: state.error?.message ?? unfinishedMessage ?? null,
102104
};
103105
}
104106
if (update.originalSessionUpdate === "session_message") {
Collapse file

‎packages/provider-acp/src/server/adapter.ts‎

Copy file name to clipboardExpand all lines: packages/provider-acp/src/server/adapter.ts
+42-6Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,22 @@ function makeProviderThread(input: {
10211021
};
10221022
}
10231023

1024+
/** Stop reasons where the agent ended without finishing. ACP asks clients to show refusals. */
1025+
export function acpUnfinishedStopMessage(
1026+
stopReason: EffectAcpSchema.StopReason | null | undefined,
1027+
): string | undefined {
1028+
switch (stopReason) {
1029+
case "refusal":
1030+
return "The agent refused this request. The agent's next turn won't include this message or its reply.";
1031+
case "max_tokens":
1032+
return "The agent stopped because its reply reached the output token limit.";
1033+
case "max_turn_requests":
1034+
return "The agent stopped because it reached its request limit for this turn.";
1035+
default:
1036+
return undefined;
1037+
}
1038+
}
1039+
10241040
function appendToolContentText(content: unknown, text: string): unknown[] {
10251041
const next: unknown[] = Array.isArray(content) ? [...content] : [];
10261042
const last = unknownRecord(next.at(-1));
@@ -3441,8 +3457,10 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
34413457
);
34423458
}
34433459

3460+
// A failed child's result explains the failure; it is not the child's reply.
34443461
if (
34453462
taskStatus !== "running" &&
3463+
reported.status !== "failed" &&
34463464
subagent.assistantText.length === 0 &&
34473465
update.result !== null
34483466
) {
@@ -3812,16 +3830,18 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
38123830
const update = notification.update;
38133831
if (update.sessionUpdate === "state_update") {
38143832
const child = nativeChild(notification.sessionId);
3833+
const unfinishedMessage =
3834+
update.state === "idle" ? acpUnfinishedStopMessage(update.stopReason) : undefined;
38153835
setNativeChildState(
38163836
child,
38173837
update.state !== "idle"
38183838
? "running"
3819-
: update.stopReason === "error"
3839+
: update.stopReason === "error" || unfinishedMessage !== undefined
38203840
? "failed"
38213841
: update.stopReason === "cancelled"
38223842
? "cancelled"
38233843
: "completed",
3824-
update.state === "idle" ? (update.error?.message ?? null) : null,
3844+
update.state === "idle" ? (update.error?.message ?? unfinishedMessage ?? null) : null,
38253845
);
38263846
}
38273847
if (context !== null) yield* syncNativeChildren(context);
@@ -5027,6 +5047,17 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
50275047
class: "provider_error",
50285048
});
50295049

5050+
const stopReasonFailure = (
5051+
stopReason: EffectAcpSchema.StopReason | null | undefined,
5052+
error: EffectAcpSchema.PromptResponse["error"],
5053+
) => {
5054+
if (stopReason === "error") return idleErrorFailure(error);
5055+
const message = acpUnfinishedStopMessage(stopReason);
5056+
return message === undefined
5057+
? undefined
5058+
: makeProviderFailure({ message, code: stopReason, class: "provider_error" });
5059+
};
5060+
50305061
const settleIdleWork = Effect.fnUntraced(function* (
50315062
context: ActiveAcpTurn,
50325063
): Effect.fn.Return<void> {
@@ -5043,7 +5074,10 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
50435074
if (work.stopReason === "cancelled" && pendingStopCloseTurn === context) {
50445075
context.interrupted = true;
50455076
}
5046-
const failure = work.stopReason === "error" ? idleErrorFailure(work.error) : undefined;
5077+
const failure = context.interrupted
5078+
? undefined
5079+
: stopReasonFailure(work.stopReason, work.error);
5080+
if (failure !== undefined) yield* terminalizeOpenForegroundTools(context, "failed");
50475081
yield* finalizeTurn(
50485082
context,
50495083
failure !== undefined
@@ -8671,8 +8705,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
86718705
});
86728706
}
86738707
if (context.finalized || followsAgentWorkState) return;
8674-
// ACP v2 reports a failed prompt as an idle `error`, not an RPC error.
8675-
const idleError = result.stopReason === "error" && !context.interrupted;
8708+
// ACP v2 reports a failed prompt through its idle stop reason, not an RPC error.
86768709
const hiddenFailure =
86778710
checkPromptOutcome === undefined ||
86788711
context.interrupted ||
@@ -8684,7 +8717,10 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
86848717
yield* Ref.set(runtimeRestartRequired, true);
86858718
}
86868719
const failure =
8687-
hiddenFailure ?? (idleError ? idleErrorFailure(result.error) : undefined);
8720+
hiddenFailure ??
8721+
(context.interrupted
8722+
? undefined
8723+
: stopReasonFailure(result.stopReason, result.error));
86888724
const status =
86898725
failure !== undefined
86908726
? "failed"

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.