Skip to content

feat(engine): rust runner#4582

Merged
MasterPtato merged 1 commit intomainfrom
04-06-feat_engine_rust_runner
Apr 8, 2026
Merged

feat(engine): rust runner#4582
MasterPtato merged 1 commit intomainfrom
04-06-feat_engine_rust_runner

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@claude
Copy link
Copy Markdown

claude bot commented Apr 7, 2026

PR Review: feat(engine): rust runner

This is a significant architectural refactor that:

  • Introduces a Rust-based test envoy (engine/sdks/rust/test-envoy) replacing the TypeScript one
  • Creates @rivetkit/engine-runner and @rivetkit/engine-runner-protocol as new TypeScript packages
  • Moves runner-protocol from engine/sdks/rust/runner-protocol to engine/packages/runner-protocol
  • Switches datacenter config from array to map format

Critical: No integration test coverage

rivetkit-typescript/packages/engine-runner/tests/lifecycle.test.ts is entirely commented out. This leaves the new TypeScript runner without any integration tests. These should either be wired up before merging or tracked as a follow-up with a clear TODO referencing the blocker.


Performance: Arc<Mutex<HashMap>> throughout envoy.rs

Per CLAUDE.md: "ALWAYS prefer a dedicated concurrency container like scc::HashMap or moka::Cache over Arc<Mutex<HashMap<_,_>>>".

Several fields in Envoy use this pattern:

  • actors: Arc<Mutex<HashMap<String, ActorState>>>
  • actor_event_indices: Arc<Mutex<HashMap<String, i64>>>
  • kv_pending_requests: Arc<Mutex<HashMap<u32, oneshot::Sender<...>>>>
  • tunnel_requests: Arc<Mutex<HashMap<String, TunnelRequestState>>>

Even for test code this guideline exists to avoid contention bugs surfacing differently in test vs prod. Consider scc::HashMap or note that this is intentional test-only code.


Performance: Linear scan in Tunnel::requestToActor

In tunnel.ts, #requestToActor is an Array<{gatewayId, requestId, actorId}> searched linearly (O(n)) when routing requests to actors. Under any non-trivial actor count this will degrade. Use a Map<string, string> keyed on a concatenation of idToStr(gatewayId) and idToStr(requestId).


Unused constant

In src/mod.ts:

const KV_EXPIRE: number = 30_000;

This constant is declared but does not appear to be used anywhere in the file. Remove it or wire it up.


PROTOCOL_VERSION sync

src/mod.ts declares const PROTOCOL_VERSION: number = 7 as a private constant. Make sure the value is kept in sync with PROTOCOL_MK2_VERSION in engine/packages/runner-protocol/src/lib.rs (path moved in this PR).


Hardcoded commit hash in comment

In tunnel.ts there is a comment referencing a specific commit hash URL. Pinning a comment to a specific commit hash will rot quickly. Reference the file path instead.


Datacenter config: breaking format change

All config.jsonc files change "datacenters" from an array to a map. This is a silent breaking change for anyone running self-hosted with a config file not under version control. If the engine config parser does not accept both formats, document this migration explicitly.


Minor: anyhow! vs .context()

In test_runner.rs, RunnerConfigBuilder::build uses .ok_or_else(|| anyhow::anyhow!("...")) while EnvoyConfigBuilder::build already uses .context("...") correctly. Per CLAUDE.md, prefer .context() over anyhow!.


Nit: u64 key format padding

In test_runner.rs:

format!("key-{:012x}", rand::random::<u64>())

u64 produces up to 16 hex digits; :012x pads to only 12. Use :016x for a correctly padded hex representation of a u64.


Overall the restructuring is clean and the Rust test-envoy is a clear improvement over the TypeScript one. The adapter layer in test_runner.rs maintaining backwards compatibility for existing engine tests is a good pattern. The main concern before merging is restoring integration test coverage in lifecycle.test.ts.

Copy link
Copy Markdown
Contributor

MasterPtato commented Apr 8, 2026

Merge activity

  • Apr 8, 8:52 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Apr 8, 9:15 PM UTC: Graphite rebased this pull request as part of a merge.
  • Apr 8, 9:16 PM UTC: @MasterPtato merged this pull request with Graphite.

@MasterPtato MasterPtato changed the base branch from 04-06-chore_remove_non-engine_drivers to graphite-base/4582 April 8, 2026 21:12
@MasterPtato MasterPtato changed the base branch from graphite-base/4582 to main April 8, 2026 21:14
@MasterPtato MasterPtato force-pushed the 04-06-feat_engine_rust_runner branch from d348737 to 62d3883 Compare April 8, 2026 21:14
@MasterPtato MasterPtato merged commit bc0c7f3 into main Apr 8, 2026
5 of 14 checks passed
@MasterPtato MasterPtato deleted the 04-06-feat_engine_rust_runner branch April 8, 2026 21:16
@MasterPtato MasterPtato mentioned this pull request Apr 9, 2026
11 tasks
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.

2 participants