Skip to content

fix: route mid-action cancel and time_limit through the fallback cancel path#312

Draft
seant-aws wants to merge 3 commits into
OpenJobDescription:mainlinefrom
seant-aws:phase1-containers
Draft

fix: route mid-action cancel and time_limit through the fallback cancel path#312
seant-aws wants to merge 3 commits into
OpenJobDescription:mainlinefrom
seant-aws:phase1-containers

Conversation

@seant-aws

Copy link
Copy Markdown
Contributor

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

When an action is running, the session object is checked out to a background thread, so cancel_action falls back to firing the shared cancellation token. That path dropped time_limit and (before the paired openjd-rs change) had no listener on the cross-user helper path, so cancellation was silently lost for running actions.

Paired change: OpenJobDescription/openjd-rs#258

What was the solution? (How)

  • Cascade the action cancel token from a parent token and pre-create/inject a per-action cancel-request channel in prepare_action_cancel.
  • cancel_action sends time_limit on that channel before firing the token so runners receive both the wake-up and the grace period.
  • Results are correctly classified as canceled when a cancel is delivered mid-action.

What is the impact of this change?

Mid-action cancellation now delivers time_limit to the Rust runner, allowing it to gracefully terminate cross-user processes within the specified grace period instead of silently ignoring the cancel request.

How was this change tested?

  • cargo build / clippy clean
  • Validated via the AWS Deadline Cloud worker agent e2e suite (cancel scenarios all passing)

Was this change documented?

  • Relevant docstrings updated in the code base.

Is this a breaking change?

No. The new methods (prepare_action_cancel, set_cancel_parent_token, set_cancel_request_channel) are additive. Existing callers that do not use cancellation are unaffected.

Does this change impact security?

No. The cancel channel is internal to the session and does not create or modify files.


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

Previously, cancel_action required the session mutex to be available,
which it never is during a running action (the background thread takes
ownership).  This meant cancel was effectively a no-op during execution.

Add a shared CancellationToken slot (`cancel_token`) that is set before
each action spawns.  When cancel_action is called while the session is
taken, it cancels this token — which cascades to the action's child
token that the subprocess runner selects on — killing the process.

Also update the snapshot state to CANCELING so the Python poll thread
can observe the transition and continue polling until the terminal
READY_ENDING state arrives with the correct ActionStatus.

Signed-off-by: Sean Tang <seant-aws@users.noreply.github.com>
Signed-off-by: Sean Tang <171081544+seant-aws@users.noreply.github.com>
…el path

When an action is running the session object is checked out to a
background thread, so cancel_action falls back to firing the shared
cancellation token. That path previously dropped the time_limit argument
entirely.

cancel_action now sends the time_limit on the per-action cancel-request
channel (pre-created and injected in prepare_action_cancel) before
firing the token, so subprocess runners receive both the wake-up and the
grace-period payload, and completed actions classify as Canceled.

Signed-off-by: Sean Tang <171081544+seant-aws@users.noreply.github.com>
Comment thread rust-bindings/Cargo.toml
# openjd-expr = { path = "../../openjd-rs/crates/openjd-expr" }
# openjd-model = { path = "../../openjd-rs/crates/openjd-model" }
# openjd-sessions = { path = "../../openjd-rs/crates/openjd-sessions" }
[patch.crates-io]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This uncomments the local-dev [patch.crates-io] overrides, but the comment block directly above (lines 51-53) states these must stay commented out for committed work and CI: "the published wheel is built against the crates.io versions, which is what the Cargo.lock file pins."

With this active, any build outside a machine that has a sibling ~/openjd-rs checkout at ../../openjd-rs/crates/... will fail to resolve the path dependencies — this breaks CI and the published-wheel build. Consistent with that, Cargo.lock now drops the source/checksum for openjd-expr, confirming it is being resolved from the local patch rather than crates.io.

This looks like an accidental commit of a local iteration state. It should be reverted (re-comment the block, and remove the corresponding [patch.crates-io] addition in the workspace Cargo.toml) before merge.

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