Skip to content

fix(rivetkit): stall stop handler until start completes#4192

Merged
NathanFlurry merged 1 commit intomainfrom
02-13-fix_rivetkit_stall_stop_handler_until_start_completes
Feb 27, 2026
Merged

fix(rivetkit): stall stop handler until start completes#4192
NathanFlurry merged 1 commit intomainfrom
02-13-fix_rivetkit_stall_stop_handler_until_start_completes

Conversation

@MasterPtato
Copy link
Contributor

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

@railway-app railway-app bot temporarily deployed to rivet-frontend / rivet-pr-4192 February 13, 2026 21:53 Destroyed
@railway-app
Copy link

railway-app bot commented Feb 13, 2026

🚅 Deployed to the rivet-pr-4192 environment in rivet-frontend

Service Status Web Updated (UTC)
frontend-cloud ❌ Build Failed (View Logs) Web Feb 26, 2026 at 8:42 pm
frontend-inspector 😴 Sleeping (View Logs) Web Feb 26, 2026 at 7:53 pm
ladle ❌ Build Failed (View Logs) Web Feb 26, 2026 at 7:42 pm
website 😴 Sleeping (View Logs) Web Feb 25, 2026 at 10:57 pm
mcp-hub ✅ Success (View Logs) Web Feb 13, 2026 at 9:55 pm

Copy link
Contributor Author

MasterPtato commented Feb 13, 2026

@claude
Copy link

claude bot commented Feb 13, 2026

PR Review: fix(rivetkit): stall stop handler until start completes

The core fix is correct and well-motivated: instead of immediately rejecting the start promise when stop is called during startup (which left the actor in a broken state), the new code awaits start completion before proceeding with teardown. The added test coverage is a solid improvement.

A few issues worth addressing:


High Priority

1. No timeout on awaiting start — potential indefinite hang

In #runnerOnActorStop, if actorStartPromise never resolves (stuck I/O, infinite loop in onWake, etc.), the await blocks forever and the actor can never be stopped. A timeout with forced cleanup would prevent this from stalling the engine.

2. The onDestroy test has a logical flaw

In the test onDestroy is called even when actor is destroyed during start, getState() is called before destroy(). Once onStop runs it sets #stopCalled = true, causing assertReady() to throw on any subsequent action call. If getState() runs before the actor starts stopping it will return destroyCalled: false; if it runs after, it throws entirely. Either way, the assertion state.destroyCalled === true cannot pass. To test this correctly, destroy the actor first, then verify persisted state by recreating/reading it directly.


Medium Priority

3. lifecycleObserver is registered but never used

lifecycleObserver is registered in registry.ts but none of the new lifecycle tests reference it. Either wire it into a test or remove it.

4. conn-error-serialization test may not correctly pass params to createConnState

The test passes { params: { shouldThrow: true } } as options to getOrCreate, but createConnState receives connection-level params, not actor-level creation params. If these are separate in the SDK, createConnState will receive an empty params object and the error will never be thrown, making the error-path test a false positive. Verify that actor-level params from getOrCreate are forwarded as connection params to createConnState.


Low Priority

5. Test naming inconsistency

The test onBeforeActorStart completes before stop proceeds tests the onWake lifecycle hook, not a hook named onBeforeActorStart. The name does not match the API being tested.

6. Date.now() keys risk collisions in parallel test runs

Using Date.now() as an actor key suffix can collide if two tests start within the same millisecond. Prefer crypto.randomUUID() or a monotonic counter for uniqueness.

7. Trivial assertion

expect(true).toBe(true) in the rapid cycle test conveys no information and can simply be removed. The test completing without throwing is sufficient.

8. conn.dispose() after a connection error may itself throw

In the error-serialization test, conn.dispose() is called after catching the error without a try/catch. If dispose() throws when the connection was never fully established, the test fails for the wrong reason.


Minor Nit

The whitespace-only changes (() => {}() => { }) are cosmetically inconsistent with the rest of the codebase and add noise to the diff.

this.#runnerStarted.resolve(undefined);
},
onDisconnected: (_code, _reason) => {},
onDisconnected: (_code, _reason) => { },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove spaces inside the empty function braces to comply with Biome linter formatting rules. Change onDisconnected: (_code, _reason) => { }, to onDisconnected: (_code, _reason) => {},

Spotted by Graphite Agent (based on CI logs)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

return streamSSE(c, async (stream) => {
// NOTE: onAbort does not work reliably
stream.onAbort(() => {});
stream.onAbort(() => { });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove spaces inside the empty function braces to comply with Biome linter formatting rules. Change stream.onAbort(() => { }); to stream.onAbort(() => {});

Spotted by Graphite Agent (based on CI logs)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Comment on lines +1 to +71
import { actor } from "rivetkit";

/**
* Actor designed to test start/stop race conditions.
* Has a slow initialization to make race conditions easier to trigger.
*/
export const startStopRaceActor = actor({
state: {
initialized: false,
startTime: 0,
destroyCalled: false,
startCompleted: false,
},
onWake: async (c) => {
c.state.startTime = Date.now();

// Simulate slow initialization to create window for race condition
await new Promise((resolve) => setTimeout(resolve, 100));

c.state.initialized = true;
c.state.startCompleted = true;
},
onDestroy: (c) => {
c.state.destroyCalled = true;
// Don't save state here - the actor framework will save it automatically
},
actions: {
getState: (c) => {
return {
initialized: c.state.initialized,
startTime: c.state.startTime,
destroyCalled: c.state.destroyCalled,
startCompleted: c.state.startCompleted,
};
},
ping: (c) => {
return "pong";
},
destroy: (c) => {
c.destroy();
},
},
});

/**
* Observer actor to track lifecycle events from other actors
*/
export const lifecycleObserver = actor({
state: {
events: [] as Array<{
actorKey: string;
event: string;
timestamp: number;
}>,
},
actions: {
recordEvent: (c, params: { actorKey: string; event: string }) => {
c.state.events.push({
actorKey: params.actorKey,
event: params.event,
timestamp: Date.now(),
});
},
getEvents: (c) => {
return c.state.events;
},
clearEvents: (c) => {
c.state.events = [];
},
},
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run the Biome formatter on this file to ensure proper formatting and sorted imports. The file is new and likely has formatting issues that don't match the project's style guide.

Spotted by Graphite Agent (based on CI logs)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@MasterPtato MasterPtato force-pushed the 02-13-fix_rivetkit_stall_stop_handler_until_start_completes branch from 1b0d832 to 0f6bab1 Compare February 13, 2026 22:51
@railway-app railway-app bot temporarily deployed to rivet-frontend / rivet-pr-4192 February 13, 2026 22:51 Destroyed
Comment on lines +71 to +72
import { startStopRaceActor, lifecycleObserver } from "./start-stop-race";
import { connErrorSerializationActor } from "./conn-error-serialization";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imports should be sorted alphabetically. Consider reordering these imports to maintain consistent sorting.

Spotted by Graphite Agent (based on CI logs)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

import { runActorConnHibernationTests } from "./tests/actor-conn-hibernation";
import { runActorConnStateTests } from "./tests/actor-conn-state";
import { runActorDbTests } from "./tests/actor-db";
import { runConnErrorSerializationTests } from "./tests/conn-error-serialization";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import should be sorted alphabetically with the other imports to maintain consistent ordering.

Spotted by Graphite Agent (based on CI logs)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@MasterPtato MasterPtato force-pushed the 02-13-fix_rivetkit_stall_stop_handler_until_start_completes branch from 0f6bab1 to 8f7b569 Compare February 18, 2026 02:14
@railway-app railway-app bot temporarily deployed to rivet-frontend / rivet-pr-4192 February 18, 2026 02:14 Destroyed
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 18, 2026

More templates

@rivetkit/cloudflare-workers

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/cloudflare-workers@4192

@rivetkit/framework-base

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/framework-base@4192

@rivetkit/next-js

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/next-js@4192

@rivetkit/react

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/react@4192

rivetkit

pnpm add https://pkg.pr.new/rivet-dev/rivet/rivetkit@4192

@rivetkit/sql-loader

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/sql-loader@4192

@rivetkit/sqlite-vfs

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/sqlite-vfs@4192

@rivetkit/traces

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/traces@4192

@rivetkit/workflow-engine

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/workflow-engine@4192

@rivetkit/virtual-websocket

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/virtual-websocket@4192

@rivetkit/engine-runner

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/engine-runner@4192

@rivetkit/engine-runner-protocol

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/engine-runner-protocol@4192

commit: 2d6e590

@MasterPtato MasterPtato force-pushed the 02-13-fix_rivetkit_stall_stop_handler_until_start_completes branch from 02b2c93 to 2d6e590 Compare February 27, 2026 00:12
@NathanFlurry NathanFlurry merged commit e3b39a0 into main Feb 27, 2026
14 of 23 checks passed
@NathanFlurry NathanFlurry deleted the 02-13-fix_rivetkit_stall_stop_handler_until_start_completes branch February 27, 2026 00:29
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