Skip to content

fix(octane): compare captured signal handles by the cell they resolve to - #1750

Merged
trueadm merged 1 commit into
mainfrom
fix/signal-handle-captures
Oct 5, 2026
Merged

trueadm merged 1 commit into
mainfrom
fix/signal-handle-captures

Conversation

@trueadm

@trueadm trueadm commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1735, fixes #1736, fixes #1737.

All three reports share one root cause, and it is not specific to queries. Every render declares a component's derived$ and query$ handles again, building a new descriptor each time. A local declaration whose closure read another local derived$ or query$ therefore had a capture list that never compared equal (Object.is on descriptors). So every render redeclared it and re-ran its closure through a private declaration view (#1550). That alone is wasted work. It livelocks when the re-run result can never equal the committed one:

Accepting the view promotes that state into the committed cell and notifies its downstream derived values. Their native observers schedule the component, and its next render declares the computation again, forever. act() reports that the scheduler did not stabilize. In a browser, a microtask-driven loop starves the event loop, so the tab hangs while the query stays pending or after it rejects. OCTANE_HMR=0 avoided it in #1736 because the prod compiler's memo region reuses descriptors while its deps are unchanged. Prod still loops once those deps change (for example on a parent re-render), and the reported fixtures fail in the prod and Strong projects too.

Fix (runtime, packages/octane/src/signals): a captured descriptor now matches the committed one when both come from the same declaration (same class, key, site and declaring owner) and the current descriptor resolves, for the binding's owner, to the committed cell rather than to this render's private view. Resolving runs the dependency's own redeclaration for this render, exactly as the closure's read would. A sibling that presents a redeclared definition in this render still compares unequal, so its dependents keep reading the definition their render presents (the #1550 consistency guarantee). The comparison is a small SIGNAL_SAME_CAPTURE protocol between redeclaration.ts and Descriptor, so the redeclaration module does not import the facade. The act() drain limit is unchanged.

docs/signals.md previously documented the identity rule ("Any other handle is compared by identity … reevaluates when that handle is declared again") and now describes resolution-based comparison.

Validation

New packages/octane/tests/signals-local-chains.test.ts plus its .tsrx fixture. It runs in octane-signals, octane-signals-prod and octane-signals-strong, so dev, prod and Strong compiles are all covered. The issue repros became jsdom tests: the #1736 and #1737 browser repros keep their layout-effect microtask activation and their get()/snapshot(), abort/error/abort-skip and ready/pending controls.

Risk / follow-ups

  • Comparing a captured handle now resolves its descriptor during the dependent's redeclaration. If its other captures already match, this can declare a sibling that the render would not otherwise have read. That is the same declaration a read performs, and it is cheaper than the probe it replaces. Resolution errors fall back to the previous behavior: unequal, so the dependent redeclares.
  • A capture that genuinely changes on every render (for example an inline object created in the component body) still re-runs its declaration each render. If the result is pending, rejected or a new object and is read downstream, that can still loop. This change removes the spurious source of that churn (handles), not that general hazard.
  • Signal-driven re-renders don't count toward NESTED_UPDATE_LIMIT, so outside act() a framework livelock like this one hangs the browser instead of throwing "Maximum update depth exceeded". That is a separate diagnostic gap, not fixed here.

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
Touches core signal redeclaration and capture equality used by every compiled local derived$/query$; wrong equality could either restore livelocks or break staged redeclaration consistency, though new tests target those contracts.

Overview
Fixes infinite re-render loops when component-local derived$ / query$ chains read each other while async work is pending or rejected (#1735–#1737).

Each render creates new handle descriptors, so redeclaration treated captured local handles as always changed (Object.is) and re-ran closures every time. Non-stable results (pending queries, fresh error snapshots, new objects) then kept waking readers until act() or the browser hung.

Runtime: adds SIGNAL_SAME_CAPTURE so sameCaptures treats two handles as equal when they are the same declaration and the current handle resolves to the committed cell (not this render’s private declaration view). Descriptor in facade.ts implements the check; redeclaration.ts passes the binding owner into comparison.

Docs / release: docs/signals.md documents cell-based capture comparison; changeset marks an octane patch.

Tests: new signals-local-chains fixtures and Vitest suite cover pending nested snapshots, pending-query selectors, rejected-query chains, object/error intermediates, and consistent redeclaration on prop updates.

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

Every render declares a component's derived$ and query$ again, so a local
declaration that read another local derived$ or query$ captured a new
descriptor each render. Its captures never compared equal, so every render
re-ran its computation through a private view. When the result could never
equal the committed one (a pending read's new wakeup, a rejected query's
error snapshot, a new object), accepting the view notified the committed
readers. Their component rendered and declared it again, a livelock that
exhausted act()'s drain and hung the browser while a query was pending or
after it was rejected.

A captured descriptor now matches the committed one when both come from
the same declaration and the current one resolves to the committed cell
rather than this render's private view. A sibling presenting a redeclared
definition still differs, so a dependent reads the definition its render
presents.

Fixes #1735, fixes #1736, fixes #1737.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm marked this pull request as ready for review October 5, 2026 07:48
@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
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-reachability: 1 value(s) increased within budget

Compares d7ee29b77, the merge commit's first parent with 35bbf219b 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.267 3.533 −1.5% −6.0% … +0.0% ⚪ within noise
octane-tsrx replace 7.258 6.400 −0.8% −4.6% … ±0.0% ⚪ within noise
octane-tsrx add 2.833 2.783 +3.8% ±0.0% … +4.0% ⚪ within noise
octane-tsrx update 0.129 0.125 +0.3% −1.8% … +3.5% ⚪ within noise
octane-tsrx select 0.006 0.006 −1.0% −2.6% … +2.0% ⚪ within noise
octane-tsrx swap 0.043 0.044 +0.3% −2.8% … +5.5% ⚪ within noise
octane-tsrx remove 0.020 0.019 +0.6% −1.9% … +2.4% ⚪ within noise
octane-tsrx runlots 29.108 27.642 +0.6% −3.9% … +3.8% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 −0.7% −1.3% … +3.5% ⚪ within noise
octane-tsrx clear 39.133 37.508 −3.1% −5.6% … +2.9% ⚪ within noise
octane-jsx run 3.833 3.900 +0.0% −2.6% … +2.8% ⚪ within noise
octane-jsx replace 6.842 7.333 +1.4% −1.4% … +4.3% ⚪ within noise
octane-jsx add 3.508 3.442 −2.6% −2.9% … ±0.0% ⚪ within noise
octane-jsx update 0.291 0.290 +0.0% −2.1% … +5.4% ⚪ within noise
octane-jsx select 0.149 0.154 −0.9% −3.5% … +4.6% ⚪ within noise
octane-jsx swap 0.249 0.258 −0.9% −3.8% … +5.0% ⚪ within noise
octane-jsx remove 0.184 0.186 +1.3% −4.3% … +4.4% ⚪ within noise
octane-jsx runlots 32.442 32.725 +1.1% +0.2% … +2.2% ⚪ within noise
octane-jsx select_lots 1.763 1.756 −0.0% −2.5% … +1.9% ⚪ within noise
octane-jsx clear 36.442 40.300 +10.7% +2.6% … +16.1% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx bindings_js_gzip 240,865 240,853 −12 (−0.0%) 🟢
octane-tsrx bindings_js_brotli 205,129 204,952 −177 (−0.1%) 🟢
octane-tsrx bindings_app_gzip 121,729 121,717 −12 (−0.0%) 🟢
octane-tsrx bindings_app_brotli 101,815 101,638 −177 (−0.2%) 🟢

56 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
binding-apollo-client-esbuild brotli 100,154 100,163 +9 (+0.0%) 🔴

104 other measured values are unchanged.

@trueadm
trueadm merged commit 21e0575 into main Oct 5, 2026
49 of 52 checks passed
@trueadm
trueadm deleted the fix/signal-handle-captures branch October 5, 2026 10:03
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

1 participant