Skip to content

test(engine): force overdue branch in alarm-during-sleep test with negative offset#4758

Draft
NathanFlurry wants to merge 1 commit intosleep-cleanup/12-sleep-destroy-mid-shutdown-diagnosticfrom
sleep-cleanup/13-alarm-test-deterministic
Draft

test(engine): force overdue branch in alarm-during-sleep test with negative offset#4758
NathanFlurry wants to merge 1 commit intosleep-cleanup/12-sleep-destroy-mid-shutdown-diagnosticfrom
sleep-cleanup/13-alarm-test-deterministic

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 24, 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 24, 2026

Code Review

PR: test(engine): force overdue branch in alarm-during-sleep test with negative offset
File: engine/packages/engine/tests/runner/actors_alarm.rs

Overview

This PR converts a previously ignored, timing-dependent regression test into a deterministic one by switching the alarm offset from +100ms to -1000ms. The negative offset guarantees the alarm is already overdue when Decision::Sleep runs in handle_stopped, eliminating the race window that required the #[ignore] annotation.

What's Good

  • Determinism over racing: Replacing the "+100ms leaves enough time..." comment with a negative offset that always satisfies now >= alarm_ts is the right call. Test reliability goes from "probably works unless the scheduler is slow" to "always exercises the target branch".
  • #[ignore] removal is correct: The test was ignored because it was a timing race. Making it deterministic justifies promoting it to a regular test, improving CI confidence.
  • Type safety is fine: alarm_offset_ms: i64 already accepts negative values (confirmed at line 181). No type issues.
  • Comment quality follows conventions: Sentences are complete, no em dashes, no delta commentary.

Minor Concern: Subscription Ordering

The comment on the new subscribe_lifecycle_events() call says "subscribe before the actor enters sleep", but ready_tx is sent inside on_start after send_sleep_intent(). The actor has already dispatched the sleep intent by the time ready_rx.await unblocks the test. There is a small window between unblocking and the subscription call where the engine could process handle_stopped and fire the reallocation Started event before the subscription is registered.

In practice this is likely fine — the engine handles sleep intents asynchronously with sufficient scheduling slack — but the comment overstates the guarantee slightly. If this ever shows intermittent CI failures, subscribing before actor creation would be the robust fix.

Verdict

Solid improvement. The deterministic approach is clearly correct, the #[ignore] removal is warranted, and the code follows project conventions. The subscription-ordering note is worth keeping in mind if flakiness appears, but should not block merging.

@NathanFlurry NathanFlurry force-pushed the sleep-cleanup/12-sleep-destroy-mid-shutdown-diagnostic branch from 1939547 to 68ddecb Compare April 24, 2026 13:16
@NathanFlurry NathanFlurry force-pushed the sleep-cleanup/13-alarm-test-deterministic branch from 3f88401 to 0e7355d Compare April 24, 2026 13:16
@github-actions
Copy link
Copy Markdown
Contributor

Preview packages published to npm

Install with:

npm install rivetkit@pr-4758

All packages published as 0.0.0-pr.4758.7327430 with tag pr-4758.

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

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