@@ -4958,6 +4958,154 @@ describe("ClaudeAdapterV2 background wake turns", () => {
49584958 ),
49594959 );
49604960
4961+ // regression: #15708 Stop must not silently drop a steer Claude queued behind a foreground task
4962+ it.effect.each([
4963+ {
4964+ readBy: "none",
4965+ echoes: true,
4966+ title: "warns that a steer Claude never read before Stop was not delivered",
4967+ },
4968+ {
4969+ readBy: "none",
4970+ echoes: false,
4971+ title: "does not warn about a steer on a CLI that never echoes prompt uuids",
4972+ },
4973+ {
4974+ readBy: "assistant",
4975+ echoes: true,
4976+ title: "does not warn about a steer Claude read before Stop",
4977+ },
4978+ ] as const)("$title", ({ readBy, echoes }) =>
4979+ Effect.gen(function* () {
4980+ const harness = yield* makeWakeHarnessWithOptions({
4981+ close: (sdkMessages) => Queue.shutdown(sdkMessages),
4982+ freshQueueOnReopen: true,
4983+ });
4984+ const idAllocator = yield* IdAllocator.IdAllocatorV2;
4985+ const firstInput = makeClaudeTestTurnInput({
4986+ threadId: harness.threadId,
4987+ providerThread: harness.providerThread,
4988+ now: yield* DateTime.now,
4989+ attemptId: RunAttemptId.make("attempt-claude-unread-steer-1"),
4990+ text: "Run the slow curl in the foreground.",
4991+ attachments: [],
4992+ });
4993+ yield* harness.runtime.startTurn(firstInput);
4994+ const providerTurnId = idAllocator.derive.providerTurn({
4995+ driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
4996+ nativeTurnId: `turn:${firstInput.attemptId}`,
4997+ });
4998+ yield* harness.offerAndWait(
4999+ claudeSdkFrame({
5000+ type: "assistant",
5001+ uuid: "00000000-0000-4000-8000-000000015701",
5002+ session_id: WAKE_NATIVE_SESSION,
5003+ parent_tool_use_id: null,
5004+ ...(echoes ? { user_message_uuids: [harness.promptUuid(0)] } : {}),
5005+ message: {
5006+ id: "msg_unread_steer_bash",
5007+ type: "message",
5008+ role: "assistant",
5009+ model: "claude-sonnet-4-6",
5010+ content: [
5011+ {
5012+ type: "tool_use",
5013+ id: "toolu-unread-steer-bash",
5014+ name: "Bash",
5015+ input: { command: "curl http://127.0.0.1:9/hang" },
5016+ },
5017+ ],
5018+ },
5019+ }),
5020+ );
5021+ // Past task_started the CLI queues a "now" steer until the call returns.
5022+ yield* harness.offerAndWait(
5023+ claudeSdkFrame({
5024+ type: "system",
5025+ subtype: "task_started",
5026+ task_id: "task-unread-steer-bash",
5027+ tool_use_id: "toolu-unread-steer-bash",
5028+ description: "Slow curl",
5029+ is_backgrounded: false,
5030+ task_type: "local_bash",
5031+ uuid: "00000000-0000-4000-8000-000000015702",
5032+ session_id: WAKE_NATIVE_SESSION,
5033+ }),
5034+ );
5035+ const steerText = "Codeword: PELICAN. Remember it, I will ask for it later.";
5036+ yield* harness.runtime.steerTurn({
5037+ threadId: harness.threadId,
5038+ runId: firstInput.runId,
5039+ providerThread: harness.providerThread,
5040+ providerTurnId,
5041+ message: {
5042+ createdBy: "user",
5043+ creationSource: "web",
5044+ messageId: MessageId.make("unread-steer"),
5045+ text: steerText,
5046+ attachments: [],
5047+ },
5048+ });
5049+ const steerUuid = harness.offeredMessages.at(-1)?.uuid;
5050+ assert.isDefined(steerUuid);
5051+ if (readBy === "assistant") {
5052+ yield* harness.offerAndWait(
5053+ claudeSdkFrame({
5054+ type: "assistant",
5055+ uuid: "00000000-0000-4000-8000-000000015703",
5056+ session_id: WAKE_NATIVE_SESSION,
5057+ parent_tool_use_id: null,
5058+ user_message_uuids: [steerUuid],
5059+ message: {
5060+ id: "msg_unread_steer_reply",
5061+ type: "message",
5062+ role: "assistant",
5063+ model: "claude-sonnet-4-6",
5064+ content: [{ type: "text", text: "Noted." }],
5065+ },
5066+ }),
5067+ );
5068+ }
5069+ const noticesBefore = harness.events.length;
5070+ yield* harness.runtime.interruptTurn({
5071+ providerThread: harness.providerThread,
5072+ providerTurnId,
5073+ });
5074+ assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "interrupted");
5075+
5076+ const notices = harness.events
5077+ .slice(noticesBefore)
5078+ .flatMap((event) =>
5079+ event.type === "turn_item.updated" && event.turnItem.type === "system_notice"
5080+ ? [event.turnItem.message]
5081+ : [],
5082+ );
5083+ const undelivered = notices.find((message) =>
5084+ /not (have )?(been )?delivered|never (reached|delivered)/i.test(message ?? ""),
5085+ );
5086+ if (readBy !== "none" || !echoes) {
5087+ assert.isUndefined(undelivered);
5088+ return;
5089+ }
5090+ assert.isDefined(
5091+ undelivered,
5092+ `expected an undelivered-steer notice, got ${JSON.stringify(notices)}`,
5093+ );
5094+ assert.match(undelivered ?? "", /resend|send it again|re-send/i);
5095+ assert.include(undelivered, "PELICAN");
5096+ }).pipe(
5097+ Effect.scoped,
5098+ Effect.provide(
5099+ Layer.mergeAll(
5100+ IdAllocator.layer,
5101+ McpProviderSessions.layer,
5102+ NodeServices.layer,
5103+ NodeCrypto.layer,
5104+ ),
5105+ ),
5106+ ),
5107+ );
5108+
49615109 // regression: #23948 Claude holds a steer behind a running foreground tool
49625110 // call and goes silent, so each steer stays pending until Claude starts it.
49635111 it.effect("keeps a steer pending until Claude starts it", () =>
0 commit comments