Skip to content

docs(agent): run package operations via bypass route - #2238

Draft
Benoît Cortier (CBenoit) wants to merge 6 commits into
masterfrom
claude/agent-bypass-contract-0b6111
Draft

Benoît Cortier (CBenoit) wants to merge 6 commits into
masterfrom
claude/agent-bypass-contract-0b6111

Conversation

@CBenoit

@CBenoit Benoît Cortier (CBenoit) commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

The 2.0 broker runs a remote package operation from a request that the Agent writes and authorizes with a bypass token, so the Agent need not refuse the requests that the 1.x grant route cannot express, such as Chocolatey operations, machine scope outside WinGet, or installs without a source.

Specify the ExecuteBypassRequest registration-pipe command, through which UniGetUI forwards the Agent's request and token to POST /v2/package-requests/execute-bypass unchanged; how the Agent maps each Authority field into that request; how it gives and withdraws tokens; and how it turns what the Broker shows in process into an operation result.
The Broker shows the Agent whether a request used a token for as long as the Agent waits, so a used token is never reported as a failure that started nothing.

A UniGetUI that answers UnsupportedCommand gets the operation on the grant route instead, once the Agent has withdrawn the unused token, so no operation runs twice.
The Authority request and result are unchanged.
The bypass request carries no row identity, so an update or uninstall acts on what the manager finds for the package in the requested scope.

Only a WinGet uninstall can name the Devolutions Agent by its MSI product code, so when that code cannot be read, the Agent and the Broker refuse WinGet uninstalls only, on both routes; a device without the Agent MSI has no product code rather than an unreadable one.

Issue: DGW-512

🤖 Generated with Claude Code

The 2.0 broker runs a remote package operation from a request that the
Agent writes and authorizes with a bypass token, so the Agent need not
refuse the requests that the 1.x grant route cannot express, such as
Chocolatey operations, machine scope outside WinGet, or installs
without a source.

Specify the ExecuteBypassRequest registration-pipe command, through
which UniGetUI forwards the Agent's request and token to the bypass
route unchanged; how the Agent maps each Authority field into that
request; how it gives and withdraws tokens; and how it turns what the
broker shows into an operation result.

A UniGetUI that answers UnsupportedCommand gets the operation on the
grant route instead, once the Agent has withdrawn the unused token, so
no operation runs twice. The Authority request and result are
unchanged.

Issue: DGW-512

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Have the Broker show the Agent whether a request used a token for as
long as the Agent waits on it, so a used token is never reported as
"nothing was started" and the fallback never follows a hidden use.
Bound the wait from when the Agent gives the token, end it when the
command was provably not written, and report UNKNOWN when the Broker
no longer holds a started operation.

Scope the grant route's source requirements to ExecutePackageOperation,
state that the bypass request carries no row identity, and tighten the
response, elevation and body-encoding wording.

Issue: DGW-512

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A failed execution-pipe check after sending leaves only UniGetUI without
the outcome; the Agent still learns it from the Broker. Name the
Authority request's manager string in the exit-code error on both
routes, state that elevated runs use machine-wide sources, and narrow
the bypass route's own checks to writing the request.

Issue: DGW-512

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI adaptive review requested due to automatic review settings December 1, 2026 18:19
@CBenoit

Copy link
Copy Markdown
Member Author

Lines changed

  • Production code: 0
  • Tests: 0
  • Other: crates/agent-channel-proto/CONTRACT.package-management.md (contract text), +159 / −45

Merge order

Merge after Devolutions/now-libraries#141 lands at 3014fcb or later.
CONTRACT.wire.md §protected-package exists only there, and only there does CONTRACT.wire.md §bypass bound how long the Broker holds an unused bypass token, which this contract cites to keep tokens short-lived.

Acceptance evidence

  • git diff --stat origin/master lists only the contract file; no channel.proto or Authority-visible message change.
  • §provisional-errors and §provisional-decisions are byte-identical to master.
  • Text moved within the file is verbatim apart from 22 edited lines (multiset line diff against master).
  • Every cited wire and policy anchor exists at now-libraries 3014fcb.
  • The exit-code trust list holds for the 2.0 launch paths: on the 2.0 broker branch, elevated and unelevated PowerShell builders share the -NoProfile -Command … ; exit 0 script.
  • Fresh-context contract review, 3 rounds; final verdict "approve with non-blocking findings", whose remaining items are the open questions below.

Choices made in the text

  • Command ExecuteBypassRequest with operationId, request (JSON text in a string, so UniGetUI never parses it) and token.
  • Bypass tokens carry at least 128 bits from a CSPRNG.
  • The Agent withdraws a still-unused token on any UniGetUI answer and when its wait ends; the fallback is that withdrawal plus a new grant on the same connection, so it never retries through another endpoint.
  • The Broker shows the Agent whether a token was used until the Agent's wait ends; the wait is bounded at 30 minutes from giving the token.
  • Scope and Elevation both come from the Authority scope; reported_scope maps to nothing on this route, and its presence check stays.
  • NoUpgrade only for a WinGet install.
  • The existing exit-code trust list applies to bypass terminal statuses, so Chocolatey operations that ran report UNKNOWN.
  • One known-failure text when the Broker launched no manager process.
  • §operations is split into common rules, §bypass-route, §grant-route and §operation-results.

Open questions

  1. Busy exemption. A request presenting a pending grant is served over the Broker's connection limit; the bypass route has no such exemption, and adding one is a now-libraries wire rule. Under local load, a bypass operation can end with the known failure where the grant route would have run it.
  2. Row identity. The bypass request carries no reported_scope and UniGetUI checks no row, so an update or uninstall acts on what the manager finds for the package in the requested scope, for example the user copy of a PowerShell 7 module installed machine-wide.
  3. UniGetUI settings. A disabled manager or broker routing turned off no longer gates remote operations on the bypass route.
  4. Sourced updates. PowerShell 5.1 and Scoop updates that name a source fail at the Broker on the bypass route, which cannot check the recorded source, and do not fall back.
  5. Diagnosability. ProtectedPackage, BypassRequestUnreadable, BrokerBusy and an expired token all reach DVLS as one known-failure text; a specific reason needs the Broker to record refusals per token.
  6. Uninstall version. An uninstall's requested version is dropped on the bypass route and kept on the grant route.

Implementation consequences

The 2.0 broker token store (v2/bypass/tokens.rs) forgets every token after 60 seconds and has no withdraw API.
It needs use tracking that lasts until the Agent's wait ends, and a withdrawal that reports whether a request used the token.

UNTESTED

None: this change is contract text only.

Note

LLM-assisted content (no human feedback).

Copilot AI left a comment

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.

🟡 Changes recommended

Approval is blocked by unresolved critical contract inconsistencies around token withdrawal, reuse, and expiry, plus a conflicting success interpretation for unlisted managers.

4 open issues
What changed in this PR

This pull request extends the Agent package-management contract with a Broker bypass route for Agent-authorized operations while retaining the grant route as a fallback for older UniGetUI versions.

Changes:

  • Defines ExecuteBypassRequest registration-pipe semantics and forwarding to the Broker endpoint.
  • Specifies bypass request construction, token lifecycle, Broker outcome handling, and fallback sequencing.
  • Updates operation journaling, result mapping, scope handling, and inventory rescan rules.
File Description
crates/​agent-channel-proto/​CONTRACT.package-management.md Adds the bypass-route protocol, token lifecycle, Broker execution and outcome handling, fallback behavior, and revised package-operation semantics.

Review effort: Lite (adaptive)

The Agent generates each bypass token from a cryptographically secure random source, with at least 128 random bits, in the form that [`CONTRACT.wire.md §bypass`][wire bypass] gives a bypass token, so that no process can guess a token it was not given.
It gives the Broker the token in process, bound to the bypass request, `RequestId` included, and to the SID of the target user, as [`CONTRACT.wire.md §bypass`][wire bypass] expects.
It gives the Broker each token once and binds no other request to it, because the Broker remembers a used-up token for a limited time and holds a token given again after that as a new one.
How long the Broker holds a token that no request used is what [`CONTRACT.wire.md §bypass`][wire bypass] states.
Comment on lines +424 to +426
When UniGetUI answers, whatever the answer, the Agent withdraws the token unless a request has used it.
A withdrawal and a request presenting the token never both take effect: either the request used the token first, or the request starts no operation, and no request uses the token after the withdrawal.
A withdrawal tells the Agent whether a request had used the token.
| `Failed` or `Canceled`, and a launched manager process without an exit code | `UNKNOWN` | true |
| a status that is not terminal | `UNKNOWN` | true when the manager process was launched, absent otherwise |

For a manager that `CONTRACT.package-management.md §grant-route` does not list among the managers whose exit code establishes the outcome, the Agent reports `UNKNOWN` instead of a known success or of a known failure with an exit code, because only for the listed managers are the Broker's launch paths known to return the manager's own exit code.
Only a WinGet uninstall can name the Devolutions Agent by its MSI
product code, so an unreadable product code refuses only WinGet
uninstalls, on the Agent and on both Broker routes, and a device
without the Agent MSI has no product code rather than an unreadable
one.

Cite the wire contract for the limit on answering a request with a
held bypass token as busy, and for relying on the Agent to give each
token once.

Issue: DGW-512

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Broker's connection-limit rule now defers to the wire contract for
a bypass request presenting a token the Broker holds, so it no longer
answers such a request busy where the wire contract serves it.

Name the failure for an uninstall that names the Agent whatever the
product-code read found, state the absent-MSI case by what the read
finds, and state the single-use rule by the token's characters.

Issue: DGW-512

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A bypass request presenting a held token is served like a grant slot,
so it no longer counts toward the over-limit connections that make the
Broker close a further one unread.

Issue: DGW-512

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI adaptive review requested due to automatic review settings December 2, 2026 09:19
@CBenoit

Copy link
Copy Markdown
Member Author

Update: product code, busy replies and tokens

Lines changed: production code 0, tests 0, other 1 file (CONTRACT.package-management.md, +165 / −48).

Merge order

This now relies on Devolutions/now-libraries#141 at 5ca5989 or later:

  • CONTRACT.wire.md §protected-package: an unreadable product code protects WinGet uninstalls only, and a missing Agent MSI is not a failed read.
  • CONTRACT.wire.md §bypass: the limit on answering a request with a held token BrokerBusy, and the Agent giving each token once.

Changes

  • An unreadable product code refuses WinGet uninstalls only, in the Agent's own refusal and on both Broker routes. A WinGet uninstall keeps the "cannot verify" failure in that state; any other uninstall that names the Agent, such as Chocolatey devo-agent, gets the "cannot be uninstalled remotely" failure (Agent) or "does not uninstall" message (grant route).
  • §broker-grant-errors defers to CONTRACT.wire.md §bypass for a bypass request presenting a held token, and leaves such served connections out of the count behind the unread close.
  • The Agent never gives the Broker a token with the characters of one it gave before.
  • Row identity and the four accepted consequences stay as written.
  • Fresh-context contract review, 3 rounds; final verdict "approve".

Open question

§broker-grant-errors has the Broker close a further over-limit connection without reading it once 16 are being read. CONTRACT.wire.md does not allow that close, and a held-token bypass request can hit it. Either CONTRACT.wire.md §transport allows the close (the client resends with the same token, which matches today's pipe code), or the Broker stops accepting connections so clients get ERROR_PIPE_BUSY, which the wire contract already allows.

Implementation consequences

  • The Agent's refuse_agent_uninstall (devolutions-agent/src/device_management/operation.rs) and the Broker's product-code check (crates/now-package-broker/src/server/mod.rs, installed_agent_product_code) still refuse every uninstall when the code is unreadable; the implementing change narrows both, updates their doc comments and adds a non-WinGet case.
  • crates/now-package-broker/src/pipe.rs has grant slots but no way to serve a held-token bypass request over the limit.

UNTESTED

None: this change is contract text only.

Note

LLM-assisted content (no human feedback).

Copilot AI left a comment

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.

🟡 Changes recommended

Elevated PowerShell operations can install attacker-controlled modules because an explicit source can still resolve to a user-controlled repository rather than an administrator-protected feed.

6 open issues
8 previously missed issues

In code that hasn't changed since last review

Medium severity Qualify uninstall scope by the manager's actual enforcement

crates/​agent-channel-proto/​CONTRACT.package-management.md:401

For PowerShell and Pip uninstalls, CONTRACT.policy.md §manager-powershell and §manager-pip leave scope unknown, so a request can affect an installation outside Scope. This sentence incorrectly promises a scope boundary. Qualify it by what the manager's command actually enforces.

Medium severity Bound unanswered bypass requests to prevent slot exhaustion

crates/​agent-channel-proto/​CONTRACT.package-management.md:422

There is no response deadline or cleanup for an unanswered ExecuteBypassRequest. Eight stuck Broker submissions can therefore fill all registration slots even after their operation waits finish, while heartbeats keep the connection alive. Close the connection after a bounded response wait, as the rescan rule does.

Low severity Reconcile bypass retry and termination rules across contracts

crates/​agent-channel-proto/​CONTRACT.package-management.md:421

The cited wire contract says a client that does not know a bypass request's outcome sends the same request and token again, whereas this permits UniGetUI to stop without retrying. For example, an InternalError or lost response before acceptance can immediately become a final failure instead of receiving the wire contract's recovery attempt. Please reconcile the retry requirement and its termination conditions across both contracts.

Low severity Allow time for UnsupportedCommand before finalizing token failure

crates/​agent-channel-proto/​CONTRACT.package-management.md:437

If the Broker discards an unused token before an older UniGetUI answers UnsupportedCommand, this rule finalizes a failure and ignores the later response. That prevents the grant fallback even when the response arrives before the 30-minute deadline and no operation could have started. Keep waiting for the command response within an agreed deadline after proving the token unused and unusable.

Low severity Choose the outcome from atomic withdrawal results

crates/​agent-channel-proto/​CONTRACT.package-management.md:441

A request can consume the token between the observation that ends the wait and the Agent's withdrawal. Selecting the outcome from that earlier snapshot can report “nothing was started” even when withdrawal reports use. Base the result on the atomic withdrawal result and read the associated operation before ending the wait.

Low severity Condition retry failures on proven token non-use and withdrawal

crates/​agent-channel-proto/​CONTRACT.package-management.md:458

A retry can receive BrokerBusy or BypassTokenRejected after an earlier request already started the operation. Requiring a known failure unless a later request uses the token then contradicts the outcome table. Condition that result on the Broker proving no request used the token and withdrawal preventing future use.

Low severity Move grant-record rules into the Broker-record paragraph

crates/​agent-channel-proto/​CONTRACT.package-management.md:590

These grant-record rules now share the paragraph about .NET source overrides, although they apply to every manager. Move them into the Broker-record paragraph immediately above.

Low severity Clarify grant and token wording on authorization routes

crates/​agent-channel-proto/​CONTRACT.package-management.md:780

Now that grants and bypass tokens are distinct, “the token” is ambiguous on the grant-only ExecutePackageOperation route. Use “the grant” here, and name both authorization types in the no-authorization statements at lines 352 and 362.

1 resolved since last review

Review effort: Max (adaptive)

`NoUpgrade` keeps a WinGet install from replacing an existing installation, as on the grant route.
The Agent rejects an operation whose package ID, or whose source or requested version when the request carries it, is outside the domain that [`CONTRACT.wire.md §package-request`][wire package request] gives the member it fills, so that it never sends a request that the Broker answers `BadRequest`.
It does not check whether the Broker can read the request, such as an elevated install or update without `Source` ([`CONTRACT.wire.md §bypass-reading`][wire bypass reading]), and the outcome table below covers the Broker's answer.
Elevated installs and updates use only sources from machine-wide configuration ([`CONTRACT.wire.md §bypass-reading`][wire bypass reading]), and the Agent does not verify the effective feed.
| Grant route not implemented by a rebuilt Broker | 501 | `UnsupportedEndpoint` |
| Grant route absent on an older Broker | 404 | No structured body is required. |
| Broker over its connection limit, overall or for the caller's user, and not serving the request in a grant slot as described below | 503 | `BrokerBusy` |
| Broker over its connection limit, overall or for the caller's user, and not serving the request in a grant slot as described below or as [`CONTRACT.wire.md §bypass`][wire bypass] has it serve a bypass request presenting a token it holds | 503 | `BrokerBusy` |
Comment on lines +800 to +801
[wire protected package]: https://github.com/Devolutions/now-libraries/blob/master/policies/CONTRACT.wire.md#protected-package
[wire bypass]: https://github.com/Devolutions/now-libraries/blob/master/policies/CONTRACT.wire.md#bypass

This branch has not been deployed

No deployments
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