Skip to content

Commit 6b0b1dd

Browse files
fix(mobile): a queued edit cleared to nothing reports as discarded when its run starts
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 07f3976 commit 6b0b1dd

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,24 @@ describe("beginQueuedRunEdit", () => {
113113
);
114114
});
115115

116+
it("reports a cleared edit as discarded when the run starts", () => {
117+
const threadKey = "env-exit:thread-cleared";
118+
const runId = RunId.make("run-1");
119+
const runs = Atom.make<ReadonlyArray<{ readonly id: RunId; readonly status: string }> | null>([
120+
{ id: runId, status: "queued" },
121+
]);
122+
beginQueuedRunEdit(threadKey, edit([]), runs);
123+
setComposerDraftText(queuedEditDraftKey(threadKey, runId), "");
124+
125+
appAtomRegistry.set(runs, [{ id: runId, status: "running" }]);
126+
127+
expect(getQueuedRunEdit(threadKey)).toBeNull();
128+
expect(getComposerDraftSnapshot(threadKey).text).toBe("");
129+
expect(appAtomRegistry.get(threadComposerErrorsAtom)[threadKey]?.message).toBe(
130+
"That message already started, so the edit was discarded.",
131+
);
132+
});
133+
116134
it("treats a removed server attachment as a change when the run starts", () => {
117135
const threadKey = "env-exit:thread-removed";
118136
const runId = RunId.make("run-1");

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,17 @@ function exitQueuedRunEdit(threadKey: string, edit: QueuedRunEdit): void {
7373
const editDraftKey = queuedEditDraftKey(threadKey, edit.runId);
7474
const editDraft = getComposerDraftSnapshot(editDraftKey);
7575
const threadDraft = getComposerDraftSnapshot(threadKey);
76+
const editRestorable = editDraft.text.trim().length > 0 || editDraft.attachments.length > 0;
7677
const recovery = resolveQueuedEditExit({
7778
editChanged:
78-
(editDraft.text.trim().length > 0 || editDraft.attachments.length > 0) &&
79-
(editDraft.text !== edit.originalText ||
80-
editDraft.attachments.length > 0 ||
81-
edit.removedExistingAttachment === true),
82-
threadDraftEmpty: threadDraft.text.trim().length === 0 && threadDraft.attachments.length === 0,
79+
editDraft.text !== edit.originalText ||
80+
editDraft.attachments.length > 0 ||
81+
edit.removedExistingAttachment === true,
82+
// A cleared edit has nothing to put back, so it can only be discarded.
83+
threadDraftEmpty:
84+
editRestorable &&
85+
threadDraft.text.trim().length === 0 &&
86+
threadDraft.attachments.length === 0,
8387
});
8488
if (recovery === "kept") {
8589
// The merge publishes the draft before writing it, so a failed write only delays persistence to the next one.

0 commit comments

Comments
 (0)