Skip to content

Commit c9f9a64

Browse files
Jreevoclaude
andcommitted
fix(server): a Claude /goal no longer reads as complete while a background subagent runs
Claude Code skips the /goal evaluation when a turn ends with a subagent or background shell command still running. The adapter inferred completion from a normal turn end plus an empty background-task roster, but the roster leaves subagents out, so a turn that ended while a background Agent ran marked the goal complete. The completion check now also requires that the live process runs no background work. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent c9b21b2 commit c9f9a64

2 files changed

Lines changed: 60 additions & 2 deletions

File tree

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8311,6 +8311,58 @@ describe("ClaudeAdapterV2 background wake turns", () => {
83118311
}).pipe(Effect.scoped, Effect.provide(Layer.merge(IdAllocator.layer, NodeServices.layer))),
83128312
);
83138313

8314+
it.effect("keeps a goal active when a turn ends while a background subagent runs", () =>
8315+
Effect.gen(function* () {
8316+
const harness = yield* makeWakeHarness;
8317+
const condition = "both reviewers find no bugs";
8318+
yield* harness.runtime.startTurn(
8319+
makeClaudeTestTurnInput({
8320+
threadId: harness.threadId,
8321+
providerThread: harness.providerThread,
8322+
now: yield* DateTime.now,
8323+
attemptId: RunAttemptId.make("goal-background-subagent-attempt"),
8324+
text: `/goal ${condition}`,
8325+
attachments: [],
8326+
}),
8327+
);
8328+
for (const frame of [
8329+
syntheticFrame("goal-background-set", `Goal set: ${condition}`),
8330+
makeAssistantTextFrame({
8331+
uuid: "goal-background-work",
8332+
text: "Waiting for the background subagent before round 1.",
8333+
}),
8334+
claudeSdkFrame({
8335+
type: "system",
8336+
subtype: "task_started",
8337+
task_id: "task-goal-background-subagent",
8338+
tool_use_id: "toolu-goal-background-subagent",
8339+
description: "Implement the fix",
8340+
subagent_type: "general-purpose",
8341+
is_backgrounded: true,
8342+
task_type: "local_agent",
8343+
prompt: "Implement the fix.",
8344+
uuid: "goal-background-task-started",
8345+
session_id: WAKE_NATIVE_SESSION,
8346+
}),
8347+
makeResultFrame({
8348+
uuid: "goal-background-result",
8349+
result: "Waiting for the background subagent before round 1.",
8350+
}),
8351+
]) {
8352+
yield* Queue.offer(harness.sdkMessages, frame);
8353+
}
8354+
const terminal = yield* Queue.take(harness.terminalReceipts);
8355+
assert.equal(terminal.status, "completed");
8356+
// Claude skips the goal check while the subagent runs, so the goal
8357+
// has not passed.
8358+
assert.deepEqual(goalStatuses(harness.events).at(-1), {
8359+
objective: condition,
8360+
status: "active",
8361+
checks: 0,
8362+
});
8363+
}).pipe(Effect.scoped, Effect.provide(Layer.merge(IdAllocator.layer, NodeServices.layer))),
8364+
);
8365+
83148366
it.effect("keeps a goal active after a command turn with no model output", () =>
83158367
Effect.gen(function* () {
83168368
const harness = yield* makeWakeHarness;

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5082,20 +5082,26 @@ export function makeClaudeAdapterV2(
50825082
input.context.input.providerThread.nativeConversationHeadRef !== null;
50835083
// While a goal is set, Claude ends a turn on its own only after the
50845084
// goal's Stop hook passes. It defers that check while background
5085-
// work runs, and a hook that stops the turn reports another reason.
5085+
// work runs, background subagents included (they stay off the
5086+
// roster), and a hook that stops the turn reports another reason.
50865087
// SDK mode does not report an evaluator timeout or an impossible
50875088
// verdict, so those still read as complete.
50885089
const goal =
50895090
nativeThreadId === null ? undefined : goalsByNativeThread.get(nativeThreadId);
50905091
const goalChecked = goalCheckedTurns.delete(input.context.providerTurnId);
50915092
const terminalReason = input.result?.terminal_reason;
5093+
const liveQuery = yield* Ref.get(queryContext);
50925094
if (
50935095
nativeThreadId !== null &&
50945096
goal?.status === "active" &&
50955097
goalChecked &&
50965098
input.status === "completed" &&
50975099
(terminalReason === undefined || terminalReason === "completed") &&
5098-
roster.size === 0
5100+
roster.size === 0 &&
5101+
!(
5102+
liveQuery?.nativeThreadId === nativeThreadId &&
5103+
(yield* liveProcessRunsBackgroundWork(liveQuery))
5104+
)
50995105
) {
51005106
goalsByNativeThread.set(nativeThreadId, {
51015107
objective: goal.objective,

0 commit comments

Comments
 (0)