refactor(rivetkit): split workflow context into WorkflowContext + WorkflowStepContext#5231
Conversation
|
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.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
🚅 Deployed to the rivet-pr-5231 environment in rivet-frontend
|
a4c2e70 to
cfec500
Compare
78c0bd1 to
2db62bf
Compare
|
PR Review: refactor(rivetkit): split workflow context into WorkflowContext + WorkflowStepContext Overview This PR delivers two coupled refactors to the RivetKit TypeScript API:
Strengths
Issues and Notes Breaking API surface (document before merging) c.key to c.actorKey and c.name to c.actorName are breaking changes for all existing actors. The PR description template is left unfilled and there is no migration note. At minimum, the PR body should describe what to change and why. WorkflowLoopContextOf and WorkflowBranchContextOf now both resolve to WorkflowContext, which no longer exposes state, vars, db, client, broadcast, or queue.send. This is the desired outcome but should be called out explicitly. queue.send removed from WorkflowContext.queue The outer loop/orchestration context queue previously included send; it has been removed and send now lives only on WorkflowStepContext.queue. Any existing code calling loopCtx.queue.send() outside a step will now fail at compile time (better than a runtime error). Worth a comment in the public API docs. destroy() only callable from inside a step destroy() moved from WorkflowContext to WorkflowStepContext. Correct - destroy is a side effect and must be inside a step - but it is a behavioral change for anyone calling ctx.destroy() directly in a loop body. Good that the test fixture was updated. any in implementation overloads next, nextBatch, and join use any in their implementation signatures to satisfy TypeScript while keeping typed public overloads. Pragmatic tradeoff; end users are not exposed to any. WorkflowStepContext.queue creates a new object on every access queue is a getter that allocates a fresh object each call. In hot step paths this creates unnecessary GC pressure. Consider building it once in the constructor or using a lazily initialized field. Minor but worth fixing. WorkflowBranchContextOf still maps to WorkflowContextOf Semantically correct - branch callbacks receive a WorkflowContext and should sequence further steps inside it. The alias adds nothing over WorkflowContextOf and could be removed to simplify the public surface. Minor
Summary The core design is sound and well-executed. Enforcing step-only actor data access at the type system level rather than through a runtime depth counter plus @ts-nocheck is strictly better. Main asks before merging: fill out the PR description with a migration guide for the c.key/c.name renames and note that WorkflowLoopContextOf / WorkflowBranchContextOf no longer carry actor data accessors. The queue getter allocation is the only code-level item worth fixing. |
2db62bf to
8e183b6
Compare
cfec500 to
7d39682
Compare
7d39682 to
7b6ca99
Compare
7b6ca99 to
7c136e3
Compare
Merge activity
|
7c136e3 to
8ee3d8a
Compare
8e183b6 to
ac12ef8
Compare
8ee3d8a to
456d99c
Compare

Description
Please include a summary of the changes and the related issue. Please also include relevant motivation and context.
Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes.
Checklist: