Skip to content

fix(octane): pace ready query results and finish backlog investigation - #1983

Merged
trueadm merged 3 commits into
mainfrom
codex/finish-scheduler-investigation
Oct 10, 2026
Merged

trueadm merged 3 commits into
mainfrom
codex/finish-scheduler-investigation

Conversation

@trueadm

@trueadm trueadm commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

One hundred independent query promises settling together could still spend an entire ~234 ms checkpoint delivering subscribers, even though their component renders coalesced. Publish successful query results through the existing shared host budget, rechecking ownership after each wait. In the paired production Chromium probe, the longest checkpoint falls to ~8 ms and all 15 later keystrokes run before completion.

This also completes the remaining investigation work in #1864: an externally supervised infinite-producer regression; cold/ready, small/large, multi-root and fragmented-reader browser cases; deferred/Action React controls; frame and main-thread traces; allocation/retention observations; count/time/combined budget comparisons; and waiting-island selection, IME and user-activation checks. See the measurements and policy decisions.

Changes

  • Pace one-shot query successes at the existing publication boundary; preserve retained/seed reads and the existing rejection path. Add completion, replacement and disposal regressions.
  • Make both awaited act() drains include the existing budget sentinel, so they await paced query/stream publications and their resulting UI. Cover synchronous and asynchronous callbacks.
  • Extend the existing production backlog runner and compiled form fixture. Keep alternative budget policies confined to benchmark builds.
  • Clarify passive effects draining before a following render, and the limits of Action callback execution. Update the scheduling reference and its generated copies.

Validation

  • Scoped formatting and pnpm typecheck:files; pnpm sync.
  • Scheduler/reader/deferred/effect/island suites: 206 tests in dev/prod.
  • Signals node suite: 273 tests; native collection/server observation/ownership plus external watchdog: 96 tests in dev/prod.
  • Production backlog and dev/production compiled form browser suites: 68 tests.
  • Behavior-root suite: 698 tests in dev/prod. Replace fixed microtask-count waits with act() for query publication; all DOM, identity, error, and disposal assertions remain. All 698 cases pass with the updated waits.
  • Scoped typechecking passed for the implementation and original tests. The behavior-root file and its imported fixtures have identical existing standalone typecheck diagnostics on main and this branch; no new diagnostics. Production typechecking passed CI.
  • Awaited act() regression: all 12 dev/prod cases fail before the drain fix (only 3–6 of 12 values arrive) and pass after it. The broader act()/scheduler/reader/effect/behavior-root rerun passes 932 tests.
  • The three query-promise regressions fail before the publication fix. The external watchdog separately covers the existing query/derived stream budget for Investigate microtask megatasks in streams, hydration, actions, and deferred rendering #1864; disabling that budget makes both controls hit their external kill deadline.
  • 52 browser conditions at each of 1× and 6× CPU, plus five-sample paired baseline/candidate and elapsed/count/combined comparisons for expensive and cheap backlogs. Ordered values, final UI and input state are checked throughout.
  • Minimal root-static, hooks-state, and server-render reachability controls: identical raw/gzip/brotli sizes on current main and the candidate. Query fixture delta: +86 raw / +12 gzip bytes in the paired probe.
  • Current-head CI at 6e58afcb36: all test shards, production typechecking, lint, React parity, browser/Node/website integration, example apps, package validation, compatibility, and provenance passed. Bugbot completed without findings; all 32 checks passed.
  • Current-head benchmarks: all 64 work counters unchanged. Full-export byte growth and the reported JSX clear timing delta are accounted for under Risk / follow-ups below.

perf-review: scan reports 0 candidates. Hot path: receivePromiseValue, once per successful query result plus admission retries. No new record fields, DOM work, task poster, or compiler output. One conditional retry closure per exhausted-budget wait; publication still uses the existing native-producer batch. Whole-page allocation sampling and commit/effect counts quantify the cost. The additional budget-sentinel check runs only in the two asynchronous act() drains and adds no state, allocation, or per-render work. The root/state/server bundle controls remain byte-identical. No unresolved must-fix finding.

concise-code: shipped/runtime source +34 −11. Reusing the existing sentinel avoids a second pending-work counter and its cancellation bookkeeping. New files are the externally supervised worker and test, the private benchmark declaration bridge, the investigation report, and the required changeset. Extending the existing budget avoids a second queue or public policy option; extending the existing browser server and form fixture avoids separate harnesses. A promise-only watchdog cannot escape starvation.

Risk / follow-ups

  • Responsiveness trades throughput and allocation for progress: the 100-query/2 ms-subscriber probe completes in 245 → 367 ms, with 2 → 21 commits/passive bodies including mount. First commit improves from 245 → 23 ms; observed Event Timing p99 from 248 → 24 ms. These are synthetic, instrumented measurements, not a general speedup claim.
  • Keep elapsed budgeting: count/combined limits unnecessarily split cheap work, taking 36–42 ms versus ~13 ms for 100 cheap query results. Full results and measurement limitations are in the report.
  • Action callback invocation remains React-compatible and unpaced. A blocked-first queue of 100 callbacks at 2 ms each still creates a ~231 ms checkpoint in Octane (~236 ms in React). Atomic render/callback limits and narrower held-transition exceptions are explicitly documented, not claimed fixed.
  • Even a single successful result can wait after earlier work spends the shared budget; synchronous SSR after promise resolution can still see pending. Rejections retain prompt failure notification and cleanup, so expensive rejection bursts remain unpaced and can overtake a waiting success.
  • The full export bundle, which includes act(), grows by 39 raw / 76 gzip / 121 Brotli bytes. The other 54 application-bundle measurements are unchanged; 109 public-import measurements are unchanged and hydrate-frame compression decreases slightly. The new sentinel check is confined to awaited act() drains.
  • CI reports JSX clear at +9.1% (paired 95% interval +4.3% to +13.3%); the observation is retained. A serial rebuild of octane-jsx-jsbench against base c82354bf84 and this head with the same locked dependencies produces byte-identical JavaScript, HTML, and client-build metadata. The JavaScript SHA-256 is 6bf018fb2a14e84fa72b9aa24e13a9cfa4cd6baedfb38a76886fc86ec2b2cc94. Together with unchanged operation/DOM counters, this is evidence against attributing that timing delta to changed application code; it is not a claim that the measured delta was zero.
  • Heap observations include browser/runtime bookkeeping and retained numeric harness logs; they are not a proof that every payload was collected. A trace paint after a commit is not a compositor presentation guarantee.

Refs #1864.

Provenance

  • An agent produced this diff (agent-authored)

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 core scheduler/query publication timing and act() drain semantics; apps/tests that assumed immediate query publication or microtask settling may need updates, though rejections and retained reads are unchanged.

Overview
Ready query successes now share the same ~5 ms host budget as streams, so large bursts of independent promise completions can yield between publications instead of running all subscriber/render work in one microtask checkpoint. receivePromiseValue calls yieldForHostBudget, retries after a host task, and re-checks request ownership; rejections stay on the existing prompt path.

Awaited act() now treats a pending budget sentinel as work to drain (hasPendingHostBudget), and tests/docs call out that sync SSR right after resolve may still see pending and that microtask-count settling is unreliable.

#1864 investigation is wrapped up in-repo: expanded Chromium backlog runner (queries, RPC/renderer readers, deferred, matrix/policy builds), investigation.md with measurements, scheduling skill copies and docs/differences-from-react.md updated (Action bodies unpaced, passive drain-before-render, query pacing edge cases). Regression coverage adds signal-task pacing/disposal tests, an external-process infinite-producer watchdog, browser scheduler-backlogs scenarios, and a waiting independent-island form test (selection/IME/user activation).

Reviewed by Cursor Bugbot for commit 6e58afc. 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
@trueadm
trueadm marked this pull request as ready for review October 10, 2026 20:53
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website 6e58afc Commit Preview URL

Branch Preview URL
Oct 10 2026, 09:28 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website-mcp 6e58afc Commit Preview URL

Branch Preview URL
Oct 10 2026, 09:31 PM

@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🟡 js-framework: 1 timed operation(s) slower beyond ±3%
  • 🔴 bundle-size: 6 value(s) increased

Compares c82354bf8, the merge commit's first parent with 8efc395d9 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

target operation base ms head ms head/base 95% CI
octane-jsx clear 36.792 38.408 +9.1% +4.3% … +13.3% 🟡 slower
All 20 timed operations (19 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 2.658 2.692 −0.0% −3.4% … ±0.0% ⚪ within noise
octane-tsrx replace 5.725 5.733 −0.8% −2.6% … +0.8% ⚪ within noise
octane-tsrx add 2.483 2.500 ±0.0% ±0.0% … +2.0% ⚪ within noise
octane-tsrx update 0.129 0.125 −1.3% −3.2% … +0.6% ⚪ within noise
octane-tsrx select 0.006 0.006 +1.8% +0.8% … +3.3% ⚪ within noise
octane-tsrx swap 0.017 0.017 −0.7% −2.1% … +1.8% ⚪ within noise
octane-tsrx remove 0.014 0.014 −0.9% −1.8% … +1.8% ⚪ within noise
octane-tsrx runlots 25.375 25.475 −0.4% −0.8% … +0.8% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 −0.3% −1.2% … +1.2% ⚪ within noise
octane-tsrx clear 37.900 38.008 +0.4% −2.6% … +2.9% ⚪ within noise
octane-jsx run 3.450 3.458 ±0.0% −1.3% … +1.3% ⚪ within noise
octane-jsx replace 6.367 6.342 −1.5% −3.7% … −0.0% ⚪ within noise
octane-jsx add 3.150 3.175 ±0.0% ±0.0% … +2.9% ⚪ within noise
octane-jsx update 0.246 0.250 +2.4% +0.3% … +4.4% ⚪ within noise
octane-jsx select 0.132 0.132 −0.6% −1.7% … +0.6% ⚪ within noise
octane-jsx swap 0.171 0.172 +0.6% −0.6% … +1.7% ⚪ within noise
octane-jsx remove 0.179 0.177 −0.0% −1.8% … +2.8% ⚪ within noise
octane-jsx runlots 31.092 29.933 +0.2% −2.6% … +2.1% ⚪ within noise
octane-jsx select_lots 1.538 1.617 −0.8% −2.9% … +0.7% ⚪ within noise
octane-jsx clear 36.792 38.408 +9.1% +4.3% … +13.3% 🟡 slower

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx full_fw_raw 575,606 575,645 +39 (+0.0%) 🔴
octane-tsrx full_fw_gzip 173,935 174,011 +76 (+0.0%) 🔴
octane-tsrx full_fw_brotli 146,307 146,428 +121 (+0.1%) 🔴
octane-jsx full_fw_raw 575,606 575,645 +39 (+0.0%) 🔴
octane-jsx full_fw_gzip 173,935 174,011 +76 (+0.0%) 🔴
octane-jsx full_fw_brotli 146,307 146,428 +121 (+0.1%) 🔴

54 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
hydrate-frame gzip 110,020 110,016 −4 (−0.0%) 🟢
hydrate-frame brotli 94,427 94,400 −27 (−0.0%) 🟢

109 other measured values are unchanged.

@trueadm trueadm left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Review

The pacing itself looks right. receivePromiseValue re-enters currentEntry(attempt) after every wait, carries nothing from the stale entry across it, and reuses the existing budget without adding a queue or fields. The replace/dispose regressions cover the lease. The investigation is thorough. Two things block merge, though. Both come from the change reaching further than bursts.

Blocking

1. CI is red because of this change. test shard (Node 24, 1/4) has 16 failures in packages/octane/tests/behavior-root.test.ts: 4 tests × dev/prod × octane/octane-prod. Main is green at the base (c82354bf84). Fail-fast cancelled shards 2/4 and 4/4; they did not fail. 4/4 had already passed 664/664 files, but 2/4 never reported, so there may be more failures. I reproduced the same 8 failures locally on 0760168 with vitest run --project octane packages/octane/tests/behavior-root.test.ts.

The cause: yieldForHostBudget fixes started at the first check in a host task and keeps it until the sentinel task runs. These tests only await microtasks (settle() is 4 × await Promise.resolve()), and between those awaits they compile and SSR fixtures synchronously. Once any earlier check has opened the window, the next query result moves to the sentinel task, which settle() never reaches.

  • adopts and switches @Try arms… fails even when run alone. first, second and recovered publish. Then the second fixture() compile runs in the same task, and fourth is deferred (L9811).
  • builds a @Try region inside an arm… passes alone but fails in the full file, because an earlier test opened the window. The outcome now depends on test order.
  • keeps a server-resolved @Try arm…: the query resolves before the synchronous renderToString, yet the server still renders @pending. It fails at L10119 in the file run and at L10130 alone.
  • hydrates a binding view's settled @Try arms…: in the ready case the server renders @pending, then the client hydrates ready and replaces the server node (L9923). The error case passes because rejections aren't paced.

2. act() no longer drains query results. The async drain in act loops only while hasPendingWork() || DEFERRED_SWAPS !== null || transitionTask !== 0. A result waiting on the budget sentinel doesn't count as pending work. Probe setup: 12 query resources, each subscriber adds 2 ms to a mocked performance.now and bumps a useState, and all 12 are resolved inside await act(async () => …).

  • base requests.ts: 12/12 published and rendered after act
  • this PR: 6/12

Stream pacing already had this gap. This PR extends it to every promise query, which app tests use far more often. Suggested fix: export a cheap check from host-budget.ts that says a budget wait is pending (for example sentinel !== undefined), add it to both hadWork sites, and add a regression in signal-task.test.ts.

Contract and docs

3. The behavior change is broader than "large bursts". A single successful query result can now arrive one host task after its promise settles. That happens whenever the current task has already used about 5 ms since any budget check: a compile, hydration, a long render, another producer, or a previous test. I'd keep that. It is closer to React, where Suspense pings go through Scheduler tasks that act() drains. But it should be stated plainly:

  • In differences-from-react.md L1423 and the changeset, say:
    • a lone result can also wait one host task;
    • a synchronous renderToString run right after the promise resolves can still render pending;
    • tests should use act() (once #2 is fixed) or a host-task wait instead of counting microtasks.
  • Then update the four behavior-root tests to wait the right way, with the same final-state assertions. That fixes an assumption that is now wrong; it doesn't weaken the tests.

4. Rejections stay unpaced (failAttempt). In one task, a failing query shows @catch immediately, while a sibling success that settled earlier waits for the sentinel. The hydration test above shows exactly that split. Is there a reason not to pace rejections too? A burst of rejections with expensive @catch subscribers produces the same long checkpoint. If they stay unpaced on purpose, say so in the differences doc, not only in investigation.md.

Minor

  • signals-ready-process.test.ts only drives kind: 'stream' and derived$ producers, so it guards the existing stream budget, not receivePromiseValue. Keeping it to close out #1864 is fine. The PR body just reads as if it covers the query fix.
  • differences-from-react.md has two lines that weren't rewrapped ("…so many producers do" and "…Use useLayoutEffect when the"), and so does investigation.md ("unthrottled control. Use --work-ms=0…").

Also checked and fine: the benchmark-only policy swap (an esbuild onLoad rewrite guarded by assert.match) never reaches shipped code; the generated scheduling.md copies match .rulesync; and the bench report shows no byte or work-counter changes.

@trueadm
trueadm merged commit d7c1de0 into main Oct 10, 2026
34 checks passed
@trueadm
trueadm deleted the codex/finish-scheduler-investigation branch October 10, 2026 22:01
@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.

1 participant