Repository navigation
feat: T53 — A typed session entry starts from its own expanded body and lifetime - #3500
minimal-foundry[bot] wants to merge 10 commits into
Conversation
BoxSpec::build reads lifetime from the entry's settings in place of a hard-coded until_complete. BoxSpec::for_session_entry builds a session spec from an expanded entry (BCLI-029).
stamp_session_spec_as builds the spec from session_box_expansion, and project_bep_and_grants reads the entry's secrets, vars and Box Egress Proxy settings from it. plan_start no longer refuses a typed session entry other than default (BCLI-029, BCLI-071).
…ssion-entry-starts-from-its-own-expand
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
|
Undrafting at
|
|
Reviewed: no findings; approval withheld, 7 threads unresolved at APPROVE withheld: 7 unresolved threads — minimal-foundry[bot] crates/mfile/src/spec.rs, minimal-arch[bot] crates/mfile/src/spec.rs, minimal-arch[bot] crates/mfile/src/spec.rs, minimal-arch[bot] crates/minimal/src/cmd/boxes/create.rs, minimal-foundry[bot] crates/mfile/src/spec.rs, …. Resolving the last thread releases the approval on this head. Resolve the open threads. Resolving the last one releases the approval on this head; no new review is required. Verdict APPROVE, posted as a comment: the App cannot review its own pull request; the check and the label carry it. Clobber: none seen. |
| /// when the entry sets none. [`crate::File::validate`] and the expansion | ||
| /// refuse a bad value before a spec is built, so a bad value here reads as | ||
| /// `None`. | ||
| fn entry_lifetime(extra: &toml::Table) -> Option<Lifetime> { | ||
| first_value(extra, &[&["lifetime"], &["box", "lifetime"]]) | ||
| .and_then(|value| value.clone().try_into().ok()) |
There was a problem hiding this comment.
MEDIUM · correctness · confidence 0.60 · in entry_lifetime
The doc comment says File::validate and the expansion refuse a bad lifetime before a spec is built. I found no such check: expand.rs only checks that lifetime is a string. So lifetime = "until-stopped" or a typo reads as None here, and the box silently stores until_complete. Validate the value at expansion, or return an error from this function.
What the reviewer checked
entry_lifetime:
.and_then(|value| value.clone().try_into().ok()); expand.rs:1408("lifetime", Shape::Str); no other Lifetime validation found by rg.
Hand this to an agent
Act on a code-review finding.
File: crates/mfile/src/spec.rs
Lines: 329-334
Category: correctness
Severity: medium (reviewer confidence 0.60)
Finding:
The doc comment says `File::validate` and the expansion refuse a bad `lifetime` before a spec is built. I found no such check: expand.rs only checks that `lifetime` is a string. So `lifetime = "until-stopped"` or a typo reads as `None` here, and the box silently stores `until_complete`. Validate the value at expansion, or return an error from this function.
First verify this against the code yourself. It is model output and
may be wrong. If it is wrong, or the tradeoff was deliberate, say so
and change nothing.
👍 useful · 👎 noise — react to tell the reviewer. Replying works too, and says more.
There was a problem hiding this comment.
Addressed in 8a583e73b42a: The expansion now refuses a lifetime other than until_complete or until_stopped, flat or under [box], with the UnknownValue message. A test pins both forms, and the doc comment is corrected.
…ssion-entry-starts-from-its-own-expand
There was a problem hiding this comment.
arch-review: CONDITIONS · 1 condition · the full ruling
The typed session entry now starts from its own expansion, and the interim refusal is gone cleanly. One defect is left. The new first_value in crates/mfile/src/spec.rs reads a flat key before its nested form, whatever layer set it. So a flat lifetime in [defaults.session] or a legacy [session] beats the entry's [box] lifetime, and packages with install.packages do not union. The design says that the entry beats every default and that lists union (architecture.md lines 1247-1253). Resolve the two forms by layer rank, as C1 states.
Ruled at f5ac57c against gominimal/arch@327e1b57d16b by claude-opus-5-5.
|
|
||
| /// The first value that one of `paths` finds in `table`. An expanded spec | ||
| /// can carry a key flat or under its `box.toml` section. | ||
| fn first_value<'a>(table: &'a toml::Table, paths: &[&[&str]]) -> Option<&'a toml::Value> { |
There was a problem hiding this comment.
C1 · This reads the flat key first, whatever layer set it. fold keeps lifetime and box.lifetime as separate keys. So a flat lifetime in [defaults.session] beats the entry's [box] lifetime. Lines 1247-1253 say that the entry beats every default. Take the form from the later layer by report.values, as expand.rs does for loadout_mode.
There was a problem hiding this comment.
Addressed in 65a914d54c75: Removed first_value. lifetime, timeout and hooks_on_resume now take the flat or the section form from the later layer in report.values, as loadout_mode does.
| #[must_use] | ||
| pub fn for_session_entry(entry: &str, expanded: &toml::Table, flags: SpecFlags) -> Self { | ||
| let packages: Vec<String> = | ||
| first_value(expanded, &[&["packages"], &["install", "packages"]]) |
There was a problem hiding this comment.
C1 · This takes only one of packages and install.packages. The expansion keeps them as separate keys, so [defaults] packages beside the entry's [install] packages stores only the flat list. Line 1247 says that lists union. Union both lists in layer order, and remove the duplicates.
There was a problem hiding this comment.
Addressed in 65a914d54c75: layered_packages now unions packages and install.packages in layer order without duplicates. Pinned by box_spec_takes_lifetime_from_expansion_unions_packages.
| )?; | ||
| let mut spec = match &expanded { | ||
| Some(expanded) => { | ||
| mfile::spec::BoxSpec::for_session_entry(&expanded.wire.name, &expanded.spec, flags) |
There was a problem hiding this comment.
C1 · Pass the expansion report here. Add report to BoxEntryExpansion from full.report in box_entry, and give it to BoxSpec::for_session_entry. Then the spec can resolve the flat and nested forms by layer rank.
There was a problem hiding this comment.
Addressed in 65a914d54c75: BoxEntryExpansion now carries report from full.report, and stamp_session_spec_as passes it to BoxSpec::for_session_entry.
|
/revise Head C1: the stored spec takes each setting from the later layer, not the flat key first.
|
|
That Nothing to type again: the command gets a rocket when its round starts, or a refusal that names the reason. No round was counted for it yet. |
A typo such as lifetime = "until-stopped" read as no lifetime, and the box stored until_complete. The expansion now refuses any value that is not until_complete or until_stopped, flat or under [box].
|
Round 1 of 10 on the runtime's review findings, pushed as
Verify Outside the task's
Converted to a draft: something above needs a person before review. Review threads the coder judged:
With [sessions.dev] declaring its own packages, secrets and on_activate hook, and [sessions.dev.box] lifetime = "until_stopped", min session start dev and min box start dev start the box from dev's own expansion. The stored spec names dev and carries dev's packages, secrets, hook and until_stopped, the same as min box spec dev. A lifetime value other than until_complete or until_stopped is now refused when the entry expands, so a typo no longer stores until_complete silently. Notes from the agent: Revise round 1: the lifetime check is in crates/mfile/src/spec.rs. check_section now also checks a flat key that a section carries, so the flat lifetime key is checked there and expand.rs (outside the layers) does not change. The refusal reuses the existing SpecKeyProblem::UnknownValue message: ' sets |
There was a problem hiding this comment.
arch-review: PASS · the full ruling
The change conforms to the design. A typed session entry now stores its own expanded body, and pty_enabled stays true as the session type constrains it. The fix commit refuses a lifetime that is not until_complete or until_stopped, from every layer. A typo no longer stores until_complete. The stored spec still does not include the selected loadouts. Issue #3236 tracks that gap, and it is a residual.
Ruled at 8a583e7 against gominimal/arch@327e1b57d16b by claude-opus-5-5.
The flat key and its section's key are separate top-level keys in an expansion, so the flat one won whatever layer set it. The spec now ranks the two forms by the expansion report, and unions packages and install.packages in layer order.
| let hooks_on_resume = extra.is_some_and(hooks_on_resume); | ||
| let timeout = extra.and_then(entry_timeout); | ||
| // A spec that sets no lifetime keeps the `until_complete` that the | ||
| // shipped `session` and `task` types declare. | ||
| let lifetime = extra | ||
| .and_then(entry_lifetime) | ||
| .unwrap_or(Lifetime::UntilComplete); |
There was a problem hiding this comment.
MEDIUM · correctness · confidence 0.55 · in BoxSpec::build
BoxSpec::build now reads lifetime for every caller, but only expanded entries are validated (check_keys in expand.rs). for_session(Some(&Session)) and for_task pass raw extra. File::validate checks only timeout there. A typo such as lifetime = "until-stopped" in [session] or [tasks.x] silently stores until_complete. A valid until_stopped on a task now changes the stored spec, which the task scope did not intend. The doc comment on entry_lifetime claims the value is always validated, which is false for these two paths.
What the reviewer checked
spec.rs:211
session.map(|s| settings_of(&s.extra)); spec.rs:264Some(&settings_of(&task.extra)); lib.rs File::validate calls only check_entry_timeout; check_section is called only from expand.rs:1454.
Hand this to an agent
Act on a code-review finding.
File: crates/mfile/src/spec.rs
Lines: 280-286
Category: correctness
Severity: medium (reviewer confidence 0.55)
Finding:
`BoxSpec::build` now reads `lifetime` for every caller, but only expanded entries are validated (`check_keys` in expand.rs). `for_session(Some(&Session))` and `for_task` pass raw `extra`. `File::validate` checks only `timeout` there. A typo such as `lifetime = "until-stopped"` in `[session]` or `[tasks.x]` silently stores `until_complete`. A valid `until_stopped` on a task now changes the stored spec, which the task scope did not intend. The doc comment on `entry_lifetime` claims the value is always validated, which is false for these two paths.
First verify this against the code yourself. It is model output and
may be wrong. If it is wrong, or the tradeoff was deliberate, say so
and change nothing.
👍 useful · 👎 noise — react to tell the reviewer. Replying works too, and says more.
There was a problem hiding this comment.
Addressed in 6a66a614d921: Still true at head for the task path: BoxSpec::for_task passes the raw [tasks.x] table, so build reads lifetime unchecked. The entry_lifetime doc now speaks only of expanded specs. The /revise note limited this round to C1, so this path is not changed yet. The fix is to read lifetime only for an expanded entry.
Keeps BoxSpec::build within clippy's argument limit.
|
Round 2 of 10 on a /revise note, pushed as
Verify Outside the task's
Converted to a draft: something above needs a person before review. Review threads the coder judged:
1 outdated runtime thread(s) were not judged: With [sessions.dev] declaring its own packages, secrets and an on_activate hook, and [sessions.dev.box] lifetime = "until_stopped", min session start dev and min box start dev start the box from dev's expansion. The stored spec names dev and carries dev's packages, secrets, hook and until_stopped. A [defaults.session] lifetime or a legacy [session] lifetime no longer overrides the entry's [box] lifetime, and [defaults] packages join the entry's [install] packages. Notes from the agent: This round addresses only C1. first_value is removed. The new later_value ranks the flat key and its section key by the Layer of their origin in report.values. The nested form wins only when its layer is strictly later, which is the same tie rule as loadout_mode in expand.rs. for_session and for_task pass no report, so they keep the flat form on a tie in their one table. layered_packages merges packages and install.packages by origin layer, with a stable sort and de-duplication. One limit: Layer ranks all type-defaults layers as one rank, and all loadouts as one rank. Two forms set by two different loadouts, or by two types in the chain, therefore tie, and the flat form wins. The report does not carry the position in the layer list, so the spec cannot order them more finely. BoxSpec::build now takes the report beside the settings table as one tuple argument, to stay within clippy's too_many_arguments limit. The two new tests are box_spec_takes_lifetime_from_expansion_later_layer_wins and box_spec_takes_lifetime_from_expansion_unions_packages. They use the name prefix of the plan's mfile test line, so that line runs them. |
|
Undrafting at
Round 2 answers arch ruling 1358's C1: the flat and nested forms resolve by layer rank from the expansion report, and packages union in layer order. The agent note in this body that says "the spec reads the flat key first" describes the earlier head, not this one. |
There was a problem hiding this comment.
arch-review: PASS_WITH_CONDITIONS · 1 condition · the full ruling
The compare fixes the main defect. The stored spec now takes lifetime, timeout and hooks_on_resume from the later layer, and the packages union across layers, as line 1247 says. One gap stays. later_value ranks by Layer only, so in an extends chain the parent type's flat key beats the derived type's [box] key. Line 1283 says the more specific type wins. C1 breaks that tie by the type chain order, as loadout_mode in expand.rs does.
Ruled at 65a914d against gominimal/arch@327e1b57d16b by claude-opus-5-5.
| .and_then(|t| t.get(key)); | ||
| match (flat, nested) { | ||
| (Some(f), Some(n)) => { | ||
| let rank = |k: &str| report.and_then(|r| Some(r.values.get(k)?.first()?.layer)); |
There was a problem hiding this comment.
C1 · This rank uses Origin::layer only. Two types of one extends chain are both Layer::TypeDefaults, so they tie and the flat key wins. Line 1283 says the more specific type wins. Break the tie by the position of Origin::box_type in the type chain, as loadout_mode in expand.rs does.
There was a problem hiding this comment.
Addressed in 6a66a614d921: Fixed in 6a66a61. Inside Layer::TypeDefaults, the rank now uses the position of Origin::box_type in the type chain, root first, which BoxEntryExpansion passes to for_session_entry. The fix covers lifetime, timeout, hooks_on_resume and packages, and box_spec_takes_lifetime_from_expansion_derived_type_wins pins it.
|
/revise Head C1: a derived Box Type's setting beats its parent's.
Reply on the arch thread with the commit. |
…ssion-entry-starts-from-its-own-expand
| /// The entry's own `lifetime`, from `lifetime` or `box.lifetime`. `None` | ||
| /// when the entry sets none. The expansion refuses a value that is not | ||
| /// one of [`Lifetime::ACCEPTED`] (see [`check_section`]), so an expanded | ||
| /// spec never reaches here with a bad value. | ||
| fn entry_lifetime(extra: &toml::Table, report: Option<&ExpansionReport>) -> Option<Lifetime> { | ||
| later_value(extra, report, "lifetime", "box").and_then(|value| value.clone().try_into().ok()) | ||
| } |
There was a problem hiding this comment.
LOW · correctness · confidence 0.50 · in entry_lifetime
entry_lifetime drops an invalid value with .ok() and relies on the expansion to refuse it. BoxSpec::for_task and BoxSpec::for_session call build with settings_of(extra) and never pass through check_section. A task or legacy [session] with lifetime = "until-stopped" still stores until_complete without an error. A task with a valid until_stopped now stores it, and before this change it stored until_complete. The doc comment says an expanded spec never reaches here with a bad value, which is false for these callers. Reject a bad value there, or limit the lifetime read to the expanded path.
What the reviewer checked
spec.rs:340
later_value(extra, report, "lifetime", "box").and_then(|value| value.clone().try_into().ok()); for_task passesSome((&settings_of(&task.extra), None)); check_section is called only at expand.rs:1454
Hand this to an agent
Act on a code-review finding.
File: crates/mfile/src/spec.rs
Lines: 336-342
Category: correctness
Severity: low (reviewer confidence 0.50)
Finding:
`entry_lifetime` drops an invalid value with `.ok()` and relies on the expansion to refuse it. `BoxSpec::for_task` and `BoxSpec::for_session` call `build` with `settings_of(extra)` and never pass through `check_section`. A task or legacy `[session]` with `lifetime = "until-stopped"` still stores `until_complete` without an error. A task with a valid `until_stopped` now stores it, and before this change it stored `until_complete`. The doc comment says an expanded spec never reaches here with a bad value, which is false for these callers. Reject a bad value there, or limit the lifetime read to the expanded path.
First verify this against the code yourself. It is model output and
may be wrong. If it is wrong, or the tradeoff was deliberate, say so
and change nothing.
👍 useful · 👎 noise — react to tell the reviewer. Replying works too, and says more.
Every type of an extends chain is a TypeDefaults layer, so a rank by layer alone tied them and the flat key won. The stored spec now ranks an origin by layer, then by the type's position in the chain, root first, as loadout_mode does. One ranking serves lifetime, timeout, hooks_on_resume and the package union. BoxEntryExpansion carries the chain to BoxSpec::for_session_entry.
|
Round 3 of 10 on a /revise note, pushed as
Verify Outside the task's
Converted to a draft: something above needs a person before review. Review threads the coder judged:
With [sessions.dev] declaring its own packages, secrets and an on_activate hook, and [sessions.dev.box] lifetime = "until_stopped", min session start dev and min box start dev store a spec that names dev and carries dev's body and until_stopped. When a derived Box Type sets box.lifetime and its parent sets a flat lifetime, the stored spec now takes the derived type's value. Notes from the agent: Round 3 answers arch C1 in commit 6a66a61. spec.rs has one Ranking (layer, then the type's position in the chain, root first) for lifetime, timeout, hooks_on_resume and the package union. BoxEntryExpansion carries type_chain from whole.type_defaults to BoxSpec::for_session_entry. The new test declares the entry as [boxes.dev] type = "b", because read_entries refuses type = "b" under [sessions.dev]. Foundry thread PRRT_kwDOPdfcxM64nNrB holds for the task path. task.rs calls BoxSpec::for_task with the raw [tasks.x] table, so build reads lifetime there without checking the value, and File::validate checks only timeout. The /revise note limits this round to C1, so I did not change that path. One fix is to read lifetime only for an expanded entry, where a ranking is present. That fix is in spec.rs. Ran cargo clippy -p mfile --all-targets and -p minimal --all-targets with no warnings, and cargo fmt. Did not run just ci or clippy-strict. |
There was a problem hiding this comment.
arch-review: PASS · the full ruling
The new commit ranks a value by its layer and then by its type's position in the extends chain, root first. So a derived type's [box] lifetime now beats its parent's flat lifetime. Line 1283 of architecture.md requires this: defaults in a chain are overridden by the more specific layer. The order is the same one that loadout_mode uses, and the new test checks the rule itself. The merge of main is clean. No condition is open.
Ruled at 6a66a61 against gominimal/arch@327e1b57d16b by claude-opus-5-5.
There was a problem hiding this comment.
minimal-review — approval withheld
Verdict COMMENT — APPROVE withheld: 7 unresolved threads — minimal-foundry[bot] crates/mfile/src/spec.rs, minimal-arch[bot] crates/mfile/src/spec.rs, minimal-arch[bot] crates/mfile/src/spec.rs, minimal-arch[bot] crates/minimal/src/cmd/boxes/create.rs, minimal-foundry[bot] crates/mfile/src/spec.rs, …. No findings.
Panel: 3 of 3 personas ran (correctness, security, supply-chain).
T53 — A typed session entry starts from its own expanded body and lifetime
slice: S3
kind: task
covers: BCLI-029, BCLI-071
size: M
est: 220 code, 200 tests
executor: agent
difficulty: needs care
model: strongest
diagnostics: none new; the
NamedSessionUnsupportedrefusal is removed, and the tests that pin it move with itobservability: none new
layers:
- mfile:
- crates/mfile/src/spec.rs:
BoxSpec::buildtakes the lifetime from the expanded spec instead of hard-codinguntil_complete; the spec tests pin both valuestest: cargo nextest run -p mfile box_spec_takes_lifetime_from_expansion
- client:
- crates/minimal/src/cmd/boxes/create.rs:
stamp_session_spec_asbuilds the create's spec fromsession_box_expansionfor the typed entry, not from[session];project_bep_and_grantsreads that expansion for secrets, env and the Box Egress Proxy;plan_startdropsNamedSessionUnsupportedand the #3204 interim comments- crates/minimal/src/tests.rs: tests
test: cargo nextest run -p minimal start_typed_session_entry_stores_its_own_body
test: cargo nextest run -p minimal session_entry_until_stopped_stores_until_stopped
produces: none
consumes: none
proof: With
[sessions.dev]declaring its own packages, secrets and anon_activatehook, and[sessions.dev.box] lifetime = "until_stopped",min session start devandmin box start devboth start the box. Its stored spec namesdevand carries dev's packages, secrets, hook anduntil_stopped, matchingmin box spec dev, andmin box restartreaches it.depends on:
- blocked by #3409
Proof
With [sessions.dev] that declares its own packages, a secret and an on_activate hook, and [sessions.dev.box] lifetime = "until_stopped", min session start dev and min box start dev both plan a session start. They are not refused now. The spec that the create stores names dev and carries dev's packages, dev's hook and until_stopped, and the activation grants dev's secret. The test creates that box on an in-process daemon, and min box spec renders the same stored spec. The tests do not run min box restart against the box.
Notes from the agent: crates/minimal/src/main.rs is outside the layers. Its failure_exit_code test listed StartEntryRefusal::NamedSessionUnsupported, so it did not compile after the removal. I removed only that one entry, as the task's diagnostics line says the pinning tests move with the refusal. project_bep_and_grants is now pub(crate) and takes the entry name, so tests.rs can check dev's secrets. Its return type changed from ProjectFileInvalid to anyhow::Error, and the error text for a broken file is the same. Behaviour change: a legacy [session] table reads as [defaults.session], so its packages, secrets and vars now reach every session entry through the expansion, typed entries included. Before this change, a typed entry got only the [session] body. stamp_session_spec_as also uses the picked entry's name for spec.entry when no entry is given (a bare activate of a sole [sessions.x] stores entry x, not default). BoxSpec::build also reads timeout and hooks_on_resume from their execution.* nested form. The mfile expansion merges these keys, and the spec reads the flat key first. pty_enabled stays true for every session spec. Not verified: min box restart on the started box (no test drives it), and the dashboard activation in dash/rpc.rs, which still builds no stored spec (a known gap that this change does not touch).
Tests
cargo nextest run -p mfile box_spec_takes_lifetime_from_expansioncargo nextest run -p minimal start_typed_session_entry_stores_its_own_bodycargo nextest run -p minimal session_entry_until_stopped_stores_until_stoppedVerify
min task run agent-verifyexited 100, so this PR is a draft.Base
The base branch moved while the coder worked; it was merged in before the tests ran.
Out of scope
These files are outside the task's
layers:, so this PR is a draft:crates/minimal/src/main.rsCloses #3486