Commit Graph
3 Commits
Author SHA1 Message Date
AlexKucera 2334afc392 fix(editor): quit rides the departure gate
shutdown() flushed both sessions best-effort and ignored the
results — quitting with an unanswered #67 conflict wrote local
text over the foreign disk body (flush() holds for conflicts
only in the debounce), and a failed quit-time flush silently
dropped the only copy of the edits.

Quit now routes through the same departure gate as navigation:
documentsMayDepart runs both sessions through sessionMayDepart,
and the failed-flush-at-quit posture is BLOCK QUIT —
applicationShouldTerminate (quitReply(posts:), before the Cold
Turkey ask) refuses termination with one spoken reason via a
hosted-guarded alert. PostsModel.active (weak, registered by
AppGateState.init — the WritingLockState.active precedent) is
the delegate's reachability.

Finish-audit fixes folded in: sessionMayDepart refuses a
never-loaded session's retyped words (its flush is a vacuous
success — the same gap closed for navigation); shutdown stays
void (no production reader of a Bool).

+5 pins (conflict hold, clean flush, guest flush, never-loaded
refusal, delegate refusal incl. chmod-injected flush failure),
all flip-verified. Rail 708/708; format+lint clean.

Closes #200
2026-11-19 13:18:19 +01:00
AlexKucera 250a662f3e fix(editor): guard document departure on failed flushes
teardown(flushFirst:) discarded flush()'s result, so document
navigation (newPost, newOutline, select, openExternal, dismissExternal,
openUnguarded) dropped the outgoing dirty session after a failed write
and replaced the only retained copy of the unsaved prose.

One shared departure gate now covers every site, placed before any
document-specific state clears:

- sessionMayDepart(_:): flushOrAbort's two gates (unanswered #67
  conflict holds; failed flush holds) lifted to document departure —
  flushOrAbort routes through it unchanged.
- dismissExternal() -> Bool: the guest departs only when its flush
  lands; on failure the guest, its buffer, and its watcher stay live.
- departOpenDocuments(): the full-switch composition (guest + post
  session) behind newPost/newOutline/openExternal.
- select/openUnguarded gate their same-id-conditional session teardowns
  through sessionMayDepart directly.

Departure now aborts with the strip error set and the dirty session
retained; retrying after writability returns lands the edits and
completes the switch. All six PostsModelDepartureTests pins RED at
11b196d, GREEN with this change.

brief-25 [failed-flush-discarded-on-document-switch]
2026-11-16 20:17:58 +01:00
AlexKucera ecd14d1714 test(editor): pin document departure aborting on failed flushes
CI / ci (push) Canceled after 0s
RED at pinned base 11b196d: all six PostsModelDepartureTests pins fail.
Document departure (newPost, newOutline, select, openExternal,
dismissExternal, openUnguarded) tears the outgoing session down with
teardown(flushFirst: true), discards the flush result, and replaces the
only retained copy of unsaved prose when the write fails. Both
navigation families (saved-post session, external guest) pinned with
injected write failures (read-only piece folder / guest directory), plus
the unanswered #67 conflict hold. Retry after writability is restored
proves the edits land and the switch then completes.

brief-25 [failed-flush-discarded-on-document-switch]
2026-11-16 20:14:32 +01:00