Skip to content

fix(rivetkit): allow workflow steps to destroy actors#4466

Merged
NathanFlurry merged 2 commits intomainfrom
workflow-destroy-run
Mar 21, 2026
Merged

fix(rivetkit): allow workflow steps to destroy actors#4466
NathanFlurry merged 2 commits intomainfrom
workflow-destroy-run

Conversation

@NathanFlurry
Copy link
Member

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

  • 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?

Attempted pnpm check-types and pnpm test -t "workflow steps can destroy the actor" from rivetkit-typescript/packages/rivetkit, but this workspace has no node_modules, so tsc and vitest were unavailable.

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

@railway-app railway-app bot temporarily deployed to rivet-frontend / rivet-pr-4466 March 21, 2026 07:54 Destroyed
@railway-app
Copy link

railway-app bot commented Mar 21, 2026

🚅 Deployed to the rivet-pr-4466 environment in rivet-frontend

Service Status Web Updated (UTC)
ladle 🕐 Queued (View Logs) Web Mar 21, 2026 at 8:06 am
frontend-inspector 🕒 Building (View Logs) Web Mar 21, 2026 at 8:06 am
website 🕒 Building (View Logs) Web Mar 21, 2026 at 8:06 am
frontend-cloud 🕒 Building (View Logs) Web Mar 21, 2026 at 8:06 am
mcp-hub ❌ Build Failed (View Logs) Web Mar 21, 2026 at 8:06 am

@railway-app railway-app bot temporarily deployed to rivet-frontend / rivet-pr-4466 March 21, 2026 08:06 Destroyed
@NathanFlurry NathanFlurry merged commit 88790d1 into main Mar 21, 2026
9 of 18 checks passed
@NathanFlurry NathanFlurry deleted the workflow-destroy-run branch March 21, 2026 08:07
@claude
Copy link

claude bot commented Mar 21, 2026

PR Review: fix(rivetkit): allow workflow steps to destroy actors

Overall 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.

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