@devries-cameron20 / t3code-1 / commits / 07066c0406
Fork 0

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

fix(client): a queued-edit save keeps its claim until it finishes (#25169)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 25, 2026 at 17:49 UTC 07066c0406753d70de387bfd99ef4a2b2ea8542e
2 files changed +29 -5
packages/client-runtime/src/queuedRunEdit.test.ts
+21 -1
@@ -102,7 +102,6 @@ describe("makeQueuedRunEditStore", () => {
102 const finishStale = store.startSave("env:thread");
103 begin();
104 store.update("env:thread", (edit) => ({ ...edit, text: "newer" }));
105 - expect(registry.get(store.savingAtom)).toEqual({});
105
106 expect(finishStale?.(true)).toBe(false);
107 expect(finishStale?.(false)).toBe(false);
@@ -111,6 +110,27 @@ describe("makeQueuedRunEditStore", () => {
110 expect(exits).toEqual([{ threadKey: "env:thread", text: "newer" }]);
111 });
112
113 + // The server orders saves by arrival, not by edit age, so a second save could
114 + // land before the first and then be overwritten by it.
115 + it("keeps the save claimed until it settles, even when the edit is begun again or ended", () => {
116 + const { registry, store, begin } = setup();
117 + begin();
118 + const finishStale = store.startSave("env:thread");
119 + begin();
120 + expect(registry.get(store.savingAtom)).toEqual({ "env:thread": true });
121 + expect(store.startSave("env:thread")).toBeNull();
122 + store.end("env:thread");
123 + begin();
124 + expect(store.startSave("env:thread")).toBeNull();
125 +
126 + expect(finishStale?.(true)).toBe(false);
127 + expect(registry.get(store.savingAtom)).toEqual({});
128 + expect(finishStale?.(false)).toBe(false);
129 + const finishNewer = store.startSave("env:thread");
130 + expect(finishNewer?.(true)).toBe(true);
131 + expect(store.get("env:thread")).toBeNull();
132 + });
133 +
134 it("does not revive a cancelled edit when its save fails", () => {
135 const { registry, runs, store, exits, begin } = setup();
136 begin();
packages/client-runtime/src/queuedRunEdit.ts
+8 -4
@@ -141,7 +141,6 @@ export function makeQueuedRunEditStore<E extends { readonly runId: RunId }>(opti
141 if (watch === undefined) return;
142 unsubscribe(watch);
143 watches.delete(threadKey);
144 - setSaving(threadKey, false);
144 };
145
146 return {
@@ -178,21 +177,26 @@ export function makeQueuedRunEditStore<E extends { readonly runId: RunId }>(opti
177 },
178 /**
179 * Claims the open edit for a save, or returns null when there is no edit
181 - * or a save already holds it. The exit watch pauses so the save's result
182 - * decides the edit's fate.
180 + * or a save is in flight. The exit watch pauses so the save's result decides
181 + * the edit's fate. The claim outlives the edit: the server orders saves by
182 + * arrival, so an overlapping older save could overwrite a newer one.
183 */
184 startSave(threadKey: string): FinishQueuedRunEditSave | null {
185 const watch = watches.get(threadKey);
186 if (watch === undefined || threadKey in registry.get(savingAtom)) return null;
187 setSaving(threadKey, true);
188 unsubscribe(watch);
189 + let settled = false;
190 return (succeeded) => {
191 + if (!settled) {
192 + settled = true;
193 + setSaving(threadKey, false);
194 + }
195 if (watches.get(threadKey) !== watch) return false;
196 if (succeeded) {
197 stopWatch(threadKey);
198 write(threadKey, null);
199 } else {
195 - setSaving(threadKey, false);
200 subscribe(threadKey, watch);
201 }
202 return true;