Skip to content

Commit 6c037a8

Browse files
fix(web): a queued message stays editable against an older server
A server without the edit hold rejects the hold command, and the editor then refused to open. When the hold fails the edit now opens unheld, as before holds existed; the queue watcher still ends it if the run has left the queue. AI-assisted; verified with the tests and tools listed above.
1 parent 8ea794b commit 6c037a8

5 files changed

Lines changed: 21 additions & 35 deletions

File tree

‎apps/mobile/src/features/threads/ThreadQueueControl.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
132132
const promote = useAtomCommand(threadEnvironment.promoteQueuedRun, "promote queued message");
133133
const cancel = useAtomCommand(threadEnvironment.cancelQueuedRun, "remove queued message");
134134
const resume = useAtomCommand(threadEnvironment.resumeThreadQueue, "resume queue");
135-
// beginQueuedRunEdit reports a failed hold itself.
135+
// An older server has no hold; the edit then opens unheld, as before.
136136
const holdEdit = useAtomCommand(threadEnvironment.holdQueuedRunEdit, { reportFailure: false });
137137
const [resuming, setResuming] = useState(false);
138138
const [busyRunId, setBusyRunId] = useState<RunId | null>(null);

‎apps/mobile/src/state/queued-run-edit.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function exitQueuedRunEdit(threadKey: string, edit: QueuedRunEdit): void {
109109

110110
/**
111111
* `runs` is the thread's runs; the edit ends when its run leaves the queue.
112-
* The edit opens once `hold` has the server hold the run, and reports when it cannot.
112+
* The edit opens once the server answers `hold`; an older server's edit opens unheld.
113113
*/
114114
export function beginQueuedRunEdit(
115115
threadKey: string,
@@ -130,11 +130,7 @@ export function beginQueuedRunEdit(
130130
setComposerDraftContext(draftKey, edit.context);
131131
return queuedRunEdits
132132
.begin(threadKey, { ...edit, originalText }, { runs, onRunLeftQueue: exitQueuedRunEdit, hold })
133-
.then((outcome) => {
134-
if (outcome !== "failed") return;
135-
clearComposerDraft(draftKey);
136-
setThreadComposerError(threadKey, "Couldn't edit that message. It may have already started.");
137-
});
133+
.then(() => {});
138134
}
139135

140136
export function removeQueuedRunEditAttachment(threadKey: string, attachmentId: string): void {

‎apps/web/src/components/chat/useQueuedRunEdit.ts‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export function useQueuedRunEdit(input: {
211211
composerRef,
212212
} = input;
213213
const editQueuedRunCommand = useEditQueuedRunCommand();
214-
// A failed hold keeps the editor closed and says so below.
214+
// An older server has no hold; the edit then opens unheld, as before.
215215
const holdQueuedRunEdit = useAtomCommand(threadEnvironment.holdQueuedRunEdit, {
216216
reportFailure: false,
217217
});
@@ -328,19 +328,7 @@ export function useQueuedRunEdit(input: {
328328
},
329329
)
330330
.then((outcome) => {
331-
if (outcome === "opened") {
332-
focusComposerSoon();
333-
return;
334-
}
335-
if (outcome === "superseded") return;
336-
clearEditDraft(request.runId);
337-
toastManager.add(
338-
stackedThreadToast({
339-
type: "error",
340-
title: "Couldn't edit the queued message",
341-
description: "It may have already started. Try again if it is still queued.",
342-
}),
343-
);
331+
if (outcome === "opened") focusComposerSoon();
344332
});
345333
});
346334
const cancelEdit = useStableCallback(() => {

‎packages/client-runtime/src/queuedRunEdit.test.ts‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe("makeQueuedRunEditStore", () => {
108108
]);
109109
});
110110

111-
it("opens the edit only once the server holds its run", async () => {
111+
it("opens the edit only once the server answers its hold", async () => {
112112
const { store } = setup();
113113
const replies: Array<(held: boolean) => void> = [];
114114
const released: Array<boolean> = [];
@@ -129,24 +129,26 @@ describe("makeQueuedRunEditStore", () => {
129129
},
130130
);
131131

132-
const refused = begin();
133-
expect(store.get("env:thread")).toBeNull();
134-
replies[0]!(false);
135-
expect(await refused).toBe("failed");
136-
expect(store.get("env:thread")).toBeNull();
137-
138132
// Cancelled before the server answered: the late hold is released.
139133
const cancelled = begin();
140134
store.end("env:thread");
141-
replies[1]!(true);
135+
replies[0]!(true);
142136
expect(await cancelled).toBe("superseded");
143137
expect(store.get("env:thread")).toBeNull();
144138
expect(released).toEqual([false]);
145139

146140
const accepted = begin();
147-
replies[2]!(true);
141+
expect(store.get("env:thread")).toBeNull();
142+
replies[1]!(true);
148143
expect(await accepted).toBe("opened");
149144
expect(store.get("env:thread")).toEqual({ runId: RUN, text: "draft" });
145+
store.end("env:thread");
146+
147+
// An older server has no hold command: the edit still opens, as it did before holds.
148+
const unsupported = begin();
149+
replies[2]!(false);
150+
expect(await unsupported).toBe("opened");
151+
expect(store.get("env:thread")).toEqual({ runId: RUN, text: "draft" });
150152
});
151153

152154
it("holds the exit during a save and replays it when the save fails", async () => {

‎packages/client-runtime/src/queuedRunEdit.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ export function makeQueuedRunEditStore<E extends { readonly runId: RunId }>(opti
166166
savingAtom,
167167
get,
168168
/**
169-
* Starts an edit, replacing any open one. It opens only once the server holds
170-
* the run, so the run never starts with its original text while the user types.
171-
* When the run leaves the queue, `onRunLeftQueue` receives the edit.
169+
* Starts an edit, replacing any open one. It opens once the server answers the
170+
* hold, so the run cannot start with its original text while the user types. An
171+
* older server has no hold; its edit opens unheld. `onRunLeftQueue` ends either.
172172
*/
173173
async begin(
174174
threadKey: string,
@@ -178,7 +178,7 @@ export function makeQueuedRunEditStore<E extends { readonly runId: RunId }>(opti
178178
readonly onRunLeftQueue: (threadKey: string, edit: E) => void;
179179
readonly hold: QueuedRunEditHold;
180180
},
181-
): Promise<"opened" | "failed" | "superseded"> {
181+
): Promise<"opened" | "superseded"> {
182182
const open = () => {
183183
write(threadKey, edit);
184184
const next: ExitWatch<E> = { ...watch, runId: edit.runId, cancel: null };
@@ -202,7 +202,7 @@ export function makeQueuedRunEditStore<E extends { readonly runId: RunId }>(opti
202202
return "superseded";
203203
}
204204
acquiring.delete(threadKey);
205-
return held ? open() : "failed";
205+
return open();
206206
},
207207
update(threadKey: string, f: (edit: E) => E) {
208208
const edit = get(threadKey);

0 commit comments

Comments
 (0)