Repository navigation
T2 — Write each box's lifecycle events where only the daemon can reach - #2654
mitodrummer merged 17 commits into
Conversation
Add the BoxEvent type and an events.jsonl file in the box's state directory, outside every path mounted into the box. Appends keep write order, and reads return complete lines from any offset (BOX-040, BOX-162).
The client asks for one box's events, with or without follow. The daemon answers one JSON line per event, then one terminal line (BOX-162).
The daemon writes the created event as it files the record, and serves ReadEvents: every retained event in write order, then new events for a follower until the box is reaped. The diag bundle copies each box's events file (BOX-040, BOX-041, BOX-162).
Clippy's assert_is_empty lint refused assert!(x.is_empty()) in the events tests. assert_eq! against an empty array shows the value on failure.
|
Important Review skippedThis PR was authored by a bot without an assigned CodeRabbit review seat. Ask an organization administrator to assign a seat to the bot. See the seat-assignment guide. After the seat is assigned, request a review again.
|
|
Reviewed: no findings; approval withheld, 2 threads unresolved at APPROVE withheld: 2 unresolved threads — minimal-arch[bot] crates/minimald/src/box_manager/tests.rs:2364, minimal-arch[bot] crates/minimald/src/box_manager.rs:2224. 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. Clobber: none seen. |
There was a problem hiding this comment.
arch-review: CONDITIONS · 2 conditions · the full ruling
The placement and the read path conform to architecture.md lines 378, 495 and 497. Two items block the merge. The BOX-041 test runs no process inside the box. It writes files from the test host, so it does not prove that root in the box cannot append. C1 replaces it with a real exec as root in the box. BOX-040 names nine event triggers, and this change writes only created. File an issue for the other eight and link it, as C2 states.
Ruled at 5bdd1c4 against gominimal/arch@109541a48c31 by claude-opus-5-5.
The discard_new_record block was inserted between the old doc comment and log_teardown_join, so the comment attached to the wrong function.
…-box-s-lifecycle-events-where-only-the
There was a problem hiding this comment.
arch-review: CONDITIONS · 4 conditions · the full ruling
The events file is in the right place, and only minimald writes it. Four gaps remain. BoxEvent has no data object, so exited and renamed cannot carry what line 378 requires (C1). The BOX-041 test runs no process inside a box, so it does not prove line 495 (C2). A line that does not parse is dropped, and the read still ends Done, against line 497 (C3). The triggers this task does not write have no issue (C4).
Ruled at db19fc7 against gominimal/arch@109541a48c31 by claude-opus-5-5.
|
Round 1 of 10 on the runtime's review findings, pushed as
Verify Review threads the coder judged:
A box's events read back in order, and a follow replays them and then tails new events until the box is reaped. This round changes only a misplaced doc comment. Notes from the agent: Revise round 1 moves a doc comment and changes no code. I did not run the boxes and minimald-rpc test lines again, because this round does not touch those crates. |
|
/revise Arch-review conditions C1–C3 on db19fc7. Round 1 handled only the doc comment. C4 (the residuals) is done in the PR body; leave that 1. C1: events carry a 2. C2: prove BOX-041 from inside a real box. Replace the planted-file body of 3. C3: a refused line fails the read, and a torn line can't absorb the next event. In Run the plan's test lines plus |
…-box-s-lifecycle-events-where-only-the
Each event carries a data object, empty for created, so the later exited and renamed writers can record their payloads. An append after a torn last line starts on a new line, and an append for a reaped box fails with NotFound instead of recreating its directory.
write_box_event takes the event's data map, and created passes an empty one. A complete line of the events file that is not an event makes read_new fail with InvalidData naming its offset, so a read ends with Failed rather than Done.
…-box-s-lifecycle-events-where-only-the
There was a problem hiding this comment.
arch-review: PASS_WITH_CONDITIONS · 1 condition · the full ruling
The events log conforms to the design. It sits beside the record, outside every directory that the box gets, and only minimald writes it. A read replays the full stream, and follow then tails until reap (lines 378 and 497). The proof of BOX-041 is weak. in_box_root_cannot_append_events runs no process inside a box, but line 495 says the record is unwritable from inside the box, root included. C1 adds a root test in a real sandbox in the existing _root_integration lane. Or file C1 as an issue and list it under Residuals.
Ruled at 1a12832 against gominimal/arch@109541a48c31 by claude-opus-5-5.
|
Round 2 of 10 on a /revise note, pushed as
Verify Review threads the coder judged:
A box's events read back in the order the daemon wrote them, each with a data object (empty for created), and a followed read replays them and then tails new events until the box is reaped. A read that meets a line that is not an event now ends with Failed and names the byte offset, and an event appended after a torn last line stays readable. Notes from the agent: C1: BoxEvent has |
|
/revise Three changes on 1a12832. Leave the PR body's 1. arch-review C1, doc only. Change the doc comment on 2. minimal-review MEDIUM, crates/minimald/src/box_manager.rs:2289: a torn line must not become a permanently unreadable line. Today 3. minimal-review LOW, crates/minimald/src/box_manager.rs:2312. In Run the plan's test lines plus |
A torn last line was never acknowledged, so dropping it loses no event. The old leading newline left a line that failed every later read.
Also scope the in-box append test's doc comment to placement. The uid-0 proof from a real sandbox belongs to #2661.
…-box-s-lifecycle-events-where-only-the
There was a problem hiding this comment.
arch-review: CONDITIONS · 1 condition · the full ruling
The follow fix conforms. The torn-line cut in DiskBox::append_event does not. It reads the tail and then calls set_len with no lock. A concurrent append can cut an event that another append already acknowledged. Architecture line 497 says that a read returns the full retained stream of the box. Do C1: lock the events file through the cut, the write and the sync.
Ruled at b9e6232 against gominimal/arch@109541a48c31 by claude-opus-5-5.
|
Round 3 of 10 on a /revise note, pushed as
Verify Review threads the coder judged:
1 thread was already answered in earlier rounds, with nothing new on it since. A box's events read back in order, and a follow tails them until the box is reaped. A crash that tears the last line no longer makes the stream unreadable: the next append cuts the torn bytes, and every later read and follow succeeds. Notes from the agent: Item 1: only the doc comment on in_box_root_cannot_append_events changed. It now says the test proves placement only and points to the _root_integration test that #2661 owns. Item 2: DiskBox::append_event cuts the file back to just after its last newline (or to 0) when the last byte is not a newline, logs a warn! with box_id and dropped_bytes, then appends. read_new still returns InvalidData on a refused line. The test is now append_after_a_torn_line_drops_the_fragment and also covers a file that holds only a torn line. Item 3: next_events reads once more when is_retained is false, and returns None only if that read is empty. I added no test for item 3. The harness cannot put a write between the first read_new and the is_retained check without a seam inside next_events. A reap also moves or deletes the directory, so the extra read usually finds no file. The thread entry for PRRT_kwDOPdfcxM6whHMV keeps the verdict valid, and its note gives the new reason, as the note in the directive asks. Not run: just clippy-strict. |
|
/revise Two fixes on b9e6232. Leave the PR body's 1. arch-review C1: lock the events file across the cut and the write (crates/boxes/src/store.rs 2. minimal-review HIGH, crates/minimald/src/diag.rs:716: the bundle must not ship Run the plan's test lines plus |
Two appends could both see one torn tail, and the second cut removed the first append's event after it returned Ok.
An event's data can carry box names and exit reasons, so each line goes through the record's redaction. A line that does not decode is withheld.
There was a problem hiding this comment.
arch-review: PASS_WITH_CONDITIONS · 1 condition · the full ruling
The two new commits fix the open defects on b9e6232e. The events append now holds a file lock across the cut and the write, so file order stays write order (architecture.md line 497). The diag bundle now redacts each events line like the record (lines 333 and 380). One leg stays open. The BOX-041 proof from inside a real sandbox is #2661, which C1 carries forward. The change can merge with C1 open.
Ruled at 3f89971 against gominimal/arch@109541a48c31 by claude-opus-5-5.
There was a problem hiding this comment.
minimal-review — approval withheld
Verdict COMMENT — APPROVE withheld: 12 unresolved threads — minimal-arch[bot] crates/minimald/src/box_manager/tests.rs:2364, minimal-arch[bot] crates/minimald/src/box_manager.rs:2224, minimal-arch[bot] crates/boxes/src/events.rs:62, minimal-arch[bot] crates/minimald/src/box_manager.rs:2224, minimal-arch[bot] crates/minimald/src/box_manager/tests.rs:2364, …. No findings.
Panel: 3 of 3 personas ran (correctness, security, supply-chain).
|
Round 4 of 10 on a /revise note, pushed as
Verify Review threads the coder judged:
A box's events read back in the order they were written, and a follow replays them and then tails new ones. Two concurrent appends after a torn tail now keep every event. The diag bundle carries each events line redacted like the record, so a secret-keyed value in an event's data does not leave the machine. Notes from the agent: Round 4. C1: append_event now takes std File::lock after the open, before the length read, and holds it through complete_len, set_len, write_all and sync_data. The lock drops with the file. The doc comment now names the lock, not O_APPEND, as the reason two writers never interleave. New test concurrent_appends_after_a_torn_line_keep_every_event runs two threads behind a barrier, 50 appends each. The race window is narrow, so this test passing does not prove it fails without the lock. HIGH: diag.rs now reads the tail of events.jsonl itself (no-follow open, capped at MAX_SESSION_FILE_BYTES, with the partial first line dropped when it is capped), runs each line through redact_json, and writes each back as one compact line. A line that does not decode becomes the fixed JSON string "<withheld: event line is not JSON>". The manifest marks the file Keys, or TailCapped when the cap applies. The diagnostics crate has no variant for both, and it is outside this task's layers. New test diag_bundle_redacts_box_events_data. The PR body Residuals section is untouched. I did not run just clippy-strict. cargo clippy -p minimald -p boxes --all-targets is clean. |
There was a problem hiding this comment.
minimal-review — approved
Verdict APPROVE — every review thread is resolved; @mitodrummer closed the last one. The review of 3f8997102f26 withheld this approval on the threads open then. Posted as a comment: the App cannot approve its own pull request; the check and the label carry it.
|
/revise Merge crates/boxes/src/lib.rs, the module list. Main's #2614 replaced pub use client_config::keys;
pub mod events;If anything in this branch's own code used the old Run the plan's test lines plus |
…-box-s-lifecycle-events-where-only-the # Conflicts: # crates/boxes/src/lib.rs
There was a problem hiding this comment.
arch-review: PASS_WITH_CONDITIONS · 2 conditions · the full ruling
This head adds only a merge of main (#2614). The merge does not change the PR's own lines, so the ruling on 3f899710 stands. The events file is in the record, outside the box filesystem, as architecture.md lines 495 and 497 require. The proof for in-box root is by placement only. C1 keeps that leg open until #2661 adds the real-sandbox test. C2 lists the other BOX-040 triggers that later tasks write.
Ruled at 081327d against gominimal/arch@109541a48c31 by claude-opus-5-5.
|
@coderabbitai review |
|
|
Round 5 of 10 on a /revise note, pushed as Resolved conflicts in:
Verify Converted to a draft: something above needs a person before review. A box's events read back in order, and follow tails. The branch now carries origin/main and the events tests still pass. Notes from the agent: Merged origin/main and resolved the one conflict in crates/boxes/src/lib.rs as the directive gave it: |
|
@coderabbitai full review |
mitodrummer
left a comment
There was a problem hiding this comment.
Approved at 081327d. Only the daemon writes created, into a stream outside every directory the box can see. An append holds the file lock through the torn-tail cut, the write and the sync. A refused line ends a read with Failed, and a follow ends with Reaped only after a final empty read. The diag bundle redacts each event line like the record. Residuals: #2661 (the uid-0 proof in a real sandbox), the other triggers' tasks, and #2658.
|
T2 — Write each box's lifecycle events where only the daemon can reach
slice: S0
kind: task
covers: BOX-040, BOX-041, BOX-162
size: L
est: 380 code, 380 tests
executor: agent
difficulty: needs care
model: strongest
diagnostics: state collection copies events; daemon log names refusals
observability: one log line per event written
layers:
- events:
- crates/boxes/src/events.rs (new): event type
- crates/boxes/src/lib.rs: mod line
- crates/boxes/src/store.rs: per-record events file
test: cargo nextest run -p boxes events_file_appends_in_write_order
- daemon:
- crates/minimald/src/box_manager.rs: created event; read and follow
- crates/minimald/src/box_manager/tests.rs: tests
- crates/minimald/src/rpc.rs: events read handler
- crates/minimald/src/diag.rs: copies events file
test: cargo nextest run -p minimald events_written_outside_box_filesystem_with_box_parent_ts_type
test: cargo nextest run -p minimald in_box_root_cannot_append_events
test: cargo nextest run -p minimald events_read_returns_full_retained_stream_in_order
test: cargo nextest run -p minimald events_follow_replays_then_tails_until_reaped
- wire:
- crates/minimald-rpc/src/lib.rs: events read request
test: cargo nextest run -p minimald-rpc read_events_request_round_trips
produces:
- crates/boxes/src/events.rs
consumes:
- crates/boxes/src/core/record.rs
proof: A box's events read back in order, and follow tails.
depends on:
- blocked by #2387
Proof
A client that opens the minimald-v1-ReadEvents subsystem for a box gets every event of that box back in the order the daemon wrote it, starting with the created event that the daemon writes when it files the record. With follow set, the same read stays open, sends each new event as the daemon writes it, and ends with a Reaped line when the box is reaped. The tests events_read_returns_full_retained_stream_in_order and events_follow_replays_then_tails_until_reaped show both over the real RPC.
Notes from the agent: Events are stored as one JSON line per event in sessions//events.jsonl, beside record.json, with mode 0600. No directory mounted into the box (tree, home, cache, patches, hooks) contains this file. BOX-041 is enforced by where the file lives and by the absence of any append RPC. The in_box_root test plants forged files in every directory the box can see, and shows that the read ignores them. It does not start a real sandbox. This task writes only the created event. The other event types (started, exec_started, exec_exited, oom_killed, exited, renamed, resumed, detached) exist in BoxEventType, and later tasks must call box_manager::write_box_event at those triggers. The ts field is Unix milliseconds (UTC), because boxes has no chrono dependency, and Cargo.toml was not in the layers. A follower sees a reap by a 200 ms poll of the record (record.json present and no .deleting- tombstone), because a reap has several delete paths and none of them wakes the follower. A new event wakes the follower at once through a daemon-wide watch counter. If the created event cannot be written, the create fails and deletes the record, as a spec that cannot be stored already does. Extra test coverage added inside the layer files: two unit tests in events.rs and diag_bundle_copies_box_events in diag.rs. The ReadEvents refusal and failure texts reach a client only on the channel. No CLI prints them yet. Not run: just ci, just clippy-strict, and the full crate su…[truncated]
Tests
cargo nextest run -p boxes events_file_appends_in_write_ordercargo nextest run -p minimald events_written_outside_box_filesystem_with_box_parent_ts_typecargo nextest run -p minimald in_box_root_cannot_append_eventscargo nextest run -p minimald events_read_returns_full_retained_stream_in_ordercargo nextest run -p minimald events_follow_replays_then_tails_until_reapedcargo nextest run -p minimald-rpc read_events_request_round_tripsVerify
min task run agent-verifypassed ([tasks.verify]).Residuals
This task writes
created. Each other BOX-040 trigger is written by the task that owns it, throughbox_manager::write_box_event:started: T42 — Start every box's entrypoint from its spec through one launcher #2399 (T42, the entrypoint start), and T6 — Resume a stopped box from its stored spec #2393 (T6) when a resume starts it again.exec_started,exec_exited: T31 — Keep terminal and detached execs past a client loss, stop one exec, and honour exec_enabled #2406 (T31, BOX-152).oom_killed: Write the oom_killed lifecycle event when the kernel kills a process in a box #2658 (needs the resources spec, gominimal/inbox#698).exited: T3 — Stop a box and keep its record #2390 (T3, BOX-013 and BOX-154), T9 — End a box when its entrypoint returns, never for idleness or client loss #2401 (T9, BOX-038), T43 — Run a task as a task box that returns its exit code #2405 (T43, the task box), T20 — End an until-complete box at its timeout, and rerun activation hooks on resume when asked #2415 (T20, BOX-037).renamed: T12 — Keep a name unique only among running boxes #2396 (T12, BOX-010).resumed: T6 — Resume a stopped box from its stored spec #2393 (T6, BOX-025).detached: T10 — Log a box's output from its start, out of the box's reach #2402 (T10, BOX-016).BOX-041 from inside a real box: #2661. This PR proves placement only: the stream is outside every directory the box can see. The uid-0 probe in a real sandbox is the
_root_integrationtest that #2661 adds (arch-review C1).Closes #2389