Skip to content

fix(api): subscribe before namespace workflow dispatch#4654

Draft
NathanFlurry wants to merge 1 commit intobreak-up/restore-hibernating-socketsfrom
break-up/subscribe-before-namespace-dispatch
Draft

fix(api): subscribe before namespace workflow dispatch#4654
NathanFlurry wants to merge 1 commit intobreak-up/restore-hibernating-socketsfrom
break-up/subscribe-before-namespace-dispatch

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

@NathanFlurry NathanFlurry changed the base branch from 04-14-chore_engine_publish_engine_bases_in_ci to graphite-base/4654 April 14, 2026 23:43
@NathanFlurry NathanFlurry marked this pull request as ready for review April 15, 2026 01:09
@NathanFlurry NathanFlurry force-pushed the break-up/subscribe-before-namespace-dispatch branch from a05b2e5 to a91a7cb Compare April 15, 2026 02:40
@NathanFlurry NathanFlurry changed the base branch from graphite-base/4654 to 04-14-chore_engine_publish_engine_bases_in_ci April 15, 2026 02:40
@NathanFlurry NathanFlurry changed the base branch from 04-14-chore_engine_publish_engine_bases_in_ci to graphite-base/4654 April 15, 2026 02:50
@NathanFlurry NathanFlurry force-pushed the break-up/subscribe-before-namespace-dispatch branch from a91a7cb to a752140 Compare April 15, 2026 02:50
@NathanFlurry NathanFlurry changed the base branch from graphite-base/4654 to break-up/restore-hibernating-sockets April 15, 2026 02:51
@NathanFlurry NathanFlurry marked this pull request as draft April 15, 2026 02:59
@github-actions
Copy link
Copy Markdown
Contributor

Preview packages published to npm

Install with:

npm install rivetkit@pr-4654

All packages published as 0.0.0-pr.4654.8f47e27 with tag pr-4654.

Engine binary is shipped via @rivetkit/engine-cli on linux-x64-musl, linux-arm64-musl, darwin-x64, and darwin-arm64. Windows users should use the release installer or set RIVET_ENGINE_BINARY.

Docker images:

docker pull rivetdev/engine:slim-8f47e27
docker pull rivetdev/engine:full-8f47e27
Individual packages
npm install rivetkit@pr-4654
npm install @rivetkit/react@pr-4654
npm install @rivetkit/rivetkit-native@pr-4654
npm install @rivetkit/workflow-engine@pr-4654

@NathanFlurry NathanFlurry force-pushed the break-up/restore-hibernating-sockets branch from 1ba6a3b to de87a8b Compare April 15, 2026 06:55
@NathanFlurry NathanFlurry force-pushed the break-up/subscribe-before-namespace-dispatch branch from a752140 to 2aca1af Compare April 15, 2026 06:55
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