5.1 KiB
5.1 KiB
Save Indicator does not work after first save (#83)
Date: 2026-10-08 Type: issue Reference: AlexKucera/Museion#83
Goal
The save-state dot in the editor toolbar always read "Saved" for an open post — even with dirty, unflushed keystrokes. Only draft mode (the static "⌘S saves" label) was honest. Make the indicator tell the truth: maintainer's wording — dirty shows "Changed", clean shows "Saved", and "Saving…" is deleted (a synchronous write of small text files never lasts a render pass).
What Was Done
SaveState(Museion/EditorSession.swift): added.changed, deleted.saving(dead state — the flush is synchronous on the main actor, so "Saving…" could never paint).- New
syncSaveState()mirrors cleanliness:text != lastFlushedText→.changed(escalating from.savedonly —.failedis sticky), equal →.saved. Called fromedit()(every keystroke) andkeepLocal(). flush()unchanged in behavior; the dead guard-branchsyncSaveState()call was removed after review (.changed-while-clean is unreachable there).reloadFromDisk()now also callsonError?(nil)— dot and error strip agree after a Reload resolves a failure.keepLocal()(audit fix): dropped the?? textfallback on the disk read. If the post vanished while the conflict alert was up, the session now stays dirty — previously it computed.savedover text that existed only in memory, and ⌘S silently no-oped forever (data loss with "Saved" on screen).SaveStateDot(Museion/PostEditorView.swift): label "Changed"; switch stays exhaustive.- Tests (MuseionTests/EditorSessionTests.swift): new
dirty edits show Changed until flushed; reverting to flushed text clears it(dirty-during-debounce, flush→Saved, revert-to-flushed-content→Saved, keepLocal→Changed, vanished-mid-alert→stays dirty→flush→failed); sticky-.failedpinned both via revert-to-flushed and via further edits; two stale expectations that had encoded the lying "Saved" were fixed. - Docs:
Museion/AGENTS.mdeditor-core bullet and theCHANGELOG.mdUnreleased M1 entry updated to the Changed→Saved state machine.
Decisions & Rationale
| Decision | Rationale |
|---|---|
| "Changed" label, not "Unsaved Changes" | Maintainer's pick between the two offered wordings; shorter, matches the dot's size. |
Delete .saving entirely |
Maintainer call: the synchronous PostStore.overwrite of small markdown files finishes within one render pass — the state was unreachable UI. Deletion over addition. |
.failed is sticky until a write actually succeeds |
Never claim "Saved" without a verified write. Cries wolf (revert-to-flushed still shows failed) rather than falsely reassuring — conservative side chosen deliberately; the security review confirmed this bias. |
keepLocal keeps old lastFlushedText when disk is unreadable |
The vanish-teardown in PostsModel only fires on the next watcher tick, so the mid-alert race window is real. Staying dirty keeps ⌘S armed — the write is then attempted and fails loudly. |
reloadFromDisk clears .failed without a write |
After Reload, shown text == disk, so "Saved" is true; documented with a comment at the call site. |
Gotchas & Fixes
| Problem | Root Cause | Fix |
|---|---|---|
| Indicator lied "Saved" while dirty | saveState only ever mutated inside flush(); nothing represented the debounce-held-dirty window |
syncSaveState() on edit()/keepLocal() |
| First eta test failed as written | Test asserted revert-to-"Base." = clean, but disk held the flushed "Dirty." — dirty means ≠ last flushed, not ≠ original | Test fixed to assert both directions honestly |
swiftformat . reformatted 19 files (spike/, prototypes/, 5 app files) |
Repo-root run hits space-indented spike dirs — collateral churn beyond the change | Reverted all but the session's files; scope swiftformat to touched files |
Reviewers flagged the guard-branch syncSaveState() comment as a lie |
The comment claimed it cleared stale .failed; the code couldn't (and shouldn't) |
Removed the dead call; stickiness now test-pinned instead |
| Security review: vanished-post + Keep Local = lying "Saved" + dead ⌘S | ?? text fallback adopted local text as flushed when disk read failed |
if let disk = — only a real read updates lastFlushedText |
Files Changed
| File | Change Summary |
|---|---|
Museion/EditorSession.swift |
.changed added, .saving deleted, syncSaveState(), onError?(nil) on reload, keepLocal disk-read guard, doc comments |
Museion/PostEditorView.swift |
SaveStateDot label "Changed"; .saving case removed |
MuseionTests/EditorSessionTests.swift |
New dirty/sticky/vanished tests (+53/−3); stale expectations corrected |
Museion/AGENTS.md |
Editor-core bullet: Changed→Saved state machine, #83 |
CHANGELOG.md |
Unreleased M1 entry amended (honest dot wording) |
Open Items & Next Steps
- None for #83. (PRD.md carries the maintainer's own unrelated edit — deliberately left out of this commit.)
Log written by write-log skill