@devries-cameron20 / t3code Mirror · read-only / commits / f570bd2166
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 18:00 UTC

fix(server): Claude prompts no longer hang on a uuid the session already holds (#16897)

Co-authored-by: saphid <saphid@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Julius Marminge committed Oct 7, 2026 at 10:51 UTC f570bd21663f56ce94c41829d3b7d72886e25a34
3 files changed +220 -80
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+163 -54
@@ -2229,6 +2229,12 @@ describe("ClaudeAdapterV2 background wake turns", () => {
2229 processQueues,
2230 offerAndWait,
2231 offeredMessages,
2232 + // The uuid Claude echoes on the turn answering the nth offered prompt.
2233 + promptUuid: (index: number) => {
2234 + const uuid = offeredMessages[index]?.uuid;
2235 + if (uuid === undefined) throw new Error(`No prompt offered at index ${index}.`);
2236 + return uuid;
2237 + },
2238 permissionModeChanges,
2239 continuationRequests,
2240 events,
@@ -4421,12 +4427,11 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4427 const continuationAttempt = RunAttemptId.make("attempt-claude-wake-callback-3");
4428 const planToolUseId = "toolu_01WakePlanExitPlanMode";
4429 const planMarkdown = "# Wake plan\n\n1. Report the background result.";
4424 - const stamp = Effect.fnUntraced(function* (frame: SDKMessage, attemptId: RunAttemptId) {
4425 - return claudeSdkFrame({
4430 + const stamp = (frame: SDKMessage, promptIndex: number) =>
4431 + claudeSdkFrame({
4432 ...frame,
4427 - user_message_uuid: yield* ClaudeAdapterV2.claudePromptUuid(attemptId),
4433 + user_message_uuid: harness.promptUuid(promptIndex),
4434 });
4429 - });
4435 const runOf = (attemptId: RunAttemptId) => RunId.make(`run-${attemptId}`);
4436 const planToolUse = claudeSdkFrame({
4437 type: "assistant",
@@ -4479,12 +4484,12 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4484 runtimePolicy,
4485 }),
4486 );
4482 - yield* Queue.offer(harness.sdkMessages, yield* stamp(wakeTaskStarted, firstAttempt));
4487 + yield* Queue.offer(harness.sdkMessages, stamp(wakeTaskStarted, 0));
4488 yield* Queue.offer(
4489 harness.sdkMessages,
4485 - yield* stamp(
4490 + stamp(
4491 makeResultFrame({ uuid: "00000000-0000-4000-8000-000000000740", result: "STARTED" }),
4487 - firstAttempt,
4492 + 0,
4493 ),
4494 );
4495 yield* awaitUntil(() => harness.terminalEvents().length === 1, "first turn terminal");
@@ -4541,22 +4546,22 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4546 // The prompt's own turn follows and echoes its uuid.
4547 yield* Queue.offer(
4548 harness.sdkMessages,
4544 - yield* stamp(
4549 + stamp(
4550 makeAssistantTextFrame({
4551 uuid: "00000000-0000-4000-8000-000000000743",
4552 text: "USER_REPLY",
4553 }),
4549 - userAttempt,
4554 + 1,
4555 ),
4556 );
4557 yield* Queue.offer(
4558 harness.sdkMessages,
4554 - yield* stamp(
4559 + stamp(
4560 makeResultFrame({
4561 uuid: "00000000-0000-4000-8000-000000000744",
4562 result: "USER_REPLY",
4563 }),
4559 - userAttempt,
4564 + 1,
4565 ),
4566 );
4567 yield* awaitUntil(() => harness.terminalEvents().length === 2, "user turn terminal");
@@ -4721,12 +4726,11 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4726 const firstAttempt = RunAttemptId.make("attempt-claude-wake-approval-1");
4727 const userAttempt = RunAttemptId.make("attempt-claude-wake-approval-2");
4728 const bashToolUseId = "toolu_01WakeApprovalBash";
4724 - const stamp = Effect.fnUntraced(function* (frame: SDKMessage, attemptId: RunAttemptId) {
4725 - return claudeSdkFrame({
4729 + const stamp = (frame: SDKMessage, promptIndex: number) =>
4730 + claudeSdkFrame({
4731 ...frame,
4727 - user_message_uuid: yield* ClaudeAdapterV2.claudePromptUuid(attemptId),
4732 + user_message_uuid: harness.promptUuid(promptIndex),
4733 });
4729 - });
4734
4735 yield* harness.runtime.startTurn(
4736 makeClaudeTestTurnInput({
@@ -4741,16 +4745,16 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4745 );
4746 yield* Queue.offer(
4747 harness.sdkMessages,
4744 - yield* stamp(
4748 + stamp(
4749 makeAssistantTextFrame({ uuid: "00000000-0000-4000-8000-000000000780", text: "One." }),
4746 - firstAttempt,
4750 + 0,
4751 ),
4752 );
4753 yield* Queue.offer(
4754 harness.sdkMessages,
4751 - yield* stamp(
4755 + stamp(
4756 makeResultFrame({ uuid: "00000000-0000-4000-8000-000000000781", result: "One." }),
4753 - firstAttempt,
4757 + 0,
4758 ),
4759 );
4760 yield* awaitUntil(() => harness.terminalEvents().length === 1, "first turn terminal");
@@ -4845,12 +4849,11 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4849 const now = yield* DateTime.now;
4850 const firstAttempt = RunAttemptId.make("attempt-claude-echo-debris-1");
4851 const secondAttempt = RunAttemptId.make("attempt-claude-echo-debris-2");
4848 - const stamp = Effect.fnUntraced(function* (frame: SDKMessage, attemptId: RunAttemptId) {
4849 - return claudeSdkFrame({
4852 + const stamp = (frame: SDKMessage, promptIndex: number) =>
4853 + claudeSdkFrame({
4854 ...frame,
4851 - user_message_uuid: yield* ClaudeAdapterV2.claudePromptUuid(attemptId),
4855 + user_message_uuid: harness.promptUuid(promptIndex),
4856 });
4853 - });
4857
4858 yield* harness.runtime.startTurn(
4859 makeClaudeTestTurnInput({
@@ -4865,16 +4868,16 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4868 // The first turn echoes on its first frame: this process echoes early.
4869 yield* Queue.offer(
4870 harness.sdkMessages,
4868 - yield* stamp(
4871 + stamp(
4872 makeAssistantTextFrame({ uuid: "00000000-0000-4000-8000-000000000760", text: "One." }),
4870 - firstAttempt,
4873 + 0,
4874 ),
4875 );
4876 yield* Queue.offer(
4877 harness.sdkMessages,
4875 - yield* stamp(
4878 + stamp(
4879 makeResultFrame({ uuid: "00000000-0000-4000-8000-000000000761", result: "One." }),
4877 - firstAttempt,
4880 + 0,
4881 ),
4882 );
4883 yield* awaitUntil(() => harness.terminalEvents().length === 1, "first turn terminal");
@@ -4899,16 +4902,16 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4902 yield* Queue.offer(harness.sdkMessages, staleTaskNotificationResult);
4903 yield* Queue.offer(
4904 harness.sdkMessages,
4902 - yield* stamp(
4905 + stamp(
4906 makeAssistantTextFrame({ uuid: "00000000-0000-4000-8000-000000000762", text: "Two." }),
4904 - secondAttempt,
4907 + 1,
4908 ),
4909 );
4910 yield* Queue.offer(
4911 harness.sdkMessages,
4909 - yield* stamp(
4912 + stamp(
4913 makeResultFrame({ uuid: "00000000-0000-4000-8000-000000000763", result: "Two." }),
4911 - secondAttempt,
4914 + 1,
4915 ),
4916 );
4917 yield* awaitUntil(() => harness.terminalEvents().length === 2, "second turn terminal");
@@ -4944,12 +4947,11 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4947 const now = yield* DateTime.now;
4948 const firstAttempt = RunAttemptId.make("attempt-claude-echo-1");
4949 const secondAttempt = RunAttemptId.make("attempt-claude-echo-2");
4947 - const stamp = Effect.fnUntraced(function* (frame: SDKMessage, attemptId: RunAttemptId) {
4948 - return claudeSdkFrame({
4950 + const stamp = (frame: SDKMessage, promptIndex: number) =>
4951 + claudeSdkFrame({
4952 ...frame,
4950 - user_message_uuid: yield* ClaudeAdapterV2.claudePromptUuid(attemptId),
4953 + user_message_uuid: harness.promptUuid(promptIndex),
4954 });
4952 - });
4955 const assistantTexts = () =>
4956 harness.events.flatMap((event) =>
4957 event.type === "message.updated" && event.message.role === "assistant"
@@ -4969,22 +4971,18 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4971 attachments: [],
4972 }),
4973 );
4972 - assert.equal(
4973 - harness.offeredMessages[0]?.uuid,
4974 - yield* ClaudeAdapterV2.claudePromptUuid(firstAttempt),
4975 - );
4974 yield* Queue.offer(
4975 harness.sdkMessages,
4978 - yield* stamp(
4976 + stamp(
4977 makeAssistantTextFrame({ uuid: "00000000-0000-4000-8000-000000000701", text: "One." }),
4980 - firstAttempt,
4978 + 0,
4979 ),
4980 );
4981 yield* Queue.offer(
4982 harness.sdkMessages,
4985 - yield* stamp(
4983 + stamp(
4984 makeResultFrame({ uuid: "00000000-0000-4000-8000-000000000702", result: "One." }),
4987 - firstAttempt,
4985 + 0,
4986 ),
4987 );
4988 yield* awaitUntil(() => harness.terminalEvents().length === 1, "first turn terminal");
@@ -5018,6 +5016,118 @@ describe("ClaudeAdapterV2 background wake turns", () => {
5016 ),
5017 );
5018
5019 + it.effect("gives the same run attempt a fresh prompt uuid on every offer", () =>
5020 + Effect.scoped(
5021 + Effect.gen(function* () {
5022 + // Two servers sharing a database copy allocate identical run attempt
5023 + // ids and resume the same Claude session. Claude acks a prompt whose
5024 + // uuid its transcript already holds without ever running a turn.
5025 + const original = yield* makeWakeHarness;
5026 + const copy = yield* makeWakeHarness;
5027 + const now = yield* DateTime.now;
5028 + for (const harness of [original, copy]) {
5029 + yield* harness.runtime.startTurn(
5030 + makeClaudeTestTurnInput({
5031 + threadId: harness.threadId,
5032 + providerThread: harness.providerThread,
5033 + now,
5034 + attemptId: RunAttemptId.make("attempt-claude-shared-copy"),
5035 + text: "Continue where you left off.",
5036 + attachments: [],
5037 + }),
5038 + );
5039 + }
5040 + assert.notEqual(original.promptUuid(0), copy.promptUuid(0));
5041 + }).pipe(Effect.provide(Layer.merge(IdAllocator.layer, NodeServices.layer))),
5042 + ),
5043 + );
5044 +
5045 + it.effect("fails a prompt Claude completes without starting a turn for it", () =>
5046 + Effect.scoped(
5047 + Effect.gen(function* () {
5048 + // Claude answers a prompt whose uuid its transcript already holds with
5049 + // a lone completed lifecycle frame and never runs a turn for it.
5050 + const harness = yield* makeWakeHarness;
5051 + const now = yield* DateTime.now;
5052 + yield* harness.runtime.startTurn(
5053 + makeClaudeTestTurnInput({
5054 + threadId: harness.threadId,
5055 + providerThread: harness.providerThread,
5056 + now,
5057 + attemptId: RunAttemptId.make("attempt-claude-duplicate-prompt"),
5058 + text: "Bump this PR to the latest main.",
5059 + attachments: [],
5060 + }),
5061 + );
5062 + yield* Queue.offer(
5063 + harness.sdkMessages,
5064 + claudeSdkFrame({
5065 + type: "command_lifecycle",
5066 + command_uuid: harness.promptUuid(0),
5067 + state: "completed",
5068 + uuid: "00000000-0000-4000-8000-000000000790",
5069 + session_id: WAKE_NATIVE_SESSION,
5070 + }),
5071 + );
5072 + yield* awaitUntil(() => harness.terminalEvents().length === 1, "turn terminal");
5073 + const [terminal] = harness.terminalEvents();
5074 + assert.equal(terminal?.status, "failed");
5075 + if (terminal?.status !== "failed") return;
5076 + assert.equal(terminal.threadDisposition, "reusable");
5077 + assert.include(terminal.failure.message, "never started a turn");
5078 + }).pipe(Effect.provide(Layer.merge(IdAllocator.layer, NodeServices.layer))),
5079 + ),
5080 + );
5081 +
5082 + it.effect("keeps a started prompt running until its result", () =>
5083 + Effect.scoped(
5084 + Effect.gen(function* () {
5085 + const harness = yield* makeWakeHarness;
5086 + const now = yield* DateTime.now;
5087 + yield* harness.runtime.startTurn(
5088 + makeClaudeTestTurnInput({
5089 + threadId: harness.threadId,
5090 + providerThread: harness.providerThread,
5091 + now,
5092 + attemptId: RunAttemptId.make("attempt-claude-started-prompt"),
5093 + text: "Bump this PR to the latest main.",
5094 + attachments: [],
5095 + }),
5096 + );
5097 + const lifecycle = (state: string, uuid: string) =>
5098 + claudeSdkFrame({
5099 + type: "command_lifecycle",
5100 + command_uuid: harness.promptUuid(0),
5101 + state,
5102 + uuid,
5103 + session_id: WAKE_NATIVE_SESSION,
5104 + });
5105 + yield* Queue.offer(
5106 + harness.sdkMessages,
5107 + lifecycle("queued", "00000000-0000-4000-8000-000000000791"),
5108 + );
5109 + yield* Queue.offer(
5110 + harness.sdkMessages,
5111 + lifecycle("started", "00000000-0000-4000-8000-000000000792"),
5112 + );
5113 + // The CLI can report the prompt completed before its turn's result.
5114 + yield* Queue.offer(
5115 + harness.sdkMessages,
5116 + lifecycle("completed", "00000000-0000-4000-8000-000000000793"),
5117 + );
5118 + yield* Queue.offer(
5119 + harness.sdkMessages,
5120 + claudeSdkFrame({
5121 + ...makeResultFrame({ uuid: "00000000-0000-4000-8000-000000000794", result: "Done." }),
5122 + user_message_uuid: harness.promptUuid(0),
5123 + }),
5124 + );
5125 + yield* awaitUntil(() => harness.terminalEvents().length === 1, "turn terminal");
5126 + assert.equal(harness.terminalEvents()[0]?.status, "completed");
5127 + }).pipe(Effect.provide(Layer.merge(IdAllocator.layer, NodeServices.layer))),
5128 + ),
5129 + );
5130 +
5131 it.effect("buffers wake output and requests a single continuation run", () =>
5132 Effect.scoped(
5133 Effect.gen(function* () {
@@ -6031,12 +6141,11 @@ describe("ClaudeAdapterV2 background wake turns", () => {
6141 const userAttempt = RunAttemptId.make("attempt-claude-wake-subagent-2");
6142 const continuationAttempt = RunAttemptId.make("attempt-claude-wake-subagent-3");
6143 const runOf = (attemptId: RunAttemptId) => RunId.make(`run-${attemptId}`);
6034 - const stamp = Effect.fnUntraced(function* (frame: SDKMessage, attemptId: RunAttemptId) {
6035 - return claudeSdkFrame({
6144 + const stamp = (frame: SDKMessage, promptIndex: number) =>
6145 + claudeSdkFrame({
6146 ...frame,
6037 - user_message_uuid: yield* ClaudeAdapterV2.claudePromptUuid(attemptId),
6147 + user_message_uuid: harness.promptUuid(promptIndex),
6148 });
6039 - });
6149
6150 yield* harness.runtime.startTurn(
6151 makeClaudeTestTurnInput({
@@ -6048,12 +6157,12 @@ describe("ClaudeAdapterV2 background wake turns", () => {
6157 attachments: [],
6158 }),
6159 );
6051 - yield* Queue.offer(harness.sdkMessages, yield* stamp(wakeTaskStarted, firstAttempt));
6160 + yield* Queue.offer(harness.sdkMessages, stamp(wakeTaskStarted, 0));
6161 yield* Queue.offer(
6162 harness.sdkMessages,
6054 - yield* stamp(
6163 + stamp(
6164 makeResultFrame({ uuid: "00000000-0000-4000-8000-000000000770", result: "STARTED" }),
6056 - firstAttempt,
6165 + 0,
6166 ),
6167 );
6168 yield* awaitUntil(() => harness.terminalEvents().length === 1, "first turn terminal");
@@ -6120,16 +6229,16 @@ describe("ClaudeAdapterV2 background wake turns", () => {
6229 session_id: WAKE_NATIVE_SESSION,
6230 }),
6231 wakeResult,
6123 - yield* stamp(
6232 + stamp(
6233 makeAssistantTextFrame({
6234 uuid: "00000000-0000-4000-8000-000000000776",
6235 text: "USER_REPLY",
6236 }),
6128 - userAttempt,
6237 + 1,
6238 ),
6130 - yield* stamp(
6239 + stamp(
6240 makeResultFrame({ uuid: "00000000-0000-4000-8000-000000000777", result: "USER_REPLY" }),
6132 - userAttempt,
6241 + 1,
6242 ),
6243 ];
6244 for (const frame of wakeFrames) {
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.testkit.ts
+5 -2
@@ -18,6 +18,7 @@ import {
18 } from "@t3tools/contracts";
19 import * as Cause from "effect/Cause";
20 import * as Duration from "effect/Duration";
21 +import * as Crypto from "effect/Crypto";
22 import * as Effect from "effect/Effect";
23 import * as Exit from "effect/Exit";
24 import * as Layer from "effect/Layer";
@@ -1577,11 +1578,13 @@ async function recordClaudeStreamingQuery(input: {
1578 };
1579 try {
1580 for (const [index, prompt] of input.prompts.entries()) {
1580 - // Like the adapter, give each prompt a uuid Claude echoes on its turn.
1581 + // Like the adapter, give each prompt a fresh uuid Claude echoes on its turn.
1582 const message = ClaudeAdapterV2.makeClaudeUserMessage({
1583 text: prompt,
1584 uuid: await Effect.runPromise(
1584 - ClaudeAdapterV2.claudePromptUuid(`${input.sessionId}:prompt:${index + 1}`).pipe(
1585 + Crypto.Crypto.pipe(
1586 + Effect.flatMap((crypto) => crypto.randomUUIDv4),
1587 + Effect.filterOrFail(ClaudeAdapterV2.isClaudePromptUuid),
1588 Effect.provide(NodeServices.layer),
1589 ),
1590 ),
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+52 -24
@@ -71,7 +71,6 @@ import {
71 import * as Cause from "effect/Cause";
72 import * as Context from "effect/Context";
73 import * as Crypto from "effect/Crypto";
74 -import * as Hex from "effect/encoding/Hex";
74 import * as DateTime from "effect/DateTime";
75 import * as Deferred from "effect/Deferred";
76 import * as Effect from "effect/Effect";
@@ -1417,19 +1416,9 @@ const makeClaudeUserMessageWithAttachments = Effect.fnUntraced(function* (input:
1416 } satisfies SDKUserMessage;
1417 });
1418
1420 -// Stable per run attempt, so a replayed prompt offer matches its recording.
1421 -// Claude echoes it back as user_message_uuid on the turn that answers it.
1422 -export const claudePromptUuid = Effect.fn("claudePromptUuid")(function* (attemptId: string) {
1423 - const crypto = yield* Crypto.Crypto;
1424 - const digest = yield* crypto
1425 - .digest("SHA-256", new TextEncoder().encode(`t3-claude-prompt:${attemptId}`))
1426 - .pipe(Effect.orDie);
1427 - const hex = Hex.encode(digest);
1428 - const variant = ((Number.parseInt(hex[16]!, 16) & 0x3) | 0x8).toString(16);
1429 - const uuid: NonNullable<SDKUserMessage["uuid"]> =
1430 - `${hex.slice(0, 8)}-${hex.slice(8, 12)}-4${hex.slice(13, 16)}-${variant}${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
1431 - return uuid;
1432 -});
1419 +export function isClaudePromptUuid(value: string): value is NonNullable<SDKUserMessage["uuid"]> {
1420 + return /^[^-]+-[^-]+-[^-]+-[^-]+-[^-]+$/.test(value);
1421 +}
1422
1423 type ClaudeAssistantContentBlock = SDKAssistantMessage["message"]["content"][number];
1424 type ClaudeToolUseContentBlock = Extract<
@@ -2477,14 +2466,17 @@ function claudeEchoedPromptUuids(message: SDKMessage): ReadonlyArray<string> {
2466 return typeof uuid === "string" ? [uuid] : [];
2467 }
2468
2480 -// The prompt uuid a command_lifecycle frame (queued, started, completed)
2469 +// The prompt a command_lifecycle frame (queued, started, completed)
2470 // acknowledges. A CLI that sends them also echoes that uuid on the result of
2471 // the turn answering the prompt; one that does not keeps the old path.
2483 -function claudeAcknowledgedPromptUuid(message: SDKMessage): string | null {
2472 +function claudePromptLifecycle(
2473 + message: SDKMessage,
2474 +): { readonly uuid: string; readonly state: string } | null {
2475 const type: unknown = Reflect.get(message, "type");
2476 if (type !== "command_lifecycle") return null;
2477 const uuid: unknown = Reflect.get(message, "command_uuid");
2487 - return typeof uuid === "string" ? uuid : null;
2478 + const state: unknown = Reflect.get(message, "state");
2479 + return typeof uuid === "string" && typeof state === "string" ? { uuid, state } : null;
2480 }
2481
2482 // A result that answers a turn other than the pending prompt's. An echo
@@ -2750,6 +2742,8 @@ interface ActiveClaudeTurnContext {
2742 // prompt's turn echoes this uuid (see handleSdkMessage).
2743 readonly promptUuid: string | null;
2744 promptEcho: "pending" | "confirmed";
2745 + // Claude acknowledged starting the prompt (command_lifecycle "started").
2746 + promptStarted: boolean;
2747 // Root frames seen before the echo; held only when the CLI echoes early.
2748 gatedFramesBeforeEcho: number;
2749 readonly heldRootFrames: Array<SDKMessage>;
@@ -6801,11 +6795,32 @@ export function makeClaudeAdapterV2(
6795 yield* handleRoutedSdkMessage(input);
6796 return;
6797 }
6804 - if (
6805 - liveQuery.promptEchoMode === "unknown" &&
6806 - claudeAcknowledgedPromptUuid(message) === context.promptUuid
6807 - ) {
6808 - liveQuery.promptEchoMode = "acknowledged";
6798 + const lifecycle = claudePromptLifecycle(message);
6799 + if (lifecycle?.uuid === context.promptUuid) {
6800 + if (liveQuery.promptEchoMode === "unknown") {
6801 + liveQuery.promptEchoMode = "acknowledged";
6802 + }
6803 + if (lifecycle.state === "started") {
6804 + context.promptStarted = true;
6805 + }
6806 + // Claude finishes a prompt whose uuid its transcript already
6807 + // holds without starting it, and no turn will ever answer it.
6808 + if (lifecycle.state === "completed" && !context.promptStarted) {
6809 + yield* Effect.logWarning("orchestration-v2.claude-prompt-completed-without-turn", {
6810 + providerTurnId: context.providerTurnId,
6811 + promptUuid: context.promptUuid,
6812 + });
6813 + yield* finalizeActiveTurn({
6814 + context,
6815 + status: "failed",
6816 + completedAt: yield* DateTime.now,
6817 + failure: makeProviderFailure({
6818 + class: "provider_error",
6819 + message: "Claude acknowledged the message but never started a turn for it.",
6820 + }),
6821 + });
6822 + return;
6823 + }
6824 }
6825 if (!isClaudePromptEchoGatedFrame(message)) {
6826 // Frames the held turn produced through its own tool uses (a
@@ -7442,10 +7457,22 @@ export function makeClaudeAdapterV2(
7457 const startedAt = yield* DateTime.now;
7458 const nativeThreadId = yield* getNativeThreadId(turnInput.providerThread);
7459 const nativeTurnId = `turn:${turnInput.attemptId}`;
7460 + // Fresh for every offer: Claude acks a prompt whose uuid its
7461 + // transcript already holds without running a turn, and a session
7462 + // can outlive this database (or be resumed from a copy of it), so
7463 + // a uuid derived from run ids can repeat.
7464 const promptUuid = isClaudeProviderContinuationTurn(turnInput)
7465 ? null
7447 - : yield* claudePromptUuid(turnInput.attemptId).pipe(
7448 - Effect.provideService(Crypto.Crypto, crypto),
7466 + : yield* crypto.randomUUIDv4.pipe(
7467 + Effect.filterOrFail(isClaudePromptUuid),
7468 + Effect.mapError(
7469 + (cause) =>
7470 + new ProviderAdapter.ProviderAdapterProtocolError({
7471 + driver: CLAUDE_PROVIDER,
7472 + detail: "Failed to allocate a Claude prompt uuid.",
7473 + payload: cause,
7474 + }),
7475 + ),
7476 );
7477 const providerTurnId = idAllocator.derive.providerTurn({
7478 driver: CLAUDE_PROVIDER,
@@ -7505,6 +7532,7 @@ export function makeClaudeAdapterV2(
7532 subagentNodesByTaskId: new Map(),
7533 promptUuid,
7534 promptEcho: isClaudeProviderContinuationTurn(turnInput) ? "confirmed" : "pending",
7535 + promptStarted: false,
7536 gatedFramesBeforeEcho: 0,
7537 heldRootFrames: [],
7538 };