Skip to content

fix: pace buffered RPC and renderer readers - #1878

Merged
domgan-oai merged 15 commits into
octanejs:mainfrom
openai-oss-forks:codex/pace-buffered-rpc-readers
Oct 8, 2026
Merged

domgan-oai merged 15 commits into
octanejs:mainfrom
openai-oss-forks:codex/pace-buffered-rpc-readers

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

An already-buffered RPC stream can consume every value in one microtask checkpoint. A custom renderer can do the same when a held delivery acknowledgement releases a ready backlog. With 32 values and 2 ms of work per value, both paths previously finished the entire backlog before another task ran.

Pace direct RPC and optional renderer-response readers with one shared approximately 5 ms host budget. Recheck retirement and abort state after waits, preserve ordered delivery and backpressure, and keep inline document delivery on its existing path. This independently implements priority 5 in #1864 against current main; it no longer includes the unmerged transition or signal-render changes from #1872/#1875.

A paced consumer can also wait before its first transport read. The server producer now observes its result immediately, retaining the original rejection for a sanitized error frame while avoiding an unhandled rejection during that wait. Iterator acquisition and pulls remain demand-driven.

Validation

  • 59 focused development tests pass: 11 reader scheduling regressions, 35 existing RPC tests, and 13 streamed-result/cancellation tests. The 11 reader tests and 13 producer/cancellation tests also pass in production mode.
  • Coverage includes fragmented reads, staggered concurrent readers, iterator return during a wait, abort authority, malformed frames, bounded delivery backpressure, inline delivery, early promise rejection, thenable assimilation, and lazy iterator acquisition.
  • The delayed-first-read regression fails before the server fix with the same unhandled rejection seen in CI. The fixed producer still emits sanitized open/error frames. A custom thenable is observed once, with no iterator acquisition or pull before demand.
  • Changed-file TypeScript diagnostics: zero. RuleSync guidance was regenerated; formatting and git diff --check pass; independent read-only correctness/complexity reviews are clean.
  • perf-review: reader and server follow-on scans report zero candidates. Work is admitted between indivisible reader pulls, parses, and receiver calls. No component/render path, Block/Scope layout, or DOM measurement changes. The existing task poster is reused; early rejection observation adds one handler per server result, not per streamed value.
  • Current-head CI at c0e899c9d is green: CI and benchmark report. All unit, Chromium, parity, static, package/build, example, and byte-budget gates passed. The catalog omission, native-capture test timer race, and delayed server-result rejection exposed by the prior runs are corrected.
  • Full local pnpm sync and workspace typecheck: the pinned toolchain is unavailable. Sync stops at missing typescript-native/package.json; focused runtime checks use cached Vitest, while the full pinned gates remain with CI.

Production-minified Node 22.22.3 reader probe: one excluded warmup pair and three alternating measured runs against exact main source 573127fd3 on the same machine:

Workload Main task marker Candidate task marker Main total completion Candidate total completion
RPC, 32 ordered values 66.9–67.5 ms, all 32 consumed 7.5–7.8 ms, 3 consumed 66.8–67.4 ms 68.0–68.8 ms
Gated renderer, 32 ordered frames 64.6–64.9 ms, all 32 consumed 12.1–12.2 ms, 6 consumed 64.6–64.8 ms 64.7–65.1 ms

Run node benchmarks/scheduler-responsiveness/reader-backlog.mjs; pass another checkout and --report for a baseline. These measurements establish task opportunities and completion cost, not browser input/paint latency. The subsequent server ownership fix is covered by rejection and cancellation tests; it does not change these reader admission paths. CI production bundle measurements remain authoritative; no budget is raised here.

Risk / follow-ups

The shared window cannot interrupt a single expensive parse or callback. Receiver work after its own later asynchronous continuation is outside admission. Delivery deadlines include queueing and admission; the transport deadline excludes local budget waits. Component render admission and signal producers' own scheduling policy are unchanged.

Provenance

  • An agent produced this diff (agent-authored)

Codex task · 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 low-level stream/RPC consumption, cancellation, and host scheduling semantics; mistakes could cause dropped frames, stale delivery, or timing regressions without touching auth or persistence.

Overview
Buffered streamed RPC and optional readStreamedRendererResponse paths could drain large ready backlogs in a single task, starving other host work. This PR adds a shared ~5 ms host budget (yieldForHostBudget) that yields between transport pulls, frame parsing, and custom delivery admission while keeping frame order, backpressure, and inline document delivery unchanged.

RPC iteration and renderer reads re-check abort/retirement after budget waits so iterator.return() and signals cannot publish stale values or swallow fresh protocol errors. Streamed signal producers observe rejected results at creation so a delayed first consumer read does not cause unhandled rejections. Docs, performance-audit guidance, a reader-backlog benchmark probe, and broad regression tests cover the behavior; the MCP bridge also registers @tanstack/react-query-devtools.

Reviewed by Cursor Bugbot for commit c0e899c. 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 8, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review October 8, 2026 00:57
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 6 value(s) increased within budget

Compares 8444db8ae, the merge commit's first parent (main has moved 3 commit(s) past the pull request's recorded base b7d152cc0) with fa22872f1 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

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 2.542 2.517 −0.0% −3.7% … +0.0% ⚪ within noise
octane-tsrx replace 6.817 6.883 +0.7% −5.6% … +4.0% ⚪ within noise
octane-tsrx add 2.600 2.500 −1.9% −3.9% … ±0.0% ⚪ within noise
octane-tsrx update 0.118 0.118 −0.3% −2.4% … +1.9% ⚪ within noise
octane-tsrx select 0.005 0.005 +0.3% −0.5% … +1.6% ⚪ within noise
octane-tsrx swap 0.031 0.031 +0.3% ±0.0% … +1.4% ⚪ within noise
octane-tsrx remove 0.013 0.013 ±0.0% −1.2% … +3.6% ⚪ within noise
octane-tsrx runlots 24.358 23.917 −0.3% −3.0% … +2.3% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 +1.3% −0.0% … +2.1% ⚪ within noise
octane-tsrx clear 59.775 55.692 −3.1% −5.5% … −0.4% ⚪ within noise
octane-jsx run 4.842 4.742 +0.0% −9.4% … +5.7% ⚪ within noise
octane-jsx replace 12.742 13.950 +5.0% +0.8% … +13.3% ⚪ within noise
octane-jsx add 3.675 3.842 −2.1% −6.8% … ±0.0% ⚪ within noise
octane-jsx update 0.302 0.293 +0.3% −1.5% … +4.4% ⚪ within noise
octane-jsx select 0.153 0.154 +1.3% −0.6% … +3.7% ⚪ within noise
octane-jsx swap 0.275 0.271 −0.3% −3.3% … +0.3% ⚪ within noise
octane-jsx remove 0.214 0.222 +5.1% +1.1% … +8.7% ⚪ within noise
octane-jsx runlots 34.575 36.458 +0.6% −3.9% … +14.2% ⚪ within noise
octane-jsx select_lots 1.910 1.849 +1.3% −3.9% … +7.8% ⚪ within noise
octane-jsx clear 55.783 60.808 +2.9% +0.7% … +6.8% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx full_fw_raw 566,237 566,584 +347 (+0.1%) 🔴
octane-tsrx full_fw_gzip 170,500 170,629 +129 (+0.1%) 🔴
octane-tsrx full_fw_brotli 143,508 143,677 +169 (+0.1%) 🔴
octane-jsx full_fw_raw 566,237 566,584 +347 (+0.1%) 🔴
octane-jsx full_fw_gzip 170,500 170,629 +129 (+0.1%) 🔴
octane-jsx full_fw_brotli 143,508 143,677 +169 (+0.1%) 🔴

54 other measured values are unchanged.

Public-import reachability bundles (bytes)

No changes across 111 measured values.

@domgan-oai
domgan-oai merged commit c0192ec into octanejs:main Oct 8, 2026
31 checks passed
trueadm added a commit that referenced this pull request Oct 8, 2026
Main c0192ec (#1889, #1872, #1883, #1878 landing together) failed the new
"bundle size checks" job: binding-base-ui-vite measures 62,351 gzip, so the
downward ratchet requires its budget to drop from 62,384 to 62,383.
run-minimal.mjs and run.mjs --write-budgets on that head change nothing else.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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