Skip to content

test(rivetkit): avoid polling sleep actor awake#4783

Draft
NathanFlurry wants to merge 1 commit intodriver-fixes/native-sleep-side-task-drainfrom
driver-fixes/sleep-db-poll-interval
Draft

test(rivetkit): avoid polling sleep actor awake#4783
NathanFlurry wants to merge 1 commit intodriver-fixes/native-sleep-side-task-drainfrom
driver-fixes/sleep-db-poll-interval

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

Copy link
Copy Markdown
Member Author

NathanFlurry commented Apr 26, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

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

@claude
Copy link
Copy Markdown

claude Bot commented Apr 26, 2026

Code Review

Overview

This is a small, focused fix to a flaky driver test. The scheduled action stays awake until db work completes test was polling every 50ms with vi.waitFor, but each poll triggers an actor action that resets the actor's idle sleep timer — creating a liveness issue where the actor never sleeps while being observed. The fix sets the poll interval to SLEEP_DB_TIMEOUT + 250 (1250ms) so the actor has enough idle time to actually sleep between polls.

Analysis

Correctness

The fix is aligned with the documented invariant in CLAUDE.md:

Driver tests that wait for actor sleep must not poll actor actions while waiting; each action counts as activity and can reset the sleep deadline.

The old 50ms interval meant the test was calling actor.getCounts() ~100 times/second during the sleep window. At 1250ms intervals, the actor has a full idle window between polls to transition to sleep state.

Timeout adjustment

The timeout was doubled from 5,000ms to 10,000ms. With a 1250ms interval (~8 possible polls), this is appropriate. The pre-poll waitFor of ~2550ms already places the test well past the expected sleep point, so the first or second poll should succeed.

Comment placement

The check:wait-for-comments requirement is satisfied: the vi.waitFor call at line 202 already has the mandatory preceding // Poll until ... justification at line 201. The new comment is placed inline in the options object to explain the non-obvious interval choice — a reasonable location for configuration-level rationale.

Minor observation

The waitForAction helper at lines 16–35 still uses interval: 50 and calls an actor action on every tick. If any test using waitForAction also waits for sleep-triggered state changes (rather than post-sleep counts already written), it could have the same race condition. Worth a quick scan to confirm all waitForAction usages poll only for state that's available while the actor is awake — but this is out of scope for this PR.

@github-actions
Copy link
Copy Markdown
Contributor

Preview packages published to npm

Install with:

npm install rivetkit@pr-4783

All packages published as 0.0.0-pr.4783.e462097 with tag pr-4783.

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

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