Skip to content

perf(warp-core): run a single execution worker on the calling thread - #932

Open
flyingrobots wants to merge 3 commits into
mainfrom
claude/inline-worker
Open

flyingrobots wants to merge 3 commits into
mainfrom
claude/inline-worker

Conversation

@flyingrobots

Copy link
Copy Markdown
Owner

Summary

  • With one execution worker, a tick's work now runs on the calling thread instead of a spawned scoped thread that the caller then waits for. Two or more workers still spawn scoped threads, unchanged. The worker loop moved unchanged into drain_units, which both paths share.
  • New witnesses check that a rule panic and a missing store propagate identically for every worker count.
  • Behaviour note, documented in rustdoc and CHANGELOG.md: with one worker, rules run on the caller's thread and stack, so native rules must not rely on a fresh thread-local environment per tick.

Scope

  • Tests only
  • Docs only
  • Runtime code

Links

  • No issue. This came out of the stack-on-main study (docs/studies/stack-on-main.md on branch claude/measure-stack) and its review, which approved it as an isolated change.

Evidence

  • F5 tier M, application profile, append p50: 260.08 ms on main plus benches, 167.86 ms with this change. The run used a revision whose patch is identical to d578e157 (git patch-id), with durability off. Source: docs/studies/stack-on-main/summary.md on claude/measure-stack.

  • Below 1 ms (100-rewrite ticks) the runs disagreed with themselves, including on a path this change does not touch, so those rows are treated as noise.

  • Error-propagation witnesses:

    • rule_panic_propagates_identically_for_every_worker_count (1 to 32 workers), in tests/parallel_engine_worker_invariance.rs;
    • missing_store_propagates_identically_for_every_worker_count, in parallel/exec.rs.

    Both pass on the old one-thread path and on this change. Both fail against a deliberately broken inline path that swallows failures. They guard behaviour, so there was no red-before.

  • Checks on c82a23cd, local, Rust 1.96, macOS:

    • fmt, both clippy runs from the handoff, SPDX, the feature-gated test check and ban-globals pass.
    • The full warp-core suite (native_rule_bootstrap,trusted_runtime,host_test,delta_validate,application_root_profile,det_fixed) has 2,057 passed and 1 failed, special_files_are_rejected_before_a_read_attempt. That test binds a Unix socket under a scratch path longer than SUN_LEN. Rerun from a short TMPDIR, its whole target passes, 27 of 27.
  • Canonical results: golden vectors GV-001 to GV-004 and the existing worker-invariance tests pass.

Known, not changed here

  • With several workers, if two units fail in one tick, which error surfaces depends on which thread claimed which unit. With one worker it is always the first in canonical order. This predates the change.
  • EngineBuilder::workers says workers are capped at NUM_SHARDS. The engine actually caps them at the number of work units.

Documentation gate

  • I searched the README, GUIDE, docs README, architecture, spec, invariants and topics for worker-thread claims. Nothing describes the single-worker threading, so the only documentation impact is the rustdoc and the CHANGELOG.md entry in this PR.

Checklist

  • CI green (fmt, clippy, tests, rustdoc, audit/deny)
  • Kept PR small and focused (one thing)

🤖 Generated with Claude Code

flyingrobots and others added 3 commits October 20, 2026 11:30
execute_work_queue spawned and joined a scoped thread even when it had one
worker, and the engine's default is one worker. On F5 tier M under the
application-root profile, spawning and joining that thread took about 31%
of each tick, while the work it ran was about 2% of the run. A single
worker now runs the same loop inline. Several workers still each get a
thread. Nothing it computes changes.

Carried onto main from 43a8ddd on claude/stack-envelope, as an isolated
candidate with no dependency on M1, M2 or lazy blockers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add two witnesses that a single worker running inline on the caller's
thread reports failures exactly as scoped worker threads do:

- rule_panic_propagates_identically_for_every_worker_count: one of
  twenty scopes panics in its executor; for workers 1, 2, 4, 8, 16, 32
  the commit unwinds with the executor's payload, retains no evidence,
  keeps the poisoned item's evidence as a failure artifact, and leaves
  the state root unchanged.
- missing_store_propagates_identically_for_every_worker_count: an
  unresolvable warp yields exactly one MissingStore for 1, 2, 4, 8
  workers, every other worker an empty success.

Both pass with the inline path and with it disabled (the old threaded
one-worker path), and both fail against a mutant whose inline path
swallows failures.

Document on execute_work_queue, EngineBuilder::workers and in the
changelog that with one worker rules run on the caller's thread and
stack, so native rules must not rely on a fresh thread-local
environment per tick.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
clippy::manual_assert rejected an if-then panic! in the new engine
witness. assert! with a literal message keeps the same &str payload.

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

coderabbitai Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

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 1 minute.

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
  • Configuration used: Repository: flyingrobots/echo/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 780196fd-1cf9-445e-82e3-c2e4b6e7289f
📥 Commits

Reviewing files that changed from the base of the PR and between 0faaf58 and c82a23c.

📒 Files selected for processing: 4
  • CHANGELOG.md
  • crates/warp-core/src/engine_impl.rs
  • crates/warp-core/src/parallel/exec.rs
  • crates/warp-core/tests/parallel_engine_worker_invariance.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

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-21T12:04:25.534342Z c82a23c PR opened
ℹ️ 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.

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