Skip to content

Commit bfd37b7

Browse files
mwolsonmaria-rcks
andauthored
fix(web): Queued messages can be edited during Compact and send (#27310)
Co-authored-by: maria-rcks <[email protected]>
1 parent f17126c commit bfd37b7

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

‎apps/web/src/components/ChatView.logic.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,40 @@ describe("hasServerAcknowledgedLocalDispatch", () => {
193193
).toBe(false);
194194
});
195195

196+
it.each([
197+
["queued", "message-queued", true],
198+
["queued", "message-before-send", false],
199+
["preparing", "message-queued", false],
200+
["starting", "message-queued", false],
201+
] as const)("acknowledges %s with latest message %s: %s", (status, messageId, acknowledged) => {
202+
const localDispatch = createLocalDispatchSnapshot(
203+
makeThread({ latestRun: completedTurn, runtime: readySession }),
204+
{ latestUserMessageId: MessageId.make("message-before-send") },
205+
);
206+
// The shell hides the silent compaction run, so its runtime reports the queued message's run.
207+
const queuedRun = {
208+
...completedTurn,
209+
runId: RunId.make("turn-queued"),
210+
status: "queued" as const,
211+
requestedAt: "2026-03-29T00:01:00.000Z",
212+
startedAt: null,
213+
completedAt: null,
214+
};
215+
216+
expect(
217+
hasServerAcknowledgedLocalDispatch({
218+
localDispatch,
219+
phase: "running",
220+
latestRun: queuedRun,
221+
latestUserMessageId: MessageId.make(messageId),
222+
runtime: { ...readySession, status },
223+
hasPendingApproval: false,
224+
hasPendingUserInput: false,
225+
threadError: null,
226+
}),
227+
).toBe(acknowledged);
228+
});
229+
196230
it("waits for the matching running turn before acknowledging", () => {
197231
const localDispatch = createLocalDispatchSnapshot(
198232
makeThread({ latestRun: completedTurn, runtime: readySession }),

‎apps/web/src/components/ChatView.logic.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,14 +1101,15 @@ export function hasServerAcknowledgedLocalDispatch(input: {
11011101
if (input.hasPendingApproval || input.hasPendingUserInput || Boolean(input.threadError)) {
11021102
return true;
11031103
}
1104+
const latestUserMessageChanged =
1105+
input.localDispatch.latestUserMessageId !== (input.latestUserMessageId ?? null);
11041106
if (input.phase === "connecting" || derivePhase(input.runtime ?? null) === "connecting") {
1105-
return false;
1107+
// A message queued behind other work, such as an idle compaction the shell hides, has landed.
1108+
return input.runtime?.status === "queued" && latestUserMessageChanged;
11061109
}
11071110

11081111
const latestRun = input.latestRun ?? null;
11091112
const runtime = input.runtime ?? null;
1110-
const latestUserMessageChanged =
1111-
input.localDispatch.latestUserMessageId !== (input.latestUserMessageId ?? null);
11121113
const latestRunChanged =
11131114
input.localDispatch.latestRunId !== (latestRun?.runId ?? null) ||
11141115
input.localDispatch.latestRunRequestedAt !== (latestRun?.requestedAt ?? null) ||

0 commit comments

Comments
 (0)