Skip to content

id-worlds: guest calls in blocking context — first #1067 fair-scheduling slice (draft, awaiting reference-machine bench) - #12571

Merged
dezren39 merged 2 commits into
mainfrom
archer-lane-h/1067-fair-scheduling
Nov 22, 2026
Merged

dezren39 merged 2 commits into
mainfrom
archer-lane-h/1067-fair-scheduling

Conversation

@dezren39

@dezren39 dezren39 commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Refs #1067 — first scheduler slice for F12.10, opened as draft: the mechanism lands with a deterministic test, but the benchmark venue available to a sandbox lane cannot decide the ratio (evidence below), so this waits for a reference-machine bench pair before merge.

Summary

A Wasm guest call executes synchronously inside its world actor and may burn its whole fuel budget (10,000,000 by default) in one execution. World actors share one Tokio runtime, so a fuel-spinning world parked a shared worker for the full span of every call and every other world's actor waited behind it.

WorldInstance guest calls (update, view, layout, records, wants, snapshot, restore) now run through run_guest_call in crates/id-worlds/src/sandbox.rs: on a multi-thread runtime the call executes under tokio::task::block_in_place — the same guard world_store::recv_writer_reply already uses for the journal rendezvous (#557) — so the runtime hands the worker's other tasks to a replacement thread while the guest runs. Off a multi-thread runtime the call is direct, exactly as before. Fuel, ordering, and poisoning semantics are unchanged.

Also records the CI-runner measurement campaign in pkgs/id/benches/BASELINES.md (no baseline lines change).

Evidence

Mechanism tests (failing-first, sandbox::tests):

  • spinning_guest_does_not_monopolize_a_runtime_worker — on a one-worker multi-thread runtime, a victim guest call completes while a spinning guest is still burning a 4e9 fuel budget. On main it fails with "victim guest call waited for the spinning guest's whole fuel budget"; with the change it passes, and the spin still ends in fuel exhaustion.
  • guest_calls_under_a_runtime_match_plain_thread_results_and_fuel — the wrap changes neither results nor fuel accounting.
  • Local: cargo test -p id-worlds --lib --features sandbox -- sandbox:: → 38 passed, 0 failed.
  • Runner: cargo test -p id-worlds --features sandbox (fleet-run 45024947483) → 1024 passed, 1 failed. The one failure, write_lease_entries_require_journal_version_7, fails identically on unmodified main c9fbfa0 (MAX_JOURNAL_VERSION is 13 since the KV bump; the test pins 12) — pre-existing, filed as id-worlds: write_lease journal-version pin test fails on main (MAX_JOURNAL_VERSION 13 vs pinned 12) #12546, unrelated to this change.

Benchmark (fuel_spin_isolation, full profile, fleet runner — 4 visible CPUs, 3 spinners):

ref calm p99 spinning p99 ratio spins
main c9fbfa0 (run 45024947483) 1.425 ms 3.562 ms 2.500 545
branch 780ddbe (run 45024947483) 2.372 ms 5.147 ms 2.170 1,591
branch 780ddbe (run 45027312468) 1.731 ms 6.693 ms 3.867 543
main c9fbfa0 (run 45027312468) 1.439 ms 83.794 ms 58.228 525

Identical code spans ratios 2.500–58.228 on this venue: the spinning-phase p99 over 300 samples on shared 4-vCPU runners is neighbour noise, so no ratio verdict is claimed from these runs. The deciding measurement is a before/after pair on the reference machine class (16 threads, 15 spinners) where the 2.517 baseline in BASELINES.md was recorded. Evidence level: mechanism measured deterministically in unit tests (sandbox); bench measured on the CI runner and found noise-dominated there; not run on the reference laptop.

Merge danger

Low blast radius, one file of production code: every Wasm guest call on a multi-thread runtime gains a block_in_place handoff (the pattern #557 already pays on every journal append). Behaviour off multi-thread runtimes is byte-identical to today. The residual risk is per-call handoff overhead under saturation, which is part of what the reference-machine bench pair should look at. Nothing else in the PR touches production code.


Proof this PR
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Archer added 2 commits November 22, 2026 12:55
…nnot monopolize a hub worker (#1067)

First scheduler slice for F12.10. A Wasm guest call executes
synchronously inside its world actor and may burn its whole fuel
budget (10,000,000 by default) in one execution. World actors share
one Tokio runtime, so a fuel-spinning world parked a shared worker
for the full span of every call and every other world's actor
waited behind it — the contention the fuel_spin_isolation benchmark
records (victim p99 ratio 2.517 against the 1.10 target on the
reference laptop).

WorldInstance guest calls (update, view, layout, records, wants,
snapshot, restore) now run through run_guest_call: on a multi-thread
runtime the call executes under tokio::task::block_in_place — the
same guard world_store::recv_writer_reply already uses for the
journal rendezvous (#557) — so the runtime hands the worker's other
tasks to a replacement thread while the guest runs. Off a
multi-thread runtime the call is direct, exactly as before. Fuel,
ordering, and poisoning semantics are unchanged; the same call
runs, just in blocking context.

Tests (failing-first, in sandbox::tests):
- spinning_guest_does_not_monopolize_a_runtime_worker: on a
  one-worker multi-thread runtime, a victim guest call completes
  while a spinning guest is still burning a 4e9 fuel budget. On
  main this fails with "victim guest call waited for the spinning
  guest's whole fuel budget"; with the change it passes, and the
  spin still ends in fuel exhaustion.
- guest_calls_under_a_runtime_match_plain_thread_results_and_fuel:
  the wrap changes neither results nor fuel accounting.

Local: cargo test -p id-worlds --lib --features sandbox --
sandbox:: → 38 passed, 0 failed (2 ignored, pre-existing).
…dominated (#1067)

Four full-profile runs on the fleet runner (two on main, two on the
blocking-context branch) span ratios 2.170-58.228, with identical
code producing 2.500 and 58.228: at 4 visible CPUs / 3 spinners the
spinning-phase p99 is neighbour noise. Recorded in BASELINES.md so
the next #1067 worker runs the deciding pair on the reference
machine class instead of re-learning the venue limit. No baseline
lines change.
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 390dc4ef-1d16-431a-8fbc-295b48a2c611
Commits

Reviewing files that changed from the base of the PR and between 1d6ca73 and 0addcf8.

Files selected for processing: 2

  • pkgs/id/benches/BASELINES.md
  • pkgs/id/crates/id-worlds/src/sandbox.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@dezren39
dezren39 marked this pull request as ready for review November 22, 2026 13:58
@dezren39
dezren39 requested a review from a team as a code owner November 22, 2026 13:58
@dezren39
dezren39 merged commit 6bc7fe5 into main Nov 22, 2026
1 check passed
@dezren39
dezren39 deleted the archer-lane-h/1067-fair-scheduling branch November 22, 2026 13:58
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T13:59:29.804918Z 0addcf8 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

dezren39 pushed a commit that referenced this pull request Nov 22, 2026
Two back-to-back pre/post pairs on the laptop at light ambient
load (full profile, same command): ratios indistinguishable
(pre 6.049/6.711, post 6.826/6.085), wake tail persists, ack p99
worsens (3.963/6.456 -> 12.983/17.242 ms), and the victim's own
spinning-phase command mean rises ~20x (67/103 -> 1,651/2,191 us,
bucketed p99 2,000 -> 50,000 us) because every guest call now pays
the block_in_place round trip under core saturation. Placement
cannot create CPU; the supported next lever is admission -
bounding concurrent guest burns. Pair lines appended to
baseline.txt.
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.

1 participant