@@ -8990,6 +8990,84 @@ describe("ClaudeAdapterV2 background wake turns", () => {
89908990 ),
89918991 );
89928992
8993+ it.effect("preserves a confirmed native outcome after the synchronous Agent tool result", () =>
8994+ Effect.scoped(
8995+ Effect.gen(function* () {
8996+ let stopCalls = 0;
8997+ const harness = yield* makeWakeHarnessWithOptions({
8998+ stopTask: () => Effect.sync(() => void stopCalls++),
8999+ });
9000+ yield* harness.runtime.startTurn(
9001+ makeClaudeTestTurnInput({
9002+ threadId: harness.threadId,
9003+ providerThread: harness.providerThread,
9004+ now: yield* DateTime.now,
9005+ attemptId: RunAttemptId.make("attempt-stop-after-agent-result"),
9006+ text: "Run an audit.",
9007+ attachments: [],
9008+ }),
9009+ );
9010+ yield* harness.offerAndWait(
9011+ makeSubagentTaskStartedFrame({
9012+ taskId: "sync-audit",
9013+ toolUseId: "toolu-sync-audit",
9014+ uuid: "00000000-0000-4000-8000-000000004301",
9015+ }),
9016+ );
9017+ yield* Queue.take(harness.subagentReceipts);
9018+ yield* harness.offerAndWait(
9019+ makeSubagentNotificationFrame({
9020+ taskId: "sync-audit",
9021+ toolUseId: "toolu-sync-audit",
9022+ summary: "Native audit outcome.",
9023+ uuid: "00000000-0000-4000-8000-000000004302",
9024+ }),
9025+ );
9026+ const completed = yield* Queue.take(harness.subagentReceipts);
9027+ yield* TestClock.adjust("1 second");
9028+ yield* harness.offerAndWait(
9029+ claudeSdkFrame({
9030+ type: "user",
9031+ message: {
9032+ role: "user",
9033+ content: [
9034+ {
9035+ type: "tool_result",
9036+ tool_use_id: "toolu-sync-audit",
9037+ content: "Audit tool result.",
9038+ },
9039+ ],
9040+ },
9041+ parent_tool_use_id: null,
9042+ uuid: "00000000-0000-4000-8000-000000004303",
9043+ session_id: WAKE_NATIVE_SESSION,
9044+ }),
9045+ );
9046+ const updated = yield* Queue.take(harness.subagentReceipts);
9047+ assert.equal(updated.subagent.result, "Audit tool result.");
9048+ const stopping = yield* harness.runtime.stopSubagent!({
9049+ providerThread: harness.providerThread,
9050+ nativeTaskId: "sync-audit",
9051+ }).pipe(Effect.exit, Effect.forkScoped);
9052+ yield* TestClock.adjust("2 seconds");
9053+ const outcome = yield* Fiber.join(stopping);
9054+ assert.isTrue(Exit.isSuccess(outcome));
9055+ if (Exit.isSuccess(outcome)) {
9056+ assert.deepEqual(outcome.value, {
9057+ status: "completed",
9058+ completedAt: completed.subagent.completedAt!,
9059+ result: "Native audit outcome.",
9060+ });
9061+ }
9062+ assert.equal(stopCalls, 0);
9063+ }).pipe(
9064+ Effect.provide(
9065+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
9066+ ),
9067+ ),
9068+ ),
9069+ );
9070+
89939071 it.effect.each(["completed", "failed", "stopped"] as const)(
89949072 "applies an idle native subagent %s notification before replay and confirms its real outcome",
89959073 (status) =>
0 commit comments