Prevent attempting to suspend multiple times in the same run#82
Merged
virajmehta merged 2 commits intomainfrom Mar 13, 2026
Merged
Prevent attempting to suspend multiple times in the same run#82virajmehta merged 2 commits intomainfrom
virajmehta merged 2 commits intomainfrom
Conversation
The durable sql itself already checks that a task is currnetly
running when we try to suspend it, which makes it
very difficult to write tests for. However, checking in the durable sql
is insufficient, since we might have an execution that looks like:
* Tokio task A - calls `await_event("foo")`, and doesn't propagate
the `ControlFlow::Suspend` error.
* Tokio task B (possibly in another process) - calls `emit_event("foo")`
* Tokio task C - picks up the now-ready task that was previously
suspended
* Tokio task A - calls `await_event("bar")`, which succeeds, since
the task is now running.
By adding a check rust-side, we can be sure that we catch incorrect
usage of durable
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
virajmehta
approved these changes
Mar 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The durable sql itself already checks that a task is currnetly running when we try to suspend it, which makes it
very difficult to write tests for. However, checking in the durable sql is insufficient, since we might have an execution that looks like:
await_event("foo"), and doesn't propagate theControlFlow::Suspenderror.emit_event("foo")await_event("bar"), which succeeds, since the task is now running.By adding a check rust-side, we can be sure that we catch incorrect usage of durable
Note
Medium Risk
Introduces new validation that turns repeated suspend attempts into
TaskError::Validationand changes theControlFlow::Suspendvariant shape, which may break pattern matches and alter runtime behavior for tasks that previously (incorrectly) suppressed suspend errors.Overview
Prevents tasks from suspending more than once per execution by tracking a
has_suspendedflag onTaskContextand rejecting subsequent suspend attempts with a validation error.Changes
ControlFlow::Suspendto carry an internalSuspendMarker, forcing suspension to be constructed throughTaskContext(viaSuspendMarker::new(self)), and updates the worker to matchControlFlow::Suspend(_)accordingly.Written by Cursor Bugbot for commit 5348eee. This will update automatically on new commits. Configure here.