Skip to content

fix: a throwing cleanup no longer aborts the rest of the teardown - #4213

Merged
ryansolid merged 6 commits into
nextfrom
claude/project-thread-x1ore2-cleanup-throw
Oct 22, 2026
Merged

ryansolid merged 6 commits into
nextfrom
claude/project-thread-x1ore2-cleanup-throw

Conversation

@ryansolid

@ryansolid ryansolid commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Before: a cleanup that throws (onCleanup or an effect's returned cleanup) aborts the rest of disposal on both the client and the server. That skips the earlier cleanups on the same owner, any sibling subtrees not yet reached, every ancestor's cleanups, and effect cleanups. On the client the error also goes past createErrorBoundary and out of flush(). The pass that was disposing never commits, the view stays on the old branch, and the next flush throws again. On the server, renderToStream's final dispose skips the remaining cleanups (#4193's third expectation). Separately, a throw in an unfinished pass skips recompute's deferred-release drain, so lazy memos released before it stay linked (follow-up to #4176).

After: every cleanup in the tree runs, and the first error is rethrown once teardown is done:

  • A root's dispose() outside a flush rethrows it.
  • Inside a flush (a branch switch, a pass replacing an uncommitted one, an effect disposing a root), flush() rethrows it after the flush has finished, so commits and effects are never left half-applied.
  • Any other teardown leaves it to the flush that the throwing cleanup schedules.
  • A throwing unobserved hook is handled the same way, so it can't stop a teardown halfway or leave a pass's release collector installed.
  • If an uncaught error halts the reactive system, a collected cleanup error is dropped, so it never surfaces from a later, unrelated dispose().
  • The deferred-release drain is no longer skipped.
  • On the server, disposeOwner runs every cleanup, and fix(web): renderToStream serializer and cleanup errors reach the ambient error hook (#4193) #4206's render/failed report still fires.

Routing the error to the nearest boundary so its fallback shows was tried. It trips the infinite-loop guard, because the boundary re-reads a memo that then re-runs cleanly. So the error is rethrown rather than caught.

How: a single guarded runCleanup in owner.ts wraps the _disposal list, the effect _cleanup, and user unobserved hooks. It keeps the first error and schedules a flush. Only root dispose (disposeRootSelf) and flush rethrow, which keeps the check off disposeChildren's hot path. Putting it there cost about 10% on CodSpeed's createOwners. haltReactivity drops a collected error. The try/finally in recompute is gone. One try around the whole cleanup loop (resuming after a throw) was benchmarked against the per-cleanup guard: same speed in a create/dispose bench, and 33 B larger, so the per-cleanup guard stays. On the server, disposeOwner guards each child walk and each cleanup.

Tests:

Size-Exception: about +120 to +145 B minified / +4 to +100 B brotli on the client scenarios, approved by Ryan (2026-10-21) because a throwing cleanup must not leak or wedge the tree. Hello world (app: compiled floor) is 9,919 B brotli in CI, under 10 KB. Caps for every grown scenario are re-recorded from CI's numbers.

🤖 Generated with Claude Code

https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2

Every cleanup in the tree runs even when one throws: the ones registered
before it on the same owner, unvisited siblings, ancestors and effect
cleanups. The first error is rethrown once the teardown is over.

Client (@solidjs/signals): one guarded call (`runCleanup`) covers both the
`_disposal` list and the effect `_cleanup`, collecting the first error.
Outside a flush the walk that began the teardown rethrows it; inside a flush
(a commit retiring a frame, a pass replacing an uncommitted one, an effect
disposing a root) `flush()` rethrows it after the drain completes, so the
commit loop and the effect queues are never left half-applied and the pass
that tears down a frame still drains the lazy releases it collected
(#4176's follow-up case now passes without a dedicated drain).

Server (solid-js): `disposeOwner` guards each child walk and each cleanup
and rethrows the first error after the walk, so renderToStream's final
dispose runs every cleanup and #4206 still reports the error (#4193).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
@changeset-bot

changeset-bot Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8e262f9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 14 packages
Name Type
@solidjs/signals Patch
solid-js Patch
test-integration Patch
@solidjs/web Patch
@solidjs/diagnostics Patch
@solidjs/element Patch
@solidjs/h Patch
@solidjs/html Patch
@solidjs/universal Patch
board-example Patch
server-dbmon-example Patch
todos-server-example Patch
@solidjs/babel-plugin Patch
@solidjs/compiler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Size (brotli, eager entry chunk)

scenario head vs base minified vs base minified vs recorded cap lazy chunks (not counted)
signals: core floor (createSignal/Memo/Effect/Root/flush) 7.43 KB +64 B (+0.9%) +125 B 0 B 7.44 KB ✅
signals: + createStore 15.00 KB +61 B (+0.4%) +120 B 0 B 15.01 KB ✅
signals: + isPending/latest 10.24 KB +50 B (+0.5%) +123 B 0 B 10.25 KB ✅
signals: + until/refresh (truth readers, no optimism) 8.04 KB +67 B (+0.8%) +123 B 0 B 8.05 KB ✅
app: render + one signal (the simple-app floor) 9.74 KB +67 B (+0.7%) +127 B 0 B 9.75 KB ✅
app: hydrating (no stores) with Show/For/Loading/Errored/lazy 18.37 KB +38 B (+0.2%) +123 B 0 B 18.38 KB ✅ lazy-page.js 0.04 KB
app: hydrating + every store primitive family 30.40 KB +21 B (+0.1%) +120 B 0 B 30.42 KB ✅ lazy-page.js 0.04 KB
app: CSR with Show/For/Loading/Errored/lazy 13.31 KB +67 B (+0.5%) +118 B 0 B 13.33 KB ✅ lazy-page.js 0.04 KB
app: CSR, observe tier (same app on the observe artifacts) 15.06 KB +43 B (+0.3%) +116 B 0 B 15.08 KB ✅ lazy-page.js 0.04 KB
app: CSR, observe tier + attribution engine enabled 29.62 KB +4 B (+0.0%) +115 B 0 B 29.64 KB ✅ lazy-page.js 0.04 KB
app: compiled floor (one template, one text hole, one delegated click) 9.92 KB +36 B (+0.4%) +127 B 0 B 9.93 KB ✅
app: compiled CSR (JSX todo app: spread/merge/omit, events, class/style, keyed For, Show, Loading + lazy, store) 26.21 KB +91 B (+0.3%) +124 B 0 B 26.23 KB ✅ stats.js 0.18 KB
app: compiled hydrating (the same JSX todo app through hydrate(), compiled hydratable) 32.17 KB +89 B (+0.3%) +124 B 0 B 32.20 KB ✅ stats.js 0.20 KB
frames: eager client consumer (frames client + transport, lazy codec) 11.75 KB 0 B 0 B 0 B 11.76 KB ✅
page: base server components (hydrating + dynamic + frames + sf reference) 33.26 KB +83 B (+0.3%) +105 B 0 B 33.27 KB ✅ assets.js 0.78 KB, decode.js 6.25 KB, lazy-page.js 0.04 KB, regions.js 1.07 KB, trace.js 9.05 KB, wire.js 2.78 KB
page: live server components (base + live/GET + action + isPending/latest) 37.51 KB +41 B (+0.1%) +110 B 0 B 37.53 KB ✅ assets.js 0.78 KB, decode.js 6.25 KB, lazy-page.js 0.04 KB, regions.js 1.07 KB, trace.js 9.05 KB, wire.js 2.78 KB
page: compiled base server components (the base page as JSX: templates with class/style/attributes/events, For/Show; no spread) 35.27 KB +54 B (+0.2%) +114 B 0 B 35.30 KB ✅ assets.js 0.78 KB, decode.js 6.25 KB, regions.js 1.06 KB, sc-comments.js 0.20 KB, trace.js 9.05 KB, wire.js 2.77 KB
page: compiled live server components (the compiled base page + live/GET + action + isPending/latest) 41.40 KB +60 B (+0.1%) +125 B 0 B 41.42 KB ✅ eager (counted): web.js 22.04 KB; assets.js 0.78 KB, decode.js 6.25 KB, regions.js 1.06 KB, sc-comments.js 0.19 KB, trace.js 9.10 KB, wire.js 2.77 KB
page: base + router (base page + @solidjs/router: createRouter, two routes, preload, useNavigate) 40.77 KB +98 B (+0.2%) +120 B 0 B 40.78 KB ✅ assets.js 0.78 KB, decode.js 6.25 KB, lazy-page.js 0.04 KB, regions.js 1.06 KB, server.js 1.02 KB, serverForms.js 3.58 KB, trace.js 9.10 KB, wire.js 2.77 KB
page: live + router (live page + @solidjs/router: createRouter, two routes, preload, useNavigate) 46.94 KB +35 B (+0.1%) +126 B 0 B 46.96 KB ✅ eager (counted): client.js 27.15 KB; assets.js 0.78 KB, decode.js 6.25 KB, lazy-page.js 0.04 KB, regions.js 1.07 KB, server.js 1.02 KB, serverForms.js 3.32 KB, trace.js 9.08 KB, wire.js 2.80 KB
server: floor (getRequestEvent + isServer) 1.33 KB 0 B 0 B 0 B 1.34 KB ✅
server: renderToString (the server-render floor) 20.63 KB +11 B (+0.1%) +65 B 0 B 20.65 KB ✅

Bundled with Rolldown (what Vite ships), brotli q11, decimal KB. A scenario fails only when it is over its brotli cap and its minified size is more than 20 B over the minified recorded with the cap; over the cap within that allowance is brotli layout noise and passes with a warning. Caps and their recorded minified in scripts/size/scenarios.js; the floor and page caps in floor-caps.json are frozen (lower only, or Size-Exception: in the PR body). npm run ratchet lowers caps per RC; it never raises one (scripts/size/README.md).

Every scenario the change grows, at CI's measured sizes. Hello world
(app: compiled floor) is 9,928 B brotli, under 10 KB.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
@coveralls

coveralls commented Oct 21, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 39686012859

Coverage remained the same at 77.662%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 1349
Covered Lines: 1105
Line Coverage: 81.91%
Relevant Branches: 1055
Covered Branches: 762
Branch Coverage: 72.23%
Branches in Coverage %: Yes
Coverage Strength: 27.52 hits per line

💛 - Coveralls

@codspeed

codspeed Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 11.97%

2 warnings

⚠️ 3 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ Base and head ran on different runner types

Some benchmarks with significant performance changes were compared across different runner types, so the changes might not come from the code. Run base and head on the same runner type, or use CodSpeed Macro Runners for more stable results.

Learn more about Macro Runners

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 195 untouched benchmarks
⏩ 5 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ build + consume 777.6 µs 694.5 µs +11.97%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing claude/project-thread-x1ore2-cleanup-throw (8e262f9) with next (a2a5b6f)

Open in CodSpeed

Footnotes

  1. 5 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

CodSpeed flagged createOwners at -10%: the end-of-walk rethrow check in
disposeChildren slowed every disposal. Root dispose now rethrows after its
walk outside a flush; every other teardown leaves it to the flush that
runCleanup schedules. Drops the nested parameter too.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
Hello world (app: compiled floor) is 9,935 B brotli, under 10 KB.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
…halt

Review follow-ups for #4213:
- A throwing `unobserved` hook is collected like a cleanup, so the
  teardown around it carries on and a pass's release collector is
  always removed.
- A halt drops a collected cleanup error, so it never surfaces from a
  later, unrelated dispose().
- Server disposeOwner goes back to the indexed reverse loop.
- Tests for the mid-walk release, the halt, and throwing hooks.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
@ryansolid
ryansolid marked this pull request as ready for review October 21, 2026 22:46
@ryansolid
ryansolid merged commit db8241c into next Oct 22, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants