Repository navigation
fix(data): save a validated reply from the owner's copy, not the tab's - #2941
Conversation
Two tabs sharing an owner could reload the same read and leave the older result saved for the next session: the owner ordered live results by request but kept whichever tab's save arrived last. Each read the owner starts now has a start time later than every read before it, which its reply carries. A replica's value remembers the request that read it, and the owner does not save a value over one a newer request read. Fixes #2934
A read fetched by the shared owner crossed to the tab for validation and then crossed back in full to be saved, a second structured clone on the page. A tab now says which reads it saves, and the owner keeps its reply to each until a tab saves it. Where the tab's validator returned the value it was given, the tab's save names the request and carries no value, and the owner saves its own copy. A validator that returns another representation, and a value changed since it loaded, are sent as before. Fixes #2935
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website | d2d8cbe | Commit Preview URL Branch Preview URL |
Nov 15 2026, 10:50 PM |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website-mcp | d2d8cbe | Commit Preview URL Branch Preview URL |
Nov 15 2026, 10:51 PM |
Benchmark report🟢 No byte growth, no added work, and no timing changes beyond ±3%. Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
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. |
…ta-owner-save-unchanged # Conflicts: # docs/data.md # packages/octane/src/data/owner.ts
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Newer reply can drop unsaved keep
- Guarded kept.set so an existing entry whose at exceeds newestSaved is never overwritten; the newer tab receives kept: false and sends the full value in its save instead, preventing the older validated reply from being silently dropped.
Or push these changes by commenting:
@cursor push beb056f83b
Preview (beb056f83b)
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
@@ -497,9 +497,14 @@ export function createDataOwner(options: {
(reply) => {
if (!reply.ok) return;
// Kept for the tabs that save it, unless a newer request's reply was kept or saved.
- const newer = kept.get(cacheKey)?.at ?? newestSaved.get(cacheKey) ?? 0;
- if (asking.keep && !receipt && options.persist && newer < at) {
- kept.set(cacheKey, { at, value: reply.value });
+ const existing = kept.get(cacheKey);
+ const savedAt = newestSaved.get(cacheKey) ?? 0;
+ if (asking.keep && !receipt && options.persist && (existing?.at ?? savedAt) < at) {
+ // An unsaved kept reply must not be overwritten: the tab it was
+ // promised to will send a valueless save that needs the value here.
+ if (!existing || existing.at <= savedAt) {
+ kept.set(cacheKey, { at, value: reply.value });
+ }
}
// A newer read has replaced this one; its value is the one to share.
if (newest.get(key) !== started) return;
@@ -497,9 +497,14 @@ export function createDataOwner(options: {
(reply) => {
if (!reply.ok) return;
// Kept for the tabs that save it, unless a newer request's reply was kept or saved.
- const newer = kept.get(cacheKey)?.at ?? newestSaved.get(cacheKey) ?? 0;
- if (asking.keep && !receipt && options.persist && newer < at) {
- kept.set(cacheKey, { at, value: reply.value });
+ const existing = kept.get(cacheKey);
+ const savedAt = newestSaved.get(cacheKey) ?? 0;
+ if (asking.keep && !receipt && options.persist && (existing?.at ?? savedAt) < at) {
+ // An unsaved kept reply must not be overwritten: the tab it was
+ // promised to will send a valueless save that needs the value here.
+ if (!existing || existing.at <= savedAt) {
+ kept.set(cacheKey, { at, value: reply.value });
+ }
}
// A newer read has replaced this one; its value is the one to share.
if (newest.get(key) !== started) return;You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 885557e. Configure here.
A newer reply to the same read replaced the one the owner kept. If that newer reply was never saved, such as one that failed validation, the tab holding the earlier value had its save dropped and the value never reached the cache. The owner now keeps a reply until a tab saves it or a newer request's value, and a reply that lands meanwhile is sent back in full by its tabs.


Summary
createReplica(sharedOwner(...))andserveDataOwner({ persist }), a read fetched in the worker crossed to the page for validation, then the page posted the whole value back to be saved. That second structured clone ran on the page thread.mainis merged in, so this PR shows only this change.Why
Changes
owner.ts, tab side: a request says whether the tab saves that read (keep: the tab haspersist, the read haspersist, and it is not a view, whose saved rows are not its reply). A reply or broadcast value the owner kept is remembered by identity. At save time, a value that is still that very object is saved by token:stored.valueis left out. Anything else is sent in full as before: a validator that returned another representation, a value edited since, a primitive, a view's rows, and every later save of the same value.owner.ts, owner side: keeps a reply for each such read until a tab saves it or a newer request's value. A reply that lands while another is still kept is not kept, so its tabs send it back in full. A save without a value takes the kept reply if its request matches; if not, that reply or a newer request's value was already saved, and the save is dropped. The ordering from fix(data): keep the newest request's value in the shared owner's cache #2940 still applies, so a reply superseded while a tab validates it stays superseded.docs/data.md: the Cross-tab owner section states the guarantee and its limits.keepandkeptare optional. An older owner never sayskept, so a newer tab sends values in full; an older tab never asks tokeep, so a newer owner keeps nothing for it.Validation
pnpm format:check(not run repo-wide;pnpm format:files:checkon every changed file passes)pnpm typecheck(not run repo-wide;pnpm typecheck:fileson the changed files passes)pnpm test(not run locally; left to CI)targeted tests:
data-persist.test.tsanddata-owner.test.tsin--project octane(105 pass),react-compat/data.test.tsin--project octane-hosted-react-dev(12 pass).Failing first:
saves a value a tab validated unchanged from the owner’s copy, so no tab sends it backrecords everything two tabs post to their owner, for a tab that asked and a tab that was told the value. Before the fix it fails on thesavemessage carrying the rows; after it, no message carries them and a restarted tab still starts from the saved value with no request.Neighbouring behaviour:
saves the representation a tab’s validator returned, where it is not the owner’spins that a transforming validator's output is what is saved. Making the owner use its own copy for every save of a kept reply turns it red (expected { checked: 1 } to deeply equal { checked: 2 }). The crossing-replies test from fix(data): keep the newest request's value in the shared owner's cache #2940 uses identity validators, so it now runs through this path and covers a reply superseded while it validates.Review finding (a newer reply replacing a kept one that no tab had saved):
saves a value a tab validated when a newer reply that no tab can save lands before it doesfailed with a restart restoringKindredwhile the tab showedBeloved; it passes now.Measurement: time inside the tab's
postMessageof thesavemessage, same probe on both branches, Node 24MessageChannel, arrays of four-field objects, identity validator, median of 7:Not measured in a browser with a real SharedWorker; the issue's Chromium numbers for the same message were 0.8 ms and 8.9 ms.
perf-review:node scripts/perf-review-scan.mjsreports no candidates. Touched paths run once per request, reply or forwarded save, never per render or node. Per save the tab does oneWeakMap.get; the fast path allocates two small objects in place of cloning the value. No DOM, scheduling or compiled-output change.concise-code: src +83 −13, all inowner.ts(runtime,octane/dataonly); no new files or exports; alternatives: save the owner's reply as soon as it arrives (smaller, rejected: the tab's validation is what admits a value to the cache, and apersist: falseread would be saved), keep every reply without the tab'skeephint (about 10 lines fewer, rejected: the worker would holdpersist: falsevalues and view windows no tab saves), keep the value for every later save too (rejected: a second copy of the whole cache in worker memory); bytes: not applicable.Risk / follow-ups
Provenance
agent-authored)Note
Medium Risk
Changes the cross-tab owner persistence protocol and save ordering; optional
keep/keptpreserve older peers, but incorrect kept-state handling could corrupt the shared cache.Overview
Fixes redundant structured cloning when a tab shares an
octane/dataowner: previously a read crossed worker → page for validation, then the whole value was posted back for persistence even though the owner already held the same reply.Tabs now mark persistable reads with
keep, the owner retains eligible replies inkept, and replies/valuebroadcasts can carrykept. After an identity-preserving output validator,flushsends a save with nostored.valueand a validation token (requestedAt); the owner fills the save from its kept copy. Values still cross in full when the validator returns a different representation, the object was edited, or an older reply could not be kept.docs/data.mddocuments the guarantee and limits (persist: false, views).data-persist.test.tsadds coverage including message inspection so book titles never appear inpostMessagepayloads, ordering when a newer reply cannot be saved, and transforming validators still persisting the tab's representation.Reviewed by Cursor Bugbot for commit d2d8cbe. Bugbot is set up for automated code reviews on this repo. Configure here.