Skip to content

fix: poll through CANCELING state to deliver terminal callback#331

Merged
mwiebe merged 1 commit into
OpenJobDescription:mainlinefrom
seant-aws:fix/cancel-poller-canceling-state
Jul 21, 2026
Merged

fix: poll through CANCELING state to deliver terminal callback#331
mwiebe merged 1 commit into
OpenJobDescription:mainlinefrom
seant-aws:fix/cancel-poller-canceling-state

Conversation

@seant-aws

Copy link
Copy Markdown
Contributor

What was the problem/requirement? (What/Why)

The _poll_for_completion thread exited the polling loop as soon as the session state transitioned away from RUNNING. When cancel_action() is called, the pyo3 binding immediately sets the snapshot state to CANCELING — causing the poller to exit before the subprocess has been killed and before the Rust callback delivers the terminal CANCELED ActionStatus.

The result: the worker agent never receives the CANCELED callback, leaving the action stuck in CANCELING forever from the service perspective.

What was the solution? (How)

Treat CANCELING as an in-progress state (like RUNNING) and continue polling. The poller now exits only when the state reaches READY or READY_ENDING, at which point action_status contains the correct terminal state.

What is the impact of this change?

Actions that are cancelled mid-execution now correctly transition through CANCELING → CANCELED instead of hanging in CANCELING forever.

How was this change tested?

  • Validated end-to-end via the AWS Deadline Cloud worker agent e2e suite (cancel scenarios all passing; full Linux suite 48/49 with the one failure unrelated to this change).

Was this change documented?

  • Comment in code updated to reflect the new RUNNING/CANCELING loop condition.

Is this a breaking change?

No. This is a bugfix to internal polling behavior; the public API is unchanged.

Does this change impact security?

No.

Cross-port to openjd-rs

  • Cross-porting is not applicable for this change because: this fix is in the Python _v1 polling layer that bridges the Rust session to the Python callback. The Rust session itself already handles cancellation correctly — the bug was only in the Python polling shim that sits between the two.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@seant-aws
seant-aws marked this pull request as ready for review July 21, 2026 18:56
@seant-aws
seant-aws requested a review from a team as a code owner July 21, 2026 18:56
The _poll_for_completion thread exited the polling loop as soon as
the session state transitioned away from RUNNING.  When cancel_action()
is called, the pyo3 binding immediately sets the snapshot state to
CANCELING — causing the poller to exit before the subprocess has been
killed and before the Rust callback delivers the terminal CANCELED
ActionStatus.

The result: the worker agent never receives the CANCELED callback,
leaving the action stuck in CANCELING forever from the service's
perspective.

Fix: treat CANCELING as an in-progress state (like RUNNING) and
continue polling.  The poller now exits only when the state reaches
READY or READY_ENDING, at which point action_status contains the
correct terminal state.

Signed-off-by: Sean Tang <seant-aws@users.noreply.github.com>
Signed-off-by: Sean Tang <171081544+seant-aws@users.noreply.github.com>
@mwiebe
mwiebe force-pushed the fix/cancel-poller-canceling-state branch from fa3037b to 5dde728 Compare July 21, 2026 19:56
@mwiebe
mwiebe enabled auto-merge (squash) July 21, 2026 19:57
state = self._rust_session.state
status = self._rust_session.action_status
if state == SessionState.RUNNING:
if state in (SessionState.RUNNING, SessionState.CANCELING):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Validated end-to-end via the AWS Deadline Cloud worker agent e2e suite (cancel scenarios all passing; full Linux suite 48/49 with the one failure unrelated to this change).

Were there any test failing due to the lack of this change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yea, all the cancel tests in the E2E when hardcoding to use the rust runtime were not working due to this miss

@mwiebe
mwiebe merged commit d57e477 into OpenJobDescription:mainline Jul 21, 2026
51 of 60 checks passed
@seant-aws
seant-aws deleted the fix/cancel-poller-canceling-state branch July 21, 2026 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants