Skip to content

[adapters] Fix a bug + a race in suspend processing.#6615

Merged
ryzhyk merged 2 commits into
mainfrom
fix-suspend-terminated-race
Jul 11, 2026
Merged

[adapters] Fix a bug + a race in suspend processing.#6615
ryzhyk merged 2 commits into
mainfrom
fix-suspend-terminated-race

Conversation

@ryzhyk

@ryzhyk ryzhyk commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

This commit fixes a severe bug and a less severe race.

The bug: when we fail to make a checkpoint while suspending, we log the
error, but still set pipeline status to Suspended, making it look like the
Suspend succeeded. There are two options for handling this better: (1) go back
to the Running state, giving the user a chance to fix the issue and retry
(not sure what they can do if the disk runs out of space though...),
(2) stop the pipeline and set state to Failed. Like with any other failure,
some progress is lost, but at least we don't mask the error.

The race: when the checkpoint succeeded, there was a brief window after the
checkpoint completes and before we set phase to Suspended when the pipeline's
state was Stopped. This caused tests waiting for the Suspended state to fail,
since they don't expect the Stopped status.

This flaked the cloud suspend_and_resume_demos test: a demo reached
Stopped carrying PipelineTerminated instead of suspending cleanly.

@ryzhyk
ryzhyk requested a review from blp July 10, 2026 07:58
@ryzhyk ryzhyk added the connectors Issues related to the adapters/connectors crate label Jul 10, 2026
@ryzhyk
ryzhyk force-pushed the fix-suspend-terminated-race branch from d7f7624 to 31fcff5 Compare July 10, 2026 08:14
@ryzhyk
ryzhyk enabled auto-merge July 10, 2026 08:14

@mythical-fred mythical-fred left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean fix for a real race: during a suspend the circuit thread flips to Terminated before the server has installed PipelinePhase::Suspended, so a /status poll landing in that window observed Terminated and returned a 500 PipelineTerminated that the runner then recorded as a fatal error. The new terminated_status helper turns that transient window into a clean Suspended reading iff runtime_desired_status == Suspended; every other terminated case stays a PipelineTerminated error. Doc comment on the helper is precise and points a future reader at the causing invariant.

The unit test covers both branches (suspend-requested → Suspended; anything else → PipelineTerminated), which is exactly what matters here. The runtime_status_details: json!("") for the synthesized Suspended reading matches the shape used elsewhere in the same file.

Question (non-blocking): the Suspended-desired-status guard is a proxy for "a suspend has been requested." Is it possible for a pipeline to get into Terminated while runtime_desired_status == Suspended for reasons other than the intended suspend (e.g. an internal error that happens to race with a suspend request)? If so this would mask a real fatal termination as a clean suspend. If the answer is "the pipeline manager treats Suspended as the terminal desired state and any error path clears/rewrites it first," then this is fine — worth a one-line comment noting that assumption. If not, we might want to also check some "suspend in progress" flag on state before returning the Suspended reading.

LGTM as-is.

@ryzhyk
ryzhyk disabled auto-merge July 10, 2026 16:00
@ryzhyk
ryzhyk marked this pull request as draft July 10, 2026 16:00
@ryzhyk

ryzhyk commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Needs more work, will reopen soon

This commit fixes a severe bug and a less severe race.

The bug: when we fail to make a checkpoint while suspending, we log the
error, but still set pipeline status to Suspended, making it look like the
Suspend succeeded. There are two options for handling this better: (1) go back
to the Running state, giving the user a chance to fix the issue and retry
(not sure what they can do if the disk runs out of space though...),
(2) stop the pipeline and set state to Failed. Like with any other failure,
some progress is lost, but at least we don't mask the error.

The race: when the checkpoint succeeded, there was a brief window after the
checkpoint completes and before we set phase to Suspended when the pipeline's
state was Stopped. This caused tests waiting for the Suspended state to fail,
since they don't expect the Stopped status.

This flaked the cloud `suspend_and_resume_demos` test: a demo reached
`Stopped` carrying `PipelineTerminated` instead of suspending cleanly.

Signed-off-by: Leonid Ryzhyk <ryzhyk@gmail.com>
@ryzhyk
ryzhyk force-pushed the fix-suspend-terminated-race branch from 31fcff5 to 87436fe Compare July 10, 2026 20:59
@ryzhyk
ryzhyk marked this pull request as ready for review July 10, 2026 21:01
@ryzhyk ryzhyk changed the title [adapters] report Suspended (not PipelineTerminated) during suspend [adapters] Fix a bug + a race in suspend processing. Jul 10, 2026
Make sure a failed suspend is reported as a pipeline failure.

Signed-off-by: Leonid Ryzhyk <ryzhyk@gmail.com>
@ryzhyk
ryzhyk enabled auto-merge July 10, 2026 21:48

@mythical-fred mythical-fred left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@blp blp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable. Thank you for catching it.

@ryzhyk
ryzhyk added this pull request to the merge queue Jul 11, 2026
Merged via the queue into main with commit 4733636 Jul 11, 2026
1 check passed
@ryzhyk
ryzhyk deleted the fix-suspend-terminated-race branch July 11, 2026 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

connectors Issues related to the adapters/connectors crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants