fix(rivetkit): allow workflow steps to destroy actors#4466
fix(rivetkit): allow workflow steps to destroy actors#4466NathanFlurry merged 2 commits intomainfrom
Conversation
|
🚅 Deployed to the rivet-pr-4466 environment in rivet-frontend
|
PR Review: fix(rivetkit): allow workflow steps to destroy actorsOverall this is a clean, minimal, well-scoped fix. The implementation follows existing patterns correctly. Implementation (workflow/context.ts) The new destroy() method is correctly guarded with #ensureActorAccess, aligning with the rule in rivetkit-typescript/CLAUDE.md that all side-effectful #runCtx access must be guarded so side effects only run inside workflow steps and are not replayed outside them. The method is also correctly NOT wrapped in #wrapActive. That wrapper is for async operations passed to keepAwake, and destroy() is synchronous (fire-and-forget via startDestroy()). This is consistent with other synchronous guarded methods like broadcast, setPreventSleep, and waitUntil. Subtle correctness note: since destroy() is called inside ctx.step(), it only runs during first execution of that step, not during replay (the workflow engine caches the step result). Destroy is therefore not re-triggered on workflow replay, which is the correct behavior. Worth confirming startDestroy() is idempotent just in case. Test (actor-workflow.ts) The test structure is sound. vi.waitFor is used for both assertions (destroy notification and actor-not-found), correctly handling the asynchronous destroy lifecycle. Minor observation: in the error check block, if resolve() throws an unexpected non-ActorError (e.g. a network error), the expect assertions inside catch will throw and vi.waitFor will retry silently until timeout, producing an unclear failure message. Re-throwing unexpected errors would make failures more debuggable. Low-priority since this is a controlled test environment. Fixture (workflow.ts) The workflowDestroyActor fixture cleanly demonstrates the feature with minimal code. The onDestroy observer pattern mirrors other actors in the test suite. Summary Clean implementation, correct guard placement, adequate test coverage. No blocking issues. |
Description
Allow workflow step contexts to call
ctx.destroy()by forwarding to the actor run context, and add driver-test coverage that verifies a workflow can destroy its own actor.Type of change
How Has This Been Tested?
Attempted
pnpm check-typesandpnpm test -t "workflow steps can destroy the actor"fromrivetkit-typescript/packages/rivetkit, but this workspace has nonode_modules, sotscandvitestwere unavailable.Checklist: