Repository navigation
fix(octane): compare captured signal handles by the cell they resolve to - #1750
Merged
Merged
Conversation
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
marked this pull request as ready for review
October 5, 2026 07:48
Contributor
Benchmark report
Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)
56 other measured values are unchanged. Public-import reachability bundles (bytes)
104 other measured values are unchanged. |
2 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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$andquery$handles again, building a new descriptor each time. A local declaration whose closure read another localderived$orquery$therefore had a capture list that never compared equal (Object.ison 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=0avoided 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 smallSIGNAL_SAME_CAPTUREprotocol betweenredeclaration.tsandDescriptor, so the redeclaration module does not import the facade. The act() drain limit is unchanged.docs/signals.mdpreviously 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.tsplus its.tsrxfixture. It runs inoctane-signals,octane-signals-prodandoctane-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 theirget()/snapshot(), abort/error/abort-skip and ready/pending controls.Pre-fix (dev): 9 of 12 fail. Both Pending nested derived snapshots can prevent the scheduler from stabilizing #1735 cases and Rejected query read by derived snapshots can leave the renderer unresponsive #1737 pending hit the act() drain limit. Pending query selector can hang the browser in development mode #1736
get()and Rejected query read by derived snapshots can leave the renderer unresponsive #1737 error/abort/abort-skip hit the fixture's 200-render bound; without that bound they hang the run, because microtask starvation stops Vitest's timeout from firing. The two synchronous chain tests also hit the drain limit. The controls pass both before and after, matching the reports: Pending query selector can hang the browser in development mode #1736snapshot(), Rejected query read by derived snapshots can leave the renderer unresponsive #1737 ready, and the consistency test. Pending nested derived snapshots can prevent the scheduler from stabilizing #1735 and Rejected query read by derived snapshots can leave the renderer unresponsive #1737 pending also fail before the fix in prod and Strong.Post-fix: 36/36 across the three signal projects.
Mutation check: treating any same-declaration handle as equal (dropping the view check) fails only
commits a redeclared dependency together with the values derived from it, which records a tornb1|A1commit. The existingsignal-local-selectorssuites (133 tests) do not catch that mutation, so this test guards the neighbouring contract.Related suites, all green locally:
signal-local-selectors(+ hydration) inoctane/octane-prod(141),event-signal-owner, andsignals-local,signals-unified,signals-memos,signals-hook-declarations,signals-deferred-valuesandsignals-renderinginoctane-signals.Deterministic work counter, measured with a scratch test that is not committed: a five-deep local chain whose middle value is a new object, re-rendered 100 times by the parent with a new props object.
pnpm format:check(scopedpnpm format:files:checkon the changed files passed)pnpm typecheck(scopedpnpm typecheck:fileson the changed files, including the.tsrxfixture, passed)pnpm test(left to CI)targeted tests: listed above
Risk / follow-ups
NESTED_UPDATE_LIMIT, so outsideact()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
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith 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 untilact()or the browser hung.Runtime: adds
SIGNAL_SAME_CAPTUREsosameCapturestreats 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).Descriptorinfacade.tsimplements the check;redeclaration.tspasses the binding owner into comparison.Docs / release:
docs/signals.mddocuments cell-based capture comparison; changeset marks anoctanepatch.Tests: new
signals-local-chainsfixtures 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.