Skip to content

feat(data): reconcile a shared tab's seed with the other tabs - #2629

Merged
trueadm merged 4 commits into
mainfrom
feat/data-seed-handoff
Nov 14, 2026
Merged

trueadm merged 4 commits into
mainfrom
feat/data-seed-handoff

Conversation

@trueadm

@trueadm trueadm commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Phase 6, PR 6 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), implementing plan decision 6, "Hydration and the seed". A shared tab hydrates from its page's seed without waiting, then offers each seeded read to the other tabs with its load time. A tab holding an older value takes it; a tab holding a newer one offers its own back. Every tab ends up showing the newest value, without loading.
  • A replica that joins a feed connection standing at another position than its page's seed hears a gap, so it reloads what the feed covers instead of silently missing the events in between.
  • The shared-tab browser test now also runs on the React-only page (react.html), which closes the issue's "same scenarios in both bindings" acceptance item.

Why

  • The worker holds no values of its own, so the plan's "the owner answers with what it holds" becomes tabs comparing what they hold, by the wall clock every tab and the worker share. Before this, a tab opened from a newer server render left older tabs stale, and a page served from a cache showed older values than its sibling tabs, until each read's freshness ran out. A joining tab's seed cursor was also silently replaced by the connection's position.

Changes

  • owner.ts:
    • new offer message { name, input, value, at }; replicas send it and the owner passes it on unchanged;
    • the replica offers each read its seed adopts; on receiving an offer it takes a newer value (rebase with the offer's age) or offers its own back when it holds a newer one;
    • the owner's join frame carries gap when the joining tab's cursor differs from the connection's.
  • store.ts internals: onSeed(notify) after a seed is adopted, held(entry) (the confirmed value and load time, or null for a missing, stale or loading value or a view), and an age parameter on rebase.
  • Views are not offered: their rows need their window's bounds. They still take newer records from the reads they share entities with.
  • Shelf:
    • the shared-tab e2e runs on the mixed page and on the React page; a server-rendered page starts from its seed, so it may send no reads;
    • journey titles updated (also 5b's crash test), and examples/catalog.json regenerated.
  • Docs: docs/data.md, the plan (decision 6 rewritten to match, delivery item 6), website data.mdx, llms.txt.
  • Patch changeset for octane. No PROTOCOL bump: an older tab ignores offer, and gap is an existing frame field.

Validation

  • targeted tests: the data suites, plus react-compat and react-hosted data, --project octane --project octane-prod: 20 files, 484 tests; data-owner and data-persist re-run after merging main: 97 passed.
  • new tests were mutation-checked; each fails with its mechanism removed:
    • no seed offer → both seed cases fail;
    • no counter-offer → the older-seed case fails;
    • no join gap → the feed case fails.
  • Shelf e2e (shared-tab tests on both pages, plus the worker-crash test) under Vite and Rspack: 4 passed each.
  • pnpm typecheck:files on changed files, pnpm format:files:check, pnpm examples:static: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: one message per seeded read at hydration, and one comparison per offer received; adoptSeed gains one optional callback call.
  • concise-code: src +83 −7. No new files or exports. held, onSeed and rebase's age are store internals, and offers reuse the replica's existing value path (rebase + finish).
    • Rejected: an owner-side value cache. The owner holds no values, and this would add a third copy.
    • Rejected: re-sending the seed's cursor to the owner to rewind the connection. A live connection can't rewind, and a gap reload is what a non-shared store does for a missed range.
    • Bytes, esbuild minify, devalue external:
      • the octane/data entry goes from 51,217 to 51,901 raw (+684) and from 19,849 to 20,085 gzip (+236);
      • createDataStore alone goes from 31,332 to 31,489 raw (+157) and from 12,408 to 12,471 gzip (+63).

Risk / follow-ups

  • Offers compare wall-clock load times. If a device's clock jumps backwards, a value could look older than it is; the next load or feed event corrects it.
  • The value offers are covered by unit tests only. Shelf's live feed keeps tabs current on its own, so a browser test there wouldn't exercise them.
  • Remaining phase 6 items, as separate PRs: a smaller replica bundle (the plan's bundle-cost goal), and the @octanejs/app-core worker entry.

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
Changes cross-tab synchronization and feed reconnection behavior using wall-clock timestamps; a clock skew could briefly show a stale value until the next load or feed event corrects it.

Overview
Implements hydration and seed reconciliation for cross-tab octane/data: after a tab hydrates from its server-render seed, it offers each seeded read (not views) to sibling tabs with a wall-clock load time (at). Tabs compare holdings—the older side adopts the newer value or counter-offers—so every tab converges on the freshest data without an extra network read.

The owner protocol adds offer passthrough and timestamps on shared value broadcasts. Feed join frames now set gap when the replica’s seed cursor differs from the live connection, prompting a reload of the feed’s coverage instead of silently missing events.

Store internals gain onSeed, held, and optional age on rebase to support load-time comparison. Shelf e2e runs the shared-owner scenario on both mixed and React pages; unit tests cover newer/older seeds, feed gaps, overlapping async validation, and in-flight loads.

Reviewed by Cursor Bugbot for commit a065913. 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 22:35
@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

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 3 potential issues.

Autofix Details

Bugbot Autofix prepared fixes for all 3 issues found in the latest run.

  • ✅ Fixed: Gap reload can join stale request
    • Seeds now record their wire key in askedFor via the onSeed callback, so the first reload after hydration sends fresh: true and the owner creates a new request instead of joining a potentially stale in-flight one.
  • ✅ Fixed: In-flight loads skip seed offers
    • The owner's value broadcast now carries a wall-clock at timestamp, and the replica's value() handler compares it against entry.fetchedAt, skipping and counter-offering when the local value is newer, and passing the correct age to rebase when accepting.
  • ✅ Fixed: Join skips gap without a cursor
    • The join path now sends { gap: true } when the upstream's cursor is still null but the joiner has a cursor, so the replica calls missed() and reloads covered reads to recover potentially dropped events.

Create PR

Or push these changes by commenting:

@cursor push e2b6bf1cb9
Preview (e2b6bf1cb9)
diff --git a/packages/octane/src/data/owner.ts b/packages/octane/src/data/owner.ts
--- a/packages/octane/src/data/owner.ts
+++ b/packages/octane/src/data/owner.ts
@@ -139,8 +139,14 @@ type ToReplica =
 	| { readonly t: 'failed'; readonly id: number; readonly error: unknown }
 	| { readonly t: 'frame'; readonly id: number; readonly frame: FeedFrame }
 	| { readonly t: 'end'; readonly id: number; readonly error?: unknown }
-	/** Another replica loaded a read. */
-	| { readonly t: 'value'; readonly name: string; readonly input: unknown; readonly value: unknown }
+	/** Another replica loaded a read; `at` is the wall-clock time it loaded. */
+	| {
+			readonly t: 'value';
+			readonly name: string;
+			readonly input: unknown;
+			readonly value: unknown;
+			readonly at: number;
+	  }
 	/** A value another replica holds, which the owner passes on as it came. */
 	| Offer
 	/** Another replica sent a write. */

@@ -139,8 +139,14 @@ type ToReplica =
 	| { readonly t: 'failed'; readonly id: number; readonly error: unknown }
 	| { readonly t: 'frame'; readonly id: number; readonly frame: FeedFrame }
 	| { readonly t: 'end'; readonly id: number; readonly error?: unknown }
-	/** Another replica loaded a read. */
-	| { readonly t: 'value'; readonly name: string; readonly input: unknown; readonly value: unknown }
+	/** Another replica loaded a read; `at` is the wall-clock time it loaded. */
+	| {
+			readonly t: 'value';
+			readonly name: string;
+			readonly input: unknown;
+			readonly value: unknown;
+			readonly at: number;
+	  }
 	/** A value another replica holds, which the owner passes on as it came. */
 	| Offer
 	/** Another replica sent a write. */
@@ -442,6 +448,7 @@ export function createDataOwner(options: {
 							name: payload.name,
 							input: payload.input,
 							value: reply.value,
+							at: hostDateNow(),
 						};
 						for (const port of replicas) if (!asked.get(started)!.has(port)) post(port, value);
 					},

@@ -442,6 +448,7 @@ export function createDataOwner(options: {
 							name: payload.name,
 							input: payload.input,
 							value: reply.value,
+							at: hostDateNow(),
 						};
 						for (const port of replicas) if (!asked.get(started)!.has(port)) post(port, value);
 					},
@@ -478,7 +485,9 @@ export function createDataOwner(options: {
 				id,
 				frame:
 					cursor === null
-						? {}
+						? payload.cursor !== null
+							? { gap: true }
+							: {}
 						: { cursor, gap: payload.cursor !== null && payload.cursor !== cursor },
 			} satisfies ToReplica);
 			return;

@@ -478,7 +485,9 @@ export function createDataOwner(options: {
 				id,
 				frame:
 					cursor === null
-						? {}
+						? payload.cursor !== null
+							? { gap: true }
+							: {}
 						: { cursor, gap: payload.cursor !== null && payload.cursor !== cursor },
 			} satisfies ToReplica);
 			return;
@@ -905,7 +914,12 @@ export function createReplica(
 		const held = inner.held(entry);
 		if (held) send({ t: 'offer', ...held });
 	};
-	inner.onSeed(offer);
+	inner.onSeed((entry) => {
+		const key = `read\n${entry.key}`;
+		askedFor.add(key);
+		if (askedFor.size > 512) askedFor.delete(askedFor.values().next().value!);
+		offer(entry);
+	});
 
 	/**
 	 * Take a value another replica holds, if it loaded later than the one held

@@ -905,7 +914,12 @@ export function createReplica(
 		const held = inner.held(entry);
 		if (held) send({ t: 'offer', ...held });
 	};
-	inner.onSeed(offer);
+	inner.onSeed((entry) => {
+		const key = `read\n${entry.key}`;
+		askedFor.add(key);
+		if (askedFor.size > 512) askedFor.delete(askedFor.values().next().value!);
+		offer(entry);
+	});
 
 	/**
 	 * Take a value another replica holds, if it loaded later than the one held
@@ -929,18 +943,20 @@ export function createReplica(
 	}
 
 	/** Take a value another replica loaded, for a read held here and not loading. */
-	async function value(name: string, input: unknown, raw: unknown) {
+	async function value(name: string, input: unknown, raw: unknown, at: number) {
 		const entry: Entry | undefined = inner.wireEntry(entryKey(name, input));
 		if (!entry || entry.inflight || store.retired) return;
+		if (entry.hasBase && entry.fetchedAt >= at) return offer(entry);
 		let parsed: unknown;
 		try {
 			parsed = await parse(entry.read.output, raw);
 		} catch {
 			return;
 		}
 		if (store.retired || entry.inflight || inner.entries.get(entry.key) !== entry) return;
+		if (entry.fetchedAt >= at) return;
 		const reload = new Set<Entry>();
-		inner.rebase(entry, parsed, false, reload);
+		inner.rebase(entry, parsed, false, reload, Math.max(0, hostDateNow() - at));
 		inner.finish(reload, [entry], entry.names);
 	}
 

@@ -929,18 +943,20 @@ export function createReplica(
 	}
 
 	/** Take a value another replica loaded, for a read held here and not loading. */
-	async function value(name: string, input: unknown, raw: unknown) {
+	async function value(name: string, input: unknown, raw: unknown, at: number) {
 		const entry: Entry | undefined = inner.wireEntry(entryKey(name, input));
 		if (!entry || entry.inflight || store.retired) return;
+		if (entry.hasBase && entry.fetchedAt >= at) return offer(entry);
 		let parsed: unknown;
 		try {
 			parsed = await parse(entry.read.output, raw);
 		} catch {
 			return;
 		}
 		if (store.retired || entry.inflight || inner.entries.get(entry.key) !== entry) return;
+		if (entry.fetchedAt >= at) return;
 		const reload = new Set<Entry>();
-		inner.rebase(entry, parsed, false, reload);
+		inner.rebase(entry, parsed, false, reload, Math.max(0, hostDateNow() - at));
 		inner.finish(reload, [entry], entry.names);
 	}
 
@@ -986,7 +1002,7 @@ export function createReplica(
 					feeds.get(message.id)?.end(message.error);
 					break;
 				case 'value':
-					void value(message.name, message.input, message.value);
+					void value(message.name, message.input, message.value, message.at);
 					break;
 				case 'offer':
 					void offered(message);

@@ -986,7 +1002,7 @@ export function createReplica(
 					feeds.get(message.id)?.end(message.error);
 					break;
 				case 'value':
-					void value(message.name, message.input, message.value);
+					void value(message.name, message.input, message.value, message.at);
 					break;
 				case 'offer':
 					void offered(message);

You can send follow-ups to the cloud agent here.

Comment thread packages/octane/src/data/owner.ts Resolved
Comment thread packages/octane/src/data/owner.ts Resolved
Comment thread packages/octane/src/data/owner.ts Resolved
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

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

Compares 2e135078c, the merge commit's first parent (main has moved 2 commit(s) past the pull request's recorded base cdab185da) with ad248027f 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 3.092 3.017 −0.0% −4.7% … +3.5% ⚪ within noise
octane-tsrx replace 6.925 7.217 +3.7% −7.2% … +7.8% ⚪ within noise
octane-tsrx add 2.392 2.458 +4.2% ±0.0% … +4.3% ⚪ within noise
octane-tsrx update 0.077 0.079 −0.8% −3.1% … +1.2% ⚪ within noise
octane-tsrx select 0.006 0.006 +1.4% −0.5% … +4.0% ⚪ within noise
octane-tsrx swap 0.018 0.019 −0.6% −1.6% … +1.1% ⚪ within noise
octane-tsrx remove 0.015 0.016 +2.1% −1.6% … +3.9% ⚪ within noise
octane-tsrx runlots 24.192 22.633 −5.9% −8.8% … −2.3% ⚪ within noise
octane-tsrx select_lots 0.007 0.007 +1.2% −1.8% … +5.1% ⚪ within noise
octane-tsrx clear 52.367 53.642 +1.6% −3.2% … +2.6% ⚪ within noise
octane-jsx run 4.183 4.325 −2.4% −3.8% … +1.2% ⚪ within noise
octane-jsx replace 8.825 7.400 −0.1% −23.4% … +9.9% ⚪ within noise
octane-jsx add 3.700 3.733 ±0.0% −5.4% … +6.3% ⚪ within noise
octane-jsx update 0.183 0.199 −0.0% −4.3% … +3.9% ⚪ within noise
octane-jsx select 0.096 0.093 −2.8% −4.4% … +2.9% ⚪ within noise
octane-jsx swap 0.140 0.142 −0.3% −2.2% … +0.6% ⚪ within noise
octane-jsx remove 0.141 0.146 −0.5% −9.7% … +5.8% ⚪ within noise
octane-jsx runlots 34.108 34.675 +3.8% −14.8% … +11.4% ⚪ within noise
octane-jsx select_lots 1.062 1.022 +1.6% −0.8% … +4.3% ⚪ within noise
octane-jsx clear 55.242 53.758 −1.1% −3.2% … +2.1% ⚪ 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.

…d reads reload fresh; gap on a cursorless join
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website-mcp a065913 Commit Preview URL

Branch Preview URL
Nov 13 2026, 11:14 PM

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix prepared fixes for both issues found in the latest run.

  • ✅ Fixed: Older load can overwrite newer value
    • Added a post-parse freshness guard if (entry.hasBase && at <= entry.fetchedAt) return; in value() to match the same pattern offered() already uses, preventing a stale payload from overwriting a newer one adopted during await parse.
  • ✅ Fixed: Missing value timestamp breaks freshness
    • Defaulted message.at to hostDateNow() via message.at ?? hostDateNow() at the call site so an older owner that omits the field produces a usable timestamp instead of NaN.

Create PR

Or push these changes by commenting:

@cursor push d7b521a1a2
Preview (d7b521a1a2)
diff --git a/packages/octane/src/data/owner.ts b/packages/octane/src/data/owner.ts
--- a/packages/octane/src/data/owner.ts
+++ b/packages/octane/src/data/owner.ts
@@ -960,6 +960,7 @@ export function createReplica(
 			return;
 		}
 		if (store.retired || entry.inflight || inner.entries.get(entry.key) !== entry) return;
+		if (entry.hasBase && at <= entry.fetchedAt) return;
 		const reload = new Set<Entry>();
 		inner.rebase(entry, parsed, false, reload, Math.max(0, hostDateNow() - at));
 		inner.finish(reload, [entry], entry.names);

@@ -960,6 +960,7 @@ export function createReplica(
 			return;
 		}
 		if (store.retired || entry.inflight || inner.entries.get(entry.key) !== entry) return;
+		if (entry.hasBase && at <= entry.fetchedAt) return;
 		const reload = new Set<Entry>();
 		inner.rebase(entry, parsed, false, reload, Math.max(0, hostDateNow() - at));
 		inner.finish(reload, [entry], entry.names);
@@ -1007,7 +1008,7 @@ export function createReplica(
 					feeds.get(message.id)?.end(message.error);
 					break;
 				case 'value':
-					void value(message.name, message.input, message.value, message.at);
+					void value(message.name, message.input, message.value, message.at ?? hostDateNow());
 					break;
 				case 'offer':
 					void offered(message);

@@ -1007,7 +1008,7 @@ export function createReplica(
 					feeds.get(message.id)?.end(message.error);
 					break;
 				case 'value':
-					void value(message.name, message.input, message.value, message.at);
+					void value(message.name, message.input, message.value, message.at ?? hostDateNow());
 					break;
 				case 'offer':
 					void offered(message);

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 45b7b24. Configure here.

Comment thread packages/octane/src/data/owner.ts Resolved
Comment thread packages/octane/src/data/owner.ts Resolved
@trueadm
trueadm merged commit dd23f96 into main Nov 14, 2026
34 checks passed
@trueadm
trueadm deleted the feat/data-seed-handoff branch November 14, 2026 00:11
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