Skip to content

test(rivetkit): enable driver lifecycle regressions#4941

Merged
NathanFlurry merged 1 commit intomainfrom
05-04-test_rivetkit_enable_driver_regressions
May 5, 2026
Merged

test(rivetkit): enable driver lifecycle regressions#4941
NathanFlurry merged 1 commit intomainfrom
05-04-test_rivetkit_enable_driver_regressions

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 May 4, 2026

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

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 4, 2026

Code Review: test(rivetkit): enable driver lifecycle regressions

Overview

This PR re-enables three previously skipped driver tests (TODOs #4706, #4707, #4708), indicating the underlying issues have been fixed. The lifecycle test also updates its assertion strategy from reading actor-owned state to using an external observer actor.


Issues

1. Potential race condition in lifecycle test — missing vi.waitFor

File: tests/driver/actor-lifecycle.test.ts (new test block)

After await actor.destroy(), onDestroy runs asynchronously and records an event in the shared lifecycleObserver actor. The test then immediately calls observer.getEvents() with no retry/wait loop. If onDestroy hasn't completed and recorded its event yet, the assertion will fail.

Every other lifecycle test that reads observer events wraps the check in vi.waitFor with a preceding comment. For example:

// Poll until the observer records the destroy hook for this actor instance.
await vi.waitFor(
    async () => {
        const events = await observer.getEvents();
        expect(events.some(e => ...)).toBe(true);
    },
    { timeout: 5_000 },
);

The new test does this bare:

const events = await observer.getEvents();
expect(events).toContainEqual(...);

This is a likely source of flakiness. Recommend wrapping it in a vi.waitFor with a comment, consistent with the established pattern in this file.

2. Missing clearEvents() in lifecycle test

File: tests/driver/actor-lifecycle.test.ts (new test block)

Every other test in this file that uses lifecycleObserver calls observer.clearEvents() before the test body. The new test relies on a unique actorKey (Date.now()) to distinguish its events, which is functionally correct for avoiding false positives, but breaks the established pattern and makes the observer grow unboundedly across test runs if the observer persists between tests.

Recommend adding await observer.clearEvents() before the actor is created, consistent with the other tests.

3. Workflow test polling may violate the sleep constraint

File: tests/driver/actor-workflow.test.ts (re-enabled test)

let state = await actor.getState();
for (let i = 0; i < 10 && state.sleepCount === 0; i++) {
    await waitFor(driverTestConfig, 100);
    state = await actor.getState();
}

CLAUDE.md states: "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."

workflowFailedStepActor has sleepTimeout: 50. The loop calls getState() (an actor action) while waiting for the actor to sleep. Each action resets the idle deadline, potentially preventing the actor from sleeping. The test might pass in practice because network latency leaves gaps > 50ms between calls, but it is architecturally fragile.

The safer pattern used elsewhere (e.g., actor-sleep.test.ts) is vi.waitFor after disconnecting or avoiding action calls entirely while waiting for sleep.


Minor Observations

  • The re-enabled sleep test (actor sleep persists state with connect) correctly uses vi.waitFor with an adjacent comment, satisfying the check:wait-for-comments lint rule.
  • The workflow test re-enable is the simplest of the three changes — the only concern is the polling constraint above.
  • The fixture start-stop-race.ts already has the startCompleted flag and the lifecycleObserver plumbing, so the updated assertion in the lifecycle test is backed by existing infrastructure.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

Preview packages published to npm

Install with:

npm install rivetkit@pr-4941

All packages published as 0.0.0-pr.4941.79333cf with tag pr-4941.

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

@NathanFlurry NathanFlurry force-pushed the 05-04-test_rivetkit_cached_ws_db_grace branch from 0e11909 to 70ad62a Compare May 4, 2026 15:36
@NathanFlurry NathanFlurry force-pushed the 05-04-test_rivetkit_enable_driver_regressions branch from e23d8f8 to 731cdb6 Compare May 4, 2026 15:36
Base automatically changed from 05-04-test_rivetkit_cached_ws_db_grace to main May 5, 2026 14:57
@NathanFlurry NathanFlurry merged commit 731cdb6 into main May 5, 2026
41 of 54 checks passed
@NathanFlurry NathanFlurry deleted the 05-04-test_rivetkit_enable_driver_regressions branch May 5, 2026 14:58
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