Skip to content

Cross-device concurrent resume: two writers mint the same session pages and clobber each other's cloud copy #113

Open

Description

@zo-sol

Measured on-device (2026-07-11, Seeker + desktop)

While verifying #107, the phone cross-device-resumed a session the desktop was STILL actively writing (d02a0fb7…). Both devices then appended independently:

  • Phone local tier: pages p25-p29 written 07:12-07:32Z (decrypted: the phone-side conversation, Seeker device stamp)
  • Desktop: kept appending its own p25-p29+ for the same session through the afternoon
  • Cloud now holds the desktop's content for those page keys (last flush wins); the phone's branch survives only in the phone's local tier

Why it happens

SessionStore.lastPageIndex() picks the next page from what the opener can SEE at resume time; two live writers each think they own page N. Page keys are {sessionId}__p{N} with no writer fencing, so cloud uploads for the same key race and the loser's branch silently disappears from the cloud (still present in that device's local tier — nothing is unrecoverable today, but the cloud copy is a coin flip per page).

Impact

Direction options (not decided)

  1. Single-writer lease: a tiny {sessionId}__writer blob (device id + heartbeat ts); a second opener gets read-only or forks
  2. Fork-on-conflict: second concurrent writer mints a new sessionId branching at the resume point (cheap, no coordination, matches the local-first model)
  3. Per-device page namespaces + merge-on-read (heavier, but no data ever lost)

Related: #107 (how it was found), #100 (cross-surface QA).

Activity

  1. RemilioNubilio commented on Aug 22, 2026

    @RemilioNubilio
    Contributor

    I would take option 2. A lease (option 1) adds a coordination blob plus heartbeat expiry semantics, and a stale lease on a dead device blocks resume, which is the wrong failure mode for local-first. Option 3 changes the page key scheme and needs merge-on-read everywhere pages are decoded.

    Option 2 is now mostly reuse: SessionStore.fork() landed in packages/core/src/account/store.ts (line 216) and already does the hard part, re-encoding every page under a fresh sessionId with correct per-page meta, with upTo to branch at the resume point. What is left is detection and wiring:

    • at resume, remember the page index and message count the opener saw
    • before append, if the current page already holds records this writer did not observe, call fork(srcId, newId, title, upTo) at the observed count and continue on the new id
    • surface the fork in listMine so the user sees both branches instead of a silent split

    No new storage shapes, no fencing, both branches keep a cloud copy. Happy to build this if you want it. Say the word and I will put up a PR.

  2. NubsCarson commented on Sep 19, 2026

    @NubsCarson
    Contributor

    Updating the old status here: #245 merged on September 17 and addresses the concurrent-writer overwrite with per-device append-only logs merged into one session. It supersedes my earlier fork-on-conflict suggestion.

    The PR includes Mac + Seeker and live Drive evidence, plus the pagination regression follow-up. Existing legacy pages remain readable; this does not recover already-overwritten data, and old clients cannot read the new-format messages. Thanks for guiding the implementation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions