Skip to content

persistence: remember the last successfully activated document across reload #8

Description

@Jah-yee

Verified future problem

Current main always hydrates the fixture tree id, but it does not yet contain the foreign-id archive import/runtime-switch path. The unreachable-import scenario becomes real when that archive WIP lands. The same bootstrap boundary also owns a verified current-main load-window hazard.

Status: blocked on the active-document bootstrap

Do not open a narrow active-pointer PR until the bootstrap order is frozen. There is no safe document pointer if durable editing can begin before the home document is known and activated.

Before implementation, freeze:

  • the IndexedDB v1 to v2 metadata migration for one strict active-document pointer;
  • multi-tab compare-and-swap ownership for publishing that pointer;
  • the atomic order: pointer load, record load, validation, runtime activation, then durable mutation enablement;
  • archive decode, document save, runtime switch, and pointer publication/rollback ownership;
  • failure and corrupt-pointer fallback to the fixture document without hidden retrieval.

Blocking correction from WIP review

Do not merge the current resolveHydrationDecision revision comparator.

A tree revision is monotonic only inside a known lineage. It is not a snapshot hash or a cross-session timestamp. If initial rev5 loads stored rev6 A while a load-window edit creates live rev6 B, automatically hydrating A discards B without a gesture. Current main is also unsafe: equal revisions can be treated as already saved even when contents differ, while a higher live revision can CAS-overwrite stored material without an explicit conflict.

Changing <= to < does not solve this; equal revision with different content is the critical case.

Accepted outcome

The last document that was successfully activated becomes the local home document. Prefer gating admission, branch, undo, and import replacement until pointer load, record load, validation, and runtime activation complete. Pure transient navigation may remain available.

If product intent insists on durable edits during the load window, any live tree that diverges from the initial snapshot while stored material exists must enter explicit conflict. It must never auto-hydrate or auto-publish by revision ordering.

A failed or merely validated import must not move the active pointer. Missing or corrupt metadata falls back explicitly to the fixture document. This is document choice, not navigation state or hidden retrieval.

Proof

Use a delayed repository integration test, not only a pure revision comparator. Cover:

  • no stored record;
  • unchanged initial tree plus valid stored record;
  • stored and live different content at the same revision;
  • stored numerically higher and lower than a load-window edit;
  • corrupt/missing active pointer;
  • failed import and failed pointer publication;
  • same-id import and multi-tab pointer conflict;
  • mid-load foreign-id switch.

Every divergent load-window case must preserve local material behind an explicit conflict or prevent the durable edit from starting.

Non-goals

No document picker, account, sync, recent-files list, hidden session history, multiple open documents, or revision-based merge.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:persistenceLocal durability, recovery, import, and historybugSomething isn't workingpriority:P0Release or data-safety blockerstatus:blockedCannot proceed until its named dependency or authority is resolved

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions