Skip to content

feat(box): accept an optional box ID from library callers, and generate one as today when absent - #437

Merged
priyasingh2111 merged 3 commits into
mainfrom
feature/caller-supplied-box-id
Nov 13, 2026
Merged

priyasingh2111 merged 3 commits into
mainfrom
feature/caller-supplied-box-id

Conversation

@priyasingh2111

@priyasingh2111 priyasingh2111 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Description

A library caller can now give a new box its own ID through RunOptions::box_id. Box stores that ID,
prints it, and labels telemetry with it. Without box_id, Box generates box- and 16 hexadecimal
digits as before, so a direct strands-box run does not change.

Why. A caller that names its runs, such as a CLI built on the library, prints one ID while Box's
record and telemetry carry another. This makes the two the same.

Rules.

  • A supplied ID is a prefix of 1 to 16 letters, digits, ., _, or - that does not start with
    . or -, then - and 16 lowercase hexadecimal digits.
  • A configured box refuses a different supplied ID.
  • A record with a supplied ID (other than box- and 16 digits) is stored at record version 34, so
    an older build refuses it by version.
  • name grows from 32 to 33 bytes, so a caller can use one string for name and box_id.

Interface changes (approved before implementation): RunOptions::box_id; the stored box_id
grammar and record version 34; strands.box.name carrying the supplied ID; the 33-byte name
limit. A caller that lists every RunOptions field without ..Default::default() must add the
field. The ID grants no authority: policy, paths, sockets, and the workload environment do not use
it, so it is a second spelling of the identity input, not a fifth input.

Not verified by CI here: Linux was not compiled locally. The end-to-end library test runs on
macOS only.

Related Issues

None.

Type of Change

New feature

Testing

  • I ran the relevant suites: cargo test -p strands-box --all-features on macOS, 1519 passed,
    0 failed, 6 ignored.
  • cargo fmt -p strands-box --check, and cargo clippy -p strands-box --all-targets --all-features with 0 warnings in crates/box.

Each new guard was removed once and its test failed. The commit message names each test.

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions github-actions Bot added enhancement New feature or request Area - Telemetry The telemetry collector, receiver, and record targets Area - Agent Containment labels Nov 12, 2026
@priyasingh2111 priyasingh2111 changed the title feat(box): let a library caller supply the box ID feat(box): accept an optional box ID from library callers, and generate one as today when absent Nov 13, 2026
@priyasingh2111
priyasingh2111 marked this pull request as ready for review November 13, 2026 00:39
Comment thread crates/box/src/lib.rs Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Comment

The identity plumbing, the record-version handling, and the mismatch refusal are correct for every case I traced. My one finding is in the inline comment: a malformed box_id is caught too late, after the process's one run attempt is used up.

Checked and held
  • New box with a supplied ID, interrupted first use, reopen with None or the same ID, reopen with a different ID: each gets the right result. An interrupted first use takes the supplied ID, because its uncommitted identity is discarded as before.
  • Record version: a non-generated ID always stamps version 33, and Record::parse requires an exact match. A supplied box-<16 hex> keeps the base version. An older build refuses a version-33 record by its version.
  • "The ID grants no authority": GovernedBox does not enter policy evaluation (policy/src/schema.rs). No path, socket, alias, or composed environment variable reads the ID. Telemetry takes it from the stored record, and the relay still removes any strands.box.name the agent sets itself.
  • Frozen-surface rules (root AGENTS.md, .agents/references/doc-updates.md): the new record version is documented in native-filesystem-policy.md. The README, config.md, and telemetry.md are updated. documented_inputs and documented_commands pass.
  • Linux: cargo check -p strands-box --all-features --tests passes on Linux x86_64. The new record::layout and record::config identity tests pass there. Two boundary tests fail only because the trampoline helper binary was not built in my run.

Design note, no change requested: a box created before this change, or by a direct strands-box run, can never take a caller-supplied ID. On reopen Box prints nothing, so a library caller has no supported way to learn the ID that telemetry carries. That case may be worth one sentence in the README.

The tests that disable each guard in turn, as listed in the commit message, are a strong way to show each guard is load-bearing.

## Problem

A library caller that names its own runs cannot make Box use that name as the box ID. Box always
generates `box-` and 16 hexadecimal digits on first use. So the caller prints one ID, while the
stored record and every telemetry record carry another. An operator cannot match a run that the
caller printed to the records of its box.

## Solution

- `RunOptions` gets `box_id: Option<String>`. `run` passes it to `BoxRoot::settle_identity`.
  - On first use, the box stores the supplied ID instead of a generated one.
  - A configured box accepts the same ID, and refuses a different one with
    `ConfigError::IdentityMismatch`.
  - A malformed ID is refused with `ConfigError::SuppliedIdentity` before the box has an ID.
  - `None` generates `box-` and 16 hexadecimal digits, as before.
- `valid_box_identity` accepts a prefix of 1 to 16 `nameable` characters that does not start with
  `.` or `-`, then `-` and 16 lowercase hexadecimal digits. `box-` and 16 digits stays valid.
- `MAXIMUM_BOX_NAME` grows from 32 to 33 bytes, so a caller can use the same string as `name` and
  as `box_id`.
- `SUPPLIED_IDENTITY_RECORD_VERSION` (34) is the record version of a record whose `box_id` is not
  `box-` and 16 digits. An older build refuses such a box by its version. A box with a generated
  ID keeps its current record version.
- `Record::parse` checks the identity before it computes the expected version.

Interfaces that move, each approved by the owner before the code was written:
- `RunOptions::box_id`. A caller that names every `RunOptions` field without
  `..Default::default()` must add the field.
- The stored `box_id` grammar, and record version 34.
- Telemetry `strands.box.name` carries the supplied ID.
- The `name` limit, 32 to 33 bytes. This widening has no record version of its own: an older
  build refuses the configuration first.

The supplied ID grants no authority. Policy does not read the box name, and no path, socket, or
workload variable uses the ID. So the ID is a second spelling of the identity input, and not a
fifth input.

## Tests

- `record::layout`: `a_supplied_identity_names_a_new_box_and_survives_reopen`,
  `a_supplied_identity_that_differs_from_the_stored_one_is_refused`,
  `a_malformed_supplied_identity_is_refused_before_the_box_has_one`, and
  `no_supplied_identity_generates_one_as_before`.
- `record::config`: `a_supplied_box_identity_requires_its_own_record_version`.
  `a_record_with_an_invalid_box_identity_is_refused` drops `name-<hex>`, which is now valid, and
  adds a 17-character prefix and a leading `-`.
- `tests/box_library.rs`: `a_supplied_box_id_names_the_box_and_its_telemetry` runs a real box
  through `strands_box::run` on macOS. It checks the startup line, the stored `box_id`, the
  `strands.box.name` value in telemetry, a matching rerun, a refused mismatch, and a generated ID
  when none is supplied. Its config `name` differs from the ID.
- Each guard was removed once and its test failed: the supplied ID on first use, the mismatch
  check, the version branch, the leading-character check, the prefix limit, and the telemetry
  label.
- macOS: `cargo test -p strands-box --all-features` passed (1519 passed, 0 failed, 6 ignored, after a rebase onto main).
  `cargo clippy -p strands-box --all-targets --all-features` has 0 warnings in `crates/box`.
  `cargo fmt -p strands-box --check` passed.
- Not run: Linux (cross-compilation fails in `ring`), and `test-integ/run.sh` on a quiet host.
  The end-to-end library test runs on macOS only. Linux runs the unit tests.
@github-actions

Copy link
Copy Markdown

Assessment: Comment (re-review at ae571a4)

This push is a rebase onto main (#397), which takes record version 33 for limits.shell.max_stdin. A supplied ID moves to 34. The identity logic has not changed, and the open thread on lib.rs:38 still reproduces.

Checked and held at this head
  • Version numbering: 34 does not collide with any version on current main (88e8c19). Record::parse accepts 34. record_version ranks a supplied ID above max_stdin, so a box with both gets 34. A build at version 33 refuses that record by its version.
  • Tests: a_supplied_box_identity_requires_its_own_record_version uses the constant, not a literal, so the renumbering changes no test. record:: unit tests pass on Linux x86_64 (317 passed).
  • Docs: native-filesystem-policy.md and crates/box/AGENTS.md now name version 34 and SUPPLIED_IDENTITY_RECORD_VERSION.

Optional and outside this PR: native-filesystem-policy.md still has no line for version 33. #397 omitted it, so the list now jumps from 32 to 34.

Comment thread README.md Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Comment (re-review at aacc3ec; nothing blocks the merge)

The malformed-ID finding is fixed. run now checks the ID's format before it marks the process's one attempt as used. I confirmed this on Linux x86_64, and the new retry test covers it. One small docs suggestion is inline.

Checked and held at this head
  • Cases that reach the new check in lib::run:
    • A malformed ID is refused before hardening and on_ready, so a retry can still run.
    • A valid ID goes on to settle_identity as before.
    • With None, the check is skipped.
    • A malformed ID on a later call is still refused, now with the format error instead of "already attempted". Either way that call does not run.
  • Mismatch refusal: it still runs after the lock, inside settle_identity, which also keeps its own format check.
  • Record version 34 and the identity grammar: unchanged since the last review. The record:: unit tests pass on Linux.

@github-actions

Copy link
Copy Markdown

Assessment: Approve (re-review at 0b0f17e; no open findings)

This push only changes docs. The root README and the RunOptions::box_id rustdoc now state the malformed-ID exception to the one-attempt rule. Compared with main, the other 11 changed files have the same per-file line counts as at aacc3ec. lib::run still checks the format before STARTED.swap.

Checked and held: the new docs describe what the code does, and nothing else changed since my last review.

@priyasingh2111
priyasingh2111 merged commit c5f8690 into main Nov 13, 2026
38 of 43 checks passed
@priyasingh2111
priyasingh2111 deleted the feature/caller-supplied-box-id branch November 13, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area - Agent Containment Area - Telemetry The telemetry collector, receiver, and record targets enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants