Skip to content

fix(octane): re-select component-local query$ when captured props change - #1550

Merged
trueadm merged 4 commits into
mainfrom
fix/local-query-selector-redeclaration
Oct 2, 2026
Merged

trueadm merged 4 commits into
mainfrom
fix/local-query-selector-redeclaration

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • A component-local query$ whose selector captures props now re-selects when those props change. Previously it kept its first render's closure forever, apart from a narrow window while a pending @try re-created its reader owner.
  • A synchronous component-local derived$ now recomputes from captured props for the same reason.
  • A render that is later discarded (a held transition, a suspended attempt, a rolled-back transition attempt) never changes what committed readers see.

Why

ScopeImpl.declaredNode was first-declaration-wins. The compiler declares __queryAt/__derivedAt again on every render, with closures that capture that render's props, but the existing node kept the first describe/compute. Rebinding the closure in place during render would expose speculative state, which is the hazard the docs/signals.md local-derived note described.

Changes

  • Staging. RedeclarableBinding (signals/redeclaration.ts) is the new base of ResourceBinding, DerivedBinding and ScalarBinding. Each instance (i:) declaration carries a sequence number, so an older closure never rebinds a cell. Module (g:) sites and uncompiled explicit keys keep first-declaration-wins (pinned by signals-unified).
  • Renderer hook. The renderer registers a declaration stage per body invocation (registerSignalDeclarationStage). The stage lives on the native read driver's render frame, so applications without signals pay nothing in bytes or per render. It settles on capture commit/discard, and on transition-journal rollback.
  • Frozen documents. A frozen or read-barrier cell keeps presenting its committed value. It installs the new closure at acceptance and evaluates it when reads resume.
  • Equal result, same reads. The render reads the committed cell and the new closure is installed at commit. A dependency-capturing probe (readsDuring/readsMatch) skips a second evaluation.
  • Changed result. The render reads a private view node (createDeclarationView). Acceptance promotes it: state, dependencies and subscribers move to the cell, and the view's native sources forward, so render witnesses stay valid. The previous request is released, and aborted when nothing else selects it. A newer selection or unmount releases an unaccepted view. Query views are reused by request identity, so a retried held render adopts its pending request instead of refetching.
  • Signal-write transitions. Candidate frames fork a view like the cell it presents (declarationViewFork).
  • Loaders. A redeclared facade may replace its own loader closure without tripping the incompatible-loader check (202). Private forks and views publish their definition only on acceptance.
  • Asynchronous derived$. It has no selection identity to match a retried render against, so a render that may be discarded never presents its async work. The attempt is adopted on acceptance and released on discard. An already-asynchronous cell adopts a new closure for its next signal-driven restart without restarting. Documented: use query$ for async work keyed by render values.
  • Docs and changeset. docs/signals.md is updated, and an octane patch changeset is added.

Validation

  • pnpm format:check (not run repo-wide; pnpm format:files:check on every changed file passes)
  • pnpm typecheck (not run repo-wide; tsgo on packages/octane/tsconfig.json, typetests/tsconfig.json and typetests/signals-engine-node, plus typecheck:files on the changed files, all pass)
  • pnpm test (not run end to end; see the targeted runs below)
  • targeted tests:
    • New packages/octane/tests/signal-local-selectors.test.ts and hydration/signal-local-selectors.test.ts pass in dev (octane), prod and strong (octane-prod). They cover mount/update, abort and dedupe, inline loaders, signal dependencies of an adopted closure, selector failure, effects, render-phase reruns, @try strict reads, held/superseded/abandoned transitions, unmount during a hold, signal-write transitions, synchronous and asynchronous derived$, and SSR → hydrate.
    • All new tests failed on the original source. Each guard was checked by breaking it: naive rebinding during render fails the three transition tests; skipping closure adoption, presenting async derived work (refetch loop), dropping the unmount release, and per-capture instead of per-invocation stages each fail their test.
    • Before merging main: full octane + octane-prod (1293 files, 35758 passed) and all octane-signals* projects (57 files, 987 passed). pnpm ci:workflow:test (302 passed, including the signals bundle-boundary and minimal-size gates).
    • After merging main (fix(octane): share captured signal declarations across a component's arms and rows #1530 overlaps facade.ts) and addressing review (bf6b50d): full octane + octane-prod (1305 files, 36179 passed) and all octane-signals* projects (55 files, 984 passed). pnpm test:markers:check, format:files:check, typecheck:files and pnpm sync are clean.
    • Bundle size: benchmarks/bundle-size/run-minimal.mjs matches the base raw sizes in the PR bench report (for example deferred-hydration 218779, binding-hooks 87175, binding-base-ui-vite 210679). The first push's +36 bytes came from a renderBlockInner change that is now gone.

Risk / follow-ups

  • Per-render cost. Components with local declarations now evaluate the new closure on each redeclaring render. Ad-hoc jsdom timing, 200 rows re-rendered by an unrelated parent update, same machine state:

    List Before After
    Plain components ~0.15 ms ~0.15 ms (unchanged)
    Local query$ ~0.25–0.30 ms ~0.32–0.37 ms
    Local derived$ ~0.24–0.26 ms ~0.33–0.37 ms

    Most of the difference is work the old code wrongly skipped. No existing benchmark covers component-local redeclaration.

  • Async derived$ flip. An asynchronous derived$ that becomes asynchronous through captured props (props.id ? load(props.id) : 'none') presents the committed value for one commit, then its fallback, then the result. It starts its work once.

  • Abandoned held selection. A held selection that an urgent update abandons keeps loading until a newer selection replaces it or the component unmounts.

  • Hydration timing gap. Changing props before hydration adoption has released is untested.

  • Custom-hook aliasing. Two calls of one custom hook currently alias to one cell; the separate fix (fix/custom-hook-signal-declarations) changes the same facade lines. Until then that case makes two extra requests over its first two renders before settling.

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

High Risk
Touches core signal graph commit semantics, query request lifecycle, and transition/suspense staging; regressions would affect data loading and speculative renders across the runtime.

Overview
Fixes component-local query$ and synchronous derived$ so each render’s selector/compute closure can update when props or state change, instead of staying pinned to the first render.

Staging and commit. Repeated instance (i:) declarations go through RedeclarableBinding: the renderer’s per-invocation declaration stage settles on accept/discard (including transition rollback). Equal canonical selections keep the in-flight request and adopt new loader/selector closures without refetching; changed selections use private declaration view nodes until commit, then promote state and release obsolete requests. Discarded transitions and suspended attempts never change what committed readers see; held query$ work can be reused on retry.

Derived and queries. DerivedBinding, ScalarBinding, and ResourceBinding share the same redeclaration path (probes via readsDuring / readsMatch). Async derived$ does not expose speculative async work; new closures apply on the next dependency-driven restart—docs steer keyed async work to query$.

Adds docs/signals.md updates, an octane patch changeset, and broad client/hydration tests for selectors, transitions, render-phase reruns, and local derived behavior.

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

trueadm and others added 3 commits October 2, 2026 08:44
A query$ or derived$ declared in a component kept the closure from its first
render: ScopeImpl's declared nodes were first-declaration-wins, so a selector
that captured props never re-selected after its first settle.

Each render's declaration is now staged with the renderer. An equal selection
or value keeps the committed cell and adopts the new closure at commit. A
changed one is presented through a private view node, which acceptance
promotes and a newer selection or unmount releases. A held transition or
discarded attempt never changes what committed readers see, and a retried
render reuses the held request instead of refetching it. Asynchronous derived$
work is never presented by a render that may be discarded; captured render
values alone do not restart it, so query$ stays the keyed async primitive.

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

# Conflicts:
#	packages/octane/src/signals/facade.ts
A cold compile under heavy load spent the first test's five-second budget.
Collection has no test timeout.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm marked this pull request as ready for review October 2, 2026 08:35
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 2, 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 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Barrier redeclarations hide ready values
    • Added early return in both DerivedBinding.presentDefinition and ScalarBinding.presentDefinition when frozen or under a read barrier, so the committed cell's ready state is preserved instead of creating a stateless view that yields pendingState.

Create PR

Or push these changes by commenting:

@cursor push 34083ca941
Preview (34083ca941)
diff --git a/packages/octane/src/signals/computations.ts b/packages/octane/src/signals/computations.ts
--- a/packages/octane/src/signals/computations.ts
+++ b/packages/octane/src/signals/computations.ts
@@ -175,6 +175,7 @@
 
 	protected presentDefinition(compute: DerivedCompute<T>): ScopedNode | undefined {
 		if (this.asynchronous) return undefined;
+		if (this.frozen || this.owner.readBarrier !== undefined) return undefined;
 		// A zero-argument computation runs once here. An equal synchronous value
 		// needs no view; any other result seeds the view, so the closure never
 		// runs twice and asynchronous work never starts twice.

diff --git a/packages/octane/src/signals/scalar-computations.ts b/packages/octane/src/signals/scalar-computations.ts
--- a/packages/octane/src/signals/scalar-computations.ts
+++ b/packages/octane/src/signals/scalar-computations.ts
@@ -88,6 +88,7 @@
 
 	/** An equal value needs no view; a changed one is evaluated once, privately. */
 	protected presentDefinition(compute: DerivedCompute<T>): ScopedNode | undefined {
+		if (this.frozen || this.owner.readBarrier !== undefined) return undefined;
 		let probe: { value: T; reads: ScopedNode[] } | undefined;
 		if (!this.frozen && this.owner.readBarrier === undefined) {
 			try {

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

Reviewed by Cursor Bugbot for commit 5007de8. Configure here.

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🟡 js-framework: 1 timed operation(s) possibly slower
  • 🔴 bundle-reachability: 6 value(s) increased

Compares 5f354d23e with 3132e039b on the same runner. Timing verdicts require a change beyond the combined margin of error (at least 5%) and one 0.1ms timer tick, with the fastest sample also moving beyond that margin. Workflow run

js-framework: 1k/10k row operations (ms, lower is better)

target operation base head Δ noise
octane-jsx swap 0.59 0.86 +45.8% ±32% 🟡 slower
All 20 timed operations (19 within noise)
target operation base head Δ noise
octane-tsrx run 3.63 3.51 −3.3% ±21% ⚪ within noise
octane-tsrx replace 8.51 7.08 −16.8% ±38% ⚪ within noise
octane-tsrx add 3.71 3.72 +0.3% ±23% ⚪ within noise
octane-tsrx update 0.46 0.37 −19.6% ±48% ⚪ within noise
octane-tsrx select 0.21 0.20 −4.8% ±56% ⚪ within noise
octane-tsrx swap 0.46 0.40 −13.0% ±40% ⚪ within noise
octane-tsrx remove 0.66 0.41 −37.9% ±72% ⚪ within noise
octane-tsrx runlots 30.66 31.06 +1.3% ±21% ⚪ within noise
octane-tsrx select_lots 0.29 0.28 −3.4% ±52% ⚪ within noise
octane-tsrx clear 48.46 45.55 −6.0% ±9% ⚪ within noise
octane-jsx run 3.86 3.69 −4.4% ±19% ⚪ within noise
octane-jsx replace 9.50 8.49 −10.6% ±55% ⚪ within noise
octane-jsx add 3.61 3.47 −3.9% ±26% ⚪ within noise
octane-jsx update 0.71 0.63 −11.3% ±40% ⚪ within noise
octane-jsx select 0.48 0.59 +22.9% ±46% ⚪ within noise
octane-jsx swap 0.59 0.86 +45.8% ±32% 🟡 slower
octane-jsx remove 0.63 0.90 +42.9% ±57% ⚪ within noise
octane-jsx runlots 28.78 29.77 +3.4% ±20% ⚪ within noise
octane-jsx select_lots 2.65 2.60 −1.9% ±29% ⚪ within noise
octane-jsx clear 47.98 50.34 +4.9% ±12% ⚪ within noise

Application bundle size (bytes)

No changes across 45 measured values.

Public-import reachability bundles (bytes)

target metric base head Δ
binding-base-ui-esbuild gzip 67,114 67,113 −1 (−0.0%) 🟢
binding-base-ui-esbuild brotli 58,195 58,146 −49 (−0.1%) 🟢
binding-radix-esbuild brotli 58,686 58,733 +47 (+0.1%) 🔴
binding-mantine-hooks-esbuild brotli 28,883 28,906 +23 (+0.1%) 🔴
binding-apollo-client-esbuild gzip 113,475 113,476 +1 (+0.0%) 🔴
binding-apollo-client-esbuild brotli 98,872 98,874 +2 (+0.0%) 🔴
binding-usehooks-ts-esbuild gzip 32,685 32,686 +1 (+0.0%) 🔴
binding-usehooks-ts-esbuild brotli 29,016 29,036 +20 (+0.1%) 🔴

97 other measured values are unchanged.

CI job durations

  • 🟢 4 job(s) faster than every recent main run: validate publishable packages, website integration suite, test shard (Node 24, 3/4), test shard (Node 24, 4/4)

Compares the CI run for bf6b50d0b (run) with the last 5 successful main push runs. A job is only slower or faster outside the whole main range, by at least 10% and 15s. Job time excludes runner setup.

job main median main range this PR Δ
wall clock (first job start to last job end) 13m 51s 12m 39s–17m 36s 12m 48s −1m 03s (−8%) ⚪ within noise
total job time 155m 53s 140m 36s–177m 43s 134m 34s −21m 19s (−14%) 🟢 faster
validate publishable packages 4m 29s 3m 55s–5m 00s 3m 50s −39s (−14%) 🟢 faster
website integration suite 6m 21s 5m 46s–7m 00s 5m 33s −48s (−13%) 🟢 faster
test shard (Node 24, 3/4) 10m 06s 9m 24s–11m 36s 9m 04s −1m 02s (−10%) 🟢 faster
test shard (Node 24, 4/4) 11m 19s 11m 03s–14m 12s 9m 52s −1m 27s (−13%) 🟢 faster
All 26 timed jobs
job main median main range this PR Δ
React parity shard (4/4) 11m 23s 10m 43s–13m 16s 11m 37s +14s (+2%) ⚪ within noise
classify changeset release 13s 13s–15s 15s +2s (+15%) ⚪ within noise
typecheck 3s 3s–4s 3s ±0s (±0%) ⚪ within noise
examples 3s 3s–3s 3s ±0s (±0%) ⚪ within noise
lint 3s 3s–4s 3s ±0s (±0%) ⚪ within noise
React parity checks 12s 11s–15s 12s ±0s (±0%) ⚪ within noise
test (24) 3s 3s–4s 3s ±0s (±0%) ⚪ within noise
CI provenance 3s 3s–4s 3s ±0s (±0%) ⚪ within noise
example apps (1/3) 3m 14s 3m 10s–4m 01s 3m 13s −1s (−1%) ⚪ within noise
example apps (2/3) 3m 43s 3m 38s–4m 40s 3m 42s −1s (−0%) ⚪ within noise
heavy integration (package builds, eval corpus, runtime loaders, Astro) 5m 44s 5m 27s–6m 31s 5m 39s −5s (−1%) ⚪ within noise
Lynx compatibility 1m 38s 1m 32s–2m 07s 1m 32s −6s (−6%) ⚪ within noise
Three compatibility 2m 56s 2m 38s–3m 48s 2m 47s −9s (−5%) ⚪ within noise
example apps (3/3) 3m 41s 3m 19s–4m 16s 3m 20s −21s (−10%) ⚪ within noise
React parity shard (1/4) 11m 04s 10m 51s–12m 30s 10m 25s −39s (−6%) ⚪ within noise
validate publishable packages 4m 29s 3m 55s–5m 00s 3m 50s −39s (−14%) 🟢 faster
lint checks 8m 32s 7m 52s–10m 19s 7m 48s −44s (−9%) ⚪ within noise
website integration suite 6m 21s 5m 46s–7m 00s 5m 33s −48s (−13%) 🟢 faster
React parity shard (2/4) 10m 46s 9m 52s–11m 44s 9m 44s −1m 02s (−10%) ⚪ within noise
test shard (Node 24, 3/4) 10m 06s 9m 24s–11m 36s 9m 04s −1m 02s (−10%) 🟢 faster
heavy integration (browser - chromium) 12m 43s 10m 58s–16m 52s 11m 34s −1m 09s (−9%) ⚪ within noise
test shard (Node 24, 4/4) 11m 19s 11m 03s–14m 12s 9m 52s −1m 27s (−13%) 🟢 faster
test shard (Node 24, 1/4) 12m 46s 10m 36s–13m 13s 11m 19s −1m 27s (−11%) ⚪ within noise
test shard (Node 24, 2/4) 12m 22s 10m 38s–14m 29s 10m 43s −1m 39s (−13%) ⚪ within noise
React parity shard (3/4) 11m 51s 10m 08s–12m 43s 10m 09s −1m 42s (−14%) ⚪ within noise
typecheck checks 8m 30s 1m 56s–11m 03s 2m 01s −6m 29s (−76%) ⚪ within noise

…the render path

A frozen document keeps presenting committed derived values. Redeclaring a
derived$ while frozen created a private view whose first evaluation under
the read barrier was pending, so the render hid the committed value. A frozen
cell now presents its committed value, installs the new closure at
acceptance, and evaluates it when reads resume.

The per-invocation declaration stage moves from renderBlockInner onto the
native read driver's render frame, which only signal-using applications
load. Applications without signals no longer pay for it in bytes or per
render.

The render-phase selection test runs as its own dev/prod table instead of a
runIf modifier, which the test-marker check rejects.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm merged commit 3d0e5e2 into main Oct 2, 2026
32 checks passed
@trueadm
trueadm deleted the fix/local-query-selector-redeclaration branch October 2, 2026 12:06
trueadm added a commit that referenced this pull request Oct 2, 2026
Pins the combination with #1550: each custom-hook call owns its own query,
so a new captured argument re-selects that call's query and leaves the
other call's result in place.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm added a commit that referenced this pull request Oct 2, 2026
…1553)

* fix(octane): give each custom-hook call its own signal declarations

A `signal$`, `derived$` or `query$` declared inside a custom hook was keyed
only by its component instance and declaration site, so two calls of one
hook in one component aliased a single cell: `useUser$(a)`/`useUser$(b)`
rendered `X|X` and ran one loader.

Instance declarations now fold in the compiler-assigned call sites of the
enclosing custom-hook calls. Runtime hook-slot numbers follow module
evaluation order and differ between server and browser, while declaration
keys are wire identity for seeds, streamed results and early values, so
each signal-aware custom-hook call gets a position-hashed `h:` site
registered on its slot Symbol (tsrx, plain-module surgical and inline-memo
paths). Sites are emitted only for DOM targets, in modules with a runtime
signals import or for `$` hooks.

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

* fix(compiler): key aliased `$` hook calls the same way in every module kind

A `.tsrx` module checked only the local callee for a trailing `$`, while
plain modules checked only the imported name. `import { useUser$ as
useUser }` in a component module without a signals import therefore still
shared one cell across calls. All three emitters now register a call site
when either the local or the imported hook name ends in `$`; the `.tsrx`
path reads the exported name from the authored imports that its server
and client compiles share.

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

* test(octane): re-select only the changed call of a repeated query$ hook

Pins the combination with #1550: each custom-hook call owns its own query,
so a new captured argument re-selects that call's query and leaves the
other call's result in place.

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

* fix(compiler): bound hook calls in plain modules that import only signals

#1546 gave module-local custom-hook calls a withSlot boundary, but the plain
pass still walks only modules that import from `octane`. A `hooks.ts` that
imports `query$` from `octane/signals` and composes its own hooks
(`useUsers$` calling `useUser$` twice) therefore got no boundary, and both
calls shared one cell. A runtime signals import makes the module Octane's,
so its imported or declared `use*` hooks are now walked too. A module that
only declares signals is unchanged.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
trueadm added a commit that referenced this pull request Oct 3, 2026
…re unchanged (#1635)

* fix(signals): keep a local derived$ or query$ whose captured values are unchanged

Since #1550 a component-local derived$ or query$ re-ran its closure on every
render, so an object result changed identity on equal-prop renders and every
redeclaring render allocated a declaration stage. The compiler now lists the
render values each local declaration captures, with hook dependency
inference, and RedeclarableBinding returns the committed cell without staging
or evaluating when every value is Object.is-equal. A local signal$ handle with
a static key names one cell and is not listed.

A per-invocation serial from the native-read driver keeps the first
declaration in a render winning when two declarations share a cell. HMR
compiles add a per-module revision so an edited closure still replaces the
old one. A capture declared after the call is not read eagerly.

Custom-hook declaration paths now join sites with NUL, so an authored key
that spells out a path no longer aliases it, and are cached per call stack.

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

* fix(signals): present the first declaration of a shared cell during server rendering

Only the browser's native-read driver numbered render invocations, so on the
server a second declaration naming the same cell, such as a repeated
explicit key, installed its computation mid-render. That changed the cell's
revision and server rendering threw, and the browser presented the first
declaration instead. The server read driver now numbers each body scope, and
a declaration installed outside a render stage counts as its render's first.

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