Skip to content

Commit fc8188d

Browse files
refactor(server): keep Claude goal task types with subagent state
1 parent c7d069b commit fc8188d

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,10 +2076,8 @@ const CLAUDE_OPAQUE_BACKGROUND_TASK_KINDS: ReadonlyMap<
20762076
Exclude<OrchestrationV2PendingBackgroundTask["kind"], "subagent">
20772077
> = new Map([["local_bash", "command"]]);
20782078

2079-
// Task types whose running tasks make Claude skip a goal's Stop hook check,
2080-
// as Claude Code 2.1.292 decides it. local_bash (Monitor tool runs included)
2081-
// is the roster's; the rest run on the subagent path. mcp_task, monitor_mcp
2082-
// and monitor_ws tasks do not defer the check.
2079+
// Claude Code 2.1.292 defers its goal Stop hook for these subagent types.
2080+
// local_bash tasks defer it through the opaque-task roster.
20832081
const CLAUDE_GOAL_DEFERRING_TASK_TYPES: ReadonlySet<string> = new Set([
20842082
"local_agent",
20852083
"remote_agent",
@@ -3086,6 +3084,7 @@ interface ActiveClaudeProviderRetry {
30863084

30873085
interface ActiveClaudeSubagent {
30883086
task: OrchestrationV2Subagent;
3087+
readonly nativeTaskType: string | undefined;
30893088
readonly confirmedOutcome: ProviderAdapter.ProviderAdapterV2SubagentOutcome | undefined;
30903089
readonly rootNodeId: OrchestrationV2ExecutionNode["id"];
30913090
readonly childThreadId: ThreadId;
@@ -3630,8 +3629,6 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
36303629
>;
36313630
}>({ userTurns: new Map(), reports: new Map() });
36323631
const backgroundedSubagentTaskIds = yield* Ref.make<ReadonlySet<string>>(new Set());
3633-
// Subagent-path tasks whose type Claude's goal check does not wait for.
3634-
const goalExemptTaskIds = yield* Ref.make<ReadonlySet<string>>(new Set());
36353632
// Subagents another subagent started (spawn_depth above 1). Claude
36363633
// reports their end to the owning subagent, so it never wakes the root.
36373634
const nestedSubagentTaskIds = yield* Ref.make<ReadonlySet<string>>(new Set());
@@ -4511,6 +4508,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
45114508
const ids = claudeSubagentIds(resume.context, resume.taskId);
45124509
const now = yield* DateTime.now;
45134510
const subagent: ActiveClaudeSubagent = {
4511+
nativeTaskType: undefined,
45144512
confirmedOutcome: undefined,
45154513
childThread: null,
45164514
task: {
@@ -4992,6 +4990,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
49924990
readonly model?: string;
49934991
readonly effort?: string;
49944992
readonly owner?: ActiveClaudeSubagent;
4993+
readonly nativeTaskType?: string;
49954994
readonly progress?: string;
49964995
readonly workflowFrame?: unknown;
49974996
readonly workflowName?: string;
@@ -5150,6 +5149,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
51505149
} satisfies OrchestrationV2Subagent;
51515150
const subagent = {
51525151
task,
5152+
nativeTaskType: input.nativeTaskType ?? existingSubagent?.nativeTaskType,
51535153
confirmedOutcome:
51545154
input.nativeOutcome !== undefined
51555155
? confirmedSubagentOutcome(task)
@@ -7439,14 +7439,6 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
74397439
activeContext: context,
74407440
});
74417441
} else {
7442-
if (
7443-
message.task_type !== undefined &&
7444-
!CLAUDE_GOAL_DEFERRING_TASK_TYPES.has(message.task_type)
7445-
) {
7446-
yield* Ref.update(goalExemptTaskIds, (current) =>
7447-
new Set(current).add(message.task_id),
7448-
);
7449-
}
74507442
const launch =
74517443
message.tool_use_id === undefined
74527444
? undefined
@@ -7483,6 +7475,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
74837475
yield* updateClaudeSubagentNode({
74847476
context,
74857477
taskId: message.task_id,
7478+
...(message.task_type === undefined ? {} : { nativeTaskType: message.task_type }),
74867479
...(message.tool_use_id === undefined ? {} : { toolUseId: message.tool_use_id }),
74877480
...(message.prompt === undefined ? {} : { prompt: message.prompt }),
74887481
...(model === undefined ? {} : { model }),
@@ -8433,12 +8426,13 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
84338426
return true;
84348427
}
84358428
const buffered = (yield* Ref.get(wakeBuffers)).get(live.nativeThreadId)?.messages ?? [];
8436-
const ignored = options?.forGoalCheck === true ? yield* Ref.get(goalExemptTaskIds) : null;
84378429
for (const [taskId, subagent] of yield* Ref.get(sessionSubagentsByTaskId)) {
84388430
if (
84398431
subagent.task.status === "running" &&
84408432
!live.subagentsFromEarlierProcesses.has(subagent) &&
8441-
!(ignored?.has(taskId) ?? false) &&
8433+
(options?.forGoalCheck !== true ||
8434+
subagent.nativeTaskType === undefined ||
8435+
CLAUDE_GOAL_DEFERRING_TASK_TYPES.has(subagent.nativeTaskType)) &&
84428436
!buffered.some(
84438437
(message) =>
84448438
message.type === "system" &&

0 commit comments

Comments
 (0)