Skip to content

fix(rivetkit): require engine ping for health#5022

Draft
NathanFlurry wants to merge 1 commit into
counter-latency/current-actor-metricsfrom
counter-latency/require-engine-ping-health
Draft

fix(rivetkit): require engine ping for health#5022
NathanFlurry wants to merge 1 commit into
counter-latency/current-actor-metricsfrom
counter-latency/require-engine-ping-health

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 11, 2026

Review: fix(rivetkit): require engine ping for health

Overview

This PR fixes a real bug: last_ping_ts was initialized to the current time, making a freshly-started envoy appear healthy before the engine ever sent a ping. Changing the sentinel to 0 and gating is_ping_healthy() on a non-zero value is correct. The core fix is sound.


Bug: Inconsistent health semantics between native Rust and NAPI paths

The two serverless health implementations diverge for the "no active envoy yet" case:

Native Rust path (rivetkit-rust/packages/rivetkit-core/src/serverless.rs):

guard
    .as_ref()
    .map(|handle| handle.is_ping_healthy())
    .unwrap_or(true)  // no envoy → healthy

NAPI path (rivetkit-typescript/packages/rivetkit-napi/src/registry.rs):

None => health_response(503, "engine_ping_stale", &version),  // no envoy → unhealthy

In serverless mode the envoy is lazy — it is only created on the first /start request. A freshly deployed TypeScript serverless actor will have no envoy and will therefore return 503 on every health probe until its first invocation arrives. For Cloud Run, k8s, and similar orchestrators this is the "recycle me" signal — the container will be torn down before it ever handles an actor request.

The status string engine_ping_stale is also semantically wrong for this case: it implies an envoy was started but the engine went quiet, whereas here no envoy has been created at all.

The registry.rs None branch should revert to health_response(200, "ok", &version) to match the native path. The is_ping_healthy() sentinel fix already makes the Some(envoy) branch correctly unhealthy when the engine has never pinged.


Positives

  • Correct sentinel. 0 is safe: epoch 0 is always outside the 20-second threshold, and the comment on last_ping_ts documents the invariant.
  • Three test fixtures aligned. actor.rs and events.rs test contexts both initialize last_ping_ts: 0, consistent with production construction.
  • serverless.rs logic refactor. Renaming envoy_unhealthy/negation to runtime_healthy makes the branch intent clearer.
  • Test updated correctly for the native path. The handles_basic_routes test now asserts 503 on initial health, directly covering the new no-ping-received behaviour.

Minor notes

  • The is_ping_healthy() last == 0 guard could use a named constant (e.g. PING_TS_UNSET = 0) to make the sentinel self-documenting without relying solely on the field comment.
  • No test coverage for the NAPI health() path. A test asserting that the serverless-idle (no envoy) case returns 200 would prevent the inconsistency from regressing.

@MasterPtato MasterPtato force-pushed the counter-latency/require-engine-ping-health branch from 8e4c5f6 to eaa41b2 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