Skip to content

feat(agent): serve the 2.0 request encoding in the package broker - #2231

Draft
Benoît Cortier (CBenoit) wants to merge 42 commits into
claude/broker-v2-requests-7702d2from
claude/broker-v2-routes-7702d2
Draft

Benoît Cortier (CBenoit) wants to merge 42 commits into
claude/broker-v2-requests-7702d2from
claude/broker-v2-routes-7702d2

Conversation

@CBenoit

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

Copy link
Copy Markdown
Member

Temporary git dependencies, each of which must become a crates.io version before this merges (introduced at the bottom of this stack, unchanged here):

  • now-policy, now-policy-api and now-policy-server-template: [patch.crates-io] in the root Cargo.toml, on Devolutions/now-libraries at 5b23b1a616ca97590d4d6b9e610cd07772d30453.
  • now-policy-eval: a dependency of crates/now-package-broker, same repository at 25e75110c067239e44e42f005abbf566f32f803a.

Builds on #2230, which builds on #2229, which builds on #2224, #2225 and #2226.

The package broker serves the 2.0 request encoding: every endpoint of CONTRACT.wire.md under /v2/, decided against a policy in format 2.x.
A request whose path starts with /v2/ goes to its own router, and every other request reaches the 1.x router as before, so a later release can delete the 1.x routes without touching these.

Each request is answered by the first of the contract's outcomes that applies: BrokerBusy, UnknownEndpoint, UnsupportedMediaType, Unauthenticated, AdministratorRequired, RequestTooLarge, BadRequest, then the endpoint's own.
The first five are decided without reading any byte of the body, and a panic while answering is InternalError.

  • GET /v2/health answers any client with only Status, Ready exactly when the broker holds an accepted policy.
  • GET /v2/capabilities names the version of the Devolutions Agent that hosts the broker, which the Agent gives the broker when it starts it, the operation timeout and, for each manager, the opt-ins of its reading that the broker acts on.
  • POST /v2/package-requests/evaluate answers ProtectedPackage for a protected uninstall whether or not the broker holds a policy, then the decision of the accepted policy, PolicyUnavailable without one, and NotRunnable for an allowed request that would run a Pre or Post command elevated, audit mode included.
  • POST /v2/package-requests/execute, GET /v2/operations/{OperationId} and POST /v2/operations/{OperationId}/cancel start, report and cancel the operations of their owner. An execution request that is a protected uninstall is answered ProtectedPackage once its RequestId is known to be unused, starts nothing and leaves that RequestId unused. Operations of the 1.x routes are not ones a 2.0 request names or replays.
  • GET /v2/policy/management, POST /v2/policy/validate and POST /v2/policy read the management state, report the policy errors of a document, and replace the policy for an elevated administrator, with the audit records the 1.x route leaves.
  • POST /v2/package-requests/execute-bypass starts an operation without any policy for a request its bypass token authorizes. The request is read by the evaluator's bypass reading, so one without a source runs with the only source name of its manager, or leaves the choice of source to the manager, or is BypassRequestUnreadable. The broker holds tokens in memory, as digests, each bound to one bypass request and one user for 60 seconds. A token is used up once the broker holds the operation it started, and a used-up token is refused when the broker is given it again within those 60 seconds. No code issues a token yet: the entry point that binds one has no caller until the Agent's side exists, so every bypass request is answered BypassTokenRejected in a released broker.

A protected uninstall is a request that removes a package, by Uninstall or by the UninstallPrevious opt-in of an Install or Update, and either names Devolutions Agent or arrives while the broker cannot read the product code of the installed Agent.
An Install or Update that names the Agent without UninstallPrevious is evaluated like any other request.
The plan of an operation still refuses to remove the Agent, as a second check behind the routes.

The event channel of an operation a bypass request started sends its frames only to a process the broker identifies as the operation's owner, the way the request pipe identifies a client.
A client is identified as soon as it connects; any other connection is closed without a frame, and the same pipe instance listens again one second later, until the owner connects or the channel ends.
An identification that does not complete within 30 seconds closes the channel, so the identification keeps the pipe only while it reads the id of the client process.
A process of the same user that connects in a loop can therefore keep the owner off the channel, but reads nothing and cannot make the channel outlive its 60 seconds after the operation ended; the owner still learns the status with status requests.

A client whose process the broker cannot identify used to have its connection closed without a response.
Its /v2/ requests are now answered as the contract says: health normally, every other endpoint Unauthenticated without reading the body.
A request under any other path on such a connection still gets no response.

Scope item Outcome Evidence
Every /v2/ endpoint of CONTRACT.wire.md Done: ten endpoints v2::routes::tests, one group per endpoint; v2::wire::route::table_has_every_endpoint
1.x routes in a separate code path Done: 1.x router and handlers unchanged, reached for every path outside /v2/ a_path_outside_the_prefix_reaches_the_other_router, the_1_x_routes_hold_a_policy_exactly_when_the_file_is_in_format_1
Order of the outcomes Done unknown_endpoint_wins_over_the_media_type_and_the_client, unsupported_media_type_wins_over_the_client, unauthenticated_wins_over_an_oversized_body, unauthenticated_wins_over_administrator_required, administrator_required_wins_over_an_oversized_body, the_first_five_outcomes_are_answered_without_any_byte_of_the_body, a_busy_broker_answers_broker_busy_whatever_the_request
/v2/health returns only Status Done health_is_ready_exactly_when_the_broker_holds_an_accepted_policy, health_answers_a_client_the_broker_does_not_authenticate
Evaluate with the accepted 2.x policy Done an_evaluation_names_the_decision_the_policy_and_the_evaluation_time, an_evaluation_without_an_accepted_policy_is_policy_unavailable, a_denied_evaluation_is_answered_with_its_decision
Never run Pre or Post commands for an elevated run, audit mode included Done: NotRunnable an_allowed_request_with_commands_for_an_elevated_run_is_not_runnable, a_request_the_contract_refuses_whatever_the_policy_is_refused_in_audit_mode_too
Owner is the caller's SID and executable path Done a_request_id_belongs_to_its_owner, a_status_or_cancel_request_for_an_operation_the_broker_does_not_hold_for_its_owner_is_operation_not_found
1.x operations not visible on /v2/ Done an_operation_of_the_1_x_routes_is_not_one_a_2_0_request_names_or_replays
Replace a policy only with a higher Revision for the same Id Done a_replacement_with_the_id_of_the_accepted_policy_and_no_higher_revision_is_revision_not_higher, with the other replacement outcomes beside it
Policy replacement is audited Done a_policy_replacement_leaves_its_attempt_and_its_result_under_its_own_request, a_policy_replacement_refused_for_its_body_leaves_its_attempt_and_its_rejection, a_refused_policy_replacement_leaves_a_denial_record
Bypass endpoint Done on the broker's side; issuing a token is the Agent's and has no caller yet the_outcomes_of_a_bypass_request_come_in_their_order, a_used_up_token_authorizes_no_other_request, a_used_up_token_the_broker_is_given_again_authorizes_no_request, bypass_requests_with_one_token_that_arrive_together_start_one_operation, a_bypass_request_that_fails_before_the_broker_holds_its_operation_keeps_its_token, an_equal_bypass_request_with_the_token_of_an_operation_the_broker_no_longer_holds_is_bypass_token_rejected, a_bypass_request_to_uninstall_devolutions_agent_is_protected_package, a_bypass_operation_runs_as_the_bound_user_with_the_elevation_of_the_request; v2::bypass::tokens
Event channel of a bypass operation serves its owner only Done another_process_of_the_user_reads_the_frames_of_an_execution_and_none_of_a_bypass; operations::a_channel_for_the_owner_sends_its_frames_to_the_process_identified_as_the_owner_and_to_no_other; event_channel::pipe_tests: a_refused_connection_gets_no_frame_and_the_next_admitted_one_gets_them_all, the_pipe_of_a_channel_is_busy_during_the_pause_after_a_refusal, a_channel_whose_identification_of_a_client_panics_sends_no_frame_and_gives_its_pipe_up, a_channel_whose_identification_of_a_client_does_not_complete_sends_no_frame_and_gives_its_pipe_up, a_channel_whose_deadline_passes_while_the_identification_asks_its_pipe_something_gives_its_pipe_up, a_pipe_given_up_while_it_is_asked_something_closes_once_it_has_answered
Bypass request without Source Done: read by the evaluator's bypass reading a_readable_bypass_request_without_source_runs_its_command_without_the_source_option_of_its_manager, a_readable_bypass_request_without_source_whose_command_has_no_source_option_runs, a_bypass_request_without_source_that_its_other_members_make_unreadable_is_bypass_request_unreadable; v2::bypass::reading: a_request_without_source_is_read_with_the_only_source_name_of_its_manager, a_request_without_source_whose_manager_names_no_only_source_name_is_read_without_one, a_scoop_request_without_source_whose_id_names_one_app_is_readable, a_vcpkg_request_without_source_is_read_by_its_port_spec_alone
A token with the same characters given again later than 60 seconds after the first, while the broker holds the operation the first one started for the same owner Kept: the Agent never gives the same token twice, and the broker names a bypass operation by the digest of its token, so it answers such a request as one that carries the first token comment at Existing::Conflict in v2/routes/bypass.rs
Protected uninstall of Devolutions Agent on evaluate, execute and bypass Done: ProtectedPackage at its place among the outcomes of each endpoint an_evaluation_or_execution_request_that_is_a_protected_uninstall_is_protected_package, a_request_that_is_no_protected_uninstall_is_evaluated, protected_package_comes_before_the_other_outcomes_of_an_evaluation, protected_package_comes_after_a_used_request_id_and_before_the_other_outcomes_of_an_execution, a_protected_uninstall_starts_no_operation_and_leaves_its_request_id_unused, a_bypass_request_to_uninstall_devolutions_agent_is_protected_package; v2::routes::protection
ServerVersion is the version of the hosting Agent Done: devolutions-agent passes its package version, and a version the capabilities cannot carry fails the creation of the broker task capabilities_name_the_version_of_the_agent_that_hosts_the_broker; task: the_state_of_a_task_has_the_agent_version_of_its_configuration, a_task_is_not_created_with_an_agent_version_the_capabilities_cannot_carry
Client whose process the broker cannot identify Done for /v2/ paths; other paths keep the close without a response health_answers_a_client_whose_process_the_broker_did_not_identify, a_client_the_broker_did_not_identify_is_answered_in_order_without_any_byte_of_the_body, a_request_outside_the_prefix_from_a_client_the_broker_did_not_identify_gets_no_response; pipe tests
1.x routes against a 2.x policy file Deferred: they report the file as invalid and never write over it the_1_x_routes_hold_a_policy_exactly_when_the_file_is_in_format_1

Issue: DGW-499

🤖 Generated with Claude Code

A request whose path starts with `/v2/` no longer reaches the 1.x router.
It gets the outcome the wire contract ranks first: `BrokerBusy`,
`UnknownEndpoint`, `UnsupportedMediaType`, `Unauthenticated` and
`AdministratorRequired` are answered without reading the body, then
`RequestTooLarge` and `BadRequest`.
An endpoint that passes these checks answers `InternalError`, because none
is served yet, and a panic while answering does too, so such a request
never gets a 1.x body.

A refused policy replacement leaves a denial record naming
`POST /v2/policy`, counted apart from the denials of the 1.x route, whose
records do not change.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`GET /v2/health` says `Ready` only while the broker holds an accepted 2.x
policy, so a policy file in format 1.x leaves the 2.0 endpoints paused
while the 1.x routes keep their policy.

`GET /v2/capabilities` names the managers found for the client's user and
the timeout the executor stops a process after.
A manager capability lists the opt-ins the broker handles itself, and
the custom parameters and install location where the manager takes them.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`POST /v2/package-requests/evaluate` answers the decision of the 2.x
evaluator, the identity of the policy that decided and the evaluation
time, and starts nothing.
A denial is a decision in a 200 response, not an error.

Without an accepted 2.x policy the request is `PolicyUnavailable`, which
is also the answer while the policy file is in format 1.x.
An allowed request that would run a command with an elevated token is
`NotRunnable` with its decision, in audit mode too.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
An execution request under /v2/ is evaluated against the accepted policy and, when allowed, starts an operation held apart from those of the 1.x routes, so neither encoding names, replays or conflicts with an operation of the other.
The status and cancel requests answer for the owner of an operation only, with the same response for another owner's operation as for one the broker does not hold.

An allowed request that would uninstall the Devolutions Agent, or any uninstall while the product code of the installed Agent cannot be read, starts an operation that runs no step and ends Failed, because the broker never removes the Agent it runs in.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The policy management, validation and replacement requests under /v2/ answer from the 2.0 view of the policy store, so a client of the 2.0 encoding manages a 2.x policy file without the 1.x routes.
A replacement is recorded under its own request, from the attempt of an administrator to its result, and a request refused for its body leaves a result too.

The store and the wire model each mapped the validation errors of the evaluator; the wire model's mapping is the one that remains.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The broker binds a bypass token to a 1.x request and uses the token up
when it checks it, so it can neither compare a 2.0 bypass request with
the bound request nor refuse one without using up its token.
A well-formed bypass request is therefore answered with InternalError,
which lets the client treat its outcome as unknown, and no command runs
for it.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The 2.0 bypass route answered InternalError to every request, because
the tokens of the 1.x remote operations bind a 1.x request and are used
up when checked.

The broker now holds the bypass tokens of the 2.0 encoding in a store of
their own, which binds each one to a 2.0 bypass request and to a user,
and tells whether a token authorizes a request without using it up.
The route uses a token up and starts its operation while the tokens are
locked, so requests with one token that arrive together start one
operation and each equal one gets it.
Bypass operations have a registry of their own, so a RequestId of a
bypass request neither conflicts with nor replays an execution request.

A request without Source is read under the only source name of its
manager when it has one.
Any other request without Source that is not unreadable by its elevation
is answered InternalError and keeps its token, because the reading and
the command builders take a package request, which always names a
source.

Devolutions Agent does not give the broker a token of this encoding yet,
so no request is authorized outside tests.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…s body

A client that may replace the policy and whose request is refused as
too large, as not well-formed, or because its body could not be read
left no trace, while the same request on the 1.x route leaves its
attempt and a rejection. An administrator who looks for who tried to
change the policy has to find these requests as well, so they now
leave the attempt and a request_rejected denial under the request of
the 2.0 encoding.

A replacement the policy store fails to decide is answered before any
attempt is recorded, so its log line now names the client.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… the broker read

The broker reads a package request as the wire contract defines it
before it asks the evaluator for a decision, so a refusal by the
evaluator means the two read the contract differently. BadRequest was
the answer, yet that code wins over PolicyUnavailable and over a
replayed response, which the broker has decided by then, so a client
could be told its request is malformed when the contract gives it
another outcome. The failure is the broker's and no other code names
it: it is now logged and answered as InternalError.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… on for a manager

The capability of a manager named the commands and the processes the
broker runs itself, custom parameters and a custom install location,
and nothing else. A client that offers what the capabilities name
never offered Interactive, SkipHashCheck, InstallerArguments,
UninstallPrevious or NoUpgrade, which the WinGet, Chocolatey and Scoop
commands carry, and offered Cargo pre and post commands and processes
to stop, which make a Cargo request unreadable.

Each manager now gets the opt-ins that change what the broker runs
for it: the keys its reading accepts, less those its command carries
nothing for, as the PowerShell commands do for every key of the
manager itself.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ker cannot identify

The pipe server closed the connection of a client whose process it failed
to identify, for example one whose executable is on a network share, before
reading any request. The 2.0 encoding answers every request of a connected
client: the health endpoint answers any client, a request to any other
endpoint is `Unauthenticated` when the broker does not authenticate the
client process, and a connection closes without a response only on a
timeout.

Such a client now stays connected as an unidentified one. Its 2.0 requests
get `UnknownEndpoint` and `UnsupportedMediaType` first, then the health
response or `Unauthenticated`, without the broker reading a body it does not
need, and a refused policy replacement leaves a denial record that names the
user the process seemed to run as. That user reaches nothing else: the
client owns nothing, starts nothing, and is never named to the policy store.

The 1.x routes still serve no such client. The connection closes without a
response once the header of a request outside the 2.0 encoding is read.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The event channel of a bypass operation was the channel of an execution:
it served the first connection to its pipe, so any process of the user
could read the output of an operation the policy did not decide, and the
owner connecting after it got nothing. The 2.0 encoding sends the frames
of such an operation only on a connection from a process the broker
authenticates as the owner, and closes any other connection without a
frame.

The channel of a bypass operation now identifies the process of a
connection the way the request pipe identifies a client, before the
hello frame, and compares it with the owner of the operation. A
connection it refuses is disconnected and the same pipe instance listens
again, for as long as the channel would have waited for a first
connection: until 60 seconds after the status became terminal.

Identifying a process costs the broker much more than connecting costs a
client, so after a refusal the channel waits one second before it
identifies another client, with the pipe listening meanwhile. A process
of the user that connects in a loop therefore keeps no thread busy, but
can still hold the single instance of the pipe against the owner, who
keeps the status endpoint.

The channel of an execution and the 1.x channel serve the first
connection as before.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The broker forgot a bypass token as soon as a request used it up, so
the same token given once more was held as a new one and authorized a
request again: for another owner of the same user at once, and for the
owner once its operation was no longer held. A used-up token never
authorizes a request again.

The broker now remembers a used-up token until the lifetime it was held
with ends. During that time it refuses to hold the token again, the
token authorizes nothing, and it counts toward the bound on held tokens,
so remembering it costs no more memory than holding it did. Past that
time nothing tells the token from a new one, which is why whoever gives
the broker tokens must give each one once; `hold` says so.

A test also covers the equal request that arrives once the broker no
longer holds the operation its token started, which is refused.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…tion

The broker used a bypass token up before it started the operation of
the request. When starting the operation failed, the token was gone and
no operation was held, so the request the token authorized could never
run: a bypass request that starts no operation does not use up its
token.

The token is now used up after the start returned, with the tokens
still locked, so no other request sees the operation without the token
used up, nor the token used up without the operation.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ted endpoints

The table of endpoints for authenticated clients already sends the
capabilities request of a client the broker does not authenticate.
It now checks each refusal as a whole error response, content type and
message length included, so the separate capabilities test repeated one
of its rows.

Issue: DGW-499

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…rator requirement

A request that meets both `Unauthenticated` and `AdministratorRequired`
is answered with the first.
No test sent the policy replacement of a client that is neither
authenticated nor an administrator, so a broker that checked the
administrator requirement first passed every test.

Issue: DGW-499

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
An elevated Install or Update without `Source` is unreadable unless its
manager is `Winget` or `Chocolatey`.
The only test that told apart a broker that refused those two as well
expected the answer the broker gives today for a request without a
source name, so it would follow a change of that answer.
The new test states what the contract does: such a request is not
unreadable.

Issue: DGW-499

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…tion

`Operations` is a non-empty list.
Every manager the broker drives has an operation, so no request shows
what the capabilities do with one that has none, and a response that
listed such a manager with an empty list passed every test.

Issue: DGW-499

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… as it connects

After the channel of a bypass operation refused a connection, its pipe
listened during the pause that follows, and a client that connected
then was identified only once the pause ended.
The process that connected had up to one second to exit and let another
process take its id before the broker read that id and opened the
process.

The channel now identifies a client at once whenever one connects, and
after a refusal its pipe listens again only once the pause has passed.
A client that opens the pipe during the pause gets a busy pipe.
The wait for the end of the channel still wins over the pause and over
the listening, and is still one wait for the whole loop.

The pause is a parameter of the channel so that tests choose it.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…its pipe up

A channel that could no longer tell who its pipe was connected to (the
identification of a client panicked, the pipe failed to listen or to
close a refused connection, or the read of that connection did not end)
closed its pipe, logged that no client connected, and left its queue
open.
The queue then went on taking output that nobody would read.

Such a channel now closes its queue, and the broker logs the failure
for what it is, as a warning that names its cause.
A channel to which no admitted client connected before its end keeps
its behaviour and its log line.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The test of a refused connection said that the pipe allows no other
instance.
Creating an instance fails there because the access control of the pipe
gives the user of the test no right to create one, whatever the number
of instances the pipe allows: the probe shows that the channel kept its
pipe, which its comment and its message now say.

The bypass route said that a start that panics holds no operation.
That holds for a panic before the registry takes the operation only;
after it, the registry holds an operation whose token is not used up.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Copilot AI adaptive review requested due to automatic review settings December 1, 2026 05:16
@CBenoit

Copy link
Copy Markdown
Member Author

Intent drift audit: 2.0 routes, bypass endpoint and tokens, event channel of a bypass operation, unidentified clients (audited at 1577e5704)

Audited against, as copied from now-libraries policies/ at 77307f5106d9764d03a420d22fd8377c99432af5:

  • CONTRACT.wire.md (90 rows; the sections listed under "Outside this change" are not audited one by one)
  • CONTRACT.policy.md (2 rows)
  • INTENT.md (no row of its own; the second text of 6 rows)
  • INTENT.wire.md (4 rows)
  • INTENT.legacy.md (2 rows)

A row that cites two texts is counted under the first.
A statement ID is the section anchor plus the ordinal of the sentence in its section; a list or a table counts with the sentence that introduces it, and .n names an item of a list.
#operations, #event-channel, #cancel and #replacement keep the numbers of the two earlier reports.
#bypass-20 here is the statement the earlier report called #bypass-17.

Evidence is file:line at 1577e5704. Paths are relative to crates/now-package-broker/src/, and tests.rs alone is v2/routes/tests.rs.
"Published types" are now_policy_api::v2 at the pinned revision; they are a dependency, not part of the diff.
The last column says whether the behaviour is introduced by this diff or pre-existing code the diff now reaches from a 2.0 request.
Reading bodies, the operation registry, plans and the policy store were audited with the two changes below this one; a row cites them where a route depends on them.

Counts: 98 rows. 86 conforms, 2 violates (both known, both in the published types), 7 partial (4 introduced, 1 pre-existing, 2 known), 1 cannot-verify, 2 not-yet-realised (both known).

Violations and partials

ID Statement (abridged) Status Evidence Note
CONTRACT.wire.md#values-4, #json-4 A closed-set value "matches only with its exact characters"; a value of the wrong JSON type makes the request BadRequest violates (known) v2/routes/mod.rs:306-327, through v2/wire/read.rs:27-57; ignored test v2/wire/read.rs:1095-1096 The published types read a closed-set value written as an object, such as {"Install": null}, so every route that reads a body accepts it. Already reported; in the dependency.
CONTRACT.wire.md#values-3, CONTRACT.policy.md#timestamps-2 A timestamp has "seconds ... 00 to 59" violates (known) v2/routes/mod.rs:280; v2/routes/operations.rs:179-180; ignored test v2/wire/convert.rs:999-1000 EvaluatedAt, StartedAt and CompletedAt are written by the published Timestamp::from_datetime, which writes a leap second held by chrono as seconds 60. Already reported; in the dependency.
CONTRACT.wire.md#transport-13, #transport-5 While it serves other connections the broker has no instance listening (ERROR_PIPE_BUSY) or answers BrokerBusy; the contract defines the response to every /v2/ request partial pipe.rs:48, 398-418, 428-447, 650-653, 663-687, 695-698, 707-714 A connected client is closed without any response when the 16 busy replies are taken as well as the connection slots, when the spare instance is not ready, when the user of the client cannot be looked up (so GET /v2/health too), and when the user changed during capture. #transport-12 allows no response only at the 5 and 30 second limits. Pre-existing limits; the diff narrows the capture case to a client whose user cannot be looked up either (pipe.rs:198-208).
CONTRACT.wire.md#capabilities-1 (ServerVersion) "a string of 1 to 128 bytes naming the broker's version" partial (judgement) v2/routes/capabilities.rs:17; ../Cargo.toml:3 The value is the version of the crate, which is 0.0.0 in every build, so it is in its domain and names no release. The 1.x responses use the same constant (server/responses.rs:19). Introduced use.
CONTRACT.wire.md#bypass-15, INTENT.wire.md#bypass-4, INTENT.md#bypass-token-1 "A used-up token never authorizes a request again, even when its operation fails or the response is lost" partial v2/bypass/tokens.rs:18, 98-104, 122-124, 153-156, 183-187; tests v2/bypass/tokens.rs:312, 376, 393; tests.rs:2769, 2787 A used-up token is remembered until the 60 seconds it was held with end, and then forgotten. Given again after that, the same characters are held as a new token, and authorize the request again once the broker no longer holds the first operation. The code says so (tokens.rs:101-103) and relies on the Agent never giving a token twice. Introduced.
CONTRACT.wire.md#bypass-reading-4 (Scoop, Vcpkg, "every other case") A bypass request without Source is read with no Source.Name, and the broker runs its command partial (known) v2/bypass/reading.rs:56-58; v2/routes/bypass.rs:87-88; tests v2/bypass/reading.rs:318, tests.rs:3074 Only the managers with an only source name are read. Every other request without Source, which includes every Uninstall under Winget, Chocolatey, PowerShell, PowerShell7, Scoop, Vcpkg and Dotnet, is answered InternalError and keeps its token. #errors-7 allows the code, so the response is one the contract allows; the reading is not realised. Introduced.
CONTRACT.wire.md#operations-5 to -9 (the rules as a whole) "These rules decide how an operation that is not canceled ends" partial v2/execution/plan.rs:111-129; v2/execution/operations.rs:381, 453-455; tests tests.rs:2053, 2069 An allowed execution request that removes Devolutions Agent (an Uninstall, or an Install with UninstallPrevious), and any removing request while the product code of the Agent cannot be read, runs no step and ends Failed. No rule of the list says so; the contract names the protection for bypass requests only (#bypass-9.3). CONTRACT.policy.md#evaluation-4 lets an allowed request not run. Introduced.
CONTRACT.wire.md#event-channel-6 to -10 (bypass operations) "The broker closes the channel only" in the five listed cases partial event_channel.rs:822-828, 835-838, 841-850, 589 The channel of a bypass operation gives the pipe up when closing a refused connection fails, when the read of a refused connection has not ended after 5 seconds, and when the task that identifies a client fails. Failure paths only; the operation is unaffected. Introduced.
CONTRACT.policy.md#managers-4, INTENT.md#trusted-sources-10 For an Update under a manager that updates from the recorded source, the broker reads every record first and refuses unless each names Source.Name partial (known) v2/execution/plan.rs:60-67, 134-136 Every Update under Scoop or PowerShell ends Failed without a step, now for execution and bypass requests alike. Fails closed, and agrees with CONTRACT.wire.md#operations-6. Already reported; from the change below this one.

Cannot verify

ID Statement (abridged) Status Evidence Note
CONTRACT.wire.md#event-channel-5 (the owner) For a bypass operation, the broker sends frames on a connection from a process it authenticates as the operation's owner cannot-verify v2/routes/held.rs:109-116; v2/execution/operations.rs:169-170; test with a stand-in identification v2/execution/operations.rs:1445; UNTESTED: at v2/routes/held.rs:97-108 The identification is the one the request pipe uses (PipeClient::from_connected_pipe, validate_connection, owner_of), so the code reads right. No test connects a process that this function identifies as the owner, and the owner comparison is the one the earlier report found partial (v2/execution/owner.rs:60-66). Needs the check with a signed client that the comment asks for. Introduced.

Not yet realised

ID Statement (abridged) Status Evidence Note
CONTRACT.wire.md#bypass-4 "The Agent gives the broker each token with the bypass request it binds, RequestId included, and the SID of the Windows user it binds" not-yet-realised (known) v2/bypass/tokens.rs:106-115 BypassTokens::hold is the entry point, and nothing outside tests calls it, so a released broker holds no token and answers every well-formed bypass request BypassTokenRejected, which is outcome 2 as the contract has it. Already reported.
INTENT.legacy.md#format-1-1 "The broker converts a 1.x policy in memory when it loads it" not-yet-realised (known) outside the files of this diff; test tests.rs:1126 With a 1.x file the 2.0 routes answer Paused, PolicyUnavailable and a management state Invalid / Unconvertible, and the 1.x routes keep enforcing the file. Already reported.

Conforms

ID Statement (abridged) Status Evidence Note
CONTRACT.wire.md#transport-1 The broker listens on \\.\pipe\Devolutions.Now.PackageBroker.v1 conforms pipe.rs:29 Pre-existing.
CONTRACT.wire.md#transport-2 Each connection carries one request and its response, and the broker closes it after the response conforms server/connection.rs:73 Keep-alive is off. Pre-existing.
CONTRACT.wire.md#transport-4 A body is framed by Content-Length or by the chunked transfer coding conforms v2/routes/mod.rs:462-477; tests tests.rs:397, 458
CONTRACT.wire.md#transport-5 The contract covers every request whose path starts with /v2/; another path is outside it conforms v2/routes/mod.rs:42, 48-63, 107-116; server/mod.rs:264-281; tests tests.rs:543, 732 A /v2/ request never passes the layers of the 1.x router, which is handed over whole as the other router. Introduced.
CONTRACT.wire.md#transport-6 The broker ignores the query of the request target conforms v2/routes/mod.rs:108, 396 Both read uri().path(); the router itself was audited at v2/wire/route.rs.
CONTRACT.wire.md#transport-9 A request to an endpoint with a body is UnsupportedMediaType unless its Content-Type has the media type application/json, ignoring ASCII case and parameters conforms v2/routes/mod.rs:403-408, 493-505; tests tests.rs:259, 282 Introduced.
CONTRACT.wire.md#transport-10 The broker ignores Content-Type on a request to an endpoint without a body conforms v2/routes/mod.rs:403; test tests.rs:877
CONTRACT.wire.md#transport-11 Every response has the media type application/json and the status of its code, or 200 conforms v2/routes/mod.rs:529-560, 563-582; tests tests.rs:904, 1113 The status comes from the published ErrorCode::http_status; a handler that panics is answered InternalError.
CONTRACT.wire.md#transport-12 The broker may close a connection without a response at 5 seconds without a header, or 30 seconds without the exchange conforms server/connection.rs:16, 75; pipe.rs:77, 143; test pipe.rs:1824 Pre-existing.
CONTRACT.wire.md#transport-13 (BrokerBusy) Over its limits the broker may answer a request with BrokerBusy conforms v2/routes/mod.rs:93-105; server/mod.rs:232-245; pipe.rs:252-260, 386-397, 683-685; test tests.rs:531 The limits are 16 connections and 8 per user (pipe.rs:37, 43). See the partial for the clients that get no response.
CONTRACT.wire.md#endpoints-2 A method and path that match no row are UnknownEndpoint conforms v2/routes/mod.rs:395-401; test tests.rs:223
CONTRACT.wire.md#endpoints-3 A body over the endpoint's limit, counted after the transfer coding is decoded, is RequestTooLarge, so any body to an endpoint without one is conforms v2/routes/mod.rs:144-152, 462-488; tests tests.rs:397, 421, 436, 458, 636 A declared length over the limit is refused without waiting for the bytes. Introduced.
CONTRACT.wire.md#endpoints-3 (table, "Client must be") GET /v2/health answers any client, POST /v2/policy an elevated administrator, every other endpoint an authenticated client conforms v2/routes/mod.rs:162-167, 360-384; tests tests.rs:324, 368, 866 The requirement of each endpoint is the published Endpoint::client.
CONTRACT.wire.md#endpoints-5 A segment that is not an identifier names no operation conforms v2/routes/operations.rs:120-124; test tests.rs:1840
CONTRACT.wire.md#authentication-1 The broker identifies the client by the process connected to the pipe conforms pipe.rs:189-209, 226-228; v2/routes/operations.rs:20-37 UNTESTED: at pipe.rs:219-225: no test runs the production capture.
CONTRACT.wire.md#authentication-2 No request member names the client conforms v2/routes/operations.rs:28-37 The owner, the session and the user of a run come from the pipe client only.
CONTRACT.wire.md#authentication-3 A request to an endpoint for authenticated clients is Unauthenticated when the broker does not authenticate the client process conforms v2/routes/mod.rs:169-175, 376-383; auth.rs:341-366; tests tests.rs:324, 644, 1103; pipe.rs:1770 A client whose process the broker cannot identify is one it does not authenticate, and is answered instead of disconnected. Introduced.
CONTRACT.wire.md#authentication-5 POST /v2/policy is AdministratorRequired when the authenticated client's token is not elevated or lacks the enabled Administrators SID conforms v2/routes/mod.rs:177-183; auth.rs:211, 301-303; test tests.rs:368
CONTRACT.wire.md#errors-1 (Decision, Management) Decision with NotRunnable; Management with StaleStoreToken, PolicyNotWritable, RevisionNotHigher and ActivationFailed only conforms v2/routes/mod.rs:282-287; v2/routes/policy.rs:42-68, 97-99; tests tests.rs:1277, 2308, 2328, 2375, 2397, 2413 PersistenceFailed carries no state.
CONTRACT.wire.md#errors-3 (items 2 to 7) The earliest of UnknownEndpoint, UnsupportedMediaType, Unauthenticated, AdministratorRequired, RequestTooLarge, BadRequest is the response conforms v2/routes/mod.rs:131-155, 299-329, 352-385, 395-411; tests tests.rs:244, 309, 353, 382, 472, 671 Introduced.
CONTRACT.wire.md#errors-3 (item 1) BrokerBusy wins over every other outcome conforms v2/routes/mod.rs:93-105; test tests.rs:531
CONTRACT.wire.md#errors-3 (item 8) The endpoint's own outcomes come after BadRequest conforms v2/routes/mod.rs:306-328; tests tests.rs:1254, 1419 A body is parsed before its endpoint looks at anything else.
CONTRACT.wire.md#errors-4 For outcomes 1 to 5 the broker sends the response without waiting for any byte of the body conforms v2/routes/mod.rs:93-105, 134-142, 355-384; tests tests.rs:489, 671 The tests send a header that announces a body and no body, over a real connection.
CONTRACT.wire.md#errors-5 A client that fails to send its body still reads the response conforms tests tests.rs:489, 671 (exchange, tests.rs:167)
CONTRACT.wire.md#errors-6 For BrokerBusy the broker starts and changes nothing conforms v2/routes/mod.rs:93-105 The busy router holds no broker state.
CONTRACT.wire.md#errors-7 InternalError may replace an outcome of item 8 conforms v2/routes/mod.rs:273-275, 516-519, 563-582; v2/routes/bypass.rs:88; tests tests.rs:1113, 1419, 3074 A panic before item 8 is reached is answered InternalError too, which no statement covers.
CONTRACT.wire.md#health-1 Status is Ready when the broker holds an accepted policy, and Paused otherwise conforms v2/routes/mod.rs:427-435; tests tests.rs:847, 622
CONTRACT.wire.md#health-2 The response names no policy conforms v2/routes/mod.rs:434 One member.
CONTRACT.wire.md#capabilities-1 (OperationTimeoutSeconds, Managers) An integer from 1 to 2147483647; a list naming each manager once conforms v2/routes/capabilities.rs:14-25; server/mod.rs:746-764; test tests.rs:904 The timeout is the limit the executor stops a process at (executor/windows/process.rs:300), as #operations-4 has it.
CONTRACT.wire.md#capabilities-2 A manager capability has Manager, a non-empty Operations, Scopes, Architectures, OptIns conforms v2/routes/capabilities.rs:22, 28-39, 55-105; tests tests.rs:904, 1015, 1086 UNTESTED: at v2/routes/capabilities.rs:50-54: the opt-ins listed are not compared with what the builders do.
CONTRACT.wire.md#capabilities-3 Which managers are listed may depend on the client's user conforms v2/routes/mod.rs:220-227; server/mod.rs:746-764
CONTRACT.wire.md#capabilities-4 A capability is advisory conforms v2/routes/mod.rs:258-296 Nothing that decides or runs a request reads the capabilities.
CONTRACT.wire.md#evaluate-1 A RequestId in an evaluation request is BadRequest conforms v2/routes/mod.rs:306-309; test tests.rs:1254
CONTRACT.wire.md#evaluate-2, CONTRACT.policy.md#evaluation-1 The broker evaluates the request against its accepted policy at its current time, starts nothing and changes nothing conforms v2/routes/mod.rs:232-244, 258-267; test tests.rs:1201 The policy row was not yet realised in the earlier report.
CONTRACT.wire.md#evaluate-3 Outcomes in order: PolicyUnavailable, NotRunnable, the evaluation response conforms v2/routes/mod.rs:259-264, 277-287; tests tests.rs:1184, 1277, 1237 A denied request gets the evaluation response.
CONTRACT.wire.md#evaluate-4, #policy-identity-1 The response has Decision, Policy (the identity of the policy that decided) and EvaluatedAt conforms v2/routes/mod.rs:234-241, 293; test tests.rs:1201 The identity is read from the policy that evaluated.
CONTRACT.wire.md#evaluate-5 An execution request at that time would start an operation exactly when Outcome is Allow conforms v2/routes/mod.rs:253-296; v2/routes/operations.rs:53-71; tests tests.rs:1595, 1655 Both endpoints call one function. An allowed request always starts an operation, which may end Failed without a step.
CONTRACT.policy.md#evaluation-3 (last clause) The broker "runs no request while it holds no accepted policy" conforms v2/routes/mod.rs:259-264; tests tests.rs:1184, 1682 Not yet realised in the earlier report. A bypass request is not one a policy governs.
CONTRACT.wire.md#not-runnable-1, INTENT.md#broker-limits-1 An allowed request with PrePostCommands and Elevation Elevated is NotRunnable, whatever Audited conforms v2/policy.rs:127-131; v2/routes/mod.rs:277-287; tests tests.rs:1277, 1319
CONTRACT.wire.md#not-runnable-2, INTENT.md#broker-limits-2 The error carries the decision, whose Outcome is Allow, and the broker runs nothing conforms v2/routes/mod.rs:282-287; v2/routes/operations.rs:53-56; test tests.rs:1277 Not yet realised in the earlier report.
CONTRACT.wire.md#not-runnable-3 An evaluation request and an execution request get the same NotRunnable outcome conforms v2/routes/mod.rs:253-296; v2/routes/operations.rs:53 One function decides for both.
CONTRACT.wire.md#execute-2 Outcomes in order: RequestIdConflict, the replayed response, PolicyUnavailable, NotRunnable, the execution response conforms v2/routes/operations.rs:49-56, 127-135; tests tests.rs:1745, 1708, 1682 The replay is answered before the policy is looked at (tests.rs:1737-1740).
CONTRACT.wire.md#execute-3 Decision, Policy, EvaluatedAt always; OperationId and Status when allowed; EventPipe when a channel was created conforms v2/routes/operations.rs:149-174; tests tests.rs:1595, 1655
CONTRACT.wire.md#execute-4 When allowed, the broker starts one operation before writing the response, owned by the request's owner conforms v2/routes/operations.rs:28-37, 67-71; test tests.rs:1595
CONTRACT.wire.md#execute-5, #execute-6 A request that starts no operation, BrokerBusy included, leaves its RequestId unused conforms v2/routes/operations.rs:53-65; v2/routes/mod.rs:93-105; test tests.rs:1655 Only start takes a RequestId.
CONTRACT.wire.md#execute-7 A replayed response has the first response's Decision, Policy, EvaluatedAt, OperationId, EventPipe and the current Status; nothing is evaluated or started conforms v2/routes/operations.rs:49-51, 138-147; v2/routes/held.rs:23-29; test tests.rs:1708
CONTRACT.wire.md#execute-8 Requests of one owner with one RequestId that arrive together start at most one operation conforms v2/routes/operations.rs:67-71; v2/execution/operations.rs:387-390 The second caller of start gets the operation of the first. UNTESTED: at v2/execution/operations.rs:383-386.
CONTRACT.wire.md#operations-11 An operation started outside this contract is not one a 2.0 request names, conflicts with or replays conforms v2/routes/held.rs:54-66; server/mod.rs:197; test tests.rs:1991 The 1.x tracker and the 2.0 registries are separate values.
CONTRACT.wire.md#operations-12 The broker holds a terminal operation for at least 300 seconds conforms v2/routes/held.rs:87-91; task.rs:93-97 The registry was audited earlier; this diff starts its eviction. UNTESTED: at task.rs:93-96.
CONTRACT.wire.md#operations-14, #status-1, #cancel-1 A status or cancel request for an operation the broker does not hold for the request's owner is OperationNotFound conforms v2/routes/operations.rs:77-124, 197-202; tests tests.rs:1840, 1868, 2657 Both registries are searched by id for the owner. That two operations never share an id is the earlier report's cannot-verify row (v2/execution/operations.rs:392-397).
CONTRACT.wire.md#status-2 Status always; StartedAt, CompletedAt, ExitCode, Message under their conditions conforms v2/routes/operations.rs:176-184; test tests.rs:1771 The values are the registry's, audited earlier.
CONTRACT.wire.md#cancel-5 The response has one member, Status: Canceling, or the terminal status conforms v2/routes/operations.rs:97-114; tests tests.rs:1889, 1926
CONTRACT.wire.md#management-1 The response has one member, Management, the policy management state conforms v2/routes/policy.rs:20-25; tests tests.rs:2135, 2154, 2166, 2187 The state is the store's, audited earlier.
CONTRACT.wire.md#validation-4, #validation-5 The response has one member, Errors; validation reads and changes nothing the broker stores conforms v2/routes/policy.rs:91-95; test tests.rs:2202
CONTRACT.wire.md#replacement-3 Outcomes in order: StaleStoreToken, PolicyNotWritable, InvalidPolicy, RevisionNotHigher, PersistenceFailed, ActivationFailed, the replacement response conforms v2/routes/policy.rs:32-71; tests tests.rs:2308, 2328, 2347, 2375, 2397, 2413 The store decides the order, audited earlier; the route maps each result to its code.
CONTRACT.wire.md#replacement-7, #replacement-8 The replacement response has Management with the new document, and a later package request is evaluated against the new policy conforms v2/routes/policy.rs:69-71; v2/routes/mod.rs:259; test tests.rs:2263
CONTRACT.wire.md#bypass-1, INTENT.md#remote-operations-1 A bypass request is run without evaluating it against any policy, whether or not the broker holds one conforms v2/routes/bypass.rs:22-103; test tests.rs:2621 The function never reads the policy store. Introduced, as every bypass row below.
CONTRACT.wire.md#bypass-2 (header) The request carries the token as the value of an X-Devolutions-Bypass-Token header conforms v2/routes/bypass.rs:113-129; test tests.rs:2644 The body was audited earlier.
CONTRACT.wire.md#bypass-3 A token is 1 to 2048 characters of its set, the first a letter or digit conforms v2/bypass/tokens.rs:118; test v2/bypass/tokens.rs:237 Published BypassToken.
CONTRACT.wire.md#bypass-5 The broker holds a token until it is used up or discarded; a restart discards every token, and the broker may discard one earlier conforms v2/bypass/tokens.rs:18, 86-90, 153-156; v2/routes/held.rs:79; tests v2/bypass/tokens.rs:312, 328 Tokens live in memory only, for 60 seconds.
CONTRACT.wire.md#bypass-6, #bypass-7 A token authorizes a request when the broker holds it, the request has exactly one header whose field value is the token, the body equals the bound request with its RequestId, and the owner's SID is the bound user's conforms v2/routes/bypass.rs:24-26, 55-57, 113-129; v2/bypass/tokens.rs:173-178; tests v2/bypass/tokens.rs:271, 286; tests.rs:2644, 2723 Digests are compared, which are equal exactly when the characters are.
CONTRACT.wire.md#bypass-8 No response and no event channel frame carries a bypass token conforms v2/routes/bypass.rs:132-145, 150-155; v2/bypass/tokens.rs:25-45 The broker keeps a SHA-256 digest only, and no log line names the token.
CONTRACT.wire.md#bypass-9 Outcomes in order: the replayed response, BypassTokenRejected, ProtectedPackage, BypassRequestUnreadable, the bypass response conforms v2/routes/bypass.rs:44-102; tests tests.rs:2682, 2723, 2833, 2896, 2937, 2621
CONTRACT.wire.md#bypass-9.3 (product code) ProtectedPackage for an Uninstall when the broker cannot read the product code of the installed Agent conforms v2/routes/bypass.rs:59-77; test tests.rs:2833
CONTRACT.wire.md#bypass-10 An Uninstall names Devolutions Agent by Winget and Devolutions.Agent, Chocolatey and devo-agent, or a Winget id that contains the product code conforms v2/bypass/reading.rs:130-157; tests v2/bypass/reading.rs:360, 389, 414; tests.rs:2872
CONTRACT.wire.md#bypass-11 An install or update of Devolutions Agent is not ProtectedPackage conforms v2/routes/bypass.rs:59; test tests.rs:2872
CONTRACT.wire.md#bypass-12, INTENT.wire.md#bypass-3 The bypass response has OperationId, Status and EventPipe only: no decision, no policy identity conforms v2/routes/bypass.rs:132-145; test tests.rs:2621
CONTRACT.wire.md#bypass-13 For the bypass response the broker uses up the token and starts one operation before writing the response, owned by the request's owner conforms v2/routes/bypass.rs:28, 91-96
CONTRACT.wire.md#bypass-14 Every process runs with a token of the bound user, elevated exactly when Elevation is Elevated; otherwise no step runs and the operation ends Failed conforms v2/execution/operations.rs:415-431; executor/windows/token.rs:81-128; executor/windows/mod.rs:254, 271, 526-533; test tests.rs:2984 The bound user is the request's owner's (v2/bypass/tokens.rs:177). The executor is pre-existing, with its UNTESTED: at executor/windows/mod.rs:529-530.
CONTRACT.wire.md#bypass-16, INTENT.wire.md#bypass-5 A request that starts no operation does not use up its token, and its response says nothing about any other request with the token conforms v2/routes/bypass.rs:24-26, 51, 55-57, 71-88, 147-155; tests tests.rs:2723, 3074, 3089 One response whatever the reason of the rejection.
CONTRACT.wire.md#bypass-17 A replayed response has the OperationId and EventPipe of the first and the current Status; nothing is started conforms v2/routes/bypass.rs:44-45, 132-145; test tests.rs:2682
CONTRACT.wire.md#bypass-18 Requests with one token that arrive together start at most one operation, and each one with the owner, body and RequestId of the starter gets the response or its replay conforms v2/routes/bypass.rs:42-96; v2/bypass/tokens.rs:149-158; test tests.rs:3048 The tokens stay locked from the lookup of the operation to the use of the token. UNTESTED: at v2/routes/bypass.rs:32-41.
CONTRACT.wire.md#bypass-19 The same request with the same token gets the operation it started while the broker holds it, and BypassTokenRejected after conforms v2/routes/bypass.rs:44-57; v2/bypass/tokens.rs:176; tests tests.rs:2682, 2804 See the partial for a token given again.
CONTRACT.wire.md#bypass-20 A bypass RequestId neither conflicts with nor replays an execution request, and the reverse conforms v2/routes/held.rs:35, 49; v2/routes/bypass.rs:30, 44; test tests.rs:3014 Two registries, and a bypass operation is keyed by the digest of its token. Not yet realised in the earlier report.
CONTRACT.wire.md#bypass-reading-1 A bypass request with Source is read as the package request with the same members, and the broker runs the command of that reading conforms v2/bypass/reading.rs:36-66; v2/routes/bypass.rs:79-93; test v2/bypass/reading.rs:187 The command builders are the earlier report's cannot-verify row.
CONTRACT.wire.md#bypass-reading-2, INTENT.md#remote-operations-3 An unreadable bypass request gets BypassRequestUnreadable rather than a decision conforms v2/routes/bypass.rs:81-86; v2/bypass/reading.rs:95-124; tests v2/bypass/reading.rs:214; tests.rs:2896 The evaluator exports no reading, so the code evaluates against a fixed policy and looks only at whether the check is UnreadableRequest, the first of CONTRACT.policy.md#precedence.
CONTRACT.wire.md#bypass-reading-4 (only source name), CONTRACT.policy.md#manager-npm, -bun, -cargo, -pip, -dotnet Under a manager whose reading names its only source name, Source.Name is that name; a case that tests other members still applies conforms v2/bypass/reading.rs:47-51, 71-92; tests v2/bypass/reading.rs:247, 274; tests.rs:2954 npm, Bun, crates.io, pip, and nuget.org for an Install or Update.
CONTRACT.wire.md#bypass-reading-5 An elevated Install or Update without Source is unreadable unless its manager is Winget or Chocolatey conforms v2/bypass/reading.rs:40-45; test v2/bypass/reading.rs:283 Decided before the source name is looked up.
CONTRACT.wire.md#event-channel-3 (execution requests) Another process of the owner's user can read the frames of an operation started by an execution request conforms v2/routes/held.rs:73; v2/execution/operations.rs:162-164; test tests.rs:3159
CONTRACT.wire.md#event-channel-5 (other processes) For a bypass operation, the broker closes any connection that is not from the owner without sending a frame, and that connection is not the one it serves conforms v2/execution/operations.rs:152-181, 404-406; event_channel.rs:773-854; v2/routes/held.rs:74-78; tests event_channel.rs:1737, 1760; v2/execution/operations.rs:1445; tests.rs:3159 A client the broker fails to identify is refused. The same pipe instance listens again. Not yet realised in the earlier report.
CONTRACT.wire.md#event-channel-7 (bypass operations) The channel closes when no connection it serves has opened 60 seconds after the terminal status conforms event_channel.rs:785-803 One wait for the whole loop, whatever the refusals. UNTESTED: at event_channel.rs:779-784.
INTENT.wire.md#bypass-1 A bypass operation has a 2.0 route of its own conforms v2/routes/mod.rs:314-317; v2/routes/bypass.rs:22
INTENT.wire.md#encodings-1 The path alone selects the encoding, and the earlier routes stay a separate block conforms v2/routes/mod.rs:42, 107-109; server/mod.rs:264-281 See "Not covered by intent" for the 1.x pieces the 2.0 routes call.
INTENT.wire.md#encodings-3 A response uses the encoding of the request it answers conforms v2/routes/mod.rs:48-105, 563-582; server/connection.rs:32-54; tests tests.rs:531, 543, 732, 1113 Busy replies, panics and unidentified clients included.
INTENT.wire.md#replacement-1 A policy that replaces the active one with the same Id has a higher Revision conforms v2/routes/policy.rs:55-59; test tests.rs:2375 Store side audited earlier.
INTENT.legacy.md#wire-1 The broker serves the earlier encoding on its earlier paths, in its own code path conforms server/mod.rs:232-245, 264-281; server/connection.rs:32-54; tests tests.rs:543, 742, 1126; pipe.rs:1792 The 1.x router is unchanged. A 1.x request of a client the broker cannot identify still gets no response, now once its header is read.

Violations

  • Closed-set value written as an object is read (CONTRACT.wire.md#values-4, #json-4). Known. Every 2.0 endpoint that reads a body now accepts {"Install": null} where the contract requires BadRequest. Fix: in now-policy-api, read a closed-set value from a JSON string only; then un-ignore v2/wire/read.rs:1096.
  • Leap second written with seconds 60 (CONTRACT.wire.md#values-3, CONTRACT.policy.md#timestamps-2). Known. EvaluatedAt, StartedAt and CompletedAt can carry it. Fix: in now-policy-api, write a leap second as 59 with the largest fraction, or refuse it; then un-ignore v2/wire/convert.rs:1000.

Neither is in the code of this diff, and the diff adds no violation of its own.

Partials

  • Clients closed without a response (CONTRACT.wire.md#transport-13). Required: ERROR_PIPE_BUSY or BrokerBusy, and no response only at the two time limits. Done: a connected client is dropped when both pools are full, when the spare instance is missing, when its user cannot be looked up, and when its user changed during capture. Fix: let the contract allow a closed connection for a client over the limits or one whose user the broker cannot read, or answer these with BrokerBusy from a bounded writer.
  • ServerVersion is 0.0.0 (CONTRACT.wire.md#capabilities-1). Required: a string naming the broker's version. Done: the version of a crate that is never bumped. Fix: write the version of the Devolutions Agent build that hosts the broker.
  • A used-up token given again after 60 seconds (CONTRACT.wire.md#bypass-15). Required: a used-up token never authorizes again. Done: never within the lifetime it was held with; afterwards the broker cannot tell it from a new token. Fix: have the Agent's side guarantee fresh tokens and say so where it calls hold, or remember used-up digests for the life of the process within a bound, or word the contract as "while the broker remembers it".
  • Bypass requests without a source name (CONTRACT.wire.md#bypass-reading-4). Known. Required: the reading without Source.Name under Scoop, Vcpkg and every other manager. Done: InternalError, token kept. Fix: an evaluator request type, or a reading function exported by now-policy-eval, that takes a request without Source.Name; until then no bypass Uninstall runs outside Npm, Bun, Cargo and Pip.
  • Execution requests that remove Devolutions Agent (CONTRACT.wire.md#operations-5 to -9). Required: the listed rules decide how an operation ends. Done: one more rule, which ends the operation Failed without a step. Fix: add the rule to #operations, next to the two that already end an operation without a step.
  • Failure paths that close a bypass channel (CONTRACT.wire.md#event-channel-6 to -10). Required: the channel closes only in the five listed cases. Done: three failures while refusing a connection close it too. Fix: add "when the broker fails to serve the pipe" to the list, or recreate the instance instead of giving it up.
  • Recorded source of an Update (CONTRACT.policy.md#managers-4). Known; unchanged by this diff, now reached by both kinds of request.

Cannot verify

  • CONTRACT.wire.md#event-channel-5 (the owner): needs a run with a signed client, checking that the process that sent a bypass request reads the frames of its operation, and that an unsigned copy of it and another executable of the same user read none, as v2/routes/held.rs:105-106 asks.

Not yet realised

  • CONTRACT.wire.md#bypass-4: the Agent's side that gives the broker a token (known).
  • INTENT.legacy.md#format-1-1: 1.x policy conversion (known).

Known items, one line each

  • A 1.x policy file is not converted: not-yet-realised (known) against INTENT.legacy.md#format-1-1; the 2.0 routes answer as a broker without an accepted policy, and the 1.x routes keep enforcing the file (tests.rs:1126).
  • Two mismatches in the published types, kept as ignored tests: violates (known), both rows above; in the dependency.
  • An Update under Scoop or PowerShell ends Failed without a step: partial (known) against CONTRACT.policy.md#managers-4; conforms to CONTRACT.wire.md#operations-6.
  • No code issues a bypass token: not-yet-realised (known) against CONTRACT.wire.md#bypass-4; the BypassTokenRejected a released broker answers conforms to #bypass-9.2.
  • A bypass request without Source under a manager with several source names is InternalError and keeps its token: partial (known) against CONTRACT.wire.md#bypass-reading-4; the response conforms to #errors-7 and #bypass-16.
  • A policy replacement whose body never arrives leaves no audit record, and the denial record of an unidentified client has an empty executable: no statement of the governing texts covers audit records, so neither is a drift; both are under "Not covered by intent".

Intent rot

None found: no audited statement describes something the code has moved away from on purpose, apart from the partials above whose fix is a contract wording.

Outside this change

Listed once, not audited:

  • CONTRACT.wire.md: §definitions, §values, §json, §package-request, §opt-ins, §equal-requests, §decision and §policy-errors; the table of endpoints and its path matching; the members and reasons of §management-state; the store side of §validation and §replacement; the steps, statuses and rules of §operations, and what §cancel does to an operation; §event-channel other than the rows above, §frames and §frame-order; every rule for clients (#transport-3, -7, -14, #errors-8, -9, the client's part of #execute-9, #bypass-19 and #replacement-10); what the contract leaves outside itself (#transport-8, #endpoints-6, #authentication-4).
  • CONTRACT.policy.md: everything but §evaluation and the only source names cited above.
  • INTENT.md: vocabulary other than the bypass token, ownership, rules, trusted sources, decisions, fail-closed checks, #broker-limits-3, warnings.
  • INTENT.wire.md: §opt-ins, §targeting, §fields, #bypass-2, #bypass-6, #encodings-2 and -4.
  • INTENT.legacy.md: the rest of §format-1.

Not covered by intent

  • Audit records of a 2.0 policy replacement. A replacement leaves its attempt and its result, one refused for its body its attempt and its rejection, and a refused client a denial (v2/routes/mod.rs:144-151, 188-215, 322-327; tests tests.rs:558, 691, 2433, 2489). Three gaps, the first two known: a request whose body never arrives is dropped at the connection deadline while the body is read and leaves no record, as on the 1.x route; the denial of a client the broker did not identify names the user the client seemed to run as and an empty executable (v2/routes/mod.rs:366-373); a replacement the store fails to decide leaves a log line only (v2/routes/policy.rs:72-83, with its UNTESTED: comment).
  • Limits of the token store. A token lives 60 seconds and the broker holds 256 at most, refusing a further one (v2/bypass/tokens.rs:18, 23, 125-127). The contract lets the broker discard a token early and says nothing about refusing to hold one; that is for the Agent's side to handle.
  • One lock for every bypass request. The tokens stay locked while the registry is read for the product code and while the operation starts (v2/routes/bypass.rs:42-96), so bypass requests are answered one at a time.
  • A second read of the product code. A bypass Uninstall is checked against the contract's naming rule and then against the 1.x rule when its plan is made (v2/execution/plan.rs:120-125). If the second read fails, the operation starts, ends Failed, and the token is used up.
  • The pause after a refused connection. The channel of a bypass operation waits one second after a refusal before it judges the next client (event_channel.rs:585, 812, 852), and the pipe has one instance. Another executable of the same user that connects in a loop delays the owner's frames and can keep the owner from connecting within the 60 seconds. The contract makes the channel best effort; a status request still answers.
  • 1.x pieces the 2.0 routes call. The capabilities use the 1.x probe and its type and the timeout of the 1.x tracker (v2/routes/capabilities.rs:13-14; server/mod.rs:746), the plan uses helpers of the 1.x evaluator (v2/execution/plan.rs:120-123), and the audit records go through the 1.x audit functions with a label of their own (audit.rs:556-583, 789-794). INTENT.wire.md#encodings-1 wants the earlier routes to be a block the broker can drop; these need a home of their own when it is dropped.
  • A body that stops or is framed wrongly is BadRequest (v2/routes/mod.rs:480-488). The contract leaves such messages outside itself.

Related UNTESTED: comments

v2/routes/bypass.rs:32-41, v2/routes/held.rs:97-108, v2/routes/capabilities.rs:50-54, v2/routes/policy.rs:73-76, pipe.rs:219-225, task.rs:93-96, event_channel.rs:779-784, v2/execution/operations.rs:383-386, 392-396, executor/windows/mod.rs:529-530.

Line numbers are those of 1577e5704. The commits after it on this branch add tests, and change the event channel of a bypass operation in event_channel.rs: a client is identified as soon as it connects, the pipe does not listen for one second after a refusal, and a channel that fails before it serves a client closes its queue and logs the failure. The rows on #event-channel keep their verdicts; their line numbers moved.

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

Bypass authorization can accept expired tokens under mutex contention because expiry checks use a timestamp captured before waiting for the lock.

10 open issues
What changed in this PR

Connects the package broker’s 2.0 API to the policy and execution support introduced by the preceding PRs, while keeping 1.x routing separate.

Changes:

  • Serves ten /v2/ endpoints with ordered request checks and policy-write auditing.
  • Adds bound bypass tokens and owner-checked bypass event streams; token issuance remains deferred.
  • Integrates separate 2.0 operation registries and unidentified-client handling into the pipe server.
File Description
crates/​now-package-broker/​src/​v2/​routes/​policy.rs Handles policy management, validation and replacement.
crates/​now-package-broker/​src/​v2/​routes/​operations.rs Handles execution, status, cancellation and replay.
crates/​now-package-broker/​src/​v2/​routes/​mod.rs Dispatches 2.0 requests and applies ordered checks.
crates/​now-package-broker/​src/​v2/​routes/​held.rs Holds operation registries, tokens and owner identification.
crates/​now-package-broker/​src/​v2/​routes/​capabilities.rs Reports server and manager capabilities.
crates/​now-package-broker/​src/​v2/​routes/​bypass.rs Authorizes and starts bypass operations.
crates/​now-package-broker/​src/​v2/​policy.rs Reuses the shared policy-error conversion.
crates/​now-package-broker/​src/​v2/​mod.rs Exposes routes, bypass support and held operations.
crates/​now-package-broker/​src/​v2/​execution/​plan.rs Adds Agent-uninstall protection to operation planning.
crates/​now-package-broker/​src/​v2/​execution/​operations.rs Integrates protected planning and owner-checked event channels.
crates/​now-package-broker/​src/​v2/​execution/​mod.rs Exports the event-client identification callback.
crates/​now-package-broker/​src/​v2/​bypass/​tokens.rs Stores expiring, request-bound token digests.
crates/​now-package-broker/​src/​v2/​bypass/​reading.rs Reads bypass requests and identifies protected uninstalls.
crates/​now-package-broker/​src/​v2/​bypass/​mod.rs Exports bypass reading and token helpers.
crates/​now-package-broker/​src/​task.rs Initializes and evicts 2.0 operations.
crates/​now-package-broker/​src/​server/​mod.rs Wraps existing routers with 2.0 routing and state.
crates/​now-package-broker/​src/​server/​grant.rs Updates test fixtures for the new operation state.
crates/​now-package-broker/​src/​server/​connection.rs Serves unidentified clients according to the request encoding.
crates/​now-package-broker/​src/​policy_store/​mod.rs Enables routed replacement and adds test storage support.
crates/​now-package-broker/​src/​pipe.rs Dispatches identified and unidentified pipe clients.
crates/​now-package-broker/​src/​event_channel.rs Adds client admission, refusal retries and channel tests.
crates/​now-package-broker/​src/​audit.rs Distinguishes 2.0 policy-write attempts and denials.

Review effort: Max (adaptive)

pub(crate) fn authorizes(&self, token: &TokenDigest, owner_sid: &Sid, request: &v2::BypassRequest) -> bool {
self.given
.get(token)
.and_then(|given| given.bound.as_ref())
Comment on lines +823 to +825
let linger = async {
sink.finished().await;
tokio::time::sleep(NEVER_CONNECTED_LINGER).await;
Elevation::Elevated => v1::Elevation::Elevated,
};
let builder_request = builder_request(request, elevation);
if crate::evaluator::removes_package(&builder_request) {
Comment on lines +19 to +35
managers: managers
.into_iter()
// A capability names at least one operation.
.filter(|capability| !capability.operations.is_empty())
.map(manager_capability)
.collect(),
})
}

fn manager_capability(capability: v1::ManagerCapability) -> v2::ManagerCapability {
let manager = manager(capability.manager);

v2::ManagerCapability {
manager,
operations: capability.operations.into_iter().map(operation).collect(),
scopes: capability.scopes.into_iter().map(scope).collect(),
architectures: capability.architectures.into_iter().map(architecture).collect(),
Comment on lines +306 to +307
v2::Endpoint::Evaluate => match wire::read_evaluation_request(body) {
Ok(request) => self.evaluate(&request),
Comment on lines +493 to +505
fn has_json_media_type(headers: &HeaderMap) -> bool {
headers
.get(header::CONTENT_TYPE)
.and_then(|value| value.to_str().ok())
.is_some_and(|value| {
let media_type = value
.split_once(';')
.map_or(value, |(media_type, _parameters)| media_type);
media_type
.trim_matches([' ', '\t'])
.eq_ignore_ascii_case("application/json")
})
}
Comment on lines +130 to +157
pub(crate) fn uninstall_names_agent(manager: v2::Manager, package_id: &str, agent_product_code: Option<Uuid>) -> bool {
let name = package_id.split_once('#').map_or(package_id, |(name, _)| name);
let name = name.rsplit_once('@').map_or(name, |(name, _)| name);

match manager {
v2::Manager::Winget => {
name.eq_ignore_ascii_case("Devolutions.Agent")
|| agent_product_code
.is_some_and(|code| package_id.to_ascii_lowercase().contains(&code.hyphenated().to_string()))
}
v2::Manager::Chocolatey => name.eq_ignore_ascii_case("devo-agent"),
v2::Manager::PowerShell
| v2::Manager::PowerShell7
| v2::Manager::Apt
| v2::Manager::Bun
| v2::Manager::Cargo
| v2::Manager::Dnf
| v2::Manager::Dotnet
| v2::Manager::Flatpak
| v2::Manager::Homebrew
| v2::Manager::Npm
| v2::Manager::Pacman
| v2::Manager::Pip
| v2::Manager::Scoop
| v2::Manager::Snap
| v2::Manager::Vcpkg => false,
}
}
Comment on lines +115 to +119
let elevation = match request.elevation {
Elevation::NonElevated => v1::Elevation::Standard,
Elevation::Elevated => v1::Elevation::Elevated,
};
let builder_request = builder_request(request, elevation);
Comment on lines +62 to +69
Err(error) => {
warn!(
error = format!("{error:#}"),
"Failed to read the product code of the installed Devolutions Agent"
);
// The broker cannot verify that the request does not uninstall the Agent.
true
}
…nel as the code keeps them

The comment on the wait for the end of the channel said its 60 seconds
start when the status becomes terminal. They start the first time the
loop looks at the wait after that, which is later when a client is being
identified or refused at that moment.

That a client is handed to its identification as soon as it connects is
the reason the pause comes before the listening, and no test bounds the
time between the two, so the comment there now says what to keep when
the function changes.

The exit for a refused connection that sent bytes was missing from the
comment on the exits no test reaches, and the comment on the token lock
did not name the start that panics once its registry took the operation.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Copilot AI adaptive review requested due to automatic review settings December 1, 2026 05:53
@CBenoit

Copy link
Copy Markdown
Member Author

Evidence, deviations and open points

Lines changed against #2230 (approximate split): production +2344 −77, tests +4133 −2.

Checks run

  • cargo +nightly fmt --all -- --check: pass on bb80ec74c.
  • cargo clippy --workspace --all-targets -- -D warnings: pass on 3eed09620; cargo clippy -p now-package-broker --all-targets -- -D warnings passes on bb80ec74c, which changes comments only.
  • cargo test -p now-package-broker: 1112 passed, 4 ignored, on 3eed09620. Two ignored tests exist on the base of the stack; the other two are the mismatches of the published types named in feat(agent): read 2.0 package requests and run their operations in the package broker #2230.
  • ci/check-oracle-markers.ps1: pass on bb80ec74c.
  • Not run: anything with a signed client, and no integration test in testsuite (see below).

UNTESTED: properties added

  • crates/now-package-broker/src/event_channel.rs:814: The wait for the end of the channel is one wait for the whole loop: its 60 seconds start the first time the loop looks at the wait once the status is terminal, and no refused connection starts them again. A wait that started again with each refused connection would let a process that connects in a loop keep the pipe and the queued output for as long as it likes. The loop looks at the wait only where it pauses and where it listens. A status that becomes terminal while the channel identifies a client it then refuses, or closes the connection of that client, therefore starts the 60 seconds once that is over, and a wait that ends at such a time closes the channel once that is over. The start is late once at most, and the end is late once at most, whatever the clients do. No test waits 60 seconds; when changing this function, keep one wait for the whole loop, and let it win over the pause and over the listening.
  • crates/now-package-broker/src/event_channel.rs:851: A channel that fails to listen, to close a connection it refused, or to see the read of that connection end with nothing read, serves nobody and gives its pipe up: each of these exits returns its error at once, which drops the pipe, and the caller closes the queue. After any of them the channel no longer knows who its pipe is connected to, and the frames it would write next could reach a client it refused. No test makes a pipe fail in these ways; when changing this function, check that none of these exits listens again or returns the pipe.
  • crates/now-package-broker/src/event_channel.rs:866: The channel hands a client to its identification as soon as the client is connected: this function awaits nothing between the two, and the identification starts when a thread of the blocking pool takes it. In any time left between them, the process that connected may exit and its id go to another process, which the channel would then identify in its place. No test bounds that time; when changing this function, keep every wait, the pause after a refusal included, out of the lines between the connection and this call.
  • crates/now-package-broker/src/pipe.rs:219: The pipe server identifies a client process with PipeClient::from_connected_pipe, and a process that capture refuses, such as one whose executable is on a network share, is served as an unidentified client. A weaker capture here would let the routes trust a process the broker did not verify. The tests pass their own capture to ConnectedClient::capture, so none runs this function or a capture that fails on a real process. When changing this, check that the accept loop still captures with this function, and that it passes the full identity capture.
  • crates/now-package-broker/src/task.rs:93: The broker stops holding the operations of the 2.0 encoding once they ended long enough ago. Without this task every ended operation stays in memory, and its request id stays taken, until the broker restarts. No test runs the broker task, so check that this call remains when changing how the task starts.
  • crates/now-package-broker/src/v2/routes/bypass.rs:32: Another request finds either the token held and no operation started with it, or the token used up and the operation it started held, and nothing in between unless the start panics once its registry took the operation. Were the token used up before the operation is held, of two equal requests that arrive together, the second could be answered BypassTokenRejected while the first starts the operation, where the contract has it get that operation. Were the operation held before the token is used up, the same request from another executable of the user could start a second operation with the token. Everything from the lookup of the operation to the use of the token happens while the tokens are locked, and a test that sends requests together passes most of the time without that; when changing this function, keep the lock from the lookup until the token is used up.
  • crates/now-package-broker/src/v2/routes/capabilities.rs:50: An opt-in listed for a manager is one the command builder of that manager acts on, or one the broker runs itself for it, and no other opt-in is. The tests compare the list with the keys the reading of each manager accepts, not with what the builders do, so a builder that starts or stops carrying an opt-in leaves them passing while a client is told the wrong thing. When a command builder or the plan of an operation changes what it does with an opt-in, change this list with it.
  • crates/now-package-broker/src/v2/routes/held.rs:97: The event channel of a bypass operation identifies the process of a connection the way the request pipe identifies the client of a request: PipeClient::from_connected_pipe, then validate_connection with the setting of the broker state, and the owner that Connection::caller makes of such a client. A weaker identification would send the output of a bypassed operation to a process the broker does not authenticate as its owner, and an owner made another way would be refused its own frames. The tests of the channel identify with a function of their own, and the one test that runs this function connects another executable, which gets no frame; none connects a process that this function identifies as the owner, because capture does not accept the test process on every machine. When changing this, check with a signed client that the process that sent a bypass request reads the frames of its operation, and that an unsigned copy of it and another executable of the same user read none. The process identified is the one that opened the connection: a handle that process gives to another one is used without the broker seeing it.
  • crates/now-package-broker/src/v2/routes/policy.rs:73: A replacement the policy store fails to decide names its client in the log. The store fails before the attempt is recorded, so this line is the only trace of who asked. When this changes, check that every failure of replace_document still comes before its attempt is recorded, and that the line keeps the SID and the executable of the client.

Stopped or deferred

  • Issuing a bypass token. BypassTokens::hold is the entry point that binds a token to a bypass request and a user, and nothing calls it outside tests: the Agent's side does not exist yet. A released broker therefore answers every bypass request BypassTokenRejected.
  • Bypass request without Source. Where the manager's reading needs a source name to tell which of several the request means, the evaluator's request type cannot express the request, so it is answered InternalError and its token stays unused. This covers every manager but Npm, Bun, Cargo and Pip, and for Dotnet every operation but Install and Update; it includes every Uninstall under WinGet, Chocolatey, PowerShell, Scoop, Vcpkg and Dotnet.
  • A used-up token given again. The broker refuses it for the 60 seconds it was held with; afterwards nothing tells it from a new token, so hold documents that its caller never gives a token twice.
  • Limit on tokens. A used-up token counts toward the 256 the broker holds until its 60 seconds end, so the broker accepts at most 256 tokens a minute even when each is used at once. Whoever writes the issuing side decides whether remembered tokens get a larger bound of their own.
  • Event channel of a bypass operation.
    • A process of the same user that connects in a loop reads nothing but can keep the owner off the single pipe instance, and after each refusal the pipe is busy for one second. The owner still learns the status with status requests.
    • The identification of a connected client has no deadline: the call cannot be canceled and keeps the pipe, so a client whose identification stalls keeps the pipe, the queued output and one blocking thread past the channel's 60 seconds. One such channel exists per bypass operation.
    • A channel that can no longer tell who its pipe is connected to (listening fails, the identification panics, closing a refused connection fails, or the read of a refused connection does not end) gives its pipe up and serves nobody. The list of §event-channel of when the broker closes a channel has no entry for that.
    • A process the broker identified as the owner can hand its pipe handle to another process without the broker seeing it.
    • No test connects a process the production identification accepts as the owner, because the identity capture does not accept the test process on every machine; the refusal side is tested with a real other executable.
  • Uninstall of Devolutions Agent through evaluate or execute. CONTRACT.wire.md names the protection only for bypass (ProtectedPackage). An allowed execution request that would remove the Agent, and any removing request while the Agent's product code cannot be read, starts an operation that runs no step and ends Failed; the list of §operations has no rule for it.
  • ServerVersion. It is the version of the broker crate, which is 0.0.0, as on the 1.x routes.
  • Clients the broker cannot identify. Their /v2/ requests are answered as the contract says; a request under another path still gets no response, and a client is still closed without a response when the connection and busy-reply pools are both full, when its user cannot be looked up, or when its user changed during the capture.
  • Audit records of a policy replacement. A replacement whose body never arrives leaves no audit record, as on the 1.x route. The denial record of a client the broker did not identify has an empty executable. A replacement the store fails to decide leaves only a log line that names the client.
  • Bypass requests are served one at a time. The token lock is held from the lookup of the operation until the token is used up, which includes reading the Agent's product code and starting the operation.
  • 1.x routes against a 2.x policy file. They report the file as invalid and never write over it; serving them from a 2.x policy is not part of this change.
  • 1.x pieces the 2.0 routes call. The capability probe, the operation timeout, evaluator helpers and the audit functions are shared with the 1.x routes and need a home of their own when the 1.x encoding is dropped.
  • Single pipe instance. max_instances(1) and first_pipe_instance(true) are in the code, and no test pins them: a test process has no right to create an instance on these pipes, whatever the limit.

Deviations from the conventions

  • The description starts with the list of temporary git dependencies and carries the scope table, so it holds more than a squash commit body would.
  • All tests added are unit tests in the crate, as in the two pull requests below. No integration test was added to testsuite: nothing there drives the package broker through the Agent binary yet, so the routes are tested through the crate's router, with real named pipes for the event channels.

Review and pruning

  • Review: the last full review of the range found no behavioural defect and asked for comment changes only, which the last commit makes; a separate reading of that commit checked each changed comment against the code. Left from the reviews, not blocking:
    • the test of an identification that panics cites §event-channel for all it asserts, and the contract does not decide that the pipe is gone afterwards;
    • the wait for the end of a bypass channel could be made a parameter, as the pause is, so that tests cover it instead of the UNTESTED: comment;
    • every_manager_capability_names_at_least_one_operation would pass on an empty list of managers (three other tests catch that today);
    • the_capability_of_a_manager_names_the_opt_ins_its_reading_accepts cites CONTRACT.policy.md §managers for the keys each reading accepts, while listing exactly those keys is the broker's own rule;
    • a panic in the start of a bypass operation after the registry took the operation would leave an operation held with its token unused; no such panic is known, and the comment at that code says so;
    • the Issue: footer of four test commits is separated from the co-author line by a blank line, which the squash removes.
  • Dependencies: no manifest or lockfile change in this range.
  • Tests: 113 tests in scope, none removed for lack of value; one test that repeated a table row was folded into the table, whose rows now check the whole error response. 20 mutants written from the contract without sight of the tests: 18 caught, 2 survived, and three added tests now catch all 20. 23 mutants written against single tests were all caught, each by a test nothing else replaces. On the later event-channel commits: listening during the pause, no pause, no closing of the queue, and no draining read after a refusal are each caught; a wait between the connection and the identification is not, which is the UNTESTED: comment at that code. cargo-mutants was not run on any file of this range (about 30 seconds a mutant).
  • clippy prints a manifest warning about an unused sysevent-winevent dependency of the broker crate; it is on master and not part of this change.

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

Unresolved handle-inheritance flaws can expose bypass output to concurrent child processes and violate Windows’ cross-session restrictions for service-mode launches.

12 open issues
5 previously missed issues

In code that hasn't changed since last review

Medium severity Abandon queued output when no client connects

crates/​now-package-broker/​src/​event_channel.rs:715

When no client connects, returning here leaves the queued output in the sink retained by the operation record. A terminal operation is held for at least 300 seconds, so after the 60-second channel linger each unconsumed operation can retain up to 2 MiB of output for several more minutes. Abandon the sink before returning, as the error branch already does, to release the queue when nobody can read it.

Medium severity Record audit attempts before early request exits

crates/​now-package-broker/​src/​v2/​routes/​mod.rs:144

A replacement canceled by the connection deadline during this body read leaves no audit record; rejecting its media type in find_endpoint also bypasses auditing. Record the appropriate denial or start an attempt guard before those exits and awaits, without changing response precedence. Carry that guard into the store so cancellation records a rejection and completed requests produce exactly one attempt/result pair.

Medium severity Bound post-exit draining of child output readers

crates/​now-package-broker/​src/​v2/​routes/​operations.rs:67

These newly served operations capture output through non-strict event sinks, but executor/windows/process.rs joins their blocking readers without a post-exit deadline. A descendant that keeps stdout or stderr open can leave an operation Running or Canceling indefinitely after exit, cancellation, or the advertised timeout. Use stoppable readers with bounded post-exit draining before assigning the terminal status.

Low severity Use the selected intent in terminal audit records

crates/​now-package-broker/​src/​audit.rs:521

Optional: the terminal audit recorders still hard-code INTENT or DOCUMENT_INTENT instead of using the intent chosen in begin_as. A mismatched completion method would then label the attempt and result as different requests. Use state.intent in failed_at, succeeded_at, document_failed_at, and document_succeeded_at so every record has one source of truth.

Low severity Share the policy test double instead of duplicating it

crates/​now-package-broker/​src/​policy_store/​mod.rs:1311

TestPolicyFile duplicates the byte storage, generation-based observation, retained-target handling, and conditional write logic of FileDouble in policy_store/document_tests.rs:37–209. Keeping both implementations makes it easy to update the storage behavior for only one set of tests. Share the existing double through a #[cfg(test)] support module and extend its fault cases as needed.

Review effort: Max (adaptive)

let audience = self.inner.event_audience.of(&caller.owner, &operation_id);
let (events, event_pipe, channel_error) =
match open_operation_channel_announcing(ChannelVersion::V2_0, &operation_id, user_sid) {
match open_operation_channel_serving(audience, ChannelVersion::V2_0, &operation_id, user_sid) {
pub(super) fn of(&self, state: &BrokerState) -> &Registries {
self.registries.get_or_init(|| Registries {
executions: Operations::protecting_agent(Arc::clone(&state.executor), state.agent_product_code),
bypasses: Operations::protecting_agent_with_events_for_owner(
…ities

The 2.0 capabilities carry the version of the Devolutions Agent that
hosts the broker, and the broker named the version of its own crate,
which is not one any Agent is released with.

The Agent now gives its package version to the broker task.
A version the capabilities cannot carry, empty or longer than 128 bytes,
is refused when the task is created, so the service fails to start with
the cause instead of answering every capabilities request with an
internal error.

The 1.x routes keep reporting the version they reported.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…Package

The wire contract has no request start an operation that would uninstall
the Devolutions Agent, which hosts the broker, and names where
`ProtectedPackage` falls among the outcomes of an evaluation, an
execution and a bypass request.
The broker answered it for a bypass request only: an evaluation said
such a request was allowed, and an execution started an operation that
ended `Failed` and kept its `RequestId`.

One function now decides a protected uninstall for the three requests.
A request that removes a package, by its operation or by
`UninstallPrevious`, is refused when it names the Agent or when the
product code of the installed Agent cannot be read; the product code is
read for no other request.
An evaluation answers it before anything else, and an execution after a
used `RequestId` and before the policy is looked at, so it starts
nothing and leaves its `RequestId` unused.

The plan of an operation still refuses to remove the Agent, for a
request the Agent turns out to be named by once the operation starts.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The wire contract now states how long the broker holds a bypass token:
it discards one no later than 60 seconds after the Agent gave it,
remembers a used-up one until then, and takes a token with the same
characters given after that for a new token.
The token store already does this, so its tests now name the contract as
the source of these instants instead of pinning them as the broker's own
choice, and one test follows a used-up token across the 60 seconds.
What the contract leaves to the broker, the exact instant a lifetime
ends and how a remembered token counts against the bound, stays pinned
as such.

The comments of the store and of the bypass route say the same, and the
route names what a token digest cannot tell apart while the broker holds
the operation an earlier token started.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…dable

A client refuses the status of a `Completed` operation that has no
`StartedAt`, since a manager process that exited on its own was
launched.
The status route copies what the registry recorded, and the registry
records a launch only when the executor reports one, so the response
depends on a property of the executor that no test checks.
The comment names that property where the response is built.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…the event channel

The wire contract now states that the broker does not listen on the
event pipe for one second after it closes a connection it does not
serve, that opening the pipe fails with a busy pipe meanwhile, and that
the broker closes the channel when a failure leaves it unable to tell
which process is connected.
The channel already behaves so, and its tests pinned the pause and the
busy pipe as the broker's own choice: they now name the contract as
their source, and the comments at the pause and at the exits that give
the pipe up name the section that decides them.

No test of the pause runs with the value the broker uses, which a
comment at that value now says.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… for what it shows

The test of where `ProtectedPackage` falls among the outcomes of an
execution named two replies `replay` and `reply`, which clippy refuses
as too similar and which told a reader nothing of the second.
It is the reply that comes before the policy is looked at, and is named
so.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ion of its client

The identification of the client connected to an event channel owned the
pipe for as long as it ran, so the channel could do nothing with its
pipe until the identification returned.
The channel now keeps the pipe and lends it: the identification reaches
it through the channel each time it asks the pipe something, and the
channel takes it back once the identification is over.

What the channel sends, and how a client is identified, do not change.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…does not complete

The wire contract has the broker close an event channel when the
identification of a process connected to its pipe does not complete,
since the broker then cannot tell which process is connected.
The channel waited for the identification for as long as it ran, so one
that never returned left the pipe connected to a client the channel knew
nothing of, and busy for every other client, for as long as the broker
ran.

The channel now waits 30 seconds for the identification of a client.
When they pass it closes its pipe at once, sends no frame and closes its
queue, as it does when the identification panics.
It does not wait for the identification, which reaches the pipe through
the channel and finds none from then on; a pipe that the identification
is asking something at that instant closes as soon as it has answered.

The channels that identify no client are unchanged.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…its client

An event channel closes its pipe when the identification of a client
does not complete in time, and cannot close it while the identification
keeps it.
The identification of the broker kept the pipe for the whole capture of
the client process, which opens the executable of the client and checks
who can write it, so a capture that never returned still left the pipe
connected and busy.

The capture asks the pipe one thing, the id of the client process, as it
starts and once more before it returns.
It now takes that question as a function, and the identification of an
event channel answers it through the channel, which keeps the pipe only
for the length of each answer.
The capture of the client of a request is the same function with the
pipe it is given, and does what it did.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A request without a source that got a plan with a source option, or no
plan at all, was still answered with an operation id, so the test of the
route passed either way. It now waits for the run and reads its command.

An elevated Install or Update without a source through Windows
PowerShell or .NET tool gets a command from its builder, so only the
reading of the bypass request refuses it: both are now cases of the
unreadable requests.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The channel marked a pipe as given up with an atomic flag and then tried
the lock a query of the pipe held, while the query unlocked and then
read the flag. Each of the two could read the other's earlier value on a
processor that lets a load run ahead of a store, as ARM64 does, and then
neither closed the pipe: it stayed connected until the identification
returned, which the deadline exists not to wait for.

A query now takes the pipe out of the lock for as long as it runs and
puts it back, or closes it when the channel gave it up meanwhile, so
every change of the state happens under the lock and none waits for a
query.

The test of a pipe given up during a query drives the pipe itself, so it
no longer depends on the identification reaching its query before the
deadline passes.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…est takes

The assertion that a bypass request without a source runs a command
without one looked for two spellings in every case, though half of the
cases build a command that has neither spelling with a source as well.
Each case now names the option its manager takes a source with, or none,
and a case whose operation does not run fails under its name.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
No test asked the pipe of a channel anything and then expected the
channel to serve its client, so a pipe that a query did not give back
left every test passing while no owner could read a frame. The audience
of the pipe tests now asks the pipe twice, as an identification does.

A test through the channel makes the deadline pass while a query of the
pipe runs: a channel that only took its pipe back then would leave it
connected once the query returned.

The test of a pipe given up during a query bounds the time giving up
takes, so a pipe that waited for the query fails it.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… command shows

Half of the cases had no source option to look for and took another path
through the body of the test. They are a test of their own, which checks
that their operation runs, and both tests let the operation end, so no
executor outlives its case.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Copilot AI adaptive review requested due to automatic review settings December 1, 2026 22:10
@CBenoit

Copy link
Copy Markdown
Member Author

Update for head 1f4c8e97f, which follows CONTRACT.wire.md at Devolutions/now-libraries@3014fcbb899d. It replaces the matching parts of the earlier evidence comment.

Checks run locally on this head

  • cargo +nightly fmt --all -- --check: clean.
  • cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo test -p now-package-broker: 1146 passed, 0 failed, 2 ignored.
  • cargo test -p devolutions-agent --no-run: builds.
  • ci/check-oracle-markers.ps1 on the files this stack changes: clean.

What changed since the earlier comment

  • A bypass request without Source is no longer InternalError: the evaluator's bypass reading decides whether it is readable, and a readable one runs.
  • ProtectedPackage is an outcome of evaluate, execute and bypass. The earlier comment listed the Agent uninstall on evaluate and execute as a deviation; it no longer is one.
  • ServerVersion is the version of the hosting Agent.
  • The event channel of a bypass operation closes when the identification of a connected process does not complete within 30 seconds.

UNTESTED: properties added or changed

  • v2/execution/plan.rs: an elevated Install or Update without a source under a manager other than WinGet and Chocolatey runs no step. The plan does not refuse it; the route does, by reading the request as a bypass request first.
  • command_builder/scoop.rs: the Update refusal now covers only a request that chooses its source.
  • event_channel.rs: the pause after a refused connection is the contract's one second; the identification deadline is longer than an identification that completes and shorter than the 60 seconds of an ended operation's channel.
  • v2/routes/held.rs: the identification keeps the pipe of the channel only while it reads the id of the client process.
  • v2/routes/operations.rs: the response of a Completed operation has StartedAt, which relies on the executor reporting the launch of every process whose exit it returns.
  • devolutions-agent/src/service.rs: the broker is given the package version of the Agent that hosts it.

Stopped, waiting for a decision

  • A token with the same characters given again later than 60 seconds after the first, while the broker still holds the operation the first one started for the same owner. The broker names a bypass operation by the digest of its token, so an equal request replays the held operation and an unequal one is BypassTokenRejected, though the new token authorizes it. One way out with little change: refuse to hold a token whose digest names a bypass operation the broker still holds, with the answer it gives for a token it already holds. No code issues a token yet, so nothing reaches this today.
  • PowerShell 7 passes -TrustRepository on an Install or Update without a source, as it does with one. Without a source the manager picks the repository, so the option then trusts whichever repository that is.

Notes for the reviewer

  • The 30 seconds of the identification deadline are a choice of this change: the contract says the channel closes when the identification does not complete, and names no duration.
  • A thread that is inside the one question the identification asks the pipe (GetNamedPipeClientProcessId) keeps the pipe until that call returns. An identification that hangs elsewhere, reading the executable or validating its signature, no longer keeps it.
  • An identification that never returns still keeps one thread of the blocking pool for as long as it runs: the deadline frees the pipe, not the thread.
  • Once a channel closed at the deadline, its pipe name is free while the operation may still run, as it is after any other close of a channel.
  • The plan of an operation still refuses to remove the Agent, with the rules it had; a request the routes let through and the plan refuses ends Failed.
  • A removing request reads the product code of the installed Agent from the registry while the bypass tokens are locked, and a request that starts reads it a second time in its plan.
  • BrokerTaskConfig::default() names the broker crate's own version; the Agent service overrides it.
  • Still out of scope here: installer arguments that remove the Agent, product codes under managers other than WinGet, and KillBeforeOperation.

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.

pub(crate) fn authorizes(&self, token: &TokenDigest, owner_sid: &Sid, request: &v2::BypassRequest) -> bool {
self.given
.get(token)
.and_then(|given| given.bound.as_ref())
…heir own

The query of the test that lets the deadline pass during it waited for
the test to release it. A channel that waited for that query would do so
on the thread the test runs on, and the test would never end instead of
failing, so the query now ends after a bounded time.

The test of bypass requests that arrive together lets its operation end,
so its executor does not outlive it, and the wait for the operation of a
bypass request without a source shows a status request that fails.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Copilot AI adaptive review requested due to automatic review settings December 1, 2026 22:36
@CBenoit

Copy link
Copy Markdown
Member Author

Head is now 7fecff236: one more commit, tests only, on top of the head the comment above describes.

It bounds a wait in the event-channel test that lets the deadline pass during a query, lets the operation of the test of bypass requests that arrive together end, and makes the wait for a sourceless bypass operation show a status request that fails.

Run locally on this head: cargo +nightly fmt --all -- --check clean, cargo clippy -p now-package-broker --all-targets -- -D warnings clean, cargo test -p now-package-broker 1146 passed, 0 failed, 2 ignored, ci/check-oracle-markers.ps1 clean.

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.

@CBenoit

Copy link
Copy Markdown
Member Author

The two points the earlier comment listed as waiting for a decision are settled, with no change to the code:

  • A token given again while the broker still holds the operation its earlier use started is treated as the earlier one. The Agent never gives the same token twice, and the broker's single use of a token relies on that.
  • PowerShell 7 keeps -TrustRepository on an Install or Update without a source, which is never an elevated one.

Note

LLM-assisted content (no human feedback).

…-routes-7702d2

A connection over a limit is classified by the grant its request
presents, and its client is no longer served by a router of its own.
The router that classifies it is wrapped so that a request of the 2.0
encoding still gets `BrokerBusy` in that encoding: no such request
presents a grant, since the grant route is a 1.x route.

A client is admitted with the lookup of its user first, then with the
capture that keeps a client whose process is not identified.

The busy reply of the 1.x encoding now carries `BrokerBusy` as well, so
the test that tells the two encodings apart reads the `ResponseKind`
member, which only a 1.x error has.

Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Copilot AI adaptive review requested due to automatic review settings December 2, 2026 09:25
@CBenoit

Copy link
Copy Markdown
Member Author

Merged master up the stack (merge commits only); head 1834430d7.

master reworked what the broker does with a connection over a limit: the request is classified by the grant it presents, and the busy reply carries BrokerBusy on the 1.x routes too. Two places met the 2.0 routes:

  • The router that classifies a connection over a limit is wrapped by the 2.0 busy routing, so a request under /v2/ still gets BrokerBusy in the 2.0 encoding and every other request is classified as on master. No 2.0 request presents a grant, since the grant route is a 1.x route. a_request_of_the_2_0_encoding_over_the_limit_gets_the_busy_reply_of_that_encoding covers the wiring on a real pipe.
  • A client is admitted with the lookup of its user first, as on master, then with the capture that keeps a client whose process is not identified.

The test that tells the two encodings apart on a busy connection now reads ResponseKind, which only a 1.x error has, because both busy replies carry BrokerBusy.

Open point, unchanged by the merge: master rate-limits the warnings for rejected clients so that a local flood of failing connections cannot fill the log, and the warning logged for a client whose process is not identified (which is served, not rejected) is not rate-limited.

Checked locally on this head: cargo +nightly fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test -p now-package-broker (1158 passed, 2 ignored), cargo test -p devolutions-agent --no-run.

Note

LLM-assisted content (no human feedback).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Comment on lines +150 to +151
pub(crate) fn lock(&self) -> HeldTokens<'_> {
self.lock_at(Instant::now())
Comment on lines +832 to +835
Ok(None) => {
debug!(operation_id, "No client connected to the event channel");
return;
}
Comment on lines +220 to +224
warn!(
error = format!("{error:#}"),
%user_sid,
"Failed to identify named pipe client; none of its requests is authenticated"
);
Comment on lines +93 to +120
fn names_agent(manager: v2::Manager, package_id: &str, agent_product_code: Option<Uuid>) -> bool {
let name = package_id.split_once('#').map_or(package_id, |(name, _)| name);
let name = name.rsplit_once('@').map_or(name, |(name, _)| name);

match manager {
v2::Manager::Winget => {
name.eq_ignore_ascii_case("Devolutions.Agent")
|| agent_product_code
.is_some_and(|code| package_id.to_ascii_lowercase().contains(&code.hyphenated().to_string()))
}
v2::Manager::Chocolatey => name.eq_ignore_ascii_case("devo-agent"),
v2::Manager::PowerShell
| v2::Manager::PowerShell7
| v2::Manager::Apt
| v2::Manager::Bun
| v2::Manager::Cargo
| v2::Manager::Dnf
| v2::Manager::Dotnet
| v2::Manager::Flatpak
| v2::Manager::Homebrew
| v2::Manager::Npm
| v2::Manager::Pacman
| v2::Manager::Pip
| v2::Manager::Scoop
| v2::Manager::Snap
| v2::Manager::Vcpkg => false,
}
}

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