@@ -9159,6 +9159,172 @@ describe("ClaudeAdapterV2 background wake turns", () => {
91599159 ),
91609160 );
91619161
9162+ // regression: #17531 a mod that holds a tool behind a focused pane must fail the turn, not hang it
9163+ it.effect.each([
9164+ { case: "fails a turn whose mod requests focus for a pane T3 cannot show", focus: true },
9165+ { case: "keeps a turn running beside a passive mod pane", focus: false },
9166+ ] as const)("$case", ({ focus }) =>
9167+ Effect.scoped(
9168+ Effect.gen(function* () {
9169+ const closed = yield* Deferred.make<void>();
9170+ const harness = yield* makeWakeHarnessWithOptions({
9171+ close: () => Deferred.succeed(closed, undefined),
9172+ });
9173+ const now = yield* DateTime.now;
9174+ yield* harness.runtime.startTurn(
9175+ makeClaudeTestTurnInput({
9176+ threadId: harness.threadId,
9177+ providerThread: harness.providerThread,
9178+ now,
9179+ attemptId: RunAttemptId.make("attempt-claude-mod-pane-focus"),
9180+ text: "Run rm -r build",
9181+ attachments: [],
9182+ }),
9183+ );
9184+ // Captured from Claude 2.1.303 with the blast-radius mod holding a Bash
9185+ // call: the mod waits for keyboard input in its pane and nothing else
9186+ // arrives until it gives up.
9187+ yield* Queue.offer(
9188+ harness.sdkMessages,
9189+ claudeSdkFrame({
9190+ type: "system",
9191+ subtype: "ui_panes",
9192+ panes: [
9193+ { id: "blast-radius", title: "Blast Radius", plugin: "blast-radius", rows: 10 },
9194+ ],
9195+ shown_id: "blast-radius",
9196+ focused_id: null,
9197+ focus_requested_id: focus ? "blast-radius" : null,
9198+ uuid: "00000000-0000-4000-8000-000000000795",
9199+ session_id: WAKE_NATIVE_SESSION,
9200+ }),
9201+ );
9202+ yield* Queue.offer(
9203+ harness.sdkMessages,
9204+ claudeSdkFrame({
9205+ type: "system",
9206+ subtype: "ui_invalidate",
9207+ event: "ui.render",
9208+ uuid: "00000000-0000-4000-8000-000000000796",
9209+ session_id: WAKE_NATIVE_SESSION,
9210+ }),
9211+ );
9212+ // Frames are handled in order, so a later notice proves the pane frame
9213+ // was handled without the turn ending.
9214+ yield* Queue.offer(
9215+ harness.sdkMessages,
9216+ claudeSdkFrame({
9217+ type: "system",
9218+ subtype: "informational",
9219+ content: "Processing barrier.",
9220+ level: "warning",
9221+ uuid: "00000000-0000-4000-8000-000000000797",
9222+ session_id: WAKE_NATIVE_SESSION,
9223+ }),
9224+ );
9225+ yield* harness.until(
9226+ () =>
9227+ harness.terminalEvents().length > 0 ||
9228+ harness.events.some(
9229+ (event) =>
9230+ event.type === "turn_item.updated" && event.turnItem.type === "system_notice",
9231+ ),
9232+ );
9233+ const [terminal] = harness.terminalEvents();
9234+ if (!focus) {
9235+ assert.equal(terminal, undefined);
9236+ return;
9237+ }
9238+ assert.equal(terminal?.status, "failed");
9239+ if (terminal?.status !== "failed") return;
9240+ assert.include(terminal.failure.message, "blast-radius");
9241+ // The held tool call is abandoned by closing the query, never answered.
9242+ yield* Deferred.await(closed);
9243+ }).pipe(
9244+ Effect.provide(
9245+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
9246+ ),
9247+ ),
9248+ ),
9249+ );
9250+
9251+ // regression: #17531 a follow-up sent while the failed mod turn's process closes gets a new process
9252+ it.effect("runs a follow-up in a fresh query while the mod-blocked query is closing", () =>
9253+ Effect.scoped(
9254+ Effect.gen(function* () {
9255+ const releaseClose = yield* Deferred.make<void>();
9256+ const replacementClosedOld = yield* Deferred.make<void>();
9257+ let oldCloses = 0;
9258+ const harness = yield* makeWakeHarnessWithOptions({
9259+ // The held CLI never answers an interrupt; closure must not need one.
9260+ interrupt: Effect.never,
9261+ close: (sdkMessages) =>
9262+ Effect.suspend(() =>
9263+ ++oldCloses === 2 ? Deferred.succeed(replacementClosedOld, undefined) : Effect.void,
9264+ ).pipe(
9265+ Effect.andThen(Deferred.await(releaseClose)),
9266+ Effect.andThen(Queue.shutdown(sdkMessages)),
9267+ ),
9268+ freshQueueOnReopen: true,
9269+ });
9270+ // Added after the harness so it runs first: a failed assertion must not
9271+ // leave teardown waiting on the held close.
9272+ yield* Effect.addFinalizer(() => Deferred.succeed(releaseClose, undefined));
9273+ const now = yield* DateTime.now;
9274+ const turnInput = makeClaudeTestTurnInput({
9275+ threadId: harness.threadId,
9276+ providerThread: harness.providerThread,
9277+ now,
9278+ attemptId: RunAttemptId.make("attempt-claude-mod-pane-blocked"),
9279+ text: "Run rm -r build",
9280+ attachments: [],
9281+ });
9282+ yield* harness.runtime.startTurn(turnInput);
9283+ yield* Queue.offer(
9284+ harness.sdkMessages,
9285+ claudeSdkFrame({
9286+ type: "system",
9287+ subtype: "ui_panes",
9288+ panes: [
9289+ { id: "blast-radius", title: "Blast Radius", plugin: "blast-radius", rows: 10 },
9290+ ],
9291+ shown_id: "blast-radius",
9292+ focused_id: null,
9293+ focus_requested_id: "blast-radius",
9294+ uuid: "00000000-0000-4000-8000-000000000798",
9295+ session_id: WAKE_NATIVE_SESSION,
9296+ }),
9297+ );
9298+ assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "failed");
9299+
9300+ const followUp = yield* harness.runtime
9301+ .startTurn({
9302+ ...turnInput,
9303+ attemptId: RunAttemptId.make("attempt-claude-after-mod-pane"),
9304+ providerTurnOrdinal: 2,
9305+ })
9306+ .pipe(Effect.forkScoped);
9307+ // Reusing the closing process would offer the prompt to it instead.
9308+ yield* Effect.raceFirst(
9309+ Deferred.await(replacementClosedOld),
9310+ harness.until(() => harness.offeredMessages.length >= 2),
9311+ );
9312+ assert.isTrue(yield* Deferred.isDone(replacementClosedOld));
9313+ yield* Deferred.succeed(releaseClose, undefined);
9314+ yield* Fiber.join(followUp);
9315+ assert.equal(harness.processQueues.length, 2);
9316+ yield* harness.offerAndWait(
9317+ makeResultFrame({ uuid: "after-mod-pane-result", result: "Done." }),
9318+ );
9319+ assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "completed");
9320+ }).pipe(
9321+ Effect.provide(
9322+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
9323+ ),
9324+ ),
9325+ ),
9326+ );
9327+
91629328 // regression: #16897 a prompt whose uuid the session already holds must not hang or end early
91639329 it.effect("keeps a started prompt running until its result", () =>
91649330 Effect.scoped(
0 commit comments