Repository navigation
fix(rivetkit): run onSleep after in-flight work and refuse dispatch once it starts - #5860
Open
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. |
Contributor
|
Review: run The design is sound and the ordering is well tested. The paused-time Rust tests assert real ordering. I have a few concerns, mostly about the TypeScript cleanup change. Potential issues
Smaller notes
Style and conventions No CLAUDE.md violations found. Overall this looks good once item 1 is confirmed. |
eersnington
force-pushed
the
stack/fix-rivetkit-run-onsleep-after-in-flight-work-kttnpoyx
branch
from
October 11, 2026 20:26
6701f1d to
5b6cfaf
Compare
eersnington
force-pushed
the
stack/fix-rivetkit-run-onsleep-after-in-flight-work-kttnpoyx
branch
from
October 13, 2026 23:09
5b6cfaf to
69cdf48
Compare
eersnington
changed the base branch from
main
to
fix/rivetkit-restarting-after-on-sleep
October 13, 2026 23:09
eersnington
force-pushed
the
stack/fix-rivetkit-run-onsleep-after-in-flight-work-kttnpoyx
branch
from
October 14, 2026 20:40
69cdf48 to
bc8a66d
Compare
eersnington
added this pull request to stack #5879
October 14, 2026 20:40
This was referenced Oct 14, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Order:
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.Reserve:
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.Refusal point: fix(rivetkit): refuse actions after onSleep with actor.restarting #5876 refuses dispatch with
actor.restartingafter the sleep hooks finish. This PR refuses it once the hooks start, because the hooks now run after in-flight work drains. Before the hooks run, dispatch is still accepted.DestroyGracekeepsactor.stopping.SQLite close moves to core: On the drained path,
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)This is part 5 of 6 in a stack: