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(server): a Claude /goal no longer reads as complete while a backg… · Pipyakas/t3code@8eac722

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/orchestration-v2/Adapters
    • ClaudeAdapterV2.test.ts
    • ClaudeAdapterV2.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+132Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15419,6 +15419,138 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1541915419
),
1542015420
);
1542115421

15422+
it.effect(
15423+
"defers goal completion until an ambient subagent finishes and Claude checks again",
15424+
() =>
15425+
Effect.gen(function* () {
15426+
const harness = yield* makeWakeHarness;
15427+
const condition = "the review finds no bugs";
15428+
const taskId = "task-goal-review";
15429+
const toolUseId = "toolu-goal-review";
15430+
const now = yield* DateTime.now;
15431+
yield* harness.runtime.startTurn(
15432+
makeClaudeTestTurnInput({
15433+
threadId: harness.threadId,
15434+
providerThread: harness.providerThread,
15435+
now,
15436+
attemptId: RunAttemptId.make("goal-background-attempt"),
15437+
text: `/goal ${condition}`,
15438+
attachments: [],
15439+
}),
15440+
);
15441+
for (const frame of [
15442+
syntheticFrame("goal-background-set", `Goal set: ${condition}`),
15443+
claudeSdkFrame({
15444+
...makeSubagentTaskStartedFrame({ taskId, toolUseId, uuid: "goal-review-start" }),
15445+
ambient: true,
15446+
skip_transcript: true,
15447+
}),
15448+
makeAssistantTextFrame({
15449+
uuid: "goal-background-wait",
15450+
text: "Waiting for the review.",
15451+
}),
15452+
makeResultFrame({ uuid: "goal-background-result", result: "Waiting for the review." }),
15453+
]) {
15454+
yield* Queue.offer(harness.sdkMessages, frame);
15455+
}
15456+
assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "completed");
15457+
assert.deepEqual(goalStatuses(harness.events).at(-1), {
15458+
objective: condition,
15459+
status: "active",
15460+
checks: 0,
15461+
});
15462+
15463+
yield* harness.offerAndWait(
15464+
makeSubagentNotificationFrame({
15465+
taskId,
15466+
toolUseId,
15467+
summary: "No bugs found.",
15468+
uuid: "goal-review-done",
15469+
}),
15470+
);
15471+
yield* harness.offerAndWait(wakeTurnInit);
15472+
yield* Queue.take(harness.continuationReceipts);
15473+
assert.equal(goalStatuses(harness.events).at(-1)?.status, "active");
15474+
yield* harness.runtime.startTurn(
15475+
makeClaudeTestTurnInput({
15476+
threadId: harness.threadId,
15477+
providerThread: harness.providerThread,
15478+
now,
15479+
attemptId: RunAttemptId.make("goal-background-wake"),
15480+
text: "Background task completed.",
15481+
attachments: [],
15482+
providerTurnOrdinal: 2,
15483+
messageCreatedBy: "agent",
15484+
messageCreationSource: "provider",
15485+
}),
15486+
);
15487+
yield* harness.offerAndWait(
15488+
makeAssistantTextFrame({ uuid: "goal-background-wake-work", text: "No bugs found." }),
15489+
);
15490+
yield* harness.offerAndWait(
15491+
makeResultFrame({
15492+
uuid: "goal-background-wake-result",
15493+
result: "No bugs found.",
15494+
origin: { kind: "task-notification" },
15495+
}),
15496+
);
15497+
assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "completed");
15498+
assert.deepEqual(goalStatuses(harness.events).at(-1), {
15499+
objective: condition,
15500+
status: "complete",
15501+
checks: 0,
15502+
});
15503+
}).pipe(
15504+
Effect.scoped,
15505+
Effect.provide(
15506+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
15507+
),
15508+
),
15509+
);
15510+
15511+
it.effect.each([
15512+
{ taskType: "mcp_task", status: "complete" },
15513+
{ taskType: undefined, status: "active" },
15514+
] as const)("leaves the goal $status with a running $taskType task", ({ taskType, status }) =>
15515+
Effect.gen(function* () {
15516+
const harness = yield* makeWakeHarness;
15517+
const condition = "the docs build";
15518+
yield* harness.runtime.startTurn(
15519+
makeClaudeTestTurnInput({
15520+
threadId: harness.threadId,
15521+
providerThread: harness.providerThread,
15522+
now: yield* DateTime.now,
15523+
attemptId: RunAttemptId.make("goal-task-type-attempt"),
15524+
text: `/goal ${condition}`,
15525+
attachments: [],
15526+
}),
15527+
);
15528+
for (const frame of [
15529+
syntheticFrame("goal-task-type-set", `Goal set: ${condition}`),
15530+
claudeSdkFrame({
15531+
type: "system",
15532+
subtype: "task_started",
15533+
task_id: "task-goal-docs",
15534+
description: "Watch the docs",
15535+
...(taskType === undefined ? {} : { task_type: taskType }),
15536+
uuid: "goal-task-type-start",
15537+
session_id: WAKE_NATIVE_SESSION,
15538+
}),
15539+
makeAssistantTextFrame({ uuid: "goal-task-type-work", text: "The docs build." }),
15540+
makeResultFrame({ uuid: "goal-task-type-result", result: "The docs build." }),
15541+
]) {
15542+
yield* Queue.offer(harness.sdkMessages, frame);
15543+
}
15544+
assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "completed");
15545+
assert.equal(goalStatuses(harness.events).at(-1)?.status, status);
15546+
}).pipe(
15547+
Effect.scoped,
15548+
Effect.provide(
15549+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
15550+
),
15551+
),
15552+
);
15553+
1542215554
it.effect("keeps a goal active after a command turn with no model output", () =>
1542315555
Effect.gen(function* () {
1542415556
const harness = yield* makeWakeHarness;
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+24-1Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2124,6 +2124,15 @@ const CLAUDE_OPAQUE_BACKGROUND_TASK_KINDS: ReadonlyMap<
21242124
Exclude<OrchestrationV2PendingBackgroundTask["kind"], "subagent">
21252125
> = new Map([["local_bash", "command"]]);
21262126

2127+
// Claude Code 2.1.292 defers its goal Stop hook for these subagent types.
2128+
// local_bash tasks defer it through the opaque-task roster.
2129+
const CLAUDE_GOAL_DEFERRING_TASK_TYPES: ReadonlySet<string> = new Set([
2130+
"local_agent",
2131+
"remote_agent",
2132+
"in_process_teammate",
2133+
"local_workflow",
2134+
]);
2135+
21272136
function isClaudeOpaqueBackgroundTaskType(taskType: string | null | undefined): boolean {
21282137
return typeof taskType === "string" && CLAUDE_OPAQUE_BACKGROUND_TASK_KINDS.has(taskType);
21292138
}
@@ -3162,6 +3171,7 @@ interface ActiveClaudeProviderRetry {
31623171

31633172
interface ActiveClaudeSubagent {
31643173
task: OrchestrationV2Subagent;
3174+
readonly nativeTaskType: string | undefined;
31653175
// Local parent-turn cleanup can end the card without a native task outcome.
31663176
readonly confirmedOutcome: ProviderAdapter.ProviderAdapterV2SubagentOutcome | undefined;
31673177
// The launch run's root node. task.parentNodeId is that same node, or the
@@ -4680,6 +4690,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
46804690
const ids = claudeSubagentIds(resume.context, resume.taskId);
46814691
const now = yield* DateTime.now;
46824692
const subagent: ActiveClaudeSubagent = {
4693+
nativeTaskType: undefined,
46834694
confirmedOutcome: undefined,
46844695
childThread: null,
46854696
task: {
@@ -5127,6 +5138,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
51275138
// started this one; read only when this call registers the subagent.
51285139
readonly effort?: string;
51295140
readonly owner?: ActiveClaudeSubagent;
5141+
readonly nativeTaskType?: string;
51305142
readonly progress?: string;
51315143
/** Raw SDK frame, folded into the coordinator's workflow snapshot. */
51325144
readonly workflowFrame?: unknown;
@@ -5308,6 +5320,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
53085320
} satisfies OrchestrationV2Subagent;
53095321
const subagent = {
53105322
task,
5323+
nativeTaskType: input.nativeTaskType ?? existingSubagent?.nativeTaskType,
53115324
confirmedOutcome:
53125325
input.nativeOutcome !== undefined
53135326
? confirmedSubagentOutcome(task)
@@ -6252,13 +6265,18 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
62526265
nativeThreadId === null ? undefined : goalsByNativeThread.get(nativeThreadId);
62536266
const goalChecked = goalCheckedTurns.delete(input.context.providerTurnId);
62546267
const terminalReason = input.result?.terminal_reason;
6268+
const liveQuery = yield* Ref.get(queryContext);
62556269
if (
62566270
nativeThreadId !== null &&
62576271
goal?.status === "active" &&
62586272
goalChecked &&
62596273
input.status === "completed" &&
62606274
(terminalReason === undefined || terminalReason === "completed") &&
6261-
roster.size === 0
6275+
roster.size === 0 &&
6276+
!(
6277+
liveQuery?.nativeThreadId === nativeThreadId &&
6278+
(yield* liveProcessRunsBackgroundWork(liveQuery, { forGoalCheck: true }))
6279+
)
62626280
) {
62636281
goalsByNativeThread.set(nativeThreadId, {
62646282
objective: goal.objective,
@@ -7516,6 +7534,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
75167534
yield* updateClaudeSubagentNode({
75177535
context,
75187536
taskId: message.task_id,
7537+
...(message.task_type === undefined ? {} : { nativeTaskType: message.task_type }),
75197538
...(message.tool_use_id === undefined ? {} : { toolUseId: message.tool_use_id }),
75207539
...(message.prompt === undefined ? {} : { prompt: message.prompt }),
75217540
...(model === undefined ? {} : { model }),
@@ -8601,6 +8620,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
86018620
// already buffered is done: the buffer outlives the process.
86028621
const liveProcessRunsBackgroundWork = Effect.fnUntraced(function* (
86038622
live: ClaudeLiveQueryContext,
8623+
options?: { readonly forGoalCheck?: boolean },
86048624
) {
86058625
if (
86068626
rosterForNativeThread(
@@ -8615,6 +8635,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
86158635
if (
86168636
subagent.task.status === "running" &&
86178637
!live.subagentsFromEarlierProcesses.has(subagent) &&
8638+
(options?.forGoalCheck !== true ||
8639+
subagent.nativeTaskType === undefined ||
8640+
CLAUDE_GOAL_DEFERRING_TASK_TYPES.has(subagent.nativeTaskType)) &&
86188641
!buffered.some(
86198642
(message) =>
86208643
message.type === "system" &&

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.