TypeScript
fix(web): Queued messages can be edited during Compact and send (#27310)
Mike Olsonbfd37b774bc3
diff --git a/apps/web/src/components/ChatView.logic.test.ts b/apps/web/src/components/ChatView.logic.test.tsindex 14125c68404..e7781653f8e 100644--- a/apps/web/src/components/ChatView.logic.test.ts+++ b/apps/web/src/components/ChatView.logic.test.ts@@ -193,6 +193,40 @@ describe("hasServerAcknowledgedLocalDispatch", () => {).toBe(false);});+ it.each([+ ["queued", "message-queued", true],+ ["queued", "message-before-send", false],+ ["preparing", "message-queued", false],+ ["starting", "message-queued", false],+ ] as const)("acknowledges %s with latest message %s: %s", (status, messageId, acknowledged) => {+ const localDispatch = createLocalDispatchSnapshot(+ makeThread({ latestRun: completedTurn, runtime: readySession }),+ { latestUserMessageId: MessageId.make("message-before-send") },+ );+ // The shell hides the silent compaction run, so its runtime reports the queued message's run.+ const queuedRun = {+ ...completedTurn,+ runId: RunId.make("turn-queued"),+ status: "queued" as const,+ requestedAt: "2026-03-29T00:01:00.000Z",+ startedAt: null,+ completedAt: null,+ };++ expect(+ hasServerAcknowledgedLocalDispatch({+ localDispatch,+ phase: "running",+ latestRun: queuedRun,+ latestUserMessageId: MessageId.make(messageId),+ runtime: { ...readySession, status },+ hasPendingApproval: false,+ hasPendingUserInput: false,+ threadError: null,+ }),+ ).toBe(acknowledged);+ });+it("waits for the matching running turn before acknowledging", () => {const localDispatch = createLocalDispatchSnapshot(makeThread({ latestRun: completedTurn, runtime: readySession }),diff --git a/apps/web/src/components/ChatView.logic.ts b/apps/web/src/components/ChatView.logic.tsindex 49fe3a441fb..c289976d3b0 100644--- a/apps/web/src/components/ChatView.logic.ts+++ b/apps/web/src/components/ChatView.logic.ts@@ -1101,14 +1101,15 @@ export function hasServerAcknowledgedLocalDispatch(input: {if (input.hasPendingApproval || input.hasPendingUserInput || Boolean(input.threadError)) {return true;}+ const latestUserMessageChanged =+ input.localDispatch.latestUserMessageId !== (input.latestUserMessageId ?? null);if (input.phase === "connecting" || derivePhase(input.runtime ?? null) === "connecting") {- return false;+ // A message queued behind other work, such as an idle compaction the shell hides, has landed.+ return input.runtime?.status === "queued" && latestUserMessageChanged;}const latestRun = input.latestRun ?? null;const runtime = input.runtime ?? null;- const latestUserMessageChanged =- input.localDispatch.latestUserMessageId !== (input.latestUserMessageId ?? null);const latestRunChanged =input.localDispatch.latestRunId !== (latestRun?.runId ?? null) ||input.localDispatch.latestRunRequestedAt !== (latestRun?.requestedAt ?? null) ||