Skip to content

fix(signals): a landed transaction stops being the flush's, so a cleanup's action never swallows the next write (#5233) - #5236

Merged
ryansolid merged 2 commits into
solidjs:mainfrom
yumemi-thomas:fix/cleanup-action-lost-write
Nov 27, 2026
Merged

ryansolid merged 2 commits into
solidjs:mainfrom
yumemi-thomas:fix/cleanup-action-lost-write

Conversation

@yumemi-thomas

Copy link
Copy Markdown
Contributor

Summary

Fixes #5233.

When a cleanup (onCleanup, or a cleanup returned by an effect) runs while a transition lands and calls a synchronous action, the next action's write was shown but never committed. The binding rendered the new value, but the signal still read the old one, so a later write that compared against it was skipped. This is a regression from #5161 (shipped in 2.0.4).

After this change, the next action's write commits as it did in 2.0.3.

const [open, setOpen] = createSignal(false);
const changeOpen = action(function* (value: boolean) {
  if (value !== untrack(open)) setOpen(value);
});
const onClose = action(function* () {});
function Part() {
  onCleanup(() => void onClose());
  return <span>Part</span>;
}
// <Show when={open()}><Part /></Show>, then Open, Close, Open, Close
before after
rendered after each step F T F T T F T F T F
untrack(open) 0 1 0 0 0 0 1 0 1 0

Cause

The first Close lands its transaction, and the commits in land() dispose the branch. The branch's cleanup calls onClose, whose action opens a fresh transaction T3 and joins it (joinFuture): T3 becomes flushTransaction. T3 has nothing to wait on, so the same landing loop in settle() lands it as well, but flushTransaction still points at it. settle() only reads and clears flushTransaction before that loop, so the pointer survives into the next tick.

The next changeOpen(true) joins its transaction T4. Because flushTransaction is T3, joinFuture merges T4 into T3 and removes T4 from transactions. The next settle() stages open into T3, which has already landed and is never judged again. The binding shows the staged value, but the write is never committed.

Before #5161, land() ended with if (flushTransaction === u) flushTransaction = null; (added for #4089). #5161 removed it, reasoning that once joinFuture refuses to join a landed transaction, the reset "can no longer trigger". That holds for a write to a node the landing still holds (the #4089 and #5159 cases). It does not hold here: T3 is still live when the flush joins it and only lands afterwards, in a later iteration of the same loop.

Fix

The landing loop in settle() clears flushTransaction when it resolves to the transaction u it is about to land:

if (flushTransaction && resolveTx(flushTransaction) === u) flushTransaction = null;
transactions.splice(k, 1);
endLanesHook?.(u);
land(u);

It runs before u's lanes end and before its commits, not after the commits as the pre-#5161 line did. Both steps can run user code. The commits run cleanups, and ending a lane commits its truth over a guess and calls that guess's equals. An action started from either one has to open a transaction of its own instead of merging into u. resolveTx covers a flush transaction that a guess merged into u.

The reset has to come before the lanes end, not only before the commits. If it ran only before the commits (inside land()), an optimistic equals that starts an action as the lane ends would join u. That action's first write would then commit during its yield: it reads 1 while the action waits, where it should stay 0 until the action ends with 2. The new lane teardown test covers this case.

I also tried the other change that makes the repro pass: liveTx(joined) instead of resolveTx(joined) in settle(), without the reset. I didn't use it, because it lets the later action's writes commit too early. With an action that writes 1, yields, writes 2, yields, and writes 3, the pairs (rendered, committed) after each step are (1,1) (2,2) (3,3) with that change, against (0,0) (0,0) (3,3) with this one. Each write commits as it is made instead of once when the action ends.

Clearing the pointer where a transaction stops being live keeps #5161's scheduler invariant, "a landed transaction holds nothing". Every later join then sees either null or a live transaction. An action's writes commit once every body in the hold has returned and the work they put in flight has landed (D-7).

#5159 does not come back. joinFuture keeps #5161's liveTx guard, so a write to a node a landed transaction still lists never joins or merges it. This change only adds the reset. cleanup-write-landing-merge-5159.test.ts (3 cases, including held-first, which fails before #5161) and cleanup-write-during-landing-4089.test.ts pass unchanged.

Rules: D-7 (an action's writes commit once every body in the hold has returned and the work they put in flight has landed) and D-9 (holds are formed by the graph, and a hold ends when nothing it waits on is left, so a landed transaction is no hold a later action can join). "A landed transaction holds nothing" is #5161's scheduler invariant, not a rule statement. No rule changed. RULES-INDEX.md was regenerated for the citations.

How it was tested

New packages/signals/tests/cleanup-action-landing-5233.test.ts (7 tests). A memo branch with a cleanup stands in for <Show> with a child, and each test runs Open, Close, Open, Close through changeOpen, checking the render and untrack(open) after each step:

  • onCleanup calling an empty synchronous action (the issue's repro);
  • an effect's returned cleanup calling it;
  • a cleanup action that throws (its rejection is caught);
  • async, the control: the cleanup's action awaits before it ends, so it is still live when the landing loop ends;
  • a cleanup action whose write re-runs a second memo, whose own cleanup calls another action (Open, Close, Open, Close, Open; checks the final render and all three signals);
  • two cases where an action that writes 1, yields, and writes 2 is started while a transaction lands. It must read 0 while it waits and 2 at the end. In regular commit it starts from a cleanup the landing's commits run. In lane teardown it starts from an optimistic value's equals, called when the landing ends a lane.

On upstream/main (3448597): 6 failed, 1 passed (async). With the reset inside land(), before the commits but after the lanes end: 6 passed, 1 failed (lane teardown). With this change: 7 passed.

I also checked a nested action called from inside the cleanup's action. It passes before and after the fix, so I didn't commit it.

Commands, each with NODE_OPTIONS=--max-old-space-size=2048 and --maxWorkers=3, after pnpm build in packages/signals, packages/solid, packages/web and packages/universal:

command result
packages/signals: vitest run 574 files, 7296 passed, 17 expected fail, 2 skipped
packages/signals: vitest run tests/cleanup-action-landing-5233.test.ts tests/cleanup-write-landing-merge-5159.test.ts tests/cleanup-write-during-landing-4089.test.ts tests/for-row-cleanup-action.test.ts 4 files, 16 passed
packages/web: test/for-row-cleanup-action.spec.tsx (#5124's removed-row spec; JSX through the Babel plugin, as the native compiler isn't built here) 1 file, 2 passed
packages/signals: node scripts/rules-index.mjs --check ok, RULES-INDEX.md current
packages/signals: tsc -p tsconfig.build.json (via pnpm build) clean
packages/solid: vitest run 59 files, 942 passed
prettier --check on the changed source, test and changeset clean

Size

Measured locally on macOS with scripts/size (node size.mjs --json head.json --no-gate, then node gate.mjs head.json base.json) against upstream/main, rebuilding packages/signals for each side. Minified growth is +22 B on every scenario that includes the scheduler (+23 B on the attribution app and the base page), and 0 B on frames and the two server floors. Brotli moves between −36 B and +49 B from that one change.

The gate passes on all 15 scenarios measured, with no cap raised (check-floor-caps.mjs upstream/main: no cap raised). Two are at their caps:

  • signals: + until/refresh is 8250 B against an 8.25 KB cap, so it has no headroom. Linux CI may measure a few bytes more. If it does, the gate fails there: minified is +22 B over the size recorded with the cap, 2 B past the 20 B allowance. That would need a cap decision.
  • app: hydrating (no stores) is 19145 B against 19.14 KB. It passes with a warning: its minified is 120 B under the size recorded with the cap.

The 7 compiled and router scenarios couldn't be bundled locally because the native compiler isn't built here. I expect the same +22 B minified there, and CI will measure them.

Behaviour change

  • After a cleanup calls a synchronous action during a landing, the next action's writes commit again, as in 2.0.3.
  • Unchanged, on main and with this change: when a cleanup's action is still waiting (it yields a promise), a later action in another tick still merges into it and holds until it ends. Nothing is lost in that case, but the two actions are entangled. This PR doesn't change it, and it may need a ruling of its own.

Public API changes

None.

The changeset is .changeset/cleanup-action-landing-5233.md (@solidjs/signals patch).

🤖 Generated with Claude Code

yumemi-thomas and others added 2 commits November 27, 2026 12:34
…nup's action never swallows the next write (solidjs#5233)

A cleanup that a landing's commits run can call a synchronous action. Its
transaction becomes the flush's, has nothing to wait on, and lands in the
same landing loop, while `flushTransaction` still points at it. The next
action then merged into the landed transaction: its write showed but was
never committed.

`land()` now clears `flushTransaction` when it resolves to the transaction
being landed, before that landing's commits run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lanes end (solidjs#5233)

The reset ran in `land()`, after `endLanesHook` had ended the transaction's
lanes. Ending a lane commits its truth over a guess and runs that guess's
`equals`; an action started there joined the landed transaction, and its
first write committed during its `yield` instead of with its last.

The landing loop now clears `flushTransaction` when it resolves to the
transaction it is about to land, before the splice, the lanes and the
commits. The test adds that case (a guess's `equals` starting an action as
the lane ends) beside the cleanup-started control.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Nov 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ca24d18

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

This PR includes changesets to release 5 packages
Name Type
@solidjs/signals Patch
@solidjs/web Patch
@solidjs/diagnostics Patch
solid-js Patch
@solidjs/universal 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

@codspeed

codspeed Bot commented Nov 27, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ Upgrade your CodSpeed plugin for Node.js 24

@codspeed/* 5.4.0 is only tested on Node.js 18, 20, and 22, so your Node.js 24 measurements may be inaccurate. Upgrade your @codspeed/* packages to 6.0.0 or later.

See affected benchmarks

✅ 205 untouched benchmarks
⏩ 5 skipped benchmarks1


Comparing yumemi-thomas:fix/cleanup-action-lost-write (ca24d18) with main (3448597)

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. ↩

@ryansolid
ryansolid merged commit f7b6b9c into solidjs:main Nov 27, 2026
13 of 14 checks passed
ryansolid pushed a commit that referenced this pull request Nov 27, 2026
After #5221, #5225, #5228, #5235 and #5236, until/refresh, compiled base
server components, base + router and live + router sat 6-92 B brotli over
their caps. Caps move to CI's measure on main @ f7b6b9c + 10 B and recorded
minified resets to the measure. No floors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0117BoWMR7ndYUnqBW5NjTbC
ryansolid added a commit that referenced this pull request Nov 27, 2026
…cenarios over their caps (#5241)

* fix(release): skip already-published packages in artifact verification

Since #4985, h, html and element version on their own, so a core release
leaves them at a version already on npm. verify-release-artifacts.mjs
dry-run-published every public package, and npm refuses even a dry run over
a published version, so the 2.0.1 release failed before publishing anything.
It now skips a published version the same way release.mjs does, with
packageIsPublished shared from release-packages.mjs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0117BoWMR7ndYUnqBW5NjTbC

* fix(signals): a reader linked to a settled source no longer stays pending on it

retryReaches counted a dep that is the source itself as a path even after
that source settled, so settleFamily and the re-park sweep in recompute
kept a settled derive node in a reader's pending sources. With an
optimistic store over one async memo and a slower sibling memo whose
re-ask answers unchanged, the reader stayed pending and the action's
transaction never landed. A direct link now counts only while the source
is pending.

Claude-Session: https://claude.ai/code/session_01CP9T3j2CTCEPyTS2bcKsBu

* fix(web): send an empty revalidate declaration as a non-empty header

* fix(compiler): treat only a leading comment equal to the static marker as the marker

* fix(web): a server function's ReadableStream result stays a ReadableStream

The top-level abort wrapper for streamed results matched any async
iterable, so a decoded ReadableStream (which is one in Node and Chrome)
was replaced by a plain iterable and lost getReader/pipeTo/tee. Leave a
ReadableStream out of that check; it passes through as it already does
when nested. Test shape from #5175.

Co-authored-by: Marve10s <igrimanigroman@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0117BoWMpyUtA1ZFwzKmr1sg

* fix(web): check getReader instead of instanceof ReadableStream

The instanceof check with its typeof guard cost +59 B minified on every
server-function page and put three page scenarios over their caps. A
decoded ReadableStream is told apart from an async generator's result by
its getReader method.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0117BoWMpyUtA1ZFwzKmr1sg

* fix(web): write the empty revalidate header once; digest it to no keys

Send `,` in one header write when the joined keys are only whitespace,
and digest `X-Revalidate` with empty keys filtered, so an empty
declaration reads as `[]` on the outcome instead of `[""]` or
`["", ""]`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0117BoWMR7ndYUnqBW5NjTbC

* fix(release): wait for the dispatched compiler binary run before watching it

The 2.0.4 publish stopped at `gh run watch`: `gh workflow run` printed
the new run's URL, and watching it one second later returned 404 because
the run was not readable yet. Poll `gh run view` until it resolves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0117BoWMR7ndYUnqBW5NjTbC

* fix(release): poll the compiler binary run instead of gh run watch

The 2.0.4 re-run got past the run lookup, then `gh run watch` failed on
the run's jobs (HTTP 404) before GitHub had created them. Poll
`gh run view --json status,conclusion` until the run completes, retrying
failed reads, and check the conclusion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0117BoWMR7ndYUnqBW5NjTbC

* fix(signals): a re-parked reader drops a pending source disposed while loading

The re-park prune in recompute kept any carried source still flagged
STATUS_PENDING, on the assumption that its own settle walk is still to
come. A source disposed while loading keeps that flag but never lands, so
no walk comes. When a reader parked on an async memo whose owner then
re-ran in the same hold, disposing it and creating a replacement that
failed, the reader stayed pending on the disposed memo: the hold never
landed and its staged error never reached the boundary. A disposed source
is now dropped whatever its status, as retryReaches and holdsOn already
treat a disposed node as holding nothing (F-3).

* chore(size): re-record the six scenarios over their caps on main

After the 11-24 fix batch and 2.0.4, six scenarios sat over their brotli
caps with 9-14 B of minified allowance left (warnings on main, but the
next ~10 B client fix would fail the gate). Caps move to CI's measure on
5420b4a + 10 B and recorded minified resets to the measure. No floors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0117BoWMR7ndYUnqBW5NjTbC

* chore(signals): pin Sparkplug tiering in the signals bench lane

Same flag as the web server lane (#5157). In #5141's fork runs it took
the signals lane from one benchmark varying by more than 5% across
fresh runners to none, and #4906's omit ownKeys -63% reads 226k vs 235k
instructions pinned (673k vs 237k unpinned). Benchmark mode only: the
test suite runs in worker threads, which reject V8 flags in execArgv.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0117BoWMR7ndYUnqBW5NjTbC

* chore(size): re-record the three scenarios over their caps on main

After #4906, #5209 and #5218, until/refresh, base server components and
live server components sat 5-15 B brotli over their caps, so the size gate
failed on every PR. Caps move to CI's measure on main @ 50a4bfd + 10 B and
recorded minified resets to the measure. The two page scenarios are frozen
floors (floor-caps.json).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0117BoWMR7ndYUnqBW5NjTbC

* test(signals): gate the affects(list) holder test on a promise, not a 20 ms timer

The test checked the marks after three settle() ticks while the action
waited on a 20 ms timer. On a loaded CI machine the ticks can outlast the
timer, so the action landed first and the check saw [false, false, false]
(failed on #5230's CI). The action now waits on a gate the test releases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0117BoWMR7ndYUnqBW5NjTbC

* chore(size): re-record the four scenarios over their caps on main

After #5221, #5225, #5228, #5235 and #5236, until/refresh, compiled base
server components, base + router and live + router sat 6-92 B brotli over
their caps. Caps move to CI's measure on main @ f7b6b9c + 10 B and recorded
minified resets to the measure. No floors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0117BoWMR7ndYUnqBW5NjTbC

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: gnovotny <g.novotny@gmx.ch>
Co-authored-by: Marve10s <igrimanigroman@gmail.com>
Co-authored-by: gnovotny <990945+gnovotny@users.noreply.github.com>
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.

# [2.0.4] After a cleanup calls an action, the next action's signal write is never committed (regression from #5161)

2 participants