GeezerVison is showing github.com — id(web/auto-save): cancel() does not stop an in-flight save — its retry/follow-up runs after the editor closes and saveFile() targets the newly opened document · Issue #2437 · developing-today/code
id(web/auto-save): cancel() does not stop an in-flight save — its retry/follow-up runs after the editor closes and saveFile() targets the newly opened document #2437Labels app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/xsTrivial: expected under 30 minutes of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests DescriptionProblem
AutoSaveManager.cancel() (pkgs/id/web/src/auto-save.ts:104-121) — called when the editor closes (pkgs/id/web/src/main.ts:1015, in closeEditor(), which then drops the manager) — clears the pending timers and resets the indicator, but it does nothing about a save that is already in flight. There is no disposed/cancelled flag, and onSaveResult (auto-save.ts:160+) never checks whether the manager was cancelled while its save was unresolved:
- A rate-limit result schedules a fresh retry unconditionally (
auto-save.ts:188-191): the retry timer is created after cancel() cleared the old one, so it fires and calls saveFn() for a closed editor.
- An ok result with edits that arrived during the flight runs the coalesced follow-up (
auto-save.ts:162-167): triggerSave() calls saveFn() again after cancel().
- A generic-error result with a coalesced edit does the same (
auto-save.ts:199-213).
- Every one of these paths also calls
updateIndicator(), which writes to the shared #save-btn element by global id — by then that button belongs to whatever document was opened next.
This matters because saveFn is not document-bound: the manager is constructed as new AutoSaveManager(() => this.saveFile()) (main.ts:976), and saveFile() (main.ts:1044-1056) reads the current this.collab.editor and the current #editor-container dataset (docId/hash). A stale manager's post-cancel retry/follow-up therefore saves the newly opened document's current state under its name/hash — an unrequested save that bypasses that document's own manager, breaking the one-save-in-flight serialization #1440 established (two managers can now have saves in flight for the same document), and its indicator writes can re-enable/relabel the new editor's save button mid-save. With no editor open it is "only" a spurious save attempt and state churn on a dropped manager.
Evidence (verified this run, main 5a34fa70)
Laptop probe (verbatim auto-save.ts, md5 7448db377c7567650a5ef5d4a0428652, bun, deferred saveFn; probe at ~/git/fleet/probe-2026-10-29-laneB-autosave/ on the laptop):
- Case 1 —
saveNow(), then cancel(), then resolve {ok:false, retryAfterMs:200}: state went idle (cancel) → rate-limited (completion), the retry fired, saveFn calls = 2 — a save ran after cancel.
- Case 2 —
saveNow(), edit during flight, cancel(), then resolve {ok:true}: saveFn calls = 2 — the follow-up save ran after cancel, state back to saving.
- Case 3 (control, no cancel): rate-limit retry runs as designed (calls = 2).
- Case 4 (control, cancel before any save starts): calls = 0 — cancel works for not-yet-started saves; only the in-flight completion leaks through.
auto-save.test.ts covers the #1440 serialization and the #1616 follow-up, but has no cancel-during-flight case (no cancel() test at all).
Why it matters
Closing a document is the one moment the manager's owner explicitly declares "no more saves from me". A save that fires afterwards acts on a different document than the one it was created for, because saveFile() resolves its target from live app state at call time. That is a wrong-document write path — the severity is bounded (it saves the new document's own current content under its own name, not the closed document's content into it), but it defeats the serialization invariant the class exists to provide, and the shared-button indicator writes race the new manager.
Acceptance criteria
Related: #1440 (serialization, closed), #1616 (generic-error follow-up, closed), #1494 (saveFile name decoding — different defect, open). Activitydeveloping-today commented on Oct 29, 2026 added kind/bugSomething isn't working (prefixed form of the classic bug label) task/triageQueue packet kind: verify, reproduce, and route this item effort/xsTrivial: expected under 30 minutes of work app/idPackage/app: id (pkgs/ or apps/ in this repo) on Oct 29, 2026dezren39 commented on Oct 29, 2026 dezren39 commented on Nov 3, 2026
🤖 Agent note · parked (CI starved)
developing-today commented on Nov 3, 2026 developing-today commented on Nov 3, 2026
MetadataMetadataapp/idPackage/app: id (pkgs/ or apps/ in this repo)effort/xsTrivial: expected under 30 minutes of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests DevelopmentNo branches or pull requestsIssue actions
|