Skip to content

feat(data): settle writes in flight when the data worker crashed - #2625

Merged
trueadm merged 2 commits into
mainfrom
feat/data-crash-settle
Nov 13, 2026
Merged

trueadm merged 2 commits into
mainfrom
feat/data-crash-settle

Conversation

@trueadm

@trueadm trueadm commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Phase 6, PR 5b of the octane/data cross-tab plan (octane/data: cross-tab store ownership (RFC phase 6) #2532, RFC RFC: octane/data for composable reads, mutations, forms, and recovery #2362). If a shared data worker crashes, any journaled write it had in flight now settles on its own: each tab, once reconnected, looks up the write's receipt and keeps or rolls back the edit. The write is never sent again.
  • The new worker looks each receipt up once and gives every tab the same answer, so all tabs settle the write the same way.
  • Fixes two problems in crash recovery that the new tests turned up:
    • a tab opened after a crash could recover, and roll back, another tab's write that was still in flight;
    • a new worker could not remove a journal entry the crashed worker had written.

Why

  • Before this, a write in flight when the worker crashed stayed uncertain until the app called settle or the page reloaded. The plan's crash section says a reconnected tab settles it by asking the owner, without resending.

Changes

  • owner.ts, replica:
    • after a lost owner is reopened and answers live, the replica calls the store's internal resettle();
    • receipt reads are flagged on the wire (receipt: true, recognised by the journal's receipt name);
    • the duplicated request-sending code is shared as ask.
  • owner.ts, owner:
    • keeps receipt replies by wire key, at most 256, cleared on retire; a failed or not-ok answer is asked again;
    • tracks the writes journaled through it and leaves them out of a later recover.
  • store.ts:
    • receipt lookup and settlement are factored out of recover (receipt, settleByReceipt) and reused by resettle();
    • unjournal is called only for durable writes.
  • persist.ts: unjournal of an id this persistence never saw finds the entry by its hashed name, so it removes an entry an earlier owner journaled.
  • Shelf e2e:
    • the worker-crash test now crashes the worker while a reply is in flight, then asserts that both tabs confirm the write ("3 books · 1 read") with one write sent;
    • the dataWorker helper gains crash(), which detaches DevTools first. Otherwise Chrome holds the restarted same-name shared worker until a debugger resumes it.
  • Docs: docs/data.md, website data.mdx (the "Current limits" section is replaced by "Writes in flight when the worker crashes"), llms.txt and the plan doc. Also corrects docs/data.md, which still gave the protocol version as 3.
  • Patch changeset for octane. No PROTOCOL bump: older tabs and workers ignore or omit the new flag, and the journal filter is owner-side only.

Validation

  • targeted tests: data-persist, data-owner, data-store and the other data suites, react-compat/react-hosted data, --project octane --project octane-prod: 20 files, 478 tests (before the merge); data-persist + data-owner re-run after merging main: 188 passed.
  • new tests were mutation-checked; each fails with its mechanism removed:
    • no resettle → both crash cases fail;
    • no receipt sharing → two lookups;
    • no recover filter → the later tab looks up the in-flight write;
    • no foreign unjournal → the receipt is looked up again after a restart.
  • Shelf e2e (worker-crash and data-worker tests) under Vite and Rspack: 3 passed each. Without resettle, the crash test fails.
  • pnpm typecheck:files on changed files, pnpm format:files:check, pnpm sync clean
  • pnpm test, pnpm typecheck, full Shelf suite: left to CI
  • perf-review: node scripts/perf-review-scan.mjs → no candidates. Not a runtime hot path: the new work runs once per reconnect (resettle), once per receipt lookup, and as one string comparison per replica request.
  • concise-code: src +99 −47. No new files or exports. resettle is the only new internal; it reuses the receipt settlement that recover already did, and the replica's two request senders now share one ask.
    • Rejected: having the owner do the lookups itself. It doesn't know the receipt contract, so the worker config would need journal.receipt.
    • Rejected: broadcasting the first tab's outcome. Tabs reconnect up to 5 s apart and would miss it, so each would look it up again.
    • Bytes: the octane/data entry (esbuild minify, devalue external) goes from 50,690 to 51,217 raw (+527) and from 19,648 to 19,849 gzip (+201).

Risk / follow-ups

  • A cached "not applied" receipt is reused for the worker's lifetime (at most 256 entries). If the server applies a crashed write after the first lookup, every tab still rolls it back together, which matches what a single tab's restart recovery already does.
  • In the Shelf demo, the status line of the tab that sent the write still reads "The reply was lost" after the write settles by itself; the books show the right state.

Provenance

  • An agent produced this diff (agent-authored)

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


Note

Medium Risk
Touches cross-tab crash recovery, journal ownership, and shared receipt caching; wrong behavior could double-send writes or disagree across tabs, though the change is narrow and heavily tested.

Overview
Journaled writes that were in flight when the shared data worker crashes now settle automatically after tabs reconnect: each tab looks up the write’s receipt (confirm or rollback) without resending the write. The owner deduplicates receipt reads so every tab gets the same answer from one server lookup.

On the owner, receipt requests are flagged and cached (up to 256); journal recover omits writes still journaled on the current worker so a later tab does not steal another tab’s in-flight write. On replicas, reconnecting after a crash triggers resettle() once the account is live again.

persist.unjournal can remove journal entries written by a previous owner after a crash. store shares settleByReceipt between startup recovery and resettle, and only unjournals durable writes.

Shelf e2e simulates a crash mid-reply and asserts both tabs confirm with a single write on the wire; docs and the cross-tab plan mark phase 5b done (protocol 4 in docs).

Reviewed by Cursor Bugbot for commit 1713bd5. Bugbot is set up for automated code reviews on this repo. Configure here.

@trueadm
trueadm marked this pull request as ready for review November 13, 2026 21:48
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent feat PR: new feature or capability labels Nov 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No byte growth, no added work, and no timing changes beyond ±3%.

Compares 53a2d2beb, the merge commit's first parent with 1168d9c42 on the same runner. Any increase in a js-framework work counter fails this check; byte changes are a report. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 2.833 2.750 +0.0% −2.0% … +4.0% ⚪ within noise
octane-tsrx replace 5.658 6.208 +1.0% −5.1% … +9.5% ⚪ within noise
octane-tsrx add 2.392 2.400 ±0.0% −4.3% … +2.2% ⚪ within noise
octane-tsrx update 0.099 0.099 −0.6% −3.1% … +4.0% ⚪ within noise
octane-tsrx select 0.006 0.006 +0.0% −2.4% … +3.2% ⚪ within noise
octane-tsrx swap 0.019 0.017 −3.5% −6.9% … +0.5% ⚪ within noise
octane-tsrx remove 0.016 0.016 −2.1% −3.8% … +1.3% ⚪ within noise
octane-tsrx runlots 22.542 19.850 −2.1% −8.3% … +1.0% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 −2.1% −3.3% … +0.5% ⚪ within noise
octane-tsrx clear 47.442 44.600 −3.9% −6.6% … +0.7% ⚪ within noise
octane-jsx run 3.742 3.858 ±0.0% −2.9% … +2.9% ⚪ within noise
octane-jsx replace 7.183 7.075 +1.4% −2.6% … +5.5% ⚪ within noise
octane-jsx add 3.083 3.242 ±0.0% −3.1% … +3.3% ⚪ within noise
octane-jsx update 0.165 0.162 ±0.0% −2.0% … +1.2% ⚪ within noise
octane-jsx select 0.081 0.082 +1.0% +0.2% … +2.0% ⚪ within noise
octane-jsx swap 0.129 0.126 +0.6% −0.5% … +1.3% ⚪ within noise
octane-jsx remove 0.112 0.109 +0.3% −1.6% … +3.3% ⚪ within noise
octane-jsx runlots 26.117 28.117 +2.9% −0.9% … +6.4% ⚪ within noise
octane-jsx select_lots 0.963 0.957 +0.3% −2.7% … +3.1% ⚪ within noise
octane-jsx clear 48.050 46.800 −1.1% −2.5% … +1.9% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

No changes across 111 measured values.

Public-import reachability bundles (bytes)

No changes across 141 measured values.

@trueadm
trueadm merged commit 7a0fa8a into main Nov 13, 2026
53 of 56 checks passed
@trueadm
trueadm deleted the feat/data-crash-settle branch November 13, 2026 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent feat PR: new feature or capability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant