Skip to content

fix(octane): resume a query read only through a declared handle on the server - #1766

Merged
trueadm merged 2 commits into
mainfrom
fix/declared-read-server-observation
Oct 5, 2026
Merged

trueadm merged 2 commits into
mainfrom
fix/declared-read-server-observation

Conversation

@trueadm

@trueadm trueadm commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A query$ read only through #1706's lexical __declared(x$) path now resumes during hydration. Before this change, the server never announced the query to the browser. Hydration then threw client error 267 ("The streamed signal selection bootstrap is missing or incompatible"), or, when the page streamed another query, loaded this one again in the browser.

function Render(props) @{
 <div>{props.render}</div>
}
export function App(props) @{
 const record$ = query$(() => 'record', props.load);
 @try {
  <Render render={() => @{ const label = 'x'; <p title={label}><output>{record$.get() as string}</output></p> }} />
 } @pending {
  <i>waiting</i>
 }
}

record$.get() in the render prop compiles to __declared(record$).get(). That read resolves App's cell, as it should; the browser-only case already started one query. On the server, though, the read runs while Render's render-prop body is rendering. serverSignalQueryAttemptObserver accepts only the rendering owner and its enclosingOwner chain, and App is not on that chain. So the attempt went unobserved: the HTML carried the server's value and seed, but no streamed selection.

Why this design

There were two options: let the observer also accept the descriptor's declaring owner, or have the lexical copy run its reads under an observer for its declaring owner. This PR takes the second.

  • The facade already treats a lexical use as its declaring owner's read. reader() returns this.owner for the lexical copy, so its server observation should match. The observer's rule stays the same: the rendering owner and its enclosing chain.
  • The observer can't see the descriptor. Entry.observe passes only the cell's scope key. Accepting "the declaring owner" there would need a side channel from the facade, or acceptance of any owner in the same document, which widens what every render may announce.
  • The enclosing-chain walk starts from the declaring owner. A keyed row can declare derived$(() => record$.get()), and a render prop can read it through the row's handle. The component's query is then found through the row's enclosingOwner. Accepting only the declaring owner exactly would still drop it; a mutation that does so fails the new row test.
  • fix(octane): share captured signal declarations across a component's arms and rows #1530's reader-owned contract is untouched. Handles passed as values, such as props, read(x$) and producer closures, never take the lexical path. Their resolution and observation are unchanged.

Changes

  • signals/query-attempt-observer.ts: adds runAsDeclaredServerSignalReader(owner, read).
    • With an active server observer, it runs read under the same request's observe and createObservations, re-scoped to the declaring owner.
    • It does nothing when no observer is active, as in the browser, or when the observer is already that owner.
    • It also does nothing when the declaring owner belongs to another document. A callback kept from one request and called while another request renders can't announce the first request's query in the second response.
  • signals/facade.ts: get, snapshot, latest and [SIGNAL_BINDING_READ] go through that helper only when this.lexical === this. The non-lexical path still makes its direct call, with no closure.
    • Writes need no wrapper, because a render already rejects them (assertWritable).
    • [SIGNAL_BINDING_READ] matters because __startSignalReads uses it. A server cell observes its attempt only on its first compute, so an unwrapped early start would lose the observation for good.
  • Changeset: octane patch.

Validation

  • pnpm format:check: not run repo-wide. format:files:check passed on every changed file.
  • pnpm typecheck: not run repo-wide. typecheck:files passed on all four changed source and test files.
  • pnpm test: not run locally; CI runs it.
  • targeted tests:
    • hydration/signal-declaration-owner.test.ts:
      • A new renderprop frame joins the existing matrix: one browser query, the server query resumed with a setup read, and with frame reads only.
      • New row cases: a row-declared derived value read by a render prop, in the browser and through hydration.
      • Results: 100/100 in octane (dev) and 200/200 in octane-prod (prod and strong).
    • signals-query-attempt-observer.test.ts (octane-signals), 2/2, with a new observer-level case:
      • a lexical read from a non-enclosing renderer in the same document is observed under the declaring owner's keys;
      • the same read from another document whose scope key is equal is not observed.
  • Fails without the fix: with only the source reverted, 5 tests fail in octane: the 4 read only by 'renderprop' … frames cases and the row hydration case. Run alone, a frames case throws error 267, as reported. After an earlier case has installed the selection mailbox, the same defect shows as a browser reload. That happens because resetStreamRuntimeGlobals doesn't clear the mailbox.
  • Pinned by mutations:
    • re-scoping to the declaring owner without its enclosingOwner chain fails the row hydration case;
    • dropping the document check fails the observer test;
    • reverting the facade fails the observer test.
  • Bundle size:
    • run-minimal.mjs --budgets and run.mjs --budgets octane-tsrx octane-jsx both hold, so no budget PR is needed.
    • The minified octane/signals entry (esbuild, production) grows by 388 B raw, 73 B gzip and 46 B brotli.

Risk / follow-ups

  • fix(octane): resolve a component's signal handles from its nested @{ … } blocks #1761 has merged. Merging main into this branch kept its block and row block frames beside this PR's renderprop frame in frames(). On the merged tree the file passes 135/135 in octane. The two changes compose: fix(octane): resolve a component's signal handles from its nested @{ … } blocks #1761 links a render function rendered as a child to the component rendering it, and lexical reads still resolve, and now observe, through their declaring owner.
  • Pre-existing, not changed here:
    • A server cell observes its attempt only on its first compute. If an unobserved context, such as another request, computes a cell first, a later observed read does not announce it.
    • The observer's exact-key match compares strings. Two requests that both use the default document key and the same instance key cannot be told apart through that match.
    • Both are outside this fix.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
Changes server query-attempt observation and hydration streaming for lexical signal reads; scoped to __declared paths with a document guard, but mistakes could leak or miss streamed selections.

Overview
Fixes SSR/hydration when a query$ is read only from a closure the declaring component created (e.g. a render prop), where the read runs under another component’s renderer owner so the server never streamed the query selection.

Lexical __declared reads on the signal facade (get, snapshot, latest, and binding reads) now run through runAsDeclaredServerSignalReader, which temporarily re-attaches the active server query-attempt observer to the declaring owner (still walking enclosingOwner for row-derived reads) while skipping cross-document callbacks. Non-lexical handles passed as props are unchanged.

Adds a renderprop hydration matrix case, row + render-prop client/SSR tests, and an observer unit test for same-document vs other-request isolation. octane patch changeset.

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

…on the server

A function a component body creates reads the handles it closes over through
`__declared`, which resolves the declaring owner's cell wherever the function
renders. The server's query-attempt observer only accepted the rendering
owner and its enclosing chain. A render prop rendered inside another
component therefore started the declaring owner's query unobserved, and the
server announced no streamed selection. Hydration then loaded the query again,
or threw client error 267 when the page streamed no other query.

A lexical handle's reads now run under the observer re-scoped to the
declaring owner, for the same request's document only. The observer's walk up
enclosing owners then starts from the declaring owner, so a row's derived
value that reads the component's query is announced too. Handles passed as
values keep their reader-owned resolution and observation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 5, 2026
@trueadm
trueadm marked this pull request as ready for review October 5, 2026 12:24
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 2 value(s) increased within budget

Compares 9c8429317, the merge commit's first parent with cb0d5f2de on the same runner. A byte value over its committed budget or any increase in a js-framework work counter fails this check. 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.017 2.917 −1.4% −3.6% … +0.0% ⚪ within noise
octane-tsrx replace 8.208 7.725 +3.2% −1.8% … +9.0% ⚪ within noise
octane-tsrx add 2.242 2.300 +4.3% ±0.0% … +4.5% ⚪ within noise
octane-tsrx update 0.125 0.123 −1.8% −2.1% … +2.8% ⚪ within noise
octane-tsrx select 0.005 0.005 +3.7% +0.5% … +5.6% ⚪ within noise
octane-tsrx swap 0.033 0.033 −0.4% −3.0% … +0.7% ⚪ within noise
octane-tsrx remove 0.016 0.016 −0.8% −2.6% … +0.4% ⚪ within noise
octane-tsrx runlots 23.533 24.275 +1.5% −2.8% … +2.9% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 ±0.0% −1.0% … +0.7% ⚪ within noise
octane-tsrx clear 39.900 38.992 −0.8% −2.0% … +0.4% ⚪ within noise
octane-jsx run 3.192 3.233 +3.0% −0.0% … +4.2% ⚪ within noise
octane-jsx replace 5.975 5.875 ±0.0% −2.4% … +1.6% ⚪ within noise
octane-jsx add 2.892 2.917 ±0.0% −3.3% … +0.0% ⚪ within noise
octane-jsx update 0.237 0.235 −0.0% −3.6% … +1.3% ⚪ within noise
octane-jsx select 0.123 0.119 −0.2% −3.9% … +1.0% ⚪ within noise
octane-jsx swap 0.219 0.215 −0.3% −1.1% … +1.9% ⚪ within noise
octane-jsx remove 0.169 0.168 −0.0% −0.6% … +0.9% ⚪ within noise
octane-jsx runlots 26.542 27.283 +0.9% −2.8% … +3.0% ⚪ within noise
octane-jsx select_lots 1.401 1.416 +0.6% −0.6% … +1.5% ⚪ within noise
octane-jsx clear 42.550 42.675 +0.1% −1.2% … +1.6% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx bindings_js_gzip 239,552 239,539 −13 (−0.0%) 🟢
octane-tsrx bindings_js_brotli 204,091 204,213 +122 (+0.1%) 🔴
octane-tsrx bindings_app_gzip 121,383 121,370 −13 (−0.0%) 🟢
octane-tsrx bindings_app_brotli 101,517 101,639 +122 (+0.1%) 🔴

56 other measured values are unchanged.

Public-import reachability bundles (bytes)

No changes across 105 measured values.

…ver-observation

# Conflicts:
#	packages/octane/tests/hydration/signal-declaration-owner.test.ts
@trueadm
trueadm merged commit 6182678 into main Oct 5, 2026
31 checks passed
@trueadm
trueadm deleted the fix/declared-read-server-observation branch October 5, 2026 21:04
trueadm added a commit that referenced this pull request Oct 5, 2026
…#1772 and #1794

Same method as before: each budget is main's value minus the measured
esbuild-to-Oxc difference on the merged source, never raised (131
lowered, 28 unchanged). The baseline record and home summary follow the
new bytes; every ratio guard still holds with the ceilings already cut.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm added a commit that referenced this pull request Oct 6, 2026
* ci(bench): measure bundle sizes with Vite 8's default minifier

The bundle-size and bundle-reachability harnesses forced Vite's
`minify: 'esbuild'`. That mode turns Rolldown's own minifier off, and with
it the dead-code elimination that removes branches guarded by a
never-written module flag, so the numbers were not what a Vite app ships.

- run.mjs builds every framework with `minify: 'oxc'` (Vite 8's default
  client minifier), still identical settings for every target.
- run-minimal.mjs builds its Vite scenarios with `'oxc'`; the esbuild
  bundler scenarios keep esbuild's `minify: true`. The async-identity
  encoder check accepts Oxc's template-literal quotes.
- Every budget is ratcheted down (144 lowered, 15 unchanged, 0 raised),
  the bundle-size baseline is re-recorded, the 18 cross-framework ratio
  guards are re-cut, and the website summary and copy follow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci(bench): re-measure the Oxc budgets on main with #1761 and #1782

Budgets move by the measured esbuild-to-Oxc difference on the same
source (budget - max(0, esbuild - oxc)), so the methodology change
lowers 131 values, keeps 28, raises none, and leaves the headroom #1782
granted to #1783 in place. The baseline, ratio guards and website
summary are recomputed from the merged source.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(website): compare home summary ceilings at stable precision

The smoke test rounds each summary row to 15 significant digits because
Math.log/exp can differ by one ULP between libc implementations, but it
compared the bundle-size range ends exactly. Those ends are geometric
means too: the recorded Solid ceiling was 0.9500824085923075 on macOS and
0.9500824085923076 on the Linux runner. Round them the same way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci(bench): re-derive the Oxc budgets on main with #1766, #1768, #1770, #1772 and #1794

Same method as before: each budget is main's value minus the measured
esbuild-to-Oxc difference on the merged source, never raised (131
lowered, 28 unchanged). The baseline record and home summary follow the
new bytes; every ratio guard still holds with the ceilings already cut.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci(bench): re-derive the Oxc budgets on main with #1783

#1783 landed and spent the headroom #1782/#1793/#1794 granted it. Each
budget is again main's value minus the measured esbuild-to-Oxc
difference on the merged source (131 lowered, 28 unchanged, none
raised). The baseline record, home summary and refresh note follow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci(bench): re-cut the cross-framework ratio guards after #1784

With #1784's hydrating flag folded by Oxc, Octane's totals shrink 8.5-10%
instead of about 5%, so the total-gzip ceilings had grown about 6% loose.
They are re-cut at about 1.5% headroom on the merged-source measurement;
application-code ceilings are unchanged. All 72 bundle-size guards hold.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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 fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant