Sync: one live socket, durable save checks, lineage refusal, real-server e2e #40

Closed
kayg wants to merge 0 commits from issue/29-sync-align-2 into dev
Owner

Closes #29. Replaces #38 (its web job was never scheduled, see CI below). Aligns the editor and the server on one sync contract, and runs the browser tests against the real server.

The contract (one live socket, ADR 0012)

  • Rooms ride the live socket: {"type":"join","room":"notes/<id>","tz":"+05:30","lineage":"<l>"} → joined (with info.lineage) before any frame, or join_failed; binary frames are the room name as a lib0 var-string + one y-protocols message. left → the client rejoins.
  • Durable save checks: y-protocols custom message 100 <buf: varuint id> → 101 <buf: varuint id>, answered in order once the room's durable history position covers everything the client sent before the check. Today history is written before a room moves on, so it's immediate; the durable watermark (room/acks.rs) keeps acks honest if fan-out ever moves ahead of the fsync. That's #32's design, and it's not implemented here.
  • Lineage: a join carrying another lineage is refused with lineage_changed before anything is sent; the client also compares joined.info.lineage before applying a frame. The client then keeps only its own unsaved changes (replay against the last confirmed base) and joins fresh.

Server

  • JoinOptions.lineage, ErrorCode::LineageChanged (409, retryable, "This note changed on the server. Bringing your changes over.").
  • room/acks.rs: pending checks, durable_at(seq) after every history write (typing, API edits, outside edits).
  • New tests (crates/notes/src/tests/acks.rs): saved only after history has the change; checks answered in order (and immediately when nothing is new); an older lineage is refused and nothing is doubled; lineage survives a restart.

Editor and web

  • LiveSocket (packages/editor/src/sync/live.ts): one websocket for journal + rooms, reconnect with backoff, rejoin rooms on reconnect, room transports for the sync client.
  • NoteSession takes a transport(lineage) factory; the app uses live.room('notes/<id>', { lineage, tz }). The per-note websocket and the node stand-in server are gone; an in-memory room that mirrors the server's behaviour stays for unit tests only.

Browser tests against the real binary

  • Playwright starts calternal serve on a fresh temp data dir with --dev-user on loopback; vite preview proxies /api (incl. the live socket) to it. Seeding uses notes.create, checks use notes.get, outside edits write the file in the data dir.
  • New: two tabs + an outside edit to the file converge with no duplicates, in both editors, on the server and on disk.
  • The slow-confirmation status test now delays the live socket with routeWebSocket instead of a test-server knob.
  • Locally: 14 tests × Chromium/WebKit × 390/1440, run 3× = 144 passed, 24 skipped (WebKit has no layout-shift API; IME is driven through Chromium's DevTools protocol), 0 flaky.

Results

  • Rust: 129 tests green, fmt and clippy -D warnings clean.
  • Editor unit: 48 green; tsc and svelte-check clean.

CI

The rust job now builds the debug binary first and moves it atomically to /target/e2e-bin/<sha>/ in the whitelisted calternal-target-ci volume. The web job mounts that volume, waits for the binary (up to 15 min), then runs the browser tests against it. No runner config change was needed. I tried needs: rust first (#38), but the dependent job stayed pending forever after rust succeeded, so this forge doesn't schedule needs jobs. Note: calternal-bun-cache isn't in the runner's valid_volumes, so the bun cache volume is probably being dropped; worth adding later.

🤖 Generated with Claude Code

https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T

Closes #29. Replaces #38 (its web job was never scheduled, see CI below). Aligns the editor and the server on one sync contract, and runs the browser tests against the real server. ## The contract (one live socket, ADR 0012) - Rooms ride the live socket: `{"type":"join","room":"notes/<id>","tz":"+05:30","lineage":"<l>"}` → `joined` (with `info.lineage`) before any frame, or `join_failed`; binary frames are the room name as a lib0 var-string + one y-protocols message. `left` → the client rejoins. - **Durable save checks**: y-protocols custom message `100 <buf: varuint id>` → `101 <buf: varuint id>`, answered in order once the room's **durable** history position covers everything the client sent before the check. Today history is written before a room moves on, so it's immediate; the `durable` watermark (`room/acks.rs`) keeps acks honest if fan-out ever moves ahead of the fsync. That's #32's design, and it's not implemented here. - **Lineage**: a join carrying another lineage is refused with `lineage_changed` before anything is sent; the client also compares `joined.info.lineage` before applying a frame. The client then keeps only its own unsaved changes (replay against the last confirmed base) and joins fresh. ## Server - `JoinOptions.lineage`, `ErrorCode::LineageChanged` (409, retryable, "This note changed on the server. Bringing your changes over."). - `room/acks.rs`: pending checks, `durable_at(seq)` after every history write (typing, API edits, outside edits). - New tests (`crates/notes/src/tests/acks.rs`): saved only after history has the change; checks answered in order (and immediately when nothing is new); an older lineage is refused and nothing is doubled; lineage survives a restart. ## Editor and web - `LiveSocket` (packages/editor/src/sync/live.ts): one websocket for journal + rooms, reconnect with backoff, rejoin rooms on reconnect, room transports for the sync client. - `NoteSession` takes a `transport(lineage)` factory; the app uses `live.room('notes/<id>', { lineage, tz })`. The per-note websocket and the node stand-in server are gone; an in-memory room that mirrors the server's behaviour stays for unit tests only. ## Browser tests against the real binary - Playwright starts `calternal serve` on a fresh temp data dir with `--dev-user` on loopback; `vite preview` proxies `/api` (incl. the live socket) to it. Seeding uses `notes.create`, checks use `notes.get`, outside edits write the file in the data dir. - **New**: two tabs + an outside edit to the file converge with no duplicates, in both editors, on the server and on disk. - The slow-confirmation status test now delays the live socket with `routeWebSocket` instead of a test-server knob. - Locally: 14 tests × Chromium/WebKit × 390/1440, run 3× = 144 passed, 24 skipped (WebKit has no layout-shift API; IME is driven through Chromium's DevTools protocol), 0 flaky. ## Results - Rust: 129 tests green, fmt and clippy `-D warnings` clean. - Editor unit: 48 green; `tsc` and `svelte-check` clean. ## CI The rust job now builds the debug binary first and moves it atomically to `/target/e2e-bin/<sha>/` in the whitelisted `calternal-target-ci` volume. The web job mounts that volume, waits for the binary (up to 15 min), then runs the browser tests against it. No runner config change was needed. I tried `needs: rust` first (#38), but the dependent job stayed pending forever after rust succeeded, so this forge doesn't schedule `needs` jobs. Note: `calternal-bun-cache` isn't in the runner's `valid_volumes`, so the bun cache volume is probably being dropped; worth adding later. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Sync: one live socket, durable save checks, lineage refusal, real-server e2e
Some checks failed
CI / rust (pull_request) Successful in 38s
CI / web (pull_request) Has been cancelled
1c7965fce1
Server (crates/notes, crates/server, crates/core):
- Save checks: a y-protocols custom message `100 <buf: varuint id>` is
  answered with `101 <id>` once the room's durable history position has
  reached everything the client sent before it. Today that is immediate
  (history is written before a room moves on); the `durable` watermark
  keeps acks correct if fan-out ever happens before the fsync (#32).
- Lineage: `join` carries the lineage of the client's copy; a room on
  another lineage refuses with `lineage_changed` before sending anything.
- New tests: saved only after history has the change, checks answered in
  order, older lineage refused, lineage survives a restart.

Editor and web:
- Notes sync as rooms on the one live socket (`LiveSocket`), next to the
  journal; the per-note websocket is gone. The client also checks the
  lineage in `joined` before applying a frame.
- Browser tests run against the real `calternal` binary (temp data dir,
  --dev-user on loopback) through vite preview's proxy; the stand-in node
  server is gone (an in-memory room remains for unit tests only).
- New e2e: two tabs plus an outside edit to the file converge with no
  duplicates, in the editors, on the server and on disk.

CI: the rust job leaves the debug binary per commit in the target volume;
the web job (needs: rust) runs the browser tests against it.

Closes #29

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
CI: the web job waits for the rust job's binary instead of needs
Some checks failed
CI / rust (pull_request) Successful in 39s
CI / web (pull_request) Failing after 57s
26b44ce30c
A job with `needs: rust` was never scheduled on this forge (it stayed
pending after rust succeeded). The rust job now builds the server first
and moves it into place atomically; the web job waits for it (up to 15
minutes) and then runs the browser tests.

Part of #29

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Author
Owner

Superseded by #41: same work plus the IME test fix CI caught here (insert at the body start, after the server frontmatter).

Superseded by #41: same work plus the IME test fix CI caught here (insert at the body start, after the server frontmatter).
kayg closed this pull request 2026-10-13 18:25:40 +00:00
Some checks failed
CI / rust (pull_request) Successful in 39s
CI / web (pull_request) Failing after 57s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal!40
No description provided.