Skip to content

fix(rivetkit-core): defer teardown_started until drain settles#4836

Draft
NathanFlurry wants to merge 1 commit intodriver-tests-fixes/sleep-cleanup-testsfrom
driver-tests-fixes/sleep-allow-tasks-during-drain
Draft

fix(rivetkit-core): defer teardown_started until drain settles#4836
NathanFlurry wants to merge 1 commit intodriver-tests-fixes/sleep-cleanup-testsfrom
driver-tests-fixes/sleep-allow-tasks-during-drain

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

@NathanFlurry NathanFlurry commented Apr 28, 2026

Stack Context

This stack fixes actor sleep driver-test failures around work registered during shutdown grace and a deprecated fixture sleep hold.

Why?

teardown_sleep_state() set teardown_started before draining accepted shutdown tasks, so nested waitUntil work registered while the drain was active could be refused. It also relied on task-count changes without waking the actor grace loop, which could leave shutdown waiting until the grace deadline.

What?

This PR wakes the grace loop when shutdown tasks are registered or finish, drains accepted tasks until the join set settles before setting teardown_started, and keeps the deadline path as aborting cleanup by marking when the grace deadline was reached.

Validation

  • cargo test -p rivetkit-core sleep_shutdown_waits_for_keep_awake_work_then_finishes_next_tick
  • cargo test -p rivetkit-core ctx_wait_until_during_finish_shutdown_cleanup_refused_without_leak
  • cargo test -p rivetkit-core destroy_shutdown_concurrent_wait_until_refused
  • cargo test -p rivetkit-core destroy_shutdown_times_out_at_deadline_and_aborts_stuck_shutdown_task
  • cargo test -p rivetkit-core keep_awake_region_blocks_sleep_idle_until_guard_drops
  • cargo test -p rivetkit-core nested_wait_until_during_grace_is_drained
  • cargo test -p rivetkit-core keep_awake_in_on_sleep_blocks_finalize_until_released
  • pnpm build:force
  • pnpm test tests/driver/actor-sleep-db.test.ts -t "static registry.*encoding \\(bare\\).*nested waitUntil inside waitUntil"

@railway-app
Copy link
Copy Markdown

railway-app Bot commented Apr 28, 2026

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

Service Status Web Updated (UTC)
website ✅ Success (View Logs) Web Apr 28, 2026 at 12:43 pm
frontend-cloud 😴 Sleeping (View Logs) Web Apr 28, 2026 at 12:14 pm
ladle ✅ Success (View Logs) Web Apr 28, 2026 at 6:10 am
mcp-hub ✅ Success (View Logs) Web Apr 28, 2026 at 6:10 am
frontend-inspector ❌ Build Failed (View Logs) Web Apr 28, 2026 at 6:09 am
kitchen-sink ❌ Build Failed (View Logs) Web Apr 28, 2026 at 6:09 am

Copy link
Copy Markdown
Member Author

@github-actions
Copy link
Copy Markdown
Contributor

Preview packages published to npm

Install with:

npm install rivetkit@pr-4836

All packages published as 0.0.0-pr.4836.ca70b4c with tag pr-4836.

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-ca70b4c
docker pull rivetdev/engine:full-ca70b4c
Individual packages
npm install rivetkit@pr-4836
npm install @rivetkit/react@pr-4836
npm install @rivetkit/rivetkit-napi@pr-4836
npm install @rivetkit/workflow-engine@pr-4836

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