Skip to content

fix: restore controlled inputs after deferred replay drains - #1968

Merged
trueadm merged 10 commits into
octanejs:mainfrom
openai-oss-forks:codex/deferred-controlled-replay
Oct 10, 2026
Merged

trueadm merged 10 commits into
octanejs:mainfrom
openai-oss-forks:codex/deferred-controlled-replay

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Preserve accepted controlled-input drafts during deferred replay, and restore rejected edits at the completion boundary that owns the edit.

An event replayed inside a flush can schedule an accepted update before the outer flush finishes. Restoring immediately erases its draft. Conversely, a native edit outside that flush must not wait for unrelated parked transition work.

Changes

  • Track whether the latest edit for each pending control arrived during a flush, using the existing restoration queue. Only those edits wait for held work; existing dispatch, staged-DOM and transaction fences remain in place.
  • Keep active root rendering protected, while pending root transactions only delay edits that arrived during a flush. This also covers a foreign root created during transition cleanup while fonts are pending.
  • Give input/change deliveries a small ownership token so a delayed stopped-event fallback cannot restore over a newer edit. Ownership stays on the physical host across nested dispatch and shadow-root continuation.
  • Restore surviving controls after render/commit failures while preserving the original thrown error.
  • Add public regressions for accepted/rejected drafts, parked transitions, stopped events, nested dispatch, repeated Event objects, checkbox/radio/select controls, identity, focus/selection and Send payloads.

The news benchmark fixture change has been removed. The fix uses the existing controlled driver and queue; it adds no scheduler task, Block/Scope field, public export or parallel restoration system.

Validation

  • Signed head 20f0ab92b, integrated with main 64c33de2f: 54/54 owning development/production cases and 310/310 nearby checks pass across controlled restoration, form diagnostics, native signal cleanup, scalar DOM bindings and context promotion.
  • Official scoped runtime, test and TSRX typecheck, full-plugin formatting and full pnpm sync pass with no generated changes.
  • 10/10 real Chromium cases pass for trusted input, stopped fallback, shadow roots and commit boundaries. The local subset excludes 12 React comparisons because the locked React compiler package was unavailable from the configured local gateway; full browser/parity lanes run in CI.
  • The transaction review finding was reproduced on predecessor c76654a0e: the six added mode-specific cases have four passing controls and two expected failures when transition cleanup creates a foreign root. The fix passes those cases after integration. The active initial-root accepted-edit case is neighboring compatibility coverage.
  • Earlier regressions establish the other boundaries: the published predecessor failed four parked-transition cases; origin tracking without delivery ownership failed two older stopped-event cases. These failures pass in the final suite. The historical 596 nearby executions are separate from the current-head totals above.
  • Independent source review confirms that the merge preserves both this fix and incoming controlled-commit ownership, error handling, context promotion and DOM behavior.
  • perf-review: the narrow review fix has zero candidates. The full PR has one candidate: the existing queueMicrotask(flush) is unchanged scheduling moved through cleanup nesting, not a new task. concise-code: runtime +341 −204 against main; the existing queue and driver are extended, with no new public export or Block/Scope field.
  • All current-head checks pass, including full CI and the benchmark report. All 64 work counters are unchanged. The review finding is resolved; maintainer review is still required.

Risk / follow-ups

This changes restoration ordering across flush, event and deferred-layout boundaries. Delivery ownership adds scalar event/host bookkeeping when controlled restoration is installed. The public failures justify this correctness fix; no production-latency improvement or Ripple parity is claimed.

Six matched Vite/OXC production builds against exact main 64c33de2f pass source-map reachability checks: restoration functions and the driver remain absent from no-control and event-only fixtures, with the existing queue retained equally. The controlled positive retains the restoration owners and passes accepted/rejected-input, identity and unmount gates.

Complete production fixture Raw JS change Gzip change
No controls +73 B +33 B
Events only +52 B +18 B
Controlled input +1,267 B +458 B

These are complete fixture bundles, not latency measurements. The bundle fixtures' public behavior ran in JSDOM; the separate Chromium checks above establish their stated browser scope.

Provenance

  • An agent produced this diff (agent-authored)

Codex task · implementation host com-79386.


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
Changes restoration ordering across flush, event dispatch, and deferred-layout boundaries in core runtime; behavior is heavily tested but touches form-control correctness paths.

Overview
Fixes controlled form control behavior when edits are replayed or triggered during hydration, layout effects, flushSync, deferred layout completion, or view transitions.

The runtime now defers DOM restoration until the owning flush or commit boundary finishes: pending restores record whether each edit happened during a flush, so accepted drafts are not wiped early while unrelated parked work drains. Input/change deliveries get ownership tokens (beginControlledDelivery / $$restoreDelivery) so stopped events, nested dispatch, shadow roots, and reused Event objects cannot restore over a newer edit.

restoreControlledStates runs after successful flushWork, flushSync, and completeDeferredLayouts, and rethrowAfterControlledRestore runs restoration on render/commit failures without masking the original error.

Adds hydration regression tests for text inputs, checkbox/radio/select, focus/selection, Send, animations, and error paths.

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

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 10, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review October 10, 2026 04:56
@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 43 value(s) increased
  • 🔴 bundle-reachability: 72 value(s) increased

Compares 64c33de2f, the merge commit's first parent with 950e6521b on the same runner. Any increase in a js-framework work counter fails this check; byte changes are a report. 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 2.700 2.750 ±0.0% −3.3% … ±0.0% ⚪ within noise
octane-tsrx replace 5.225 5.175 +0.0% −1.8% … +1.8% ⚪ within noise
octane-tsrx add 2.508 2.500 ±0.0% −2.0% … ±0.0% ⚪ within noise
octane-tsrx update 0.122 0.121 −0.5% −1.1% … +1.3% ⚪ within noise
octane-tsrx select 0.006 0.006 −0.2% −1.0% … +1.0% ⚪ within noise
octane-tsrx swap 0.016 0.016 −0.7% −3.2% … +0.7% ⚪ within noise
octane-tsrx remove 0.013 0.013 +0.9% −0.5% … +1.9% ⚪ within noise
octane-tsrx runlots 24.367 25.783 +0.6% −1.2% … +1.4% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 +0.3% −1.1% … +1.1% ⚪ within noise
octane-tsrx clear 35.300 34.433 −0.9% −2.4% … −0.1% ⚪ within noise
octane-jsx run 3.358 3.425 +0.0% −2.7% … +2.8% ⚪ within noise
octane-jsx replace 5.850 5.842 ±0.0% −1.6% … +1.6% ⚪ within noise
octane-jsx add 3.133 3.117 ±0.0% −2.9% … +0.0% ⚪ within noise
octane-jsx update 0.247 0.250 +0.0% −0.7% … +1.1% ⚪ within noise
octane-jsx select 0.131 0.133 +1.1% −0.0% … +3.2% ⚪ within noise
octane-jsx swap 0.171 0.175 +1.7% −0.6% … +2.9% ⚪ within noise
octane-jsx remove 0.166 0.166 ±0.0% −0.9% … +1.5% ⚪ within noise
octane-jsx runlots 29.000 30.225 −1.2% −4.3% … +1.6% ⚪ within noise
octane-jsx select_lots 1.577 1.588 +1.2% +0.3% … +2.1% ⚪ within noise
octane-jsx clear 36.592 36.725 −0.4% −3.5% … +0.6% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx js_raw 91,668 91,741 +73 (+0.1%) 🔴
octane-tsrx js_gzip 30,348 30,362 +14 (+0.0%) 🔴
octane-tsrx js_brotli 27,160 27,159 −1 (−0.0%) 🟢
octane-tsrx app_gzip 2,334 2,335 +1 (+0.0%) 🔴
octane-tsrx app_brotli 2,034 2,039 +5 (+0.2%) 🔴
octane-tsrx fw_raw 84,714 84,787 +73 (+0.1%) 🔴
octane-tsrx fw_gzip 28,014 28,027 +13 (+0.0%) 🔴
octane-tsrx fw_brotli 25,126 25,120 −6 (−0.0%) 🟢
octane-tsrx todo_js_raw 103,223 104,495 +1,272 (+1.2%) 🔴
octane-tsrx todo_js_gzip 34,614 35,049 +435 (+1.3%) 🔴
octane-tsrx todo_js_brotli 30,778 31,103 +325 (+1.1%) 🔴
octane-tsrx todo_fw_raw 98,582 99,854 +1,272 (+1.3%) 🔴
octane-tsrx todo_fw_gzip 32,377 32,812 +435 (+1.3%) 🔴
octane-tsrx todo_fw_brotli 28,878 29,203 +325 (+1.1%) 🔴
octane-tsrx chat_js_raw 102,563 103,835 +1,272 (+1.2%) 🔴
octane-tsrx chat_js_gzip 34,526 34,940 +414 (+1.2%) 🔴
octane-tsrx chat_js_brotli 30,775 31,101 +326 (+1.1%) 🔴
octane-tsrx chat_app_brotli 2,401 2,385 −16 (−0.7%) 🟢
octane-tsrx chat_fw_raw 96,780 98,052 +1,272 (+1.3%) 🔴
octane-tsrx chat_fw_gzip 31,801 32,215 +414 (+1.3%) 🔴
octane-tsrx chat_fw_brotli 28,374 28,716 +342 (+1.2%) 🔴
octane-tsrx weather_js_raw 138,758 138,810 +52 (+0.0%) 🔴
octane-tsrx weather_js_gzip 45,886 45,899 +13 (+0.0%) 🔴
octane-tsrx weather_js_brotli 40,409 40,428 +19 (+0.0%) 🔴
octane-tsrx weather_app_gzip 7,858 7,856 −2 (−0.0%) 🟢
octane-tsrx weather_app_brotli 6,658 6,669 +11 (+0.2%) 🔴
octane-tsrx weather_fw_raw 116,584 116,636 +52 (+0.0%) 🔴
octane-tsrx weather_fw_gzip 38,028 38,043 +15 (+0.0%) 🔴
octane-tsrx weather_fw_brotli 33,751 33,759 +8 (+0.0%) 🔴
octane-tsrx bindings_js_raw 678,953 680,232 +1,279 (+0.2%) 🔴
octane-tsrx bindings_js_gzip 223,605 224,050 +445 (+0.2%) 🔴
octane-tsrx bindings_js_brotli 190,315 190,691 +376 (+0.2%) 🔴
octane-tsrx bindings_app_gzip 115,672 115,671 −1 (−0.0%) 🟢
octane-tsrx bindings_app_brotli 96,215 96,161 −54 (−0.1%) 🟢
octane-tsrx bindings_fw_raw 331,211 332,490 +1,279 (+0.4%) 🔴
octane-tsrx bindings_fw_gzip 107,933 108,379 +446 (+0.4%) 🔴
octane-tsrx bindings_fw_brotli 94,100 94,530 +430 (+0.5%) 🔴
octane-tsrx full_fw_raw 573,673 575,018 +1,345 (+0.2%) 🔴
octane-tsrx full_fw_gzip 173,344 173,732 +388 (+0.2%) 🔴
octane-tsrx full_fw_brotli 145,821 146,207 +386 (+0.3%) 🔴
octane-jsx js_raw 168,403 169,673 +1,270 (+0.8%) 🔴
octane-jsx js_gzip 54,552 54,958 +406 (+0.7%) 🔴
octane-jsx js_brotli 47,818 48,190 +372 (+0.8%) 🔴
octane-jsx app_gzip 2,862 2,861 −1 (−0.0%) 🟢
octane-jsx app_brotli 2,414 2,411 −3 (−0.1%) 🟢
octane-jsx fw_raw 160,124 161,394 +1,270 (+0.8%) 🔴
octane-jsx fw_gzip 51,690 52,097 +407 (+0.8%) 🔴
octane-jsx fw_brotli 45,404 45,779 +375 (+0.8%) 🔴
octane-jsx full_fw_raw 573,673 575,018 +1,345 (+0.2%) 🔴
octane-jsx full_fw_gzip 173,344 173,732 +388 (+0.2%) 🔴
octane-jsx full_fw_brotli 145,821 146,207 +386 (+0.3%) 🔴

9 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
cli-spa-starter raw 83,280 83,332 +52 (+0.1%) 🔴
cli-spa-starter gzip 28,530 28,552 +22 (+0.1%) 🔴
cli-spa-starter brotli 25,350 25,363 +13 (+0.1%) 🔴
root-static-specialized raw 55,064 55,117 +53 (+0.1%) 🔴
root-static-specialized gzip 18,626 18,636 +10 (+0.1%) 🔴
root-static-specialized brotli 16,880 16,885 +5 (+0.0%) 🔴
root-chained-jsx raw 57,417 57,469 +52 (+0.1%) 🔴
root-chained-jsx gzip 19,328 19,345 +17 (+0.1%) 🔴
root-chained-jsx brotli 17,508 17,521 +13 (+0.1%) 🔴
root-static raw 148,149 149,421 +1,272 (+0.9%) 🔴
root-static gzip 48,004 48,411 +407 (+0.8%) 🔴
root-static brotli 42,271 42,659 +388 (+0.9%) 🔴
root-static-local raw 55,063 55,116 +53 (+0.1%) 🔴
root-static-local gzip 18,613 18,624 +11 (+0.1%) 🔴
root-callback-local raw 57,876 57,949 +73 (+0.1%) 🔴
root-callback-local gzip 19,437 19,473 +36 (+0.2%) 🔴
root-callback-local brotli 17,599 17,608 +9 (+0.1%) 🔴
hooks-state raw 67,212 67,264 +52 (+0.1%) 🔴
hooks-state gzip 22,364 22,395 +31 (+0.1%) 🔴
hooks-state brotli 20,211 20,236 +25 (+0.1%) 🔴
prop-attributes raw 64,412 64,464 +52 (+0.1%) 🔴
prop-attributes gzip 21,545 21,565 +20 (+0.1%) 🔴
prop-attributes brotli 19,476 19,473 −3 (−0.0%) 🟢
context raw 73,376 73,428 +52 (+0.1%) 🔴
context gzip 24,365 24,388 +23 (+0.1%) 🔴
context brotli 21,954 21,986 +32 (+0.1%) 🔴
hydrate-root raw 118,628 118,680 +52 (+0.0%) 🔴
hydrate-root gzip 38,595 38,621 +26 (+0.1%) 🔴
hydrate-root brotli 34,071 34,090 +19 (+0.1%) 🔴
deferred-hydration raw 202,146 202,219 +73 (+0.0%) 🔴
deferred-hydration gzip 64,368 64,391 +23 (+0.0%) 🔴
deferred-hydration brotli 55,770 55,800 +30 (+0.1%) 🔴
hydrate-frame raw 350,289 351,569 +1,280 (+0.4%) 🔴
hydrate-frame gzip 110,343 110,783 +440 (+0.4%) 🔴
hydrate-frame brotli 94,582 95,031 +449 (+0.5%) 🔴
suspense-transition raw 125,360 125,412 +52 (+0.0%) 🔴
suspense-transition gzip 40,079 40,090 +11 (+0.0%) 🔴
suspense-transition brotli 35,504 35,550 +46 (+0.1%) 🔴
component-owned-effects raw 57,881 57,933 +52 (+0.1%) 🔴
component-owned-effects gzip 19,493 19,512 +19 (+0.1%) 🔴
component-owned-effects brotli 17,668 17,695 +27 (+0.2%) 🔴
binding-hooks raw 67,794 67,846 +52 (+0.1%) 🔴
binding-hooks gzip 22,923 22,942 +19 (+0.1%) 🔴
binding-hooks brotli 20,730 20,756 +26 (+0.1%) 🔴
binding-base-ui-vite raw 187,606 188,881 +1,275 (+0.7%) 🔴
binding-base-ui-vite gzip 60,315 60,735 +420 (+0.7%) 🔴
binding-base-ui-vite brotli 52,723 53,137 +414 (+0.8%) 🔴
binding-base-ui-esbuild raw 214,932 216,249 +1,317 (+0.6%) 🔴
binding-base-ui-esbuild gzip 69,905 70,345 +440 (+0.6%) 🔴
binding-base-ui-esbuild brotli 60,733 61,167 +434 (+0.7%) 🔴
binding-aria-esbuild brotli 2,809 2,810 +1 (+0.0%) 🔴
binding-radix-vite raw 187,968 189,243 +1,275 (+0.7%) 🔴
binding-radix-vite gzip 60,222 60,614 +392 (+0.7%) 🔴
binding-radix-vite brotli 52,628 53,030 +402 (+0.8%) 🔴
binding-radix-esbuild raw 215,078 216,395 +1,317 (+0.6%) 🔴
binding-radix-esbuild gzip 69,811 70,256 +445 (+0.6%) 🔴
binding-radix-esbuild brotli 60,611 61,063 +452 (+0.7%) 🔴
binding-mantine-hooks-vite raw 67,956 68,008 +52 (+0.1%) 🔴
binding-mantine-hooks-vite gzip 22,834 22,846 +12 (+0.1%) 🔴
binding-mantine-hooks-vite brotli 20,651 20,639 −12 (−0.1%) 🟢
binding-mantine-hooks-esbuild raw 79,715 79,915 +200 (+0.3%) 🔴
binding-mantine-hooks-esbuild gzip 27,491 27,553 +62 (+0.2%) 🔴
binding-mantine-hooks-esbuild brotli 24,596 24,711 +115 (+0.5%) 🔴
binding-apollo-client-vite raw 329,763 331,042 +1,279 (+0.4%) 🔴
binding-apollo-client-vite gzip 102,534 102,975 +441 (+0.4%) 🔴
binding-apollo-client-vite brotli 89,882 90,254 +372 (+0.4%) 🔴
binding-apollo-client-esbuild raw 365,103 366,421 +1,318 (+0.4%) 🔴
binding-apollo-client-esbuild gzip 116,306 116,764 +458 (+0.4%) 🔴
binding-apollo-client-esbuild brotli 101,424 101,877 +453 (+0.4%) 🔴
binding-usehooks-ts-vite raw 68,738 68,790 +52 (+0.1%) 🔴
binding-usehooks-ts-vite gzip 23,062 23,081 +19 (+0.1%) 🔴
binding-usehooks-ts-vite brotli 20,896 20,852 −44 (−0.2%) 🟢
binding-usehooks-ts-esbuild raw 80,489 80,689 +200 (+0.2%) 🔴
binding-usehooks-ts-esbuild gzip 27,731 27,784 +53 (+0.2%) 🔴
binding-usehooks-ts-esbuild brotli 24,818 24,917 +99 (+0.4%) 🔴

36 other measured values are unchanged.

@trueadm trueadm mentioned this pull request Oct 10, 2026
13 of 14 tasks
@trueadm

trueadm commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

Needs one small change. The fix is in the right place: restores queued during a flush now wait for the ambient flush instead of writing a stale controlled value partway through. The layout-adoption rows of the new test would fail on main. One part of the new guard is broader than the fix needs, though, and it changes documented timing.

  1. Restores outside any flush now wait for parked transition work.
    • On main, restoreControlledStates restored unconditionally. The new QUEUE.length > 0 clause also applies to discrete events outside a flush.
    • Sequence: a ViewTransition animation is in flight and some transition work is queued. maybeFlushDiscrete sends the transition-only queue through flush() (L31330), and routeFlush parks it with vtWaitForHandles (L7414), so QUEUE stays non-empty.
    • A rejected edit then stays on screen until the animation finishes. A controlled input updated inside startTransition keeps its typed text where main and React snap it back.
    • differences-from-react.md#L1466 still promises "both before the dispatch returns". Please scope the QUEUE clause to restores queued while a flush is running, which is the held-foreign-work case. Otherwise, document the new timing and add a test for it.
  2. Benchmark edit (question). The fix doesn't need this change.
    • It adds an Octane-only layout-effect re-render inside the timed hydrate() window, while the other frameworks' fixtures still read the draft during render.
    • PR CI doesn't run hydration-interactivity; only the weekly bench.yml does.
    • Please drop it, or split it out with a weekly-suite run (and a main-fails run if it's meant as the end-to-end repro).
  3. Nit: the restore-then-rethrow catch block appears three times (L9329, L10196, L11316), and it causes the whole −182-line re-indent. A shared helper returning never would remove both.
  4. Nit: no replay test covers checkbox/radio (change) or select. They share the mechanism, so the risk is low.

Verified:

  • git diff -w shows the −182 lines are only re-indentation, apart from moving result/return in flushSync.
  • On main, the hydration replay restores the stale '' mid-cascade, so the second replayed input and the Send click both read it.
  • The cost is one driver-existence check per flush exit. restoreControlledStates returns on an empty list first. perf-review-scan is clean and all 64 work counters are unchanged.
  • No semantic conflict with perf(octane): tree-shake unused controlled event restoration #1946 (lazy restore driver) or perf: omit unused controlled commit helpers #1963. The original render/commit error is still rethrown, and disconnected inputs are still skipped.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.

Reviewed by Cursor Bugbot for commit c76654a. Configure here.

Comment thread packages/octane/src/runtime.ts Resolved
@trueadm

trueadm commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

The restore-timing concern is resolved. Good to go once it's green on current main.

  • An edit outside a flush gets a positive delivery stamp and restores before the dispatch returns, even when transition work is parked behind an animation (L33239–L33252). Only edits stamped during a flush wait for the ambient flush.
  • The animation test pins both the rejected-edit case and the startTransition case.
  • The benchmark edit is gone, the three catch blocks are now one rethrowAfterControlledRestore helper, and checkbox/radio/select replay is covered.

Non-blocking questions:

  1. Stopped fallback when ownership doesn't match (L31238, L33306). The fallback now skips finish when ownership doesn't match. Example: an onInputCapture handler synchronously dispatches change on the same input. That nested delivery takes ownership but finishes at depth 1. If the outer input is then stopped below the root and the change is rejected, nothing restores the input, whereas main always calls finish. This is contrived, but could the fallback skip only the enqueue?
  2. Held entry and script-dispatched clicks. While a during-flush entry is held, pendingRestores stays non-empty. So an unrelated script-dispatched click with an urgent update passes this gate and commits synchronously, unlike the documented batching. The window is narrow, and the previous head had a broader form of this.
  3. Bundle size. Controlled-input bundles grew from about +70 B to about +430 B gzip (todo +434, chat +421, octane-jsx +391). Is the delivery token needed beyond the stopped-fallback cases?
  4. Nit: $$restoreDelivery is a new enumerable string expando on edited controls. The comment near seedExpando asks that new private keys stay out of for...in. A symbol would avoid that.

Verified:

  • The stamp is a module-local symbol. The sequence counter is shared across roots and never collides, and only numbers are stored.
  • With no control armed, the cost is one null check per delegated event.
  • All checks were green on c76654a0e1.

@trueadm
trueadm merged commit dd8805f into octanejs:main Oct 10, 2026
33 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 10, 2026
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.

2 participants