Skip to content

fix(test): stabilize lifecycle, sleep, queue, and run edge cases#4660

Open
NathanFlurry wants to merge 1 commit intobreak-up/reenable-gateway-url-coveragefrom
break-up/stabilize-driver-lifecycle-tests
Open

fix(test): stabilize lifecycle, sleep, queue, and run edge cases#4660
NathanFlurry wants to merge 1 commit intobreak-up/reenable-gateway-url-coveragefrom
break-up/stabilize-driver-lifecycle-tests

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

PR #4660 Review: fix(test): stabilize lifecycle, sleep, queue, and run edge cases

Overview

This PR stabilizes a broad set of flaky tests across lifecycle, sleep, queue, and run suites. The core strategy is to replace deterministic timing-based assertions with polling (vi.waitFor) and to properly handle expected race conditions (destroy races, abort races) rather than asserting a specific outcome. Good direction overall.


Concerns

1. Fragile Runtime Detection (inline-client.ts)

Using a CWD path (process.cwd() === "/root") as a capability flag is brittle. It will silently break if the sandbox working directory changes, or give false positives in any environment that happens to run from /root. Consider using a dedicated environment variable (e.g. RIVETKIT_SANDBOX_MODE) or a proper capability check instead.

2. destroyActor silently swallows all errors

The final return; in the catch block swallows any unexpected error after the first retry. A genuine bug (e.g. a 500 from the actor runtime) will be masked. At minimum, log the unexpected error; ideally throw err on unexpected error codes so tests surface real failures instead of passing silently.

3. waitForConnectionOpen lacks a timeout

The inline Promise in waitForConnectionOpen hangs forever if the connection neither opens nor errors. Vitest's per-test timeout will catch it eventually, but the error message will be confusing. An explicit timeout with a descriptive rejection message would make failures easier to diagnose.

4. Looser sleep/start count assertions

Many tests moved from exact counts (toBe(1), toBe(2)) to toBeGreaterThanOrEqual. This is necessary for timing-sensitive tests, but some tests now accept startCount >= 2 as a pass even if the actor restarted unexpectedly many times. Consider adding an upper-bound assertion for particularly sensitive tests where more than a couple restarts would indicate a bug.

5. Structural error checking duplication

The pattern error.group === "actor" && error.code === "aborted" now appears in three places: src/actor/instance/queue.ts, fixtures/driver-test-suite/queue.ts, and src/driver-test-suite/tests/actor-lifecycle.ts. Consider a small utility like isAbortedError(err) to centralize this and keep the matching logic consistent if the error shape evolves.


Positive Changes

  • vi.waitFor polling replaces fixed waitFor sleeps - more robust and faster on fast machines.
  • waitForConnected helper with an explicit timeout is cleaner than the previous bare vi.waitFor calls with no timeout configured.
  • sleepingPromise registered before trigger (double-sleep and broadcast tests) - correctly avoids the event-listener race window.
  • c.queue.send directly in run.ts instead of going through a self-client is simpler and avoids an unnecessary round-trip.
  • lifecycleObserver actor for cross-actor event witnessing is a clean solution for inspecting lifecycle events of a destroyed actor.
  • .sequential on Actor Run Tests prevents concurrent test interference without changing test logic.
  • getOrCreate(..., { params }) API in lifecycle-hooks tests correctly routes connection params through actor params.

Minor / Nits

  • Reducing rapid-cycle iterations from 10 to 3 reduces race-window coverage. With { timeout: 20_000 } there is headroom to keep 10 iterations once stable.
  • handle.increment(0) in actor-handle.ts to force initialization before a duplicate-create test is indirect - handle.resolve() or a named ping() would be more self-documenting.
  • The Response.json() replacement across fixtures looks like a compatibility fix for environments lacking the static method. A short comment explaining the reason would prevent future contributors from reverting it.

@NathanFlurry NathanFlurry force-pushed the break-up/reenable-gateway-url-coverage branch from ecf268c to 4c4e267 Compare April 15, 2026 02:40
@NathanFlurry NathanFlurry force-pushed the break-up/stabilize-driver-lifecycle-tests branch from dcb82e8 to 1d9c571 Compare April 15, 2026 02:40
@NathanFlurry NathanFlurry force-pushed the break-up/reenable-gateway-url-coverage branch from 4c4e267 to e823f78 Compare April 15, 2026 02:50
@NathanFlurry NathanFlurry force-pushed the break-up/stabilize-driver-lifecycle-tests branch from 1d9c571 to 8e50d57 Compare April 15, 2026 02:50
@NathanFlurry NathanFlurry marked this pull request as ready for review April 15, 2026 02:57
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