@@ -13154,94 +13154,163 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1315413154 ),
1315513155 );
1315613156
13157- it.effect("projects workflow member threads after resuming a restarted session", () =>
13158- Effect.scoped(
13159- Effect.gen(function* () {
13160- const harness = yield* makeWorkflowHarnessWithOptions({
13161- subagentLaunchToolUseId: WORKFLOW_TOOL_USE_ID,
13162- });
13163- yield* harness.runtime.startTurn(
13164- makeClaudeTestTurnInput({
13165- threadId: harness.threadId,
13166- providerThread: harness.providerThread,
13167- now: yield* DateTime.now,
13168- attemptId: RunAttemptId.make("attempt-claude-workflow-resume"),
13169- text: "Continue the workflow.",
13170- attachments: [],
13171- }),
13172- );
13173- yield* harness.offerAndWait(
13174- claudeSdkFrame({
13175- ...workflowToolUse,
13176- message: {
13177- model: "claude-sonnet-4-6",
13178- content: [
13179- { type: "tool_use", id: "toolu-resume-workflow", name: "SendMessage", input: {} },
13180- ],
13181- },
13182- }),
13183- );
13184- yield* harness.offerAndWait(
13185- claudeSdkFrame({
13186- ...workflowTaskStarted,
13187- tool_use_id: "toolu-resume-workflow",
13188- prompt: "Continue the workflow.",
13189- }),
13190- );
13191- yield* harness.offerAndWait(workflowLaunchAck(harness.transcriptDir));
13192- yield* harness.offerAndWait(
13193- workflowSnapshot({ uuid: "00000000-0000-4000-8000-000000001040", state: "start" }),
13194- );
13195- yield* harness.offerAndWait(
13196- makeResultFrame({ uuid: "00000000-0000-4000-8000-000000001041", result: "Resumed." }),
13197- );
13198- yield* Queue.take(harness.terminalReceipts);
13199- const member = workflowMemberEvents(harness.events, 1).at(-1)?.subagent;
13200- const coordinator = workflowCoordinatorEvents(harness.events).at(-1)?.subagent;
13201- assert.isDefined(member);
13202- assert.equal(member?.status, "running");
13203- assert.isTrue(
13204- harness.events.some(
13205- (event) =>
13206- event.type === "app_thread.created" && event.appThread.id === member?.childThreadId,
13207- ),
13208- );
13209- assert.deepEqual(
13210- threadMessages(harness.events, member?.childThreadId).map((event) => event.message.text),
13211- ["Reply with exactly: A1", "A1 from the transcript"],
13212- );
13213- assert.isDefined(coordinator?.childThreadId);
13214- const recoveredThreads = harness.events.filter(
13215- (event) =>
13216- event.type === "app_thread.created" &&
13217- event.appThread.id === coordinator?.childThreadId,
13218- );
13219- assert.lengthOf(recoveredThreads, 1);
13220- const recovered = recoveredThreads[0];
13221- assert.equal(recovered?.type, "app_thread.created");
13222- if (recovered?.type !== "app_thread.created") throw new Error("Expected recovered thread");
13223- assert.isTrue(recovered.createOnly);
13224- assert.deepEqual(recovered.appThread.lineage, {
13225- parentThreadId: harness.threadId,
13226- relationshipToParent: "subagent",
13227- rootThreadId: harness.threadId,
13228- });
13229- assert.equal(recovered.appThread.createdBy, "agent");
13230- assert.equal(recovered.appThread.creationSource, "provider");
13231- assert.isBelow(
13232- harness.events.indexOf(recovered),
13233- harness.events.findIndex(
13157+ it.effect.each([
13158+ [WORKFLOW_TOOL_USE_ID, false],
13159+ ["toolu-resume-workflow", false],
13160+ ["toolu-resume-workflow", true],
13161+ ] as const)(
13162+ "projects workflow member threads after resuming with lifecycle ID %s, idle=%s",
13163+ ([lifecycleToolUseId, idle]) =>
13164+ Effect.scoped(
13165+ Effect.gen(function* () {
13166+ const initialResumeToolUseId = idle ? "toolu-initial-resume" : "toolu-resume-workflow";
13167+ const harness = yield* makeWorkflowHarnessWithOptions({
13168+ subagentLaunchToolUseId: WORKFLOW_TOOL_USE_ID,
13169+ });
13170+ yield* harness.runtime.startTurn(
13171+ makeClaudeTestTurnInput({
13172+ threadId: harness.threadId,
13173+ providerThread: harness.providerThread,
13174+ now: yield* DateTime.now,
13175+ attemptId: RunAttemptId.make("attempt-claude-workflow-resume"),
13176+ text: "Continue the workflow.",
13177+ attachments: [],
13178+ }),
13179+ );
13180+ yield* harness.offerAndWait(
13181+ claudeSdkFrame({
13182+ ...workflowToolUse,
13183+ message: {
13184+ model: "claude-sonnet-4-6",
13185+ content: [
13186+ { type: "tool_use", id: initialResumeToolUseId, name: "SendMessage", input: {} },
13187+ ],
13188+ },
13189+ }),
13190+ );
13191+ yield* harness.offerAndWait(
13192+ claudeSdkFrame({
13193+ ...workflowTaskStarted,
13194+ tool_use_id: initialResumeToolUseId,
13195+ prompt: "Continue the workflow.",
13196+ }),
13197+ );
13198+ yield* harness.offerAndWait(workflowLaunchAck(harness.transcriptDir));
13199+ if (idle) {
13200+ yield* harness.offerAndWait(
13201+ makeResultFrame({ uuid: "00000000-0000-4000-8000-000000001043", result: "Waiting." }),
13202+ );
13203+ yield* Queue.take(harness.terminalReceipts);
13204+ yield* harness.offerAndWait(
13205+ claudeSdkFrame({
13206+ ...workflowToolUse,
13207+ uuid: "00000000-0000-4000-8000-000000001045",
13208+ message: {
13209+ model: "claude-sonnet-4-6",
13210+ content: [
13211+ {
13212+ type: "tool_use",
13213+ id: "toolu-resume-workflow",
13214+ name: "SendMessage",
13215+ input: {},
13216+ },
13217+ ],
13218+ },
13219+ }),
13220+ );
13221+ yield* harness.offerAndWait(
13222+ claudeSdkFrame({
13223+ ...workflowTaskStarted,
13224+ uuid: "00000000-0000-4000-8000-000000001044",
13225+ tool_use_id: "toolu-resume-workflow",
13226+ prompt: "Continue the workflow.",
13227+ }),
13228+ );
13229+ }
13230+ yield* harness.offerAndWait(
13231+ claudeSdkFrame({
13232+ ...workflowSnapshot({ uuid: "00000000-0000-4000-8000-000000001040", state: "start" }),
13233+ tool_use_id: lifecycleToolUseId,
13234+ }),
13235+ );
13236+ yield* harness.offerAndWait(
13237+ claudeSdkFrame({
13238+ ...workflowNotification({
13239+ uuid: "00000000-0000-4000-8000-000000001042",
13240+ status: "completed",
13241+ }),
13242+ tool_use_id: lifecycleToolUseId,
13243+ }),
13244+ );
13245+ if (idle) {
13246+ yield* harness.runtime.startTurn(
13247+ makeClaudeTestTurnInput({
13248+ threadId: harness.threadId,
13249+ providerThread: harness.providerThread,
13250+ now: yield* DateTime.now,
13251+ attemptId: RunAttemptId.make("attempt-claude-workflow-idle-resume"),
13252+ text: "Continue the workflow.",
13253+ attachments: [],
13254+ providerTurnOrdinal: 2,
13255+ messageCreatedBy: "agent",
13256+ messageCreationSource: "provider",
13257+ }),
13258+ );
13259+ }
13260+ yield* harness.offerAndWait(
13261+ makeResultFrame({ uuid: "00000000-0000-4000-8000-000000001041", result: "Resumed." }),
13262+ );
13263+ yield* Queue.take(harness.terminalReceipts);
13264+ const member = workflowMemberEvents(harness.events, 1).at(-1)?.subagent;
13265+ const coordinator = workflowCoordinatorEvents(harness.events).at(-1)?.subagent;
13266+ assert.isDefined(member);
13267+ assert.equal(member?.status, "completed");
13268+ assert.equal(coordinator?.status, "completed");
13269+ assert.isTrue(
13270+ harness.events.some(
13271+ (event) =>
13272+ event.type === "app_thread.created" && event.appThread.id === member?.childThreadId,
13273+ ),
13274+ );
13275+ assert.deepEqual(
13276+ threadMessages(harness.events, member?.childThreadId).map(
13277+ (event) => event.message.text,
13278+ ),
13279+ ["Reply with exactly: A1", "A1 from the transcript"],
13280+ );
13281+ assert.isDefined(coordinator?.childThreadId);
13282+ const recoveredThreads = harness.events.filter(
1323413283 (event) =>
13235- event.type === "subagent.updated" &&
13236- event.subagent.childThreadId === coordinator?.childThreadId,
13284+ event.type === "app_thread.created" &&
13285+ event.appThread.id === coordinator?.childThreadId,
13286+ );
13287+ assert.lengthOf(recoveredThreads, 1);
13288+ const recovered = recoveredThreads[0];
13289+ assert.equal(recovered?.type, "app_thread.created");
13290+ if (recovered?.type !== "app_thread.created")
13291+ throw new Error("Expected recovered thread");
13292+ assert.isTrue(recovered.createOnly);
13293+ assert.deepEqual(recovered.appThread.lineage, {
13294+ parentThreadId: harness.threadId,
13295+ relationshipToParent: "subagent",
13296+ rootThreadId: harness.threadId,
13297+ });
13298+ assert.equal(recovered.appThread.createdBy, "agent");
13299+ assert.equal(recovered.appThread.creationSource, "provider");
13300+ assert.isBelow(
13301+ harness.events.indexOf(recovered),
13302+ harness.events.findIndex(
13303+ (event) =>
13304+ event.type === "subagent.updated" &&
13305+ event.subagent.childThreadId === coordinator?.childThreadId,
13306+ ),
13307+ );
13308+ }).pipe(
13309+ Effect.provide(
13310+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
1323713311 ),
13238- );
13239- }).pipe(
13240- Effect.provide(
13241- Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
1324213312 ),
1324313313 ),
13244- ),
1324513314 );
1324613315
1324713316 it.effect.each([
0 commit comments