Repository navigation
fix(rivetkit): run onSleep after in-flight work and refuse dispatch once it starts - #5860
eersnington wants to merge 1 commit into
Conversation
|
This PR was not deployed automatically as @eersnington does not have access to the Railway project. In order to get automatic PR deploys, please add @eersnington to your workspace on Railway. |
|
Review: run onSleep after in-flight work, refuse dispatch once it starts The design is sound. Moving the SQLite close into core after Likely bug: the client does not retry Missing generated artifacts Behavior and edge cases
Tests
Nits
🤖 Generated with Claude Code |
6701f1d to
5b6cfaf
Compare
Run
onSleepafter in-flight work finishes, and refuse new work onceonSleepstarts. Before this change, an action running when sleep started could fail because TypeScript closed SQLite right afteronSleep.Before
After
Changes
ActorTaskruns the sleep hooks when the shutdown counter (actions,keepAwake,waitUntil, registered tasks) and WebSocket callbacks reach zero, or at the hooks deadline. RawonRequestandrunare not waited for. Destroy runs its hooks at once, as before.SLEEP_HOOK_RESERVE_DIVISOR = 4keeps the last quarter of the grace period foronSleep, disconnects, and the final save. With the 15 second default this is 3.75 seconds.actor.restarting(503), "Actor is restarting. Retry the request." Dispatch is refused with it from the moment the hooks run until finalize. Before the hooks run, dispatch is still accepted, because the client retry budget for this error is short.DestroyGracekeepsactor.stopping.cleanupNativeSleepRuntimeStateno longer closes SQLite. Core runssync_alarmand then closes it, so the alarm sync no longer fails on every sleep. If work did not drain by the deadline, TypeScript still closes SQLite early so late work cannot write after shutdown.try_finish_gracerequires the hooks to have run, so an idle actor cannot finalize withoutonSleep.docs-internal/engine/sleep-sequence.mddescribes the new order.Behavior change
An action that waits for something
onSleepdoes, such as a flag thatonSleepsets, now waits until the hooks deadline. Long actions should watchc.abortSignal, which still fires when sleep starts. NoonSleepin the docs or examples uses this pattern (going to follow up on this)