Skip to content

T2 — Write each box's lifecycle events where only the daemon can reach - #2654

Merged
mitodrummer merged 17 commits into
mainfrom
agent/2389-write-each-box-s-lifecycle-events-where-only-the
Oct 27, 2026
Merged

mitodrummer merged 17 commits into
mainfrom
agent/2389-write-each-box-s-lifecycle-events-where-only-the

Conversation

@minimal-foundry

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

Copy link
Copy Markdown
Contributor

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

line exit tail
cargo nextest run -p boxes events_file_appends_in_write_order 0 Applying loadouts: default Running task runtime-implement-test-0 in session task-runtime-implement-test-0-6733... Compiling args v0.0.1 (/workbench/crates/args) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling paths v0.0.1 (/workbench/crates/paths) Compiling common v0.0.1 (/workbench
cargo nextest run -p minimald events_written_outside_box_filesystem_with_box_parent_ts_type 0 Applying loadouts: default Running task runtime-implement-test-1 in session task-runtime-implement-test-1-b2f8... Compiling args v0.0.1 (/workbench/crates/args) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling paths v0.0.1 (/workbench/crates/paths) Compiling stdlib v0.0.22 (/workbenc
cargo nextest run -p minimald in_box_root_cannot_append_events 0 Applying loadouts: default Running task runtime-implement-test-2 in session task-runtime-implement-test-2-69df... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald events_read_returns_full_retained_stream_in_order 0 Applying loadouts: default Running task runtime-implement-test-3 in session task-runtime-implement-test-3-c414... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald events_follow_replays_then_tails_until_reaped 0 Applying loadouts: default Running task runtime-implement-test-4 in session task-runtime-implement-test-4-a6e5... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald-rpc read_events_request_round_trips 0 Applying loadouts: default Running task runtime-implement-test-5 in session task-runtime-implement-test-5-1670... Compiling common v0.0.1 (/workbench/crates/common) Compiling boxes v0.0.1 (/workbench/crates/boxes) Compiling minimald-rpc v0.0.1 (/workbench/crates/minimald-rpc) Finished '

Verify

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

Residuals

This task writes created. Each other BOX-040 trigger is written by the task that owns it, through box_manager::write_box_event:

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_integration test that #2661 adds (arch-review C1).

Closes #2389

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.
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

This 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.

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: 944f6c90-3e9f-4d43-a170-d28cb0595d56

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

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

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

@minimal-foundry

minimal-foundry Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Reviewed: no findings; approval withheld, 2 threads unresolved at 081327d7c076.

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.

@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 — advisory review

Verdict COMMENT — 1 finding, 1 inline.

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

Comment thread crates/minimald/src/box_manager.rs Resolved

@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: 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.

Comment thread crates/minimald/src/box_manager.rs Resolved
The discard_new_record block was inserted between the old doc comment
and log_teardown_join, so the comment attached to the wrong function.

@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 — advisory review

Verdict COMMENT — 1 finding, 1 inline.

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

Comment thread crates/boxes/src/store.rs Resolved

@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: 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.

Comment thread crates/boxes/src/events.rs Resolved
Comment thread crates/minimald/src/box_manager.rs Resolved
Comment thread crates/minimald/src/box_manager.rs Resolved
Comment thread crates/boxes/src/store.rs Resolved
@minimal-foundry

Copy link
Copy Markdown
Contributor Author

Round 1 of 10 on the runtime's review findings, pushed as db19fc7993cd.

line exit tail
cargo nextest run -p boxes events_file_appends_in_write_order 0 piling hybrid-array v0.4.14 Compiling regex-automata v0.4.18 Compiling icu_normalizer v2.2.0 Compiling idna_adapter v1.2.2 Compiling rustls v0.23.46 Compiling ctutils v0.4.5 Compiling idna v1.1.0 Compiling rustls-webpki v0.103.16 Compiling block-buffer v0.12.1 Compiling cr
cargo nextest run -p minimald events_written_outside_box_filesystem_with_box_parent_ts_type 0 Applying loadouts: default Running task runtime-implement-test-1 in session task-runtime-implement-test-1-2ee5... Compiling ot v0.0.1 (/workbench/crates/ot) Compiling args v0.0.1 (/workbench/crates/args) Compiling paths v0.0.1 (/workbench/crates/paths) Compiling stdlib v0.0.22 (/workbenc
cargo nextest run -p minimald in_box_root_cannot_append_events 0 Applying loadouts: default Running task runtime-implement-test-2 in session task-runtime-implement-test-2-c9fe... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald events_read_returns_full_retained_stream_in_order 0 Applying loadouts: default Running task runtime-implement-test-3 in session task-runtime-implement-test-3-1030... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald events_follow_replays_then_tails_until_reaped 0 Applying loadouts: default Running task runtime-implement-test-4 in session task-runtime-implement-test-4-6a52... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald-rpc read_events_request_round_trips 0 Applying loadouts: default Running task runtime-implement-test-5 in session task-runtime-implement-test-5-9a0a... Compiling num-traits v0.2.19 Compiling num-integer v0.1.46 Compiling chrono v0.4.45 Compiling num-bigint v0.4.8 Compiling jaq-json v2.0.2 Compiling jaq-fmts v0.1.1 C

Verify min task run agent-verify passed.

Review threads the coder judged:

  • 👍 valid — PRRT_kwDOPdfcxM6wg-sm: Moved the 'A teardown task that ended by a panic or a cancel' doc comment back above log_teardown_join. discard_new_record now has only its own doc. (not posted on the thread: not an open thread on the pull request)

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.

@mitodrummer

Copy link
Copy Markdown
Member

/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 ## Residuals section as it is.

1. C1: events carry a data map. Add pub data: serde_json_lenient::Map<String, serde_json_lenient::Value> to BoxEvent in crates/boxes/src/events.rs, serialized as data, with #[serde(default)]. box_manager::write_box_event (crates/minimald/src/box_manager.rs) takes the data map as an argument and stamps it into the event, and the created writer passes an empty map. Extend event_serialises_with_box_parent_ts_and_type to assert that value["data"] is an object. That way the later exited and renamed writers can record reason, exit_code/signal and the old and new names.

2. C2: prove BOX-041 from inside a real box. Replace the planted-file body of in_box_root_cannot_append_events (crates/minimald/src/box_manager/tests.rs) with a test that runs a process as uid 0 inside a real box's namespaces. The process tries to open the box's events.jsonl path for append. The test asserts that the open fails and that the stream still reads only created. Gate it the way crates/minimald/tests/nsenter_integration.rs does: #[ignore = "..."], plus an early return unless an env var is set (follow its gated()). Keep a fast, ungated test that the events file is outside every directory the box can see. Keeping the current planted-file test under a new name works. If the harness can't run a process inside a real box's namespaces, say so in your notes and change nothing for C2. The maintainer will file it as a residual.

3. C3: a refused line fails the read, and a torn line can't absorb the next event. In BoxEventsReader::read_new (crates/minimald/src/box_manager.rs), return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, ...)) that names the byte offset when decoded.refused is not empty, and keep the warn!. In read_events_stream (crates/minimald/src/rpc.rs), end the read with ReadEventsUpdate::Failed, not Done, on that error. In DiskBox::append_event (crates/boxes/src/store.rs), write a leading \n when the file is not empty and its last byte is not \n. Add a test for each: a refused line makes read_new fail, and an append after a torn last line leaves both events readable.

Run the plan's test lines plus cargo nextest run -p boxes events and cargo nextest run -p minimald events.

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.

@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_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.

@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 — advisory review

Verdict COMMENT — 2 findings, 2 inline.

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

Comment thread crates/minimald/src/box_manager.rs Resolved
Comment thread crates/minimald/src/box_manager.rs Resolved
@minimal-foundry

Copy link
Copy Markdown
Contributor Author

Round 2 of 10 on a /revise note, pushed as 1a128327353e.

line exit tail
cargo nextest run -p boxes events_file_appends_in_write_order 0 Applying loadouts: default Running task runtime-implement-test-0 in session task-runtime-implement-test-0-2cf3... Compiling args v0.0.1 (/workbench/crates/args) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling paths v0.0.1 (/workbench/crates/paths) Compiling common v0.0.1 (/workbench
cargo nextest run -p minimald events_written_outside_box_filesystem_with_box_parent_ts_type 0 Applying loadouts: default Running task runtime-implement-test-1 in session task-runtime-implement-test-1-4dae... Compiling args v0.0.1 (/workbench/crates/args) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling paths v0.0.1 (/workbench/crates/paths) Compiling stdlib v0.0.22 (/workbenc
cargo nextest run -p minimald in_box_root_cannot_append_events 0 Applying loadouts: default Running task runtime-implement-test-2 in session task-runtime-implement-test-2-45f8... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald events_read_returns_full_retained_stream_in_order 0 Applying loadouts: default Running task runtime-implement-test-3 in session task-runtime-implement-test-3-36f3... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald events_follow_replays_then_tails_until_reaped 0 Applying loadouts: default Running task runtime-implement-test-4 in session task-runtime-implement-test-4-17c6... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald-rpc read_events_request_round_trips 0 Applying loadouts: default Running task runtime-implement-test-5 in session task-runtime-implement-test-5-982c... Compiling common v0.0.1 (/workbench/crates/common) Compiling boxes v0.0.1 (/workbench/crates/boxes) Compiling minimald-rpc v0.0.1 (/workbench/crates/minimald-rpc) Finished '

Verify min task run agent-verify passed.

Review threads the coder judged:

  • 👎 invalid — crates/minimald/src/box_manager/tests.rs:2362: The test does write from the test host. But TestClient::exec cannot run a command in a real box here: under cfg(test) boxes launch through MockBackend (box_runtime/mock.rs), a plain host process with no namespaces. A real-box proof needs box_runtime and test_harness.rs changes, outside this task's l
  • 👎 invalid — crates/minimald/src/box_manager.rs:2224: Wiring the other eight triggers is outside this task, which covers only created. Filing an issue and editing the PR body is not code on this branch, and this round has no credential for either. The PR body's Residuals section carries it, per the maintainer's note.
  • 👍 valid — PRRT_kwDOPdfcxM6whFtj: append_event no longer calls create_dir_all. An event for a reaped box fails with NotFound and leaves no directory (test append_after_delete_leaves_no_directory). (not posted on the thread: not an open thread on the pull request)
  • 👍 valid — crates/boxes/src/events.rs:62: BoxEvent has a data map with serde default. for_record sets it empty, and the serialise test asserts value["data"] is an object.
  • 👍 valid — crates/minimald/src/box_manager.rs:2224: write_box_event takes a data: EventData argument and stamps it into the event. created passes an empty map (test written_event_carries_its_data).
  • 👎 invalid — crates/minimald/src/box_manager/tests.rs:2362: The finding is true of the test, but the harness cannot run a uid-0 process in a real box: cfg(test) launches use MockBackend, a host process. A gated real-box test needs box_runtime and test_harness.rs, outside this task's layers. Left as a residual.
  • 👍 valid — crates/minimald/src/box_manager.rs:2275: read_new returns InvalidData naming the byte offset when a line is refused and keeps the warn. read_events_stream already maps that error to Failed (test events_read_fails_on_a_refused_line).
  • 👍 valid — crates/boxes/src/store.rs:323: append_event writes a leading newline when the file's last byte is not a newline, so both events read back (test append_after_a_torn_line_keeps_both_events).

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 data (serde default, type alias EventData = serde_json_lenient::Map<String, Value>). write_box_event takes it, and created passes an empty map. C3: read_new returns InvalidData with the offset on a refused line and keeps the warn. rpc.rs needed no change: read_events_stream already ends with ReadEventsUpdate::Failed on any read_new error. append_event writes a leading newline when the last byte is not a newline. It also no longer calls create_dir_all, so an event for a reaped box fails with NotFound (foundry thread). C2 is not done: under cfg(test) the box runtime launches boxes with MockBackend (crates/minimald/src/box_runtime/mock.rs), a plain host process, so no in-module test can run a process inside a real box's namespaces. A real-box harness needs changes outside this task's layers (box_runtime, test_harness.rs). in_box_root_cannot_append_events is unchanged, for the maintainer to file as a residual. Thread PRRT_kwDOPdfcxM6wg_OF (eight more triggers) asks for an issue and a PR-body link. I cannot file issues or edit the PR body, so that is left for the runner or maintainer; the directive says the residuals section in the PR body covers it. just clippy-strict was not run.

@mitodrummer

Copy link
Copy Markdown
Member

/revise Three changes on 1a12832. Leave the PR body's ## Residuals section as it is; it now lists #2661 for arch C1.

1. arch-review C1, doc only. Change the doc comment on in_box_root_cannot_append_events (crates/minimald/src/box_manager/tests.rs) to say that it proves placement only: the events file is outside every directory the box can see. Say that the uid-0 proof from inside a real sandbox is #2661's _root_integration test. Change no test code for this.

2. minimal-review MEDIUM, crates/minimald/src/box_manager.rs:2289: a torn line must not become a permanently unreadable line. Today append_event writes a leading \n after a torn last line. That turns the torn fragment into a complete line that does not parse, and read_new then fails on it on every call, because the offset never moves past it. That box's stream is lost for good. Instead, in DiskBox::append_event (crates/boxes/src/store.rs), when the file is not empty and its last byte is not \n, truncate the file back to just after its last \n (or to 0 if it has none), log a warn! naming the box and the number of bytes dropped, then append. A torn write was never acknowledged, so dropping it loses no event, and the next event still cannot join it (arch's earlier C3). Keep read_new returning InvalidData on a refused line. Rename and update append_after_a_torn_line_keeps_both_events: after a torn partial line, an append leaves the complete events plus the new one readable and the fragment gone, and read_new succeeds. Reply on the arch C3 thread at crates/boxes/src/store.rs:323 with the reason.

3. minimal-review LOW, crates/minimald/src/box_manager.rs:2312. In next_events, when is_retained returns false, read once more, and end with Reaped only if that read is empty. Otherwise return the events, and end on the next call. Add a test if the harness can order a write between the read and the reap. If it can't, say so in your notes.

Run the plan's test lines plus cargo nextest run -p boxes events append and cargo nextest run -p minimald events.

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.

@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: 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.

Comment thread crates/boxes/src/store.rs Resolved
Comment thread crates/boxes/src/store.rs Resolved

@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 — advisory review

Verdict COMMENT — 1 finding, 1 inline.

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

Comment thread crates/minimald/src/diag.rs Resolved
@minimal-foundry

Copy link
Copy Markdown
Contributor Author

Round 3 of 10 on a /revise note, pushed as b9e6232e4125.

line exit tail
cargo nextest run -p boxes events_file_appends_in_write_order 0 Applying loadouts: default Running task runtime-implement-test-0 in session task-runtime-implement-test-0-54d8... Compiling args v0.0.1 (/workbench/crates/args) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling paths v0.0.1 (/workbench/crates/paths) Compiling common v0.0.1 (/workbench
cargo nextest run -p minimald events_written_outside_box_filesystem_with_box_parent_ts_type 0 Applying loadouts: default Running task runtime-implement-test-1 in session task-runtime-implement-test-1-08b6... Compiling ot v0.0.1 (/workbench/crates/ot) Compiling args v0.0.1 (/workbench/crates/args) Compiling paths v0.0.1 (/workbench/crates/paths) Compiling stdlib v0.0.22 (/workbenc
cargo nextest run -p minimald in_box_root_cannot_append_events 0 Applying loadouts: default Running task runtime-implement-test-2 in session task-runtime-implement-test-2-c68f... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald events_read_returns_full_retained_stream_in_order 0 Applying loadouts: default Running task runtime-implement-test-3 in session task-runtime-implement-test-3-2ca5... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald events_follow_replays_then_tails_until_reaped 0 Applying loadouts: default Running task runtime-implement-test-4 in session task-runtime-implement-test-4-d2b2... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald-rpc read_events_request_round_trips 0 Applying loadouts: default Running task runtime-implement-test-5 in session task-runtime-implement-test-5-7f84... Compiling common v0.0.1 (/workbench/crates/common) Compiling boxes v0.0.1 (/workbench/crates/boxes) Compiling minimald-rpc v0.0.1 (/workbench/crates/minimald-rpc) Finished '

Verify min task run agent-verify passed.

Review threads the coder judged:

  • 👍 valid — crates/minimald/src/box_manager/tests.rs:2364: Changed the doc comment to say the test proves placement only. The uid-0 proof from inside a real sandbox is the _root_integration test that Prove from inside a real box that root cannot append to the box's events stream #2661 owns, so this PR adds no test code for it.
  • 👍 valid — PRRT_kwDOPdfcxM6whkPD: append_event no longer writes a leading newline after a torn line. It cuts the file back to its last newline, logs a warning with the bytes dropped, then appends, so no line that does not parse stays in the file. read_new still fails on a refused line. (not posted on the thread: not an open thread on the pull request)
  • 👍 valid — PRRT_kwDOPdfcxM6whkPF: next_events reads once more when the box is no longer retained, and ends with Reaped only if that read is empty. Otherwise it returns the events and ends on the next call. (not posted on the thread: not an open thread on the pull request)

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.

@mitodrummer

Copy link
Copy Markdown
Member

/revise Two fixes on b9e6232. Leave the PR body's ## Residuals section as it is.

1. arch-review C1: lock the events file across the cut and the write (crates/boxes/src/store.rs DiskBox::append_event). After options.open(...), take an exclusive lock with file.lock()?, using std File::lock as crates/checkouts/src/lib.rs and crates/bep/src/audit.rs do. Hold it through complete_len, set_len, write_all and sync_data, and drop it after sync_data returns. Without the lock, two appends can both see the same torn tail, and the second set_len cuts the first append's event after that append has returned Ok. Change the doc comment at line 307 to name the lock as the reason two writers never interleave; O_APPEND alone is not. Add a store.rs test with two threads appending to a file with a torn tail, and assert that both events read back and no line is refused.

2. minimal-review HIGH, crates/minimald/src/diag.rs:716: the bundle must not ship events.jsonl verbatim. BoxEvent.data is free-form, and the renamed and exited writers will put box names and reasons in it, while the bundle redacts record.json first. Run each event line through the same redaction the record goes through, decoding each line and redacting its JSON value, then writing it back as one line. Keep the tail cap. Write a line that does not decode as a fixed placeholder, not verbatim. Rewrite the comment above it: events can carry user data in data, so they are redacted like the record. Add a diag test where an event's data holds a value the record redaction removes, and assert it is absent from the bundle.

Run the plan's test lines plus cargo nextest run -p boxes append and cargo nextest run -p minimald diag events.

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.

@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_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.

@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 — 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).

@minimal-foundry

Copy link
Copy Markdown
Contributor Author

Round 4 of 10 on a /revise note, pushed as 3f8997102f26.

line exit tail
cargo nextest run -p boxes events_file_appends_in_write_order 0 Applying loadouts: default Running task runtime-implement-test-0 in session task-runtime-implement-test-0-4f67... Compiling args v0.0.1 (/workbench/crates/args) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling paths v0.0.1 (/workbench/crates/paths) Compiling common v0.0.1 (/workbench
cargo nextest run -p minimald events_written_outside_box_filesystem_with_box_parent_ts_type 0 Applying loadouts: default Running task runtime-implement-test-1 in session task-runtime-implement-test-1-f20d... Compiling ot v0.0.1 (/workbench/crates/ot) Compiling args v0.0.1 (/workbench/crates/args) Compiling paths v0.0.1 (/workbench/crates/paths) Compiling stdlib v0.0.22 (/workbenc
cargo nextest run -p minimald in_box_root_cannot_append_events 0 Applying loadouts: default Running task runtime-implement-test-2 in session task-runtime-implement-test-2-6ce6... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald events_read_returns_full_retained_stream_in_order 0 Applying loadouts: default Running task runtime-implement-test-3 in session task-runtime-implement-test-3-0156... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald events_follow_replays_then_tails_until_reaped 0 Applying loadouts: default Running task runtime-implement-test-4 in session task-runtime-implement-test-4-7ad8... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald-rpc read_events_request_round_trips 0 Applying loadouts: default Running task runtime-implement-test-5 in session task-runtime-implement-test-5-9017... Compiling common v0.0.1 (/workbench/crates/common) Compiling boxes v0.0.1 (/workbench/crates/boxes) Compiling minimald-rpc v0.0.1 (/workbench/crates/minimald-rpc) Finished '

Verify min task run agent-verify passed.

Review threads the coder judged:

  • 👍 valid — crates/boxes/src/store.rs:342: append_event takes file.lock() after the open and holds it through the length read, complete_len, set_len, write_all and sync_data. A two-thread torn-tail test checks that every event reads back.
  • 👍 valid — crates/boxes/src/store.rs: The doc comment now says the exclusive file lock is why two writers never interleave or cut each other's line, and that O_APPEND alone is not enough.
  • 👍 valid — crates/minimald/src/diag.rs:718: The bundle now decodes each events line, runs it through redact_json, and writes it back as one line. It keeps the tail cap. An undecodable line becomes a fixed placeholder. The comment is rewritten, and diag_bundle_redacts_box_events_data checks this.

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.

@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 — 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.

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

Copy link
Copy Markdown
Member

/revise Merge origin/main into this branch and resolve one conflict. Change nothing else.

crates/boxes/src/lib.rs, the module list. Main's #2614 replaced pub mod keys; with pub use client_config::keys;. This branch adds pub mod events; beside it. The resolution keeps both:

pub use client_config::keys;
pub mod events;

If anything in this branch's own code used the old boxes::keys module path in a way the re-export does not cover, fix that call site the way #2614 did. Leave the PR body's ## Residuals section as it is.

Run the plan's test lines plus cargo nextest run -p boxes and cargo check -p minimald.

…-box-s-lifecycle-events-where-only-the

# Conflicts:
#	crates/boxes/src/lib.rs

@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_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.

Comment thread crates/minimald/src/box_manager.rs Resolved
@minimal-foundry minimal-foundry Bot removed the review:approved minimal-review approved the current head label Oct 27, 2026
@mitodrummer

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review skipped.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@minimal-foundry

Copy link
Copy Markdown
Contributor Author

Round 5 of 10 on a /revise note, pushed as 081327d7c076.

Resolved conflicts in: crates/boxes/src/lib.rs

line exit tail
cargo nextest run -p boxes events_file_appends_in_write_order 0 Applying loadouts: default Running task runtime-implement-test-0 in session task-runtime-implement-test-0-6a77... Compiling args v0.0.1 (/workbench/crates/args) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling paths v0.0.1 (/workbench/crates/paths) Compiling client-config v0.0.1 (/wo
cargo nextest run -p minimald events_written_outside_box_filesystem_with_box_parent_ts_type 0 Applying loadouts: default Running task runtime-implement-test-1 in session task-runtime-implement-test-1-3a32... Compiling paths v0.0.1 (/workbench/crates/paths) Compiling args v0.0.1 (/workbench/crates/args) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling client-config v0.0.1 (/wo
cargo nextest run -p minimald in_box_root_cannot_append_events 0 Applying loadouts: default Running task runtime-implement-test-2 in session task-runtime-implement-test-2-bb50... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald events_read_returns_full_retained_stream_in_order 0 Applying loadouts: default Running task runtime-implement-test-3 in session task-runtime-implement-test-3-41f9... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald events_follow_replays_then_tails_until_reaped 0 Applying loadouts: default Running task runtime-implement-test-4 in session task-runtime-implement-test-4-d15f... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald-rpc read_events_request_round_trips 0 Applying loadouts: default Running task runtime-implement-test-5 in session task-runtime-implement-test-5-5136... Compiling common v0.0.1 (/workbench/crates/common) Compiling boxes v0.0.1 (/workbench/crates/boxes) Compiling minimald-rpc v0.0.1 (/workbench/crates/minimald-rpc) Finished '

Verify min task run agent-verify exited 100.

oes_not_leave_attaches_refused
        PASS [   0.517s] ( 643/1831) minimald box_actor::tests::a_failing_activate_hook_blocks_the_session
        PASS [   0.453s] ( 644/1831) minimald box_actor::tests::a_failing_destroy_hook_still_destroys_the_session
        PASS [   5.306s] ( 645/1831) minimald box_actor::tests::a_destroyed_holders_shared_port_is_not_bound_for_a_box_that_is_not_running
        PASS [   2.427s] ( 646/1831) minimald box_actor::tests::a_handed_box_pending_at_finalize_publishes_the_interim_when_the_verdict_lands_absent
        PASS [   0.362s] ( 647/1831) minimald box_actor::tests::a_hook_launched_shell_takes_the_attaching_terminals_term
        PASS [   0.401s] ( 648/1831) minimald box_actor::tests::a_launch_whose_record_cannot_be_written_kills_its_box
        PASS [   2.389s] ( 649/1831) minimald box_actor::tests::a_hook_launched_shell_of_a_registered_box_is_kept_for_a_terminal
        PASS [   4.746s] ( 650/1831) minimald box_actor::tests::a_hand_over_bind_the_switch_refuses_leaves_the_election_standing
        PASS [   0.014s] ( 651/1831) minimald box_actor::tests::a_probe_of_a_wedged_host_ends_instead_of_stranding_its_task
        PASS [   2.402s] ( 652/1831) minimald box_actor::tests::a_registered_box_never_launched_mints_and_binds_its_row
        PASS [   7.174s] ( 653/1831) minimald box_actor::tests::a_handed_reserved_address_waits_for_the_verdict_before_it_publishes
        FAIL [   5.360s] ( 654/1831) minimald box_actor::tests::a_mint_whose_host_dies_before_attach_reports_a_spawn_failure
  stdout ───

    running 1 test
    test box_actor::tests::a_mint_whose_host_dies_before_attach_reports_a_spawn_failure ... FAILED

    failures:

    failures:
        box_actor::tests::a_mint_whose_host_dies_before_attach_reports_a_spawn_failure

    test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 1129 filtered out; finished in 5.35s

  stderr ───

    thread 'box_actor::tests::a_mint_whose_host_dies_before_attach_reports_a_spawn_failure' (2933) panicked at crates/minimald/src/box_actor/tests.rs:1660:5:
    channel did not close within the timeout; got []
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

  Cancelling due to test failure: 3 tests still running
        PASS [   4.390s] ( 655/1831) minimald box_actor::tests::a_mint_whose_host_wedges_reports_busy_instead_of_death
        PASS [   3.829s] ( 656/1831) minimald box_actor::tests::a_restarted_daemon_launches_a_restored_own_ip_boxs_host_on_resume
        PASS [   4.742s] ( 657/1831) minimald box_actor::tests::a_restarted_daemon_re_derives_the_box_s_address_from_the_answerer
────────────
     Summary [  21.971s] 657/1831 tests run: 656 passed, 1 failed, 18 skipped
        FAIL [   5.360s] ( 654/1831) minimald box_actor::tests::a_mint_whose_host_dies_before_attach_reports_a_spawn_failure
warning: 1174/1831 tests were not run due to test failure (run with --no-fail-fast to run all tests, or run with --max-fail)
error: test run failed

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: pub use client_config::keys; then pub mod events;. The other paths in the merge commit come from main. No code on this branch used boxes::keys in a way the re-export does not cover, so no call site changed. Nothing else changed.

@minimal-foundry
minimal-foundry Bot marked this pull request as draft October 27, 2026 04:21
@mitodrummer
mitodrummer marked this pull request as ready for review October 27, 2026 04:33
@mitodrummer

Copy link
Copy Markdown
Member

@coderabbitai full review

@mitodrummer mitodrummer 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.

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.

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review skipped.

@mitodrummer
mitodrummer added this pull request to the merge queue Oct 27, 2026
Merged via the queue into main with commit 2240ddd Oct 27, 2026
37 checks passed
@mitodrummer
mitodrummer deleted the agent/2389-write-each-box-s-lifecycle-events-where-only-the branch October 27, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

T2 — Write each box's lifecycle events where only the daemon can reach

1 participant