Skip to content

feat(agent): support canceling package broker operations - #1905

Draft
Vladyslav Nikonov (vnikonov-devolutions) wants to merge 1 commit into
masterfrom
vnikonov-devolutions-package-broker-cancelation
Draft

feat(agent): support canceling package broker operations#1905
Vladyslav Nikonov (vnikonov-devolutions) wants to merge 1 commit into
masterfrom
vnikonov-devolutions-package-broker-cancelation

Conversation

@vnikonov-devolutions

Copy link
Copy Markdown
Contributor

Adds a POST /v1/package-operations/cancel endpoint to the Devolutions Agent package broker. Clients can now cancel an in-flight package operation: the broker terminates the spawned package-manager process and reports the operation as Canceled. Cancelation is idempotent, and canceling an already-finished operation simply returns its final status. Unknown operations, or operations owned by another client, are reported as not found.

This enables UniGetUI (and other broker clients) to give users a working cancel button for installs, updates, and uninstalls that run through the broker.

Depends on now-policy-api / now-policy-server-template 0.3 (cancel API, Canceling/Canceled statuses, API version 1.1).

Note

Draft: the workspace Cargo.toml temporarily patches now-policy-api and now-policy-server-template to a local path. These patches must be removed once the 0.3 crates are published to crates.io.

Adds a POST /v1/package-operations/cancel endpoint to the package broker. Canceling a running operation terminates the spawned package-manager process and reports the operation as Canceled; cancelation is idempotent and terminal operations report their final status.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@vnikonov-devolutions

Copy link
Copy Markdown
Contributor Author

Implementation notes:

  • New endpoint: POST /v1/package-operations/cancel (CancelRequest/CancelResponse from now-policy-api 0.3). Auth mirrors the status endpoint: client context + Devolutions Authenticode signature validation, plus an owner-key check (effective_user|client_executable_path), so a client can only cancel its own operations (NotFound otherwise).
  • Cancel semantics: async + idempotent. A non-terminal operation transitions to Canceling and its per-operation CancellationToken (stored in OperationTracker) is triggered; the response reports Canceling. Terminal operations return their final status unchanged. Repeated cancels are harmless.
  • Process termination: the Windows executor's create_process wait was changed from a single 1-hour blocking wait to a 500 ms polling loop that checks the cancel token and the overall deadline. On cancel it terminates the process (exit code 1) and returns a typed ExecutionCanceled error; the background execution task downcasts it and marks the operation Canceled instead of Failed.
  • Token plumbing: the cancel token only guards the pre-command and the main command; kill-before-operation and post-operation commands get a fresh token (post is best-effort cleanup and is skipped anyway when the main command errors out).
  • Race handling: mark_running refuses to regress Canceling/Canceled; mark_completed/mark_failed never overwrite Canceled. If a process exits normally before the terminate lands, its real outcome wins.
  • Testing: unit tests cover unknown-operation, running-operation (token fired + Canceling), terminal-operation (status preserved), and owner-mismatch paths, plus tracker state-transition guards. cargo +nightly fmt, cargo clippy --tests -D warnings, and cargo test -p devolutions-agent all pass.
  • Temporary: [patch.crates-io] path entries for now-policy-api/now-policy-server-template point at a local now-proto worktree until 0.3 is published; remove before merging (marked with a TODO).

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

Let maintainers know that an action is required on their side

  • Add the label release-required Please cut a new release (Devolutions Gateway, Devolutions Agent, Jetsocat, PowerShell module) when you request a maintainer to cut a new release (Devolutions Gateway, Devolutions Agent, Jetsocat, PowerShell module)

  • Add the label release-blocker Follow-up is required before cutting a new release if a follow-up is required before cutting a new release

  • Add the label publish-required Please publish libraries (`Devolutions.Gateway.Utils`, OpenAPI clients, etc) when you request a maintainer to publish libraries (Devolutions.Gateway.Utils, OpenAPI clients, etc.)

  • Add the label publish-blocker Follow-up is required before publishing libraries if a follow-up is required before publishing libraries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants