Skip to content

Commit ac8693f

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 39f2a4e commit ac8693f

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
@@ -18815,13 +18815,26 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1881518815
const cases = [
1881618816
{
1881718817
name: "delivered",
18818-
refused: false,
18818+
handback: "ran",
1881918819
isError: false,
1882018820
text: pointer,
1882118821
expected: "## Report",
1882218822
},
18823-
{ name: "failed", refused: false, isError: true, text: "Boom.", expected: "Boom." },
18824-
{ name: "refused", refused: true, isError: false, text: "Final.", expected: "Final." },
18823+
{ name: "failed", handback: "ran", isError: true, text: "Boom.", expected: "Boom." },
18824+
{
18825+
name: "refused",
18826+
handback: "refused",
18827+
isError: false,
18828+
text: "Final.",
18829+
expected: "Final.",
18830+
},
18831+
{
18832+
name: "cancelled",
18833+
handback: "cancelled",
18834+
isError: false,
18835+
text: "Final.",
18836+
expected: "Final.",
18837+
},
1882518838
];
1882618839
for (const [index, testCase] of cases.entries()) {
1882718840
const harness = yield* makeWakeHarness;
@@ -18866,7 +18879,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1886618879
},
1886718880
}),
1886818881
);
18869-
if (testCase.refused) {
18882+
if (testCase.handback !== "ran") {
1887018883
yield* harness.offerAndWait(
1887118884
claudeSdkFrame({
1887218885
type: "user",
@@ -18877,10 +18890,17 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1887718890
type: "tool_result",
1887818891
tool_use_id: `toolu-handback-${testCase.name}`,
1887918892
content: "Permission denied.",
18880-
is_error: true,
18893+
...(testCase.handback === "refused" ? { is_error: true } : {}),
1888118894
},
1888218895
],
1888318896
},
18897+
...(testCase.handback === "cancelled"
18898+
? {
18899+
tool_result_meta: [
18900+
{ id: `toolu-handback-${testCase.name}`, non_execution_kind: "cancelled" },
18901+
],
18902+
}
18903+
: {}),
1888418904
parent_tool_use_id: launchId,
1888518905
uuid: uuid(3),
1888618906
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
@@ -7437,8 +7437,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
74377437
// Unstated effort stays unknown: a custom agent definition may override the owner's.
74387438
const effort = existingSubagent === undefined ? input.effort : existingSubagent.effort;
74397439
const model = input.model ?? priorTask?.model ?? null;
7440-
const handbackText =
7441-
input.reopen === true ? null : (existingSubagent?.handbackText ?? null);
7440+
const handbackText = isReopen ? null : (existingSubagent?.handbackText ?? null);
74427441
const result =
74437442
input.status === "completed" && handbackText !== null ? handbackText : input.result;
74447443
const task = {
@@ -10918,7 +10917,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1091810917
if (
1091910918
toolCall.toolName === "SubagentHandback" &&
1092010919
parentToolUseId !== null &&
10921-
isClaudeToolResultError(toolResult)
10920+
(isClaudeToolResultError(toolResult) ||
10921+
claudeToolNonExecutionKind(message, toolResult.tool_use_id) === "cancelled")
1092210922
) {
1092310923
const subagent = yield* resolveSubagentByToolUseId(context, parentToolUseId);
1092410924
if (subagent !== undefined) subagent.handbackText = null;

0 commit comments

Comments
 (0)