Skip to content

feat(bep): free the client key of a box that ended without forget_box (T90) - #2642

Merged
norrietaylor merged 6 commits into
mainfrom
agent/2617-free-the-client-key-of-a-box-that-ended-without
Oct 27, 2026
Merged

norrietaylor merged 6 commits into
mainfrom
agent/2617-free-the-client-key-of-a-box-that-ended-without

Conversation

@minimal-foundry

@minimal-foundry minimal-foundry Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

T90 — Free the client key of a box that ended without forget_box

slice: S12
kind: task
covers: BEP-063
size: M
est: 120 code, 120 tests
executor: agent
difficulty: unknown ground
model: strongest
diagnostics: none beyond the bound's refusal text
observability: one info log line per key freed at start, naming its kid
layers:
- keys:
- crates/bep/src/control.rs: at start, each key's boxes= set is reconciled against the boxes that are still registered, so a box that ended with no forget_box (a Ctrl-C before minvmd records it, a stopped minvmd, a failed release write) no longer holds its key in use (#2617)
- docs/specs/24-spec-box-egress-proxy/24-spec-box-egress-proxy.md: the BEP-063 known-gap text that links #2617 is removed
test: cargo nextest run -p bep a_stranded_box_frees_its_key_at_start
produces: none
consumes: none
proof: After a restart, a box that ended without forget_box no longer holds its client key in use, and the bound counts only keys that running boxes use.
depends on:
- blocked by #2605
- assumes OQ3 (the mint reads the root certificate's own expiry, and the root is generated with a fixed default validity in one constant that gominimal/arch#85's ruling replaces)

Proof

After a restart, a key whose boxes= set names only boxes that the proxy does not hold as registered is no longer in use. A retired key of that kind is revoked. The bound then refuses a new key only when running boxes use every key: the test shows a new key refused before the restart and accepted after it, and the key of the box that is still registered stays.

Notes from the agent: KeyFile::restore now takes the box registry that Control::bind receives, and reconciles each key's boxes= set against it. It writes an info log line for each key that it frees, with its kid. A retired key that it revokes gets the existing retire_unused info line. In bep serve the box registry is always empty at bind: bep serve stops with the minvmd that started it (supervisor.rs), and nothing registers a box again after a restart. So at each start of bep serve every key is free, and every retired key is revoked. This matches the fact that a box from before the restart cannot redeem anyway, because the redeemer refuses a box that is not registered. An embedder that registers boxes before bind keeps those keys in use. The existing test the_registry_bound_never_drops_a_key_a_running_box_uses now registers boxes X and Y before its restart, so that its 'use survives a restart' step still holds. The spec's BEP-063 known-gap clause (the only #2617 link) now states the new behaviour and names the test. Vale is not installed on this box, so just lint-prose did not run. I also ran cargo nextest run -p bep control:: (14 passed) and cargo clippy -p bep --all-targets (clean).

Layer exception

The epic owner accepted these files outside T90's layers on 2026-10-27, for the design ruling that a stranded box's key is freed only on minvmd's live set (round 2):

  • crates/minvmd/src/box_registry.rs: BoxRegistry::live_box_ids and BoxRegistry::send_live_boxes, with the test live_boxes_names_every_box_the_registry_holds.
  • crates/minvmd/src/cmd/run.rs: the bep watcher sends live_boxes when the proxy starts to listen, with the test proxy_gets_the_live_box_ids_when_it_starts_to_listen.

Tests

line exit tail
cargo nextest run -p bep a_stranded_box_frees_its_key_at_start 0 Applying loadouts: default Running task runtime-implement-test-0 in session task-runtime-implement-test-0-c072... Compiling bep v0.0.1 (/workbench/crates/bep) Finished 'test' profile [unoptimized] target(s) in 41.08s ──────────── Nextest run ID 7389e5f5-9a9c-4422-8d56-3e40572b2e11 with nexte

Verify

min task run agent-verify passed ([tasks.verify]).

Closes #2617


Generated by Claude Code

… (T90)

At start, each key's boxes= set in the registrations file is reconciled
against the box registry. A box that the registry does not hold ended
with no forget_box, so it no longer holds its key in use, and a retired
key whose boxes all ended is revoked. The BEP-063 known-gap text is
removed from the spec.
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9b87f462-fbd9-4319-bb43-337185dfd5db

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Spec lint

docs/specs/24-spec-box-egress-proxy/24-spec-box-egress-proxy.md — 9 finding(s)

docs/specs/24-spec-box-egress-proxy/24-spec-box-egress-proxy.md:113: P004 BEP-003 names test 'bep_second_box_needs_no_sign_in', which was not found in the repository
docs/specs/24-spec-box-egress-proxy/24-spec-box-egress-proxy.md:170: P004 BEP-007 names test 'bep_box_env_holds_sealed_value_only', which was not found in the repository
docs/specs/24-spec-box-egress-proxy/24-spec-box-egress-proxy.md:214: P004 BEP-011 names test 'bep_root_ca_present_in_box_trust_store', which was not found in the repository
docs/specs/24-spec-box-egress-proxy/24-spec-box-egress-proxy.md:230: P004 BEP-012 names test 'bep_proxy_env_and_no_proxy_are_set', which was not found in the repository
docs/specs/24-spec-box-egress-proxy/24-spec-box-egress-proxy.md:284: P004 BEP-015 names test 'bep_git_and_gh_against_private_repo', which was not found in the repository
docs/specs/24-spec-box-egress-proxy/24-spec-box-egress-proxy.md:625: P004 BEP-043 names test 'bep_destroyed_box_values_refused_within_60s', which was not found in the repository
docs/specs/24-spec-box-egress-proxy/24-spec-box-egress-proxy.md:634: P004 BEP-044 names test 'bep_logout_refuses_every_reference_at_next_request', which was not found in the repository
docs/specs/24-spec-box-egress-proxy/24-spec-box-egress-proxy.md:679: P004 BEP-047 names test 'bep_and_gvproxy_are_separate_processes_and_users', which was not found in the repository
docs/specs/24-spec-box-egress-proxy/24-spec-box-egress-proxy.md:688: P004 BEP-049 names test 'prop_audit_chain_detects_unrecomputed_edit', which was not found in the repository

Advisory. None of this blocks the merge; the review decides.

Advisory, and never a merge gate. Linter: gominimal/foundry@fb5932b8, spec format: How Minimal Writes Specs.

@minimal-foundry

minimal-foundry Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Approved: no findings at 693a56d7936f.

Nothing to do.

Verdict APPROVE, posted as a comment: the App cannot review its own pull request; the check and the label carry it.

Clobber: none seen.

@minimal-foundry minimal-foundry Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

minimal-review — approved

Verdict APPROVE — No findings.

Panel: 3 of 3 personas ran (correctness, security, supply-chain).

@minimal-foundry minimal-foundry Bot added the review:approved minimal-review approved the current head label Oct 26, 2026

@minimal-arch minimal-arch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

arch-review: PASS · the full ruling

This change conforms to Gatehouse §6.10. At start, the proxy frees the key of a box that it does not hold as registered. Line 839 says a box id never returns, and the redeemer already refuses such a box with no_live_box. So the change revokes a retired key sooner and changes no redemption outcome, which is the fail-closed side. The info log names each freed kid, as the task requires. The spec no longer carries the BEP-063 known gap.

Ruled at c7efb8b against gominimal/arch@109541a48c31 by claude-opus-5-5.

@minimal-foundry

Copy link
Copy Markdown
Contributor Author

Round 1 of 10: the container stopped before the coder ran (the container took the job and stopped before it ran (exit 0 and no result, and the second start failed: Error: The container is not running, consider calling start())). The round is given back.

Copy link
Copy Markdown
Member

/revise

Round 2 of #2642, on the red tests check at c7efb8b7. Round 1 stopped before the coder ran and was given back, so no round is in flight. The epic owner ruled on the design on 2026-10-27, and the owner accepts the files outside T90's layers that this needs, as a layer exception. Add a "Layer exception" section to the PR body that names them.

The failure. cargo nextest run -p minimal a_replaced_client_key_keeps_verifying_until_its_boxes_end fails here, and it passes on main. That test serves the control socket again with an empty box registry and expects the old key to keep verifying for the boxes still running (the ruling on gominimal/arch#144: the old key stays until its boxes end, after a restart too). KeyFile::restore in this PR frees every boxes= entry that the in-memory registry does not hold, and that registry is always empty at start. So a restart revokes the old key while its boxes still run. The premise in the new module doc is not true on main. bep serve can restart while boxes keep running, and the module doc on main says a box created before a restart keeps redeeming.

  1. Do not free at start. restore keeps every boxes= entry as it is on main. Remove the running parameter and the freeing loop from restore, and remove the module-doc paragraph that says the registry is empty at start.
  2. Free on minvmd's live set. minvmd's box registry (crates/minvmd/src/box_registry.rs) knows which boxes still run. Add a control op, for example {"op":"live_boxes","box_ids":[...]}, that minvmd sends with every box id its registry holds each time it starts bep serve or finds it restarted. On that op, bep drops each boxes= entry whose box is not in the set, revokes a retired key whose boxes all ended, writes the file, and logs the info line that names the freed kid. Until the op arrives, nothing is freed.
  3. Tests. Keep a_replaced_client_key_keeps_verifying_until_its_boxes_end exactly as it is on main. Change a_stranded_box_frees_its_key_at_start so that it restarts the control with the stranded box still in the file, asserts that the key is still in use after the restart, sends live_boxes without the stranded box, and then asserts that the key is free and that the bound counts only the keys running boxes use. Add a minvmd test that the op is sent with the registry's box ids when bep serve starts.
  4. Update the BEP-063 known-gap text in the spec to state this behaviour. Change nothing else. Run cargo clippy --workspace --all-targets --locked -- -D warnings, cargo nextest run -p bep, cargo nextest run -p minimal and cargo nextest run -p minvmd.

Generated by Claude Code

A restart keeps every boxes= entry, so a box created before it keeps
redeeming. The new live_boxes op frees each box that the file held at
the start and that the list leaves out (#2617).
The proxy then frees the client key of each box that ended with no
forget_box (#2617).
Request stays as it was, so a client that matches every Request keeps
its match.

@minimal-foundry minimal-foundry Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

minimal-review — approved

Verdict APPROVE — No findings.

Panel: 3 of 3 personas ran (correctness, security, supply-chain).

@minimal-arch minimal-arch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

arch-review: PASS · the full ruling

The change conforms to Gatehouse §6.10. minvmd is the host-side creator, and it sends the live box list, as line 839 requires. The proxy frees only boxes that the file held at its start. It frees nothing before the list arrives, so a running box keeps its key for its life. The new live_boxes op uses the existing same-uid gate on the control socket. There are no conditions.

Ruled at 693a56d against gominimal/arch@109541a48c31 by claude-opus-5-5.

@minimal-foundry

Copy link
Copy Markdown
Contributor Author

Round 1 of 10 on a /revise note, pushed as 693a56d7936f.

line exit tail
cargo nextest run -p bep a_stranded_box_frees_its_key_at_start 0 Applying loadouts: default Running task runtime-implement-test-0 in session task-runtime-implement-test-0-ebd8... Compiling bep v0.0.1 (/workbench/crates/bep) Finished 'test' profile [unoptimized] target(s) in 38.57s ──────────── Nextest run ID bac95288-1b2b-4a90-8842-3dbf6a51fa6f with nexte

Verify min task run agent-verify passed.

Outside the task's layers::

  • crates/minvmd/src/box_registry.rs
  • crates/minvmd/src/cmd/run.rs

Converted to a draft: something above needs a person before review.

A restart of bep serve keeps every box in the registrations file as a user of its key, so a box that still runs keeps redeeming. When bep serve starts to listen, minvmd sends one live_boxes line with every box id in its registry. bep then frees the key of each box from the file that the list leaves out, revokes a retired key whose boxes all ended, and logs an info line that names each freed kid. After that, the bound counts only the keys that running boxes use. a_stranded_box_frees_its_key_at_start shows each step, and proxy_gets_the_live_box_ids_when_it_starts_to_listen shows the minvmd side.

Notes from the agent: Layer exception: the epic owner accepted the files outside T90's layers. They are crates/minvmd/src/box_registry.rs (BoxRegistry::live_box_ids, BoxRegistry::send_live_boxes, test live_boxes_names_every_box_the_registry_holds) and crates/minvmd/src/cmd/run.rs (the bep watcher runs send_live_boxes_on_listening when the proxy starts to listen, test proxy_gets_the_live_box_ids_when_it_starts_to_listen). Please add a 'Layer exception' section to the PR body that names these two files, as the /revise note asks. Design points that differ from the directive's wording: (1) live_boxes is a type of its own, LiveBoxesRequest, beside Request. A new Request variant broke the exhaustive matches in the minimal crate, and the module already keeps rotate_signing and revoked_box_ids in types of their own for this reason. (2) bep frees only boxes that the file held at this start (KeyFile::from_start), not every box the list leaves out. A box that registers its key after the start but reaches minvmd's registry after the snapshot is thus never freed by mistake. (3) bep serve binds its listener before its control socket, so minvmd retries the connect for up to 10 s on NotFound or ConnectionRefused. The send runs on a thread of its own, so the watcher does not wait. (4) A failed file write in live_boxes frees the keys in memory, logs an error and replies with a refu…[truncated]

@minimal-foundry
minimal-foundry Bot marked this pull request as draft October 27, 2026 01:22
@norrietaylor
norrietaylor marked this pull request as ready for review October 27, 2026 02:03

@norrietaylor norrietaylor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Own review at 693a56d. A restart keeps every box in the registrations file as a user of its key, so T84's restart guarantee holds. Its test passes. When bep serve starts to listen, minvmd sends live_boxes with its registry's box ids. bep frees the keys of the boxes the file held at that start and the list leaves out, then revokes a retired key whose boxes all ended. A box that registers after the snapshot is never freed by mistake.


Generated by Claude Code

@norrietaylor norrietaylor changed the title T90 — Free the client key of a box that ended without forget_box feat(bep): free the client key of a box that ended without forget_box (T90) Oct 27, 2026

@norrietaylor norrietaylor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Babysitter approval at 693a56d: every merge gate passes at this head (arch PASS at 693a56d, zero open threads, every lane aggregator green). Squash title feat(bep): free the client key of a box that ended without forget_box (T90) and the squashed message pass commitlint. Queued for squash merge.


Generated by Claude Code

@norrietaylor
norrietaylor added this pull request to the merge queue Oct 27, 2026
Merged via the queue into main with commit 1b7dfad Oct 27, 2026
38 checks passed
@norrietaylor
norrietaylor deleted the agent/2617-free-the-client-key-of-a-box-that-ended-without branch October 27, 2026 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:approved minimal-review approved the current head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

T90 — Free the client key of a box that ended without forget_box

1 participant