@@ -6979,6 +6979,116 @@ describe("ClaudeAdapterV2 background wake turns", () => {
69796979 uuid: input.uuid,
69806980 session_id: WAKE_NATIVE_SESSION,
69816981 });
6982+ it.effect.each(["active", "idle"] as const)(
6983+ "keeps a resumed subagent running after a stale transcript receipt while %s",
6984+ (state) =>
6985+ Effect.scoped(
6986+ Effect.gen(function* () {
6987+ const harness = yield* makeWakeHarness;
6988+ const taskId = "task-stale-transcript";
6989+ yield* harness.runtime.startTurn(
6990+ makeClaudeTestTurnInput({
6991+ threadId: harness.threadId,
6992+ providerThread: harness.providerThread,
6993+ now: yield* DateTime.now,
6994+ attemptId: RunAttemptId.make("attempt-stale-transcript"),
6995+ text: "Resume the audit.",
6996+ attachments: [],
6997+ }),
6998+ );
6999+ yield* harness.offerAndWait(
7000+ makeSubagentTaskStartedFrame({
7001+ taskId,
7002+ toolUseId: "toolu-original-audit",
7003+ uuid: "00000000-0000-4000-8000-000000000901",
7004+ }),
7005+ );
7006+ yield* Queue.take(harness.subagentReceipts);
7007+ yield* harness.offerAndWait(
7008+ makeSubagentNotificationFrame({
7009+ taskId,
7010+ toolUseId: "toolu-original-audit",
7011+ summary: "Original audit completed.",
7012+ uuid: "00000000-0000-4000-8000-000000000902",
7013+ }),
7014+ );
7015+ assert.equal((yield* Queue.take(harness.subagentReceipts)).subagent.status, "completed");
7016+ yield* harness.offerAndWait(
7017+ makeSubagentTaskStartedFrame({
7018+ taskId,
7019+ toolUseId: "toolu-resumed-audit",
7020+ uuid: "00000000-0000-4000-8000-000000000903",
7021+ }),
7022+ );
7023+ assert.equal((yield* Queue.take(harness.subagentReceipts)).subagent.status, "running");
7024+ if (state === "idle") {
7025+ yield* harness.offerAndWait(turnOneResult);
7026+ yield* Queue.take(harness.terminalReceipts);
7027+ }
7028+ yield* harness.offerAndWait(
7029+ claudeSdkFrame({
7030+ type: "user",
7031+ isSynthetic: true,
7032+ parent_tool_use_id: null,
7033+ uuid: "00000000-0000-4000-8000-000000000904",
7034+ session_id: WAKE_NATIVE_SESSION,
7035+ message: {
7036+ role: "user",
7037+ content: `<task-notification><task-id>${taskId}</task-id><status>stopped</status><summary>Old task stopped.</summary></task-notification>`,
7038+ },
7039+ }),
7040+ );
7041+ assert.isTrue(yield* harness.hasPendingBackgroundWork);
7042+ }).pipe(
7043+ Effect.provide(
7044+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
7045+ ),
7046+ ),
7047+ ),
7048+ );
7049+
7050+ it.effect("uses a known shell's transcript receipt as native wake evidence", () =>
7051+ Effect.scoped(
7052+ Effect.gen(function* () {
7053+ const harness = yield* makeWakeHarness;
7054+ yield* harness.runtime.startTurn(
7055+ makeClaudeTestTurnInput({
7056+ threadId: harness.threadId,
7057+ providerThread: harness.providerThread,
7058+ now: yield* DateTime.now,
7059+ attemptId: RunAttemptId.make("attempt-shell-transcript-wake"),
7060+ text: "Run the build in the background.",
7061+ attachments: [],
7062+ }),
7063+ );
7064+ yield* harness.offerAndWait(wakeTaskStarted);
7065+ yield* harness.offerAndWait(turnOneResult);
7066+ yield* Queue.take(harness.terminalReceipts);
7067+ yield* harness.offerAndWait(wakeNotification);
7068+ assert.lengthOf(harness.continuationRequests, 0);
7069+ yield* harness.offerAndWait(
7070+ claudeSdkFrame({
7071+ type: "user",
7072+ isSynthetic: true,
7073+ parent_tool_use_id: null,
7074+ uuid: "00000000-0000-4000-8000-000000000905",
7075+ session_id: WAKE_NATIVE_SESSION,
7076+ message: {
7077+ role: "user",
7078+ content: `<task-notification><task-id>${WAKE_TASK_ID}</task-id><status>completed</status><summary>${WAKE_SUMMARY}</summary></task-notification>`,
7079+ },
7080+ }),
7081+ );
7082+ assert.lengthOf(harness.continuationRequests, 1);
7083+ assert.equal(harness.continuationRequests[0]?.threadId, harness.threadId);
7084+ }).pipe(
7085+ Effect.provide(
7086+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
7087+ ),
7088+ ),
7089+ ),
7090+ );
7091+
69827092 const subagentRouting = (
69837093 events: ReadonlyArray<ProviderAdapter.ProviderAdapterV2Event>,
69847094 nativeToolIds: ReadonlyArray<string>,
0 commit comments