@@ -16013,6 +16013,138 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1601316013 ),
1601416014 );
1601516015
16016+ it.effect(
16017+ "defers goal completion until an ambient subagent finishes and Claude checks again",
16018+ () =>
16019+ Effect.gen(function* () {
16020+ const harness = yield* makeWakeHarness;
16021+ const condition = "the review finds no bugs";
16022+ const taskId = "task-goal-review";
16023+ const toolUseId = "toolu-goal-review";
16024+ const now = yield* DateTime.now;
16025+ yield* harness.runtime.startTurn(
16026+ makeClaudeTestTurnInput({
16027+ threadId: harness.threadId,
16028+ providerThread: harness.providerThread,
16029+ now,
16030+ attemptId: RunAttemptId.make("goal-background-attempt"),
16031+ text: `/goal ${condition}`,
16032+ attachments: [],
16033+ }),
16034+ );
16035+ for (const frame of [
16036+ syntheticFrame("goal-background-set", `Goal set: ${condition}`),
16037+ claudeSdkFrame({
16038+ ...makeSubagentTaskStartedFrame({ taskId, toolUseId, uuid: "goal-review-start" }),
16039+ ambient: true,
16040+ skip_transcript: true,
16041+ }),
16042+ makeAssistantTextFrame({
16043+ uuid: "goal-background-wait",
16044+ text: "Waiting for the review.",
16045+ }),
16046+ makeResultFrame({ uuid: "goal-background-result", result: "Waiting for the review." }),
16047+ ]) {
16048+ yield* Queue.offer(harness.sdkMessages, frame);
16049+ }
16050+ assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "completed");
16051+ assert.deepEqual(goalStatuses(harness.events).at(-1), {
16052+ objective: condition,
16053+ status: "active",
16054+ checks: 0,
16055+ });
16056+
16057+ yield* harness.offerAndWait(
16058+ makeSubagentNotificationFrame({
16059+ taskId,
16060+ toolUseId,
16061+ summary: "No bugs found.",
16062+ uuid: "goal-review-done",
16063+ }),
16064+ );
16065+ yield* harness.offerAndWait(wakeTurnInit);
16066+ yield* Queue.take(harness.continuationReceipts);
16067+ assert.equal(goalStatuses(harness.events).at(-1)?.status, "active");
16068+ yield* harness.runtime.startTurn(
16069+ makeClaudeTestTurnInput({
16070+ threadId: harness.threadId,
16071+ providerThread: harness.providerThread,
16072+ now,
16073+ attemptId: RunAttemptId.make("goal-background-wake"),
16074+ text: "Background task completed.",
16075+ attachments: [],
16076+ providerTurnOrdinal: 2,
16077+ messageCreatedBy: "agent",
16078+ messageCreationSource: "provider",
16079+ }),
16080+ );
16081+ yield* harness.offerAndWait(
16082+ makeAssistantTextFrame({ uuid: "goal-background-wake-work", text: "No bugs found." }),
16083+ );
16084+ yield* harness.offerAndWait(
16085+ makeResultFrame({
16086+ uuid: "goal-background-wake-result",
16087+ result: "No bugs found.",
16088+ origin: { kind: "task-notification" },
16089+ }),
16090+ );
16091+ assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "completed");
16092+ assert.deepEqual(goalStatuses(harness.events).at(-1), {
16093+ objective: condition,
16094+ status: "complete",
16095+ checks: 0,
16096+ });
16097+ }).pipe(
16098+ Effect.scoped,
16099+ Effect.provide(
16100+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
16101+ ),
16102+ ),
16103+ );
16104+
16105+ it.effect.each([
16106+ { taskType: "mcp_task", status: "complete" },
16107+ { taskType: undefined, status: "active" },
16108+ ] as const)("leaves the goal $status with a running $taskType task", ({ taskType, status }) =>
16109+ Effect.gen(function* () {
16110+ const harness = yield* makeWakeHarness;
16111+ const condition = "the docs build";
16112+ yield* harness.runtime.startTurn(
16113+ makeClaudeTestTurnInput({
16114+ threadId: harness.threadId,
16115+ providerThread: harness.providerThread,
16116+ now: yield* DateTime.now,
16117+ attemptId: RunAttemptId.make("goal-task-type-attempt"),
16118+ text: `/goal ${condition}`,
16119+ attachments: [],
16120+ }),
16121+ );
16122+ for (const frame of [
16123+ syntheticFrame("goal-task-type-set", `Goal set: ${condition}`),
16124+ claudeSdkFrame({
16125+ type: "system",
16126+ subtype: "task_started",
16127+ task_id: "task-goal-docs",
16128+ description: "Watch the docs",
16129+ ...(taskType === undefined ? {} : { task_type: taskType }),
16130+ uuid: "goal-task-type-start",
16131+ session_id: WAKE_NATIVE_SESSION,
16132+ }),
16133+ makeAssistantTextFrame({ uuid: "goal-task-type-work", text: "The docs build." }),
16134+ makeResultFrame({ uuid: "goal-task-type-result", result: "The docs build." }),
16135+ ]) {
16136+ yield* Queue.offer(harness.sdkMessages, frame);
16137+ }
16138+ assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "completed");
16139+ assert.equal(goalStatuses(harness.events).at(-1)?.status, status);
16140+ }).pipe(
16141+ Effect.scoped,
16142+ Effect.provide(
16143+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
16144+ ),
16145+ ),
16146+ );
16147+
1601616148 it.effect("keeps a goal active after a command turn with no model output", () =>
1601716149 Effect.gen(function* () {
1601816150 const harness = yield* makeWakeHarness;
0 commit comments