Skip to content

feat(id): PWA snapshot store + offline read restore in the browser shell (#10927 slice 1) - #12814

Open
dezren39 wants to merge 1 commit into
mainfrom
xaltha/10927-pwa-snapshot-store
Open

dezren39 wants to merge 1 commit into
mainfrom
xaltha/10927-pwa-snapshot-store

Conversation

@dezren39

@dezren39 dezren39 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Summary

First slice of #10927 (shells v1 slice 1 — PWA offline read model + catch-up). The browser shell (pkgs/id/web/src/world.ts) held all session state in memory: a reload lost the world entirely, and the reconnect cursor restarted at 0.

  • New world-snapshot-store.ts: a snapshot store keyed per host + world name, holding {world_id, last applied sequence, participants, rendered view (screen surface or text), view revision, records}. Entries are validated on load with the frame validators' shape discipline (safe non-negative integer sequences/ids, string fields, a surface the renderer accepts); a corrupt or foreign entry is ignored, never rendered and never adopted as the resume cursor. Storage failures are swallowed — the store is best-effort and never breaks the live session.
  • world.ts writes the store through on every snapshot / event / view (full, patched, form) / completed-records frame, and restores it on page load and on a world switch in connect(): participants, view and records render with no socket, the status reads "Offline — saved snapshot" with a read-only log line, and the resume cursor is seeded from the stored sequence so the join frame's after presents the last applied journal sequence across a reload. Offline stays reader-not-writer: the existing send paths refuse without an open socket (covered by test).
  • Participant badge rendering is extracted into one helper shared by the snapshot handler and the restore path.

Refs #10927 — partial slice. Remaining on the issue: re-snapshot on divergence with a history-identity check (the snapshot frame carries no history identity today — needs host/contract support), push as a re-sync hint via an F12.5 provider (the record's follow-on slice 4), and the conformance run for the shell.

Evidence

Ran locally in the sandbox (bun 1.4.4, vitest/happy-dom) at e836c39:

  • Before: bunx vitest run src/world-offline.test.ts — the 2 behavioral tests fail (no store entry written; no offline render/resume), the 3 store tests pass against the new module.
  • After: bunx vitest run src/world-offline.test.ts — 5/5 pass. Full web suite: bun run test — 42 files, 871 passed, 9 skipped, 0 failed. bun run typecheck clean.
  • Mutation check: neutering the store write-through makes both behavioral tests fail; restored and re-verified.
  • Suite registry: bash .github/scripts/check-suite-registry.sh has no complaint for the new test file (the pkgs/id/web/src/*.test.ts row covers it).

Merge Danger

Low. Web-shell-only change (TypeScript, no Rust, no wire/contract change, no new frame kinds). The store is additive: with no entry present, page behavior is byte-for-byte the old behavior. localStorage is per-origin and the key is namespaced per host+world.


Get evidence
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

First slice of #10927 (shells v1 slice 1): the browser shell now
keeps the offline read model the design record specifies — a
snapshot store (world-snapshot-store.ts) keyed per host+world,
written through from world.ts on every snapshot/event/view/records
frame, and restored on page load so the world reads fully offline
(participants, view, records) with an offline/read-only status.
The resume cursor is seeded from the stored sequence, so a join
after a reload presents the last applied journal sequence instead
of restarting at 0. Store entries are validated with the frame
validators' shape discipline; a corrupt entry is ignored.

Behavioral tests in world-offline.test.ts cover the store
round-trip/rejection, write-through, offline render after reload,
reader-not-writer offline, and resume-after-reload.

Refs #10927
@dezren39
dezren39 requested a review from a team as a code owner November 23, 2026 03:11
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 5 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 17d2b334-b9b2-4461-b196-1fb58cfe45ef
Commits

Reviewing files that changed from the base of the PR and between 6da9528 and e836c39.

Files selected for processing: 3

  • pkgs/id/web/src/world-offline.test.ts
  • pkgs/id/web/src/world-snapshot-store.ts
  • pkgs/id/web/src/world.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant