Skip to content

fix(octane): cancel a component's superseded query$ request read only by its pending @try arm - #1703

Merged
trueadm merged 1 commit into
mainfrom
fix/query-pending-supersede-abort
Oct 4, 2026
Merged

trueadm merged 1 commit into
mainfrom
fix/query-pending-supersede-abort

Conversation

@trueadm

@trueadm trueadm commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1697. A query$ declared in a committed component and read with .get() only inside that component's @try/@pending boundary kept its superseded request live. The component committed the new selection, but the old request's AbortSignal was never aborted (and a stream's iterator never closed) until the component unmounted.

Root cause. Signal facades are redeclared lazily, when a render first reads them. Here the only reader was the @try arm, so the arm staged the component's new definition on its own nested capture (the boundary's hidden reveal attempt). That attempt suspended on the new request and was discarded, which discarded the definition, even though the component's render, the one that evaluated the declaration, committed. The committed cell therefore stayed on the old selection. A snapshot() read never suspends the arm, so its capture spliced into the root and committed, which is why the control in the issue behaved.

Fix. A declaration now settles with the render that evaluated it, matching the #1530 ownership model, where arms own only the declarations they evaluate themselves.

  • A Descriptor records the render invocation that evaluated it.
  • When a reader resolves the declaring owner's cell (the owner itself, or one of its directive arms or inline rows via readerOwner()), RedeclarableBinding.redeclare asks the renderer for that invocation's stage.
  • The native-read driver's render frames now record their invocation number and capture. While the declaring invocation is still on the render stack, the runtime stages the redeclaration with that invocation's stage and capture; otherwise it falls back to the reader's own stage, as before.
  • A child component that receives the handle still owns and stages its own cell in its own render (fix(octane): isolate signals in keyed SSR rows #1281 is unchanged).
  • query$, stream query$, and derived$/scalar derived$ share RedeclarableBinding, so all of them follow this rule.

Changes

  • signals/facade.ts, query-facade.ts, derived-facade.ts: the descriptor's declaring invocation is passed to cell creation only for the declaring owner's cell.
  • signals/engine.ts, computations.ts, scalar-computations.ts: thread declaring through to declared()/redeclare().
  • signals/redeclaration.ts: the declaring invocation is the render identity for "first declaration wins", and it selects the stage.
  • signals/read-protocol.ts, native-read-client.ts, runtime.ts: the stage resolver accepts the declaring invocation. Driver frames carry invocation and capture, and the capture is cleared at endRender so a reused frame never retains it. enclosingInvocation(id) walks the frame stack and stops early.
  • New packages/octane/tests/suspense-committed-parent-query.test.ts (20 cases) covering both strong and default compiles, in dev (octane) and prod (octane-prod).
  • Patch changeset for octane.

Validation

  • pnpm format:check: not run repo-wide (local test-load rule); pnpm format:files:check on the changed files passed.
  • pnpm typecheck: not run repo-wide; pnpm typecheck:files on every changed source file and the new test passed.
  • pnpm test: not run locally (local test-load rule); CI runs it.
  • targeted tests: pnpm exec vitest run --project octane packages/octane/tests/suspense-committed-parent-query.test.ts gives 20/20 passing, and also 20/20 with OCTANE_TEST_COMPILE_MODE=prod. On main, 6 of the 20 fail:
    • the issue case ("releases the superseded pending selection when the parent commits") for promise and stream query$ × strong/default: the old AbortSignal is not aborted and the stream is not closed.
    • the async derived$ .get() case × strong/default: a dependency-driven restart reloads the stale A selection instead of the committed B.
  • The other cases pass on both main and this branch, as intended. They are neighbour controls:
    • the snapshot() control from the issue;
    • a parent render with the same selection keeps the request live, and unmount still aborts it;
    • a selection change while the boundary shows content: a settled promise is not aborted, an open stream is closed;
    • async derived$ still does not restart on captured render values alone.
  • The original issue reproduction (with flushSync drains, strong dev and prod compiles) also passes with the fix.
  • pnpm sync produced no changes.

Risk / follow-ups

  • Hot path: when signals are enabled, every beginRender now does two more field writes plus a host.capture() call, and endRender one more write. Each descriptor construction reads the declaration invocation once. The core runtime call site is byte-identical, so no benchmarks/bundle-size scenario changes. Per the local test-load rule I did not run benchmarks locally; CI bench and size gates cover this.
  • One narrow case still keeps the old behaviour: a transition hold that rolls back only an inner boundary's journal window (no whole-drain attempt) while the component commits. The component's stage, if first created inside that window, is discarded with it. That only happens for a boundary already showing resolved content, where a settled promise has nothing left to cancel.

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 render-frame staging on a hot path (beginRender); behavior change is narrow but affects async query cancellation and derived restarts around suspense boundaries.

Overview
Fixes #1697: when a component's query$ (or async derived$) is only read via .get() inside @try/@pending, a parent re-render that commits a new selection no longer leaves the previous in-flight request alive until unmount.

What changed. Signal redeclarations now settle with the render invocation that evaluated the declaration, not the nested reader (e.g. a suspending @try arm). Descriptors record that invocation; RedeclarableBinding.redeclare passes it through and resolves the declaration stage from the declaring frame's capture when that invocation is still on the stack. The native-read driver tracks per-frame invocation id and capture, adds enclosingInvocation, and clears capture on endRender so reused frames do not leak commit state.

Scope. Same plumbing for query$, stream query$, and derived$/scalar paths; child components that receive a handle still own their own cell. Adds suspense-committed-parent-query.test.ts (20 cases) and an octane patch changeset.

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

…nder

A query$ or derived$ cell is redeclared lazily when it is first read. When
only a @Try arm read its component's declaration, the arm's attempt staged
the new definition on its own nested capture. That attempt suspended and
was discarded while the component committed, so the new selection was
dropped and the previous request's AbortSignal stayed un-aborted until
the component unmounted (#1697).

A descriptor now records the render invocation that evaluated it. When a
reader resolves the declaring owner's cell (the owner itself or one of its
directive arms or inline rows), the redeclaration is staged with that
invocation's stage and capture while it is still rendering. A component
that receives the handle keeps staging its own cell in its own render.

Fixes #1697

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 4, 2026
@trueadm
trueadm marked this pull request as ready for review October 4, 2026 15:16
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🟡 js-framework: 1 timed operation(s) slower beyond ±3%

Compares 76b5b0267, the merge commit's first parent with 880c916ed 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

target operation base ms head ms head/base 95% CI
octane-tsrx select_lots 0.005 0.006 +8.9% +7.7% … +10.1% 🟡 slower
All 20 timed operations (19 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 2.700 2.692 ±0.0% −3.5% … +3.5% ⚪ within noise
octane-tsrx replace 5.500 5.658 −0.8% −3.5% … +3.6% ⚪ within noise
octane-tsrx add 2.558 2.533 −0.0% −4.0% … ±0.0% ⚪ within noise
octane-tsrx update 0.118 0.119 −0.3% −1.3% … +1.3% ⚪ within noise
octane-tsrx select 0.005 0.005 −0.6% −1.1% … +0.0% ⚪ within noise
octane-tsrx swap 0.033 0.033 −0.0% −1.2% … +1.3% ⚪ within noise
octane-tsrx remove 0.016 0.016 −1.2% −3.9% … +2.4% ⚪ within noise
octane-tsrx runlots 24.242 23.275 −3.4% −6.2% … +0.4% ⚪ within noise
octane-tsrx select_lots 0.005 0.006 +8.9% +7.7% … +10.1% 🟡 slower
octane-tsrx clear 40.275 40.317 −0.3% −1.2% … +2.9% ⚪ within noise
octane-jsx run 3.308 3.158 −3.1% −5.7% … ±0.0% ⚪ within noise
octane-jsx replace 5.975 5.975 −1.6% −2.5% … +1.7% ⚪ within noise
octane-jsx add 2.992 3.033 ±0.0% −2.7% … +3.2% ⚪ within noise
octane-jsx update 0.233 0.237 +0.3% −1.7% … +1.7% ⚪ within noise
octane-jsx select 0.125 0.123 +1.4% ±0.0% … +5.0% ⚪ within noise
octane-jsx swap 0.219 0.216 −0.6% −2.7% … +0.5% ⚪ within noise
octane-jsx remove 0.166 0.166 ±0.0% −1.5% … +1.9% ⚪ within noise
octane-jsx runlots 27.092 27.967 +0.9% −0.7% … +2.4% ⚪ within noise
octane-jsx select_lots 1.428 1.381 −0.6% −2.4% … −0.3% ⚪ within noise
octane-jsx clear 44.317 44.725 −0.7% −2.2% … +3.0% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx bindings_js_gzip 240,870 240,859 −11 (−0.0%) 🟢
octane-tsrx bindings_js_brotli 205,198 205,189 −9 (−0.0%) 🟢
octane-tsrx bindings_app_gzip 121,727 121,716 −11 (−0.0%) 🟢
octane-tsrx bindings_app_brotli 101,835 101,826 −9 (−0.0%) 🟢

50 other measured values are unchanged.

Public-import reachability bundles (bytes)

No changes across 105 measured values.

@trueadm
trueadm merged commit 77504c1 into main Oct 4, 2026
52 checks passed
@trueadm
trueadm deleted the fix/query-pending-supersede-abort branch October 4, 2026 15:31
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.

Superseded local query stays pending when read inside a pending boundary

1 participant