Skip to content

Commit b6e419a

Browse files
ahalekellyclaude
andcommitted
fix(server): a cancelled SubagentHandback, or a first start, keeps the right result
A handback call the harness cancelled delivered nothing, so drop its report like a refused one. Only a real reopen clears a recorded report, not the first task_started after task_progress registered the subagent. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 81e8633 commit b6e419a

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16729,13 +16729,26 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1672916729
const cases = [
1673016730
{
1673116731
name: "delivered",
16732-
refused: false,
16732+
handback: "ran",
1673316733
isError: false,
1673416734
text: pointer,
1673516735
expected: "## Report",
1673616736
},
16737-
{ name: "failed", refused: false, isError: true, text: "Boom.", expected: "Boom." },
16738-
{ name: "refused", refused: true, isError: false, text: "Final.", expected: "Final." },
16737+
{ name: "failed", handback: "ran", isError: true, text: "Boom.", expected: "Boom." },
16738+
{
16739+
name: "refused",
16740+
handback: "refused",
16741+
isError: false,
16742+
text: "Final.",
16743+
expected: "Final.",
16744+
},
16745+
{
16746+
name: "cancelled",
16747+
handback: "cancelled",
16748+
isError: false,
16749+
text: "Final.",
16750+
expected: "Final.",
16751+
},
1673916752
];
1674016753
for (const [index, testCase] of cases.entries()) {
1674116754
const harness = yield* makeWakeHarness;
@@ -16780,7 +16793,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1678016793
},
1678116794
}),
1678216795
);
16783-
if (testCase.refused) {
16796+
if (testCase.handback !== "ran") {
1678416797
yield* harness.offerAndWait(
1678516798
claudeSdkFrame({
1678616799
type: "user",
@@ -16791,10 +16804,17 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1679116804
type: "tool_result",
1679216805
tool_use_id: `toolu-handback-${testCase.name}`,
1679316806
content: "Permission denied.",
16794-
is_error: true,
16807+
...(testCase.handback === "refused" ? { is_error: true } : {}),
1679516808
},
1679616809
],
1679716810
},
16811+
...(testCase.handback === "cancelled"
16812+
? {
16813+
tool_result_meta: [
16814+
{ id: `toolu-handback-${testCase.name}`, non_execution_kind: "cancelled" },
16815+
],
16816+
}
16817+
: {}),
1679816818
parent_tool_use_id: launchId,
1679916819
uuid: uuid(3),
1680016820
session_id: WAKE_NATIVE_SESSION,

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7014,8 +7014,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
70147014
// Unstated effort stays unknown: a custom agent definition may override the owner's.
70157015
const effort = existingSubagent === undefined ? input.effort : existingSubagent.effort;
70167016
const model = input.model ?? priorTask?.model ?? null;
7017-
const handbackText =
7018-
input.reopen === true ? null : (existingSubagent?.handbackText ?? null);
7017+
const handbackText = isReopen ? null : (existingSubagent?.handbackText ?? null);
70197018
const result =
70207019
input.status === "completed" && handbackText !== null ? handbackText : input.result;
70217020
const task = {
@@ -10068,7 +10067,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1006810067
if (
1006910068
toolCall.toolName === "SubagentHandback" &&
1007010069
parentToolUseId !== null &&
10071-
isClaudeToolResultError(toolResult)
10070+
(isClaudeToolResultError(toolResult) ||
10071+
claudeToolNonExecutionKind(message, toolResult.tool_use_id) === "cancelled")
1007210072
) {
1007310073
const subagent = yield* resolveSubagentByToolUseId(context, parentToolUseId);
1007410074
if (subagent !== undefined) subagent.handbackText = null;

0 commit comments

Comments
 (0)