Skip to content

TODO: ktichen sink counter latency#5051

Draft
NathanFlurry wants to merge 1 commit into
rivetkit-shutdown/use-engine-stop-thresholdfrom
05-12-todo_ktichen_sink_counter_latency
Draft

TODO: ktichen sink counter latency#5051
NathanFlurry wants to merge 1 commit into
rivetkit-shutdown/use-engine-stop-thresholdfrom
05-12-todo_ktichen_sink_counter_latency

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
Contributor

claude Bot commented May 12, 2026

Code Review

This PR adds a Rust counter-latency load-test tool, renames the default runner pool from "default" to "k8s" throughout, and makes several kitchen-sink example improvements (Dockerfile PID 1 fix, WebSocket echo on the counter actor, onSleepStarted broadcast).


Issues

Pool rename inconsistency (bug)

examples/kitchen-sink/scripts/on-sleep-remote-watch.ts (the new file) defaults to "default" at POOL_NAME = stringFromConfig("pool", ["RIVET_POOL"], "default") while the entire rest of the PR renames that default to "k8s". This new script will silently target the wrong pool when RIVET_POOL is unset.


eprintln! in Rust code (args.rs, main.rs)

CLAUDE.md: "Never use eprintln! or println! for logging in Rust code. Always use tracing::info!, tracing::warn!, tracing::error!, etc."

EnvConfig::from_env() uses eprintln! + process::exit(1) for fatal errors. It should return anyhow::Result<Self> so the caller controls the exit path and errors go through tracing.


Mutex<HashMap> in stats.rs

CLAUDE.md: "Never use Mutex<HashMap<...>> or RwLock<HashMap<...>>. Use scc::HashMap."

State::worker_health is a Mutex<HashMap<WorkerId, WorkerHealth>>. The lock is not held across awaits so there is no deadlock risk, but the pattern violates the codebase invariant. Adding scc as a dependency and switching to scc::HashMap would resolve it.


Magic number 1 for WebSocket ready state (counter.ts, sigterm-sleep-probe.ts)

websocket.readyState !== 1 uses a bare integer where WebSocket.OPEN (or a named constant) is clearer and prevents silent mismatch.


Em dashes and sentence fragments in comments

CLAUDE.md: "Do not use em dashes. Use periods to separate sentences instead."

counter.ts comment block contains both an arrow character and an em dash. Suggested rewrite: "Plain echo for the rtt counter-latency harness. Any message received is sent back immediately with no state mutation or awaits, to keep the echo path as close to raw WebSocket RTT as possible."

Same fragment/dash pattern appears in file-level comments in args.rs, concurrent.rs, and endpoint.rs.


Duplicate base36 implementation

rtt.rs defines base36(n: u64) -> String and concurrent.rs defines to_base36(n: u64) -> String with identical logic and different names. These should be consolidated in a shared util.rs module.


TOCTOU race in sigterm-sleep-probe.ts broadcast

websocket.send() can throw if the socket transitions to CLOSING between the readyState !== 1 guard and the actual send. A try/catch removes the race window.


Minor notes

  • RIVET_PROTOCOLS constant in ws.rs is defined but unused and will produce a compiler warning.
  • endpoint.rs reimplements percent-encoding manually; the url crate (already a dependency) exposes percent_encoding::percent_decode_str. The manual + to space translation applies HTML form-encoding semantics that are incorrect for URL auth/path components.
  • The Dockerfile CMD comment uses an arrow character and a comma splice; period-separated sentences would follow CLAUDE.md comment style.

@NathanFlurry NathanFlurry force-pushed the 05-12-todo_ktichen_sink_counter_latency branch 3 times, most recently from be71196 to 537fd39 Compare May 12, 2026 19:16
@MasterPtato MasterPtato force-pushed the 05-12-todo_ktichen_sink_counter_latency branch from 537fd39 to fa9d09d Compare May 14, 2026 17:26
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