Repository navigation
fix(storage): merge per-device session page logs - #245
Conversation
Proposal: per-device page logs instead of branch-on-every-resumeThanks for this. The failure it targets (#113, two devices silently overwriting each other's pages) is real and worth solving, and the QA harness here is genuinely reusable. But before accepting the always-branch tradeoffs (a new session id on every cloud resume, a full history copy and re-upload per resume, one Why not conflict detectionYou were right that detection is impossible here: Drive API v3 has no conditional writes (no If-Match / etag precondition on Prior artThis is the standard answer in local-first / serverless sync, not an invention:
The pattern across the industry: systems with a server use a server sequencer (WhatsApp, Figma, Linear); systems without one all use per-writer logs. We are in the second group by design (the user's own Drive, no AgentNet server), and our payload is easier than any of the above: an append-only chat message sequence, so "merge" is just an interleave sort, no CRDT library needed. SketchKey scheme changes from flowchart TB
subgraph W["Write path: no shared keys, overwrite impossible"]
DA["Device A"] -->|append| PA["sess__devA__p0..pN"]
DB["Device B"] -->|append| PB["sess__devB__p0..pM"]
LG["Old client"] -->|append| PL["sess__p0..pK legacy chain"]
end
subgraph R["Read path, any device"]
PA --> M["interleave records by ts, deviceId"]
PB --> M
PL --> M
M --> V["one conversation, identical on every device"]
end
The #113 scenario becomes: sequenceDiagram
participant A as Device A
participant D as Drive
participant B as Device B
Note over A,B: both resume the SAME session id, both online
A->>D: append msg to sess__A__p3
B->>D: append msg to sess__B__p1
Note over D: different keys, both writes land, nothing overwritten
B->>D: list sess__*
D-->>B: chains from A and B
Note over B: merge by ts and deviceId, B sees A's turn too
Ordering: records already carry Migration: the read side treats legacy What this buys vs always-branch
DirectionI want to go this way rather than branch-per-resume. Concretely: keep this PR's QA spec and harness, rework the mechanism to device-scoped chains in |
|
sorry zo, I should have made this a draft PR — it wasn’t ready. sorry for giving you a headache, and thank you for taking the time to explain the better direction. I’ll rework it around the per-device logs you described and keep the QA harness, then test the replacement before calling it ready. |
dc5672f to
37b537a
Compare
|
Reviewed the rework at 9e8275a in depth. This is a faithful implementation of the per-device log design, and the quality is high: the One substantive defect blocks merge, and it is exactly the failure class this PR exists to eliminate: Stale local cursor permanently omits remote chains from scrollback.
Reachable scenario: device B writes some messages, then device A writes 30 or more consecutive newer messages. A's merged newest-30 window is now byte-identical to A's local window, adoption is skipped on every open, and B's older history never appears in A's scroll-up. The data is intact on disk and a fresh reader, Suggested fix (small and localized): on the equal-window skip, still adopt the merged page's Two non-blocking notes for later: a chain head that fails to decode makes Everything else is merge-ready. Fix the cursor adoption, add the regression test, and I will merge. #244 and #238 are already merged, so a quick rebase will be needed as well. |
9e8275a to
46b5258
Compare
|
Thank you — reproduced and fixed in 46b5258, rebased onto main after #238/#244. Identical newest messages now still adopt the merged cursor/hasMore, without repainting. The regression uses real SessionStore chains: B writes three older Korean messages, A writes 30 newer messages, then A reopens and scrolls up. It failed before the fix and now retrieves all of B’s messages. Post-rebase: 547 tests passed, 5 skipped; typecheck, six Chromium checks and both web builds passed. New hosted CI is running. Updated evidence is in the PR description; the sleeping phone was not rerun for this cursor-only follow-up. |
Two devices could overwrite the same cloud session page (#113). This follows Zo’s proposed per-device logs: each writer appends to its own chain, readers merge the chains, and the conversation keeps one session ID. Existing encrypted legacy pages stay readable and unchanged.
Real Mac + Seeker QA found and fixed one additional display bug: the phone skipped merged messages from the Mac when its own latest message already had the newest timestamp. Reconciliation now also checks the page contents, so earlier interleaved messages appear after restore.
Validation: both devices used the same wallet and Google Drive account, produced real model replies, continued the same conversation from independently open copies, and restored all six messages after restart. The separate live-Drive harness preserved 92 online messages and 96 after offline Korean-text writes reconnected; pagination, sealed pages, and legacy bytes were verified. Post-rebase core: 547 passed, 5 skipped; required Chromium panel checks: 6 passed; core typecheck, localhost/webview builds and isolated Android debug APK build passed.
Physical-device evidence and limits · Live-Drive receipt
Writers include a process incarnation to avoid same-device collisions; sealed pages stay immutable and pagination tracks each chain. Old clients cannot display new-format messages. This does not recover previously overwritten data or add distributed deletion tombstones or server-side fencing for timed-out uploads. Physical QA used an isolated debug package with development rootfs assets; this is not production APK release certification. No on-chain posts or transactions were made.
Refs #113. Replaces the original branch-on-resume approach. Latest follow-up:
46b5258c, rebased onto1690b0eeafter #238/#244 merged. The identical newest-page case now adopts the merged cursor and hasMore without repainting. A regression with real SessionStore device chains reproduces the pre-fix failure and verifies that B's three older Korean messages remain reachable behind A's 30 newer messages. This cursor follow-up passed the suite, typecheck, six Chromium checks and localhost/webview builds; physical-device evidence above is from the earlier six-message test. Hosted CI is running on the new head.