Repository navigation
Conversation
## Problem A box decides every request against the policy it loaded when it opened. An operator who edits the authored policy must stop the box and start a new one for the edit to take effect, which ends the agent's session and discards its history. The engine has no way to install a new authored policy over a running authority. ## Solution `PolicyEngine::reload` takes an authored policy set and installs it over the live authority. It takes `&self`, so a caller reloads through the `Arc` the box already shares, and it serialises against in-flight decisions on the authority's own lock. The box keeps its decision history, so a rule whose canonical text is unchanged keeps the budget it has already spent. A set that does not validate is refused in full, and the policy already installed keeps deciding every request. `reload` takes the policy text, not a path, so the engine opens no file. Nothing here authenticates a request either: the contained agent must never reach a reload, and what keeps it out is where the trigger lives. Which component owns an authored policy source, and which owns the trigger, are open questions this change does not settle. Canonical text is literal: a reformatted rule counts as a changed rule and starts a new budget. `Dogwood` issue 59 tracks the gensym instability behind it, with three tests already ignored in this crate against it. ## Tests `policy.rs::reload_installs_a_new_authored_policy_on_a_live_engine` opens an engine on a policy with no write rule, shows the write denied, reloads a policy that adds one, and shows the same engine permitting the same write. `a_reload_that_does_not_validate_leaves_the_previous_policy_in_force` shows a refused set leaving the installed policy deciding. Both run in-crate, so they reach the engine directly rather than through a caller. Not run: no test shows a contained workload observing a changed decision in the middle of a run. That needs a caller, and the public surface that reaches this from outside the crate is a separate change.
## Problem The library surface starts a box and returns the workload's exit status, and nothing else leaves the crate. The policy authority a run decides against stays inside, so a caller that embeds Box cannot install an edited policy on a box that already runs. The only way to apply one is to stop the box and start a new one, which discards the agent's session. ## Solution `run_with_handle` runs a box and calls `on_open` once, after the box opens and before the workload starts, with a `BoxHandle` over that run's live authority. `BoxHandle::reload` installs an authored policy set over it, and `ReloadRefused` reports a set the engine does not take. `run` keeps its signature, and both run paths share one private guard, so a request for a handle cannot start a second box. The surface stays narrow: `Policy` is re-exported, so a caller writes the input without a name from an internal crate, and no other type becomes public. ## Tests `box_library_reload.rs::a_handle_reloads_the_running_boxs_own_authority` opens a real read-only box, refuses a reload that names an undeclared action, applies one written against the box's own schema, and then ends with the workload's zero exit. `a_box_that_fails_to_open_hands_out_no_handle` shows that a missing configuration calls `on_open` for no one. A mutation that removes the `on_open` call makes the first case fail. `policy.rs::reload_installs_a_new_authored_policy_on_a_live_engine` pins the deny-reload-permit behaviour of the engine itself. The workspace suite passes at 4196 tests, with 17 ignored; three of those are the Dogwood gensym tests that issue 59 tracks. Not run: no test shows the contained workload as it observes a changed decision in the middle of a run, because this handle applies the reload before the workload starts.
8 tasks done
7 of 8 tasks
Contributor
Author
|
#217 has cleaner integration, closing this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Draft, and parked on purpose. This is the public handle split out of #122 after review. The
design in it is known to be insufficient, and it is open so the code and the constraint have an
anchor — not as a merge candidate. Depends on #122 (engine half); this PR is stacked on that branch,
so its diff is the handle only.
The engine's
PolicyEngine::reloadis unreachable from outside the crate. #116 gave the libraryrunandgenerate_policy_schema, but the policy authority a run decides against never leaves thecrate, so an embedding caller applies an edited policy only by stopping the box and starting a new
one — which discards the agent's session, the thing reload exists to avoid.
What this adds:
run_with_handlecallson_openonce, after the box opens and before the workload starts, with aBoxHandleover that run's live authority. It is additive:runkeeps its signature andmain.rsis untouched. Both run paths share one private guard, so asking for a handle cannot start a second
box.
The known constraint
BoxHandleholds anArc<PolicyEngine>. That is an in-memory pointer, so this shape only workswhile Box Core runs inside the caller's address space, and it cannot survive
runmoving into itsown process. No adjustment to the signature changes that — what crosses to the caller is an address
in this process's heap.
A cross-process shape has to carry a request rather than a pointer: the caller sends the authored
text over a channel, and the box process calls
PolicyEngine::reloadon its own engine. The enginesignature already suits that, because it takes
Policy { origin, text }and never opens a file.Open questions before this is worth designing:
runmove into its own process, and on what horizon? The 2026-10-20 sync recorded"exposed as a library method, not as an SDK or separate process", which reads as in-process, while
review says a separate process is agreed and soon. These are different axes — how reload is
exposed versus where
runexecutes — and the answer decides whether a handle is a pointer ora protocol.
Box Core would own. If Box Core owns the source, the caller may not need to pass text at all, and
the trigger may belong inside Box Core rather than above it. That inverts this PR's shape.
reloadreturns(), and a cross-process caller needs an acknowledgement far more than an in-process one does.An earlier revision of #122 did carry a cross-process trigger — a control socket in the box's private
directory with an ack — removed on the premise that the caller always holds the engine in-process. If
that premise is changing, the plumbing is in that branch's history as reference, though its shape
(a side socket plus a CLI verb) is probably not what a two-process Box Core wants.
I have not guessed at a design here. Hot reload is not blocking until milestone 4, so the cost of
waiting for the topology answer is zero, and guessing is what produced three rounds of rework on
#122.
Related Issues
Split from #122.
Type of Change
New feature
Testing
just check, orcargo test --workspace --all-features)cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warningsbox_library_reload.rs::a_handle_reloads_the_running_boxs_own_authorityopens a real read-only boxthrough the library, refuses a reload naming an action the schema does not declare, applies one
written against the box's own schema, and ends on the workload's zero exit. That refusal is the
liveness evidence: only a box carrying its own compiled schema can reject the rule, so the handle
cannot be standing over a fresh engine.
a_box_that_fails_to_open_hands_out_no_handleshows amissing configuration calls
on_openfor no one.The suite sets
harness = falseand owns itsmain, because the one-run guard is process-wide andeach case re-executes the test binary. It skips the live-handle case where the namespace backend
cannot open a box, which is every Linux host that is not aarch64.
Verified in a way CI cannot show: a mutation that removes the
on_opencall makes the first casefail at the handle assertion. Each case runs from a copy of the test binary placed beside
target/debug/strands-box, because a box resolves its sibling binaries from the running image'sdirectory and a test binary lives in
deps/, where they are not.Not run: no test shows a contained workload observing a changed decision mid-run, because this handle
applies the reload before the workload starts.
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.