Skip to content

refactor(rivetkit-core): rename StopReason to ShutdownKind and kill enum fallthroughs#4765

Merged
NathanFlurry merged 1 commit intomainfrom
sleep-cleanup/17-stop-reason-and-fallthrough-fix
Apr 27, 2026
Merged

refactor(rivetkit-core): rename StopReason to ShutdownKind and kill enum fallthroughs#4765
NathanFlurry merged 1 commit intomainfrom
sleep-cleanup/17-stop-reason-and-fallthrough-fix

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

This was referenced Apr 24, 2026
Copy link
Copy Markdown
Member Author

NathanFlurry commented Apr 24, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link
Copy Markdown

claude Bot commented Apr 24, 2026


Review: refactor(rivetkit-core): rename StopReason to ShutdownKind and kill enum fallthroughs

Overall this is a clean, well-executed refactor that also ships a meaningful bug fix. A few notes below.


Rename is semantically clearer. ShutdownKind communicates what type of shutdown (Sleep vs Destroy) rather than the vague StopReason which sounds more like an error description. Naming is a real improvement.

New map_envoy_stop_reason helper is the right call. Centralizing the protocol->lifecycle mapping into one explicit function makes the semantics visible and testable. The inline comments on each arm explaining the why (reallocation, connection loss, etc.) add genuine value.

LifecycleCommand::stop_reason fallthrough removal (line 184) is exactly the kind of change the new CLAUDE.md rule is driving: adding Start and FireAlarm arms explicitly instead of _ => None means future LifecycleCommand variants will be a compile error rather than a silent behavior change.

*RegistryState exhaustive match in registry.rs line 950 follows the same pattern correctly.


Behavioral change worth calling out explicitly

The most significant part of this PR is not the rename. It is the semantic correction for GoingAway and Lost in map_envoy_stop_reason:

Before (via the _ => StopReason::Destroy fallthrough):

  • GoingAway => Destroy — actor's onDestroy fires incorrectly on drain/reallocation
  • Lost => Destroy — actor's onDestroy fires on runner reconnect

After (explicit):

  • GoingAway => Sleep — runner drained; engine reallocates; state preserved
  • FLost => Sleep` — connection lost; actor resurrects with same id

This is a real bug fix. Actors were previously receiving an onDestroy callback and having their durable state wiped on runner drains and lost connections. That should be called out in the PR description rather than being buried in a refactor.


Minor notes

Double mark_destroy_requested call sites. Both call sites in registry/mod.rs (lines ~418 and ~432) now call map_envoy_stop_reason independently. This is correct and consistent.

map_envoy_stop_reason takes &StopActorReason. If the type is Copy (common for protocol enums), taking by value would be the conventional Rust style. Not a bug, just a minor style note.

Comment on LifecycleState fallthrough removal explains the intent well. Minor CLAUDE.md alignment: "Pre-startup, post-finalize, and tear-down states intentionally drop activity signals: there is no sleep deadline to reset and no grace window left to advance." The dash-separated list at the start is slightly fragmented. Could tighten to: "Loading, finalize, and terminated states have no active sleep deadline or grace window, so activity signals are dropped." Not blocking.


The main ask is to update the PR description to surface the GoingAway/Lost behavioral fix. It is the most impactful change and reviewers should not have to deduce it from the fallthrough elimination.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 24, 2026

Preview packages published to npm

Install with:

npm install rivetkit@pr-4765

All packages published as 0.0.0-pr.4765.cf49dd6 with tag pr-4765.

Engine binary is shipped via @rivetkit/engine-cli on linux-x64-musl, linux-arm64-musl, darwin-x64, and darwin-arm64. Windows users should use the release installer or set RIVET_ENGINE_BINARY.

Docker images:

docker pull rivetdev/engine:slim-cf49dd6
docker pull rivetdev/engine:full-cf49dd6
Individual packages
npm install rivetkit@pr-4765
npm install @rivetkit/react@pr-4765
npm install @rivetkit/rivetkit-napi@pr-4765
npm install @rivetkit/workflow-engine@pr-4765

Base automatically changed from sleep-cleanup/11-info-log-envoy-commands-events to main April 27, 2026 07:13
@NathanFlurry NathanFlurry merged commit dcf0e07 into main Apr 27, 2026
38 of 52 checks passed
@NathanFlurry NathanFlurry deleted the sleep-cleanup/17-stop-reason-and-fallthrough-fix branch April 27, 2026 07:14
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