Repository navigation
feat: T132 — Claim each export from the daemon before copying, and record a file_exported event for each - #3489
Conversation
ClaimExports grants a connection each export of the box's last end that no live connection holds and no command reported (BOX-198). ReportExport appends a file_exported event (BOX-195). A claim whose connection ended is released for the next command (BOX-202).
The command that waits claims the exports of the box's end first (BOX-198), copies only the granted ones, and names each refused one on stderr (BOX-201). It reports each export so the record holds a file_exported event (BOX-195). A failed report is named (BOX-200), and the copy stops, so a lost connection renames no further file (BOX-202).
…-export-from-the-daemon-before-copying
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
|
Reviewed: 1 finding, none blocking at Address the comments on the diff. Clobber: none seen: the diff only removes the interim comments that this task replaces. |
There was a problem hiding this comment.
arch-review: CONDITIONS · 2 conditions · the full ruling
This ruling sets two conditions. First, the daemon keeps a held export claim only in memory. Spec 29 BOX-198 says to write the claim to the box's record before the copy starts, and design line 512 uses that mechanism. C1 moves the grant onto the record. Second, when the box's files cannot be opened after the grant, the granted exports are skipped without a report, so the record gets no file_exported event (line 518). C2 reports each of them as not copied. The other requirements conform.
Ruled at 7ed97fa against gominimal/arch@327e1b57d16b by claude-opus-5-5.
| /// ended is released here: the next claim for that export replaces it. A | ||
| /// reported export is also on the record as a `file_exported` event, so a | ||
| /// daemon that restarts still refuses it. | ||
| static EXPORT_CLAIMS: std::sync::LazyLock< |
There was a problem hiding this comment.
C1 · A held claim is stored only in this static map, and it does not go to the box's record until the report. Spec 29 BOX-198 says to record the claim on the box's record before the copy starts. Design line 512 uses that mechanism. Write the grant to the record in claim_exports, and keep this map only as a cache of liveness.
There was a problem hiding this comment.
Disputed — not addressed: A claim entry on the record needs a new event type in crates/boxes/src/events.rs (BoxEventType), which is outside this task's layers. The in-memory claim is granted under one lock with the last events read, so two commands never hold one export. This is noted for a follow-up task.
There was a problem hiding this comment.
Addressed in 4e9da1b727f3: Per the arch ruling: claim_exports now writes each grant to export_claims.jsonl in the box's state directory, under the refusal lock, before it returns. The refusal check reads those lines, and EXPORT_CLAIMS only caches live connections.
| Err(e) => { | ||
| tracing::warn!(box_id = %id, "file exports: open the box's files: {e:#}"); | ||
| return not_copied(err, "min could not read the box's files"); | ||
| return not_copied(err, &granted, "min could not read the box's files"); |
There was a problem hiding this comment.
C2 · These exports are granted and skipped, but they are not reported. The record gets no file_exported event for them (design line 518), and the next wait copies them again (line 512). Report each granted path with copied: false and files: [] before you return.
There was a problem hiding this comment.
Addressed in d43adf08fc3a: Added report_not_copied: when the box's files cannot be opened, each granted export is reported with copied false and no files, and a lost report is named on stderr.
| claims.retain(|_, claim| match claim { | ||
| ExportClaim::Held(live) => live.strong_count() > 0, | ||
| ExportClaim::Reported => true, | ||
| }); |
There was a problem hiding this comment.
LOW · correctness · confidence 0.60 · in EXPORT_CLAIMS
ExportClaim::Reported entries stay in EXPORT_CLAIMS for the life of the daemon. The retain in claim_exports keeps them, and nothing removes them when a box is deleted. The map grows with every export of every box end. The file_exported event on the record already refuses a re-claim, even after a restart, so the in-memory entry only closes the window between the report and the next event read. Drop the Reported entry when the event is written, or prune entries for deleted boxes.
What the reviewer checked
claims.retain(|_, claim| match claim { Held(live) => live.strong_count() > 0, Reported => true })
Hand this to an agent
Act on a code-review finding.
File: crates/minimald/src/box_manager.rs
Lines: 6221-6224
Category: correctness
Severity: low (reviewer confidence 0.60)
Finding:
`ExportClaim::Reported` entries stay in `EXPORT_CLAIMS` for the life of the daemon. The `retain` in `claim_exports` keeps them, and nothing removes them when a box is deleted. The map grows with every export of every box end. The `file_exported` event on the record already refuses a re-claim, even after a restart, so the in-memory entry only closes the window between the report and the next event read. Drop the `Reported` entry when the event is written, or prune entries for deleted boxes.
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 d43adf08fc3a: report_export now removes the entry once the file_exported event is written. claim_exports reads the newest events while it holds the claims lock, so the event refuses the export without the entry.
| if !ended || end == 0 { | ||
| tracing::info!( | ||
| session_id = %record.id, | ||
| status = ?record.status, | ||
| end, | ||
| "export claim: the box has not ended; nothing is granted" | ||
| ); | ||
| return Err(std::io::Error::new( | ||
| std::io::ErrorKind::InvalidInput, | ||
| "the box is running again, so its files can change", | ||
| )); |
There was a problem hiding this comment.
LOW · printed-text · confidence 0.50 · in claim_exports
The same error covers a box that is not in Stopped or Exited and a box with no exited event (end == 0). The client prints it on stderr. A stopped box with no exited event is not running again, so the text "the box is running again" is wrong for it. Say only what the code can prove, for example that the box has not ended, and name the next step.
What the reviewer checked
if !ended || end == 0 { ... "the box is running again, so its files can change" }
Hand this to an agent
Act on a code-review finding.
File: crates/minimald/src/box_manager.rs
Lines: 6187-6197
Category: printed-text
Severity: low (reviewer confidence 0.50)
Finding:
The same error covers a box that is not in `Stopped` or `Exited` and a box with no `exited` event (`end == 0`). The client prints it on stderr. A stopped box with no `exited` event is not running again, so the text "the box is running again" is wrong for it. Say only what the code can prove, for example that the box has not ended, and name the next step.
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 d43adf08fc3a: A box with no exited event now gets "the box has not ended". Only a box with an end that runs again gets the running-again reason. The test pins the new text.
…-export-from-the-daemon-before-copying
The claim lock now covers the last read of the box's events, so the file_exported event refuses the export once the entry goes. A box with no end gets a refusal that says it has not ended.
When the box's files cannot be opened, each granted export now gets a file_exported report with copied false and no files, so the record holds an entry for it and the next wait does not copy it again.
|
/revise Arch ruling 1344 on 7ed97fa set two conditions. Do both. In full:
For C1, Karl ruled on 2026-11-17 that a granted claim is written to the box's record, as C1 says first. Do not take the in-memory alternative, and do not amend BOX-198. The tests this task names must still pass. Do not rewrite history and do not force-push. |
|
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. |
|
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:
Two commands that wait on one ended task box copy each export once. The second command names each export the first one holds or reported. A command whose connection ends mid-copy leaves its unreported exports to the next wait. The box's record holds one file_exported event for each export, including exports that min could not read, and keeps the entrypoint's exit code. Notes from the agent: Thread C1 (record the claim on the box's record) is not done. A claim event on the record needs a new BoxEventType variant in crates/boxes/src/events.rs, and that file is outside this task's layers. The claim is atomic in the daemon's memory, and a held claim of a dead connection is released on restart, so the guarantee of BOX-198 holds. The wording of BOX-198 asks for a record entry, so a follow-up task in crates/boxes is needed if the spec keeps that wording. The refusal for a box with no end now says "the box has not ended". The daemon does not know the box label, so this reason names no next step. |
|
/revise Addendum to the held note on arch ruling 1344. Round 1 left C1 undone because a claim event needs a new |
|
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. |
There was a problem hiding this comment.
APPROVE withheld: 4 unresolved threads — minimal-arch[bot] crates/minimald/src/box_manager.rs:6134, minimal-arch[bot] crates/minimal/src/cmd/boxes/exports.rs, minimal-foundry[bot] crates/minimald/src/box_manager.rs, minimal-foundry[bot] crates/minimald/src/box_manager.rs:6205.
minimal-review — advisory review
Verdict COMMENT — No findings.
Panel: 1 of 3 personas ran (correctness); did not complete: security, supply-chain.
There was a problem hiding this comment.
arch-review: CONDITIONS · 1 condition · the full ruling
The claim, the report and the file_exported event conform to File exports, lines 512 and 518, and to the event fields on line 382. The compare fixes the unreadable-export report and the claim-map entry. One edit is left. This PR closes #3446, but wait.rs, attach.rs and task.rs still carry interim notes that say BOX-195 and BOX-198 are later work in #3446. The wait.rs note also says that each wait copies again, which line 512 forbids and this PR stops. Make the comment edits in C1.
Outside the diff
crates/minimal/src/cmd/boxes/wait.rs:237: C1 · This interim note says that each wait copies again, and that BOX-198 and BOX-195 are later work in #3446. This PR closes #3446, and line 512 of File exports forbids a second copy. Keep only the BOX-193 (#3445) part.crates/minimal/src/cmd/boxes/attach.rs:1526: C1 · RemoveBOX-195 and BOX-198, gominimal/minimal#3446from this interim note. This PR lands both requirements.crates/minimal/src/task.rs:2089: C1 · Remove the clause that says nofile_exportedevent records the outcomes (BOX-195, #3446). This PR appends that event for each export.
Ruled at d43adf0 against gominimal/arch@327e1b57d16b by claude-opus-5-5.
The grant is a line in the box's export_claims.jsonl, with the connection id and this daemon run's boot id, written under the lock of the refusal check. The check reads those lines. EXPORT_CLAIMS now caches only which connections are live (BOX-198, BOX-202).
The open of the box's files is a parameter of the copy, so a test can fail it after a real grant. The test reads back one file_exported event with copied false for each granted export.
|
/revise Arch ruling 1344 on 7ed97fa set two conditions. Do both. In full:
For C1, Karl ruled on 2026-11-17 that a granted claim is written to the box's record, as C1 says first. Do not take the in-memory alternative, and do not amend BOX-198. The tests this task names must still pass. Do not rewrite history and do not force-push. Addendum to the held note on arch ruling 1344. Round 1 left C1 undone because a claim event needs a new |
|
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. |
|
/revise First merge origin/main into this branch and resolve the conflicts: T131 (#3487) merged at about 04:10Z on 2026-11-17 and changed Arch ruling 1344 on 7ed97fa set two conditions. Do both. In full:
For C1, Karl ruled on 2026-11-17 that a granted claim is written to the box's record, as C1 says first. Do not take the in-memory alternative, and do not amend BOX-198. The tests this task names must still pass. Do not rewrite history and do not force-push. Addendum to the held note on arch ruling 1344. Round 1 left C1 undone because a claim event needs a new |
|
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. |
|
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:
Two commands that wait on one ended task box each get a disjoint set of exports, because the daemon writes each grant to the box's record before it answers. A command killed mid-copy leaves its unreported exports free for the next wait, because a claim holds only while its connection is live on the same daemon run. The record holds a file_exported event for each export, also when min cannot open the box's files after the grant, and the entrypoint's exit code stays unchanged. Notes from the agent: C1: claim_exports now appends one line per grant to export_claims.jsonl in the box's state directory, beside events.jsonl. Each line holds the box id, end, path, connection id and the boot id of this daemon run. The append is synced under the same lock as the refusal check, and a failed append grants nothing. The refusal check reads those lines. A line is released when its boot id is not this run or its connection is not live (BOX-202), or when a file_exported event for that end and path exists. EXPORT_CLAIMS is now only a cache of live connection ids. Dead connections leave it, and ids are not reused, so the earlier growth finding no longer applies. report_export checks the record lines and writes the event under the same lock, so one claim is reported once. I chose a file beside events.jsonl over a new event type, because a new BoxEventType variant needs crates/boxes/src/events.rs, which is outside the layers, and it would show in the box's event listing. If the reviewer reads 'the box's record' as events.jsonl only, that change needs the boxes crate. The test export_claim_granted_once_for_each_end now asserts that the record holds both grants before any report. The disconnect test also asserts that a claim line from an earlier daemon run holds nothing. C2: the report of each granted export with copied false was already on the branch (d43adf0, report_not_copied, which prints report_lost_line on a failed report). This round adds the open of the box's files as…[truncated] |
…-export-from-the-daemon-before-copying Keep the export claim and report from this branch, and the exit code 125 from T131 on main. The skip lines of the claim use the one form that T131 fixes: Export <path> was not copied: <why>.
|
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. |
|
Round 4 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:
When two commands wait on one task box's end, each export is copied once. A command that is killed mid-copy leaves its unreported exports to the next wait. The box's record holds one file_exported event for each export and the entrypoint's exit code. A refused export now prints a line that names the box and points to Notes from the agent: Round 4. The refused-export line changed to: "Export of box was not copied: another min command claimed it. Run |
There was a problem hiding this comment.
arch-review: PASS_WITH_CONDITIONS · 1 condition · the full ruling
The claim, the release and the file_exported report conform to File exports lines 512 and 518, and the refused-export line now names the box (BOX-201). One edit is left. Three interim comments in wait.rs, attach.rs and task.rs still say that no claim gates the copy and that no event is written. They name #3446, and this PR closes that issue. Remove them as C1 says. The verify step exited 101, so make sure the head builds before the merge.
Outside the diff
crates/minimal/src/cmd/boxes/wait.rs:241: C1 · This interim comment is false after this PR.copy_box_exportsnow claims each export (BOX-198), so a later wait does not copy again or return 125 again. Remove lines 241-248.crates/minimal/src/cmd/boxes/attach.rs:1530: C1 · This interim comment is false after this PR. The claim gates the copy and each export is reported. Remove lines 1530-1532.crates/minimal/src/task.rs:2112: C1 · This interim note is false after this PR. The outcomes are now reported asfile_exportedevents. Remove the interim sentences on lines 2112-2114.
Ruled at 87a83d3 against gominimal/arch@327e1b57d16b by claude-opus-5-5.
The daemon also refuses an export whose earlier report said copied: false, so the line no longer says another command copied it. Remove the interim notes that this change makes untrue.
|
Round 5 of 10 on a /revise note, pushed as
Verify Outside the task's
Converted to a draft: something above needs a person before review. Two commands that wait on the same ended task box copy each export once. A command killed during a copy leaves its unreported exports for the next wait. The box's record holds one file_exported event for each export and the entrypoint's exit code. A refused export now prints: Export was not copied: another min command holds it or has already reported its result. Run Notes from the agent: Revise round 5. (1) Arch ruling C1: I removed the three interim notes that named #3446, in crates/minimal/src/task.rs, crates/minimal/src/cmd/boxes/wait.rs and crates/minimal/src/cmd/boxes/attach.rs. These three files are outside the task's layers. The /revise note asked for these changes by name. (2) claimed_elsewhere_line now prints the exact text from the note, with the box name filled in from its existing label parameter. refused_export_claim_copies_nothing pins it. The note's wording names the box only inside the |
There was a problem hiding this comment.
arch-review: PASS · the full ruling
The compare conforms. The refused-export line now says that another command holds the export or already reported its result. That is true for each refusal, because line 512 makes a recorded result final. The line still names the path and the box, as BOX-201 requires. The interim notes for #3446 are gone, and this PR implements what they waited for. Make the verify run green before you take the PR out of draft.
Ruled at 1d58549 against gominimal/arch@327e1b57d16b by claude-opus-5-5.
| && read_export_claims(&reader.object).is_ok_and(|entries| { | ||
| entries.iter().any(|entry| { | ||
| entry.box_id == record.id | ||
| && entry.end == report.end | ||
| && entry.path == report.path | ||
| && entry.connection == connection | ||
| && holders.holds(entry) | ||
| }) | ||
| }) | ||
| }); | ||
| if !holds { | ||
| tracing::info!( | ||
| session_id = %record.id, | ||
| end = report.end, | ||
| export = %report.path, | ||
| connection = ?connection, | ||
| "export report refused: this connection does not hold the export" | ||
| ); | ||
| return Err(std::io::Error::new( | ||
| std::io::ErrorKind::PermissionDenied, |
There was a problem hiding this comment.
LOW · correctness · confidence 0.50 · in report_export
report_export turns a failed read of the claims file into false with is_ok_and. The caller then gets PermissionDenied with "this command does not hold the export". The claim is held, and the real cause is an I/O error. The client cannot tell the two apart. Return the I/O error instead of the refusal.
What the reviewer checked
read_export_claims(&reader.object).is_ok_and(|entries| { ... }) then PermissionDenied if !holds
Hand this to an agent
Act on a code-review finding.
File: crates/minimald/src/box_manager.rs
Lines: 6454-6473
Category: correctness
Severity: low (reviewer confidence 0.50)
Finding:
`report_export` turns a failed read of the claims file into `false` with `is_ok_and`. The caller then gets `PermissionDenied` with "this command does not hold the export". The claim is held, and the real cause is an I/O error. The client cannot tell the two apart. Return the I/O error instead of the refusal.
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.
Tracked in #3493: return the I/O error when the claims file cannot be read, and keep the refusal for a read that shows the command does not hold the claim.
There was a problem hiding this comment.
Addressed in 077972628c88: report_export now returns the I/O error when the claims file cannot be read, in place of PermissionDenied. A test in export_claim_granted_once_for_each_end pins this.
A claims file that cannot be read returned PermissionDenied, as if the command did not hold the export. Return the I/O error instead.
|
Round 6 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:
Two commands that wait on one task box's end copy each export once. A command killed mid-copy leaves its unreported exports to the next wait. The box's record holds a file_exported event for each export and the entrypoint's exit code. This round: an export report whose claims file cannot be read now fails with that I/O error, not with a refusal that says the command does not hold the export. Notes from the agent: Revise round 6: one thread. report_export now propagates the read error of the claims file and logs it. The test export_claim_granted_once_for_each_end replaces the claims file with a directory, checks that the report fails with an error that is not PermissionDenied, then restores the file and checks that the report succeeds. I did not run just clippy-strict or a full workspace run. |
There was a problem hiding this comment.
arch-review: PASS · the full ruling
This push changes one thing. When the claims file cannot be read, report_export now returns the I/O error and not a refusal. No event is appended on either path, so the daemon fails closed. The client treats any report error as a lost report and stops the copy. Then the next wait copies the export, as File exports line 512 states. The ruling on 1d585493 stands for the rest of the change.
Ruled at 0779726 against gominimal/arch@327e1b57d16b by claude-opus-5-5.
|
Round 7 of 10 on a failed check suite: the coder changed nothing. A person needs to take it from here. |
T132 — Claim each export from the daemon before copying, and record a file_exported event for each
slice: S2
kind: task
covers: BOX-195, BOX-197, BOX-198, BOX-200, BOX-201, BOX-202
size: L
est: 260 code, 300 tests
executor: agent
difficulty: needs care
model: strongest
diagnostics: each skipped or refused export is named on stderr with its path
observability: the box's record carries a file_exporte 8000 d event for each export
layers:
- rpc:
- crates/minimald-rpc/src/lib.rs: the claim request and reply, and the export report
- daemon:
- crates/minimald/src/rpc.rs: serve the claim and the report
- crates/minimald/src/box_manager.rs: grant each export of an end once, record the claim, release unreported exports when the claiming connection ends (BOX-202), append
file_exported(BOX-195)- crates/minimald/src/box_manager/tests.rs: tests
test: cargo nextest run -p minimald export_claim_granted_once_for_each_end
test: cargo nextest run -p minimald export_claim_released_for_unreported_exports_on_disconnect
- client:
- crates/minimal/src/cmd/boxes/exports.rs: claim before copying, copy only granted exports, report each, stop copying when the connection ends
- crates/minimal/src/tests.rs: tests
test: cargo nextest run -p minimal export_report_appends_file_exported_event
test: cargo nextest run -p minimal skipped_export_leaves_record_exit_code
test: cargo nextest run -p minimal lost_export_report_named_exit_unchanged
test: cargo nextest run -p minimal refused_export_claim_copies_nothing
produces: none
consumes:
- crates/minimal/src/cmd/boxes/exports.rs
proof: two commands wait on one task box's end, and each export is copied once; a command killed mid-copy leaves its unreported exports to the next wait; the record holds a file_exported event per export and the entrypoint's exit code.
depends on:
- blocked by #3444
Proof
Two commands can wait on one ended task box, and each export is copied once. The second command prints one line for each export that the first command holds or reported, and copies none of them. When a command that holds a claim loses its connection before it reports an export, the next
min box waitcopies that export.min box events <box>shows one file_exported event for each export, with its path, whether it was copied, and each file with its size and sha256. The record keeps the entrypoint's own exit code, so a latermin box waitreturns the same code. refused_export_claim_copies_nothing and export_report_appends_file_exported_event show this against a real daemon in the test harness.Notes from the agent: Out of scope: crates/boxes/src/events.rs. BoxEventType had no file_exported variant, and BoxEvent.kind is that enum, so the daemon cannot write the event without it. The change adds the FileExported variant and its name only.
Claim storage: the daemon keeps a held claim in memory (a static map in box_manager.rs), under a weak reference to the connection's liveness token (ConnectionHandle::liveness). A claim whose connection ended is released at the next claim. A reported export is also in the record as a file_exported event that carries an
end(the count of exited events), so a daemon restart still refuses it. A held claim that is not reported is not on disk, so a daemon restart releases it. That agrees with BOX-202, because the connection ends with the daemon.BOX-202 client side: minimal-client has no public check for a closed connection, and that crate is outside the layers. So after a failed report the copy stops, and each remaining export gets one stderr line. Those exports are unreported, and the daemon releases them when the command's connection ends. While a directory export is in progress, a lost connection makes the box-side reads fail, so no further file is renamed into place. A small window remains between a whole read and it…[truncated]
Tests
cargo nextest run -p minimald export_claim_granted_once_for_each_endcargo nextest run -p minimald export_claim_released_for_unreported_exports_on_disconnectcargo nextest run -p minimal export_report_appends_file_exported_eventcargo nextest run -p minimal skipped_export_leaves_record_exit_codecargo nextest run -p minimal lost_export_report_named_exit_unchangedcargo nextest run -p minimal refused_export_claim_copies_nothingVerify
min task run agent-verifyexited 101, 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/boxes/src/events.rsCloses #3446