docs(devlog): #83 save-indicator session log
CI / ci (push) Canceled after 0s

[Generated by AI]
This commit is contained in:
AlexKucera committed 2026-10-08 18:27:28 +02:00
1 parent fc0dde4f7c
commit 4e8865e660
3 files changed
+86 -20

No files matched your search

@@ -0,0 +1,58 @@
# Save Indicator does not work after first save (#83)
> **Date:** 2026-10-08
> **Type:** issue
> **Reference:** https://git.babylondreams.de/AlexKucera/Museion/issues/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 `.saved` only — `.failed` is sticky), equal → `.saved`. Called from `edit()` (every keystroke) and `keepLocal()`.
- `flush()` unchanged in behavior; the dead guard-branch `syncSaveState()` call was removed after review (`.changed`-while-clean is unreachable there).
- `reloadFromDisk()` now also calls `onError?(nil)` — dot and error strip agree after a Reload resolves a failure.
- `keepLocal()` (audit fix): dropped the `?? text` fallback on the disk read. If the post vanished while the conflict alert was up, the session now stays dirty — previously it computed `.saved` over 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-`.failed` pinned both via revert-to-flushed and via further edits; two stale expectations that had encoded the lying "Saved" were fixed.
- Docs: `Museion/AGENTS.md` editor-core bullet and the `CHANGELOG.md` Unreleased 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*
+1
View File
@@ -5,6 +5,7 @@ Complete history of session logs in this directory, newest first. One-line summa
<!-- write-log: full-index -->
| Date | Type | File | Summary |
|------|------|------|---------|
| 2026-10-08 | issue | [20261008-issue83-save-indicator-honesty_log.md](20261008-issue83-save-indicator-honesty_log.md) | #83 honest save dot: Changed while dirty, Saving… deleted, sticky failed, vanished-disk keepLocal fix — 106 tests green |
| 2026-10-08 | issue | [20261008-issue77-editing-parity_log.md](20261008-issue77-editing-parity_log.md) | #77 editing parity: reading-mirrored presenter (30/22/19 ladder, inline traits, 66ch measure), fence-staleness audit fix — 104 tests green |
| 2026-10-06 | issue | [20261006-issue76-apex-html-reading_log.md](20261006-issue76-apex-html-reading_log.md) | #76 apex HTML reading surface: WKWebView + bundled apex, data-source-line map, TextKit reading deleted — 94 tests green, PERF-3k 20 ms |
| 2026-10-05 | issue | [20261005-issue71-reading-toggle_log.md](20261005-issue71-reading-toggle_log.md) | #71 reading toggle: block-aware renderer, tap-to-edit canvas, typography slots, kitchen-sink — 94 tests green |