fix(api): subscribe before namespace workflow dispatch#4654
fix(api): subscribe before namespace workflow dispatch#4654NathanFlurry wants to merge 1 commit intobreak-up/restore-hibernating-socketsfrom
Conversation
|
PR Review: fix(api): subscribe before namespace workflow dispatch Overview: This is a small but important race condition fix in the namespace creation API handler. The change reorders two operations in the create function in engine/packages/api-peer/src/namespaces.rs. Before: Dispatch workflow then subscribe to events. After: Subscribe to events then dispatch workflow. The Bug: This is a classic subscribe-before-publish race condition. In the original code, the workflow was dispatched first, then subscriptions were set up for CreateComplete and Failed events. If the workflow completed between those two steps, the event would be missed, causing the API call to hang indefinitely. This is especially likely on fast paths where the workflow completes quickly. Code Quality: The fix is minimal and targeted. The logic of the tokio::select! block is unchanged. No new warnings or dependencies introduced. Correctness: The fix is correct. The subscription mechanism buffers or replays events that occur after subscription is established but before next() is called, so there is no lost-event window. Minor note: if dispatch().await? errors after subscriptions are set up, create_sub and fail_sub are dropped without being consumed. This is not a regression but worth verifying the subscription type cleans up correctly on drop. Verdict: The fix is correct and well-scoped. This addresses a real race condition that could cause API calls to hang non-deterministically. No issues with the implementation. Note: The PR description checklist is not filled out and this PR is still in Draft state. |
4170ac2 to
eeabed8
Compare
a05b2e5 to
a91a7cb
Compare
a91a7cb to
a752140
Compare
Preview packages published to npmInstall with: npm install rivetkit@pr-4654All packages published as Engine binary is shipped via Docker images: docker pull rivetdev/engine:slim-8f47e27
docker pull rivetdev/engine:full-8f47e27Individual packagesnpm install rivetkit@pr-4654
npm install @rivetkit/react@pr-4654
npm install @rivetkit/rivetkit-native@pr-4654
npm install @rivetkit/workflow-engine@pr-4654 |
1ba6a3b to
de87a8b
Compare
a752140 to
2aca1af
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: