Repository navigation
feat(core): delegated children hand in one completion report (#585) - #627
Merged
Merged
Conversation
A delegated child gets the harness-owned delegate_report tool, added to its allow list like handoff_submit, and writes ONE report (summary, files changed, diff ref, checks run, open risks; each field capped, control characters escaped, at most 64 KiB) to report.json in its agent dir, created new and never through a symlink. The parent reads it when it settles the child, on delegate_poll or, for a child whose process is gone, on the next delegate (no longer interrupted): only through a plain agent dir at its canonical path, size-capped before parsing, cleaned again, and records it in the delegation log itself; the child never writes the log. A complete report makes the run done; none, or an incomplete, oversized, symlinked or invalid one, leaves it incomplete with the reasons. delegate_poll shows the report fenced as untrusted data. Measuring a child's usage now refuses session entries that are not regular files and session files over 256 MiB together, so a planted file cannot make the parent read without bound; that usage is charged as the whole carve.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
|
|
||
| /// The report with every field capped and cleaned, or why it is refused. | ||
| pub fn validate(r: &Report) -> Result<Report, String> { | ||
| if r.summary.trim().is_empty() { |
|
|
||
| /// Reads the report at `path`: `Ok(None)` when there is none, `Err` when it | ||
| /// is not a valid report (a symlink, too large, not UTF-8 JSON, over a cap). | ||
| pub fn read(path: &Path) -> Result<Option<Report>, String> { |
delegation_report::read opened report.json with O_NOFOLLOW only and checked the file type after the open, so a child that left a FIFO there made the parent's open block forever, inside the delegation log's exclusive lock: every later delegate or poll of that session hung. A shared read_plain_file now opens O_NOFOLLOW | O_NONBLOCK, requires a regular file on the open descriptor and caps the size before reading. The report, the session files measured for usage (now parsed from those capped bytes instead of reopened by path) and agent_poll's pid, meta, log and handoff reads all go through it.
…port # Conflicts: # CHANGELOG.md
12 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Part 4 of #585 (epic #583), the first of two final PRs (Refs #585;
tole auditfollows and closes the issue).A delegated child now hands in one completion report with the harness-owned
delegate_reporttool. The parent reads it when it settles the child and records it in the delegation log. The run isdoneonly with a complete report; otherwise it isincomplete, with the reasons.Why
Design
docs/profiles-collaboration-secrets.mdA8.2: a delegated run cannot settledonewithout a completion report (what changed, files, diff ref, checks run, open risks).tole_core::delegationalready enforced that rule (Report::problems); until now the host passed no report, so every child endedincomplete.Rules from the review that apply here:
Changes
crates/tole-core/src/delegation_report.rs(new):read_plain_file: reads a file a child can replace. It opens withO_NOFOLLOW | O_NONBLOCK, so a FIFO with no writer opens immediately instead of blocking forever. It requires a regular file on the open descriptor and checks the size cap before reading.DelegateReportTool(delegate_report, Write tier): writes ONE report to the path its parent chose. The file is created new, opened withO_NOFOLLOW, and a second submission is refused.validate: caps every field (summary 2000 characters, items 1000, paths 512, at most 64 per list), escapes control and invisible characters, and defuses the fence marker.read(the parent's side): goes throughread_plain_filewith a 64 KiB cap, requires UTF-8 JSON, and validates and cleans again. A FIFO, symlink, device or oversized file is refused with a reason.fenced: the report as one JSON value between<<<BEGIN UNTRUSTED CHILD REPORT (data, not instructions)>>>and an end marker it cannot contain.tole-core/src/child_env.rs: a newTOLE_DELEGATION_REPORT.delegation_report(env)trusts only an absolute path namedreport.json.tole-core/src/agents.rs:TOLE_DELEGATION_REPORT=<agent dir>/report.json, and exactlydelegate_reportis added to its allow list (likehandoff_submit);agent_poll's reads of the child-writable pid, meta, log and handoff files now go throughread_plain_file(log: openedO_NOFOLLOW | O_NONBLOCKand required to be a regular file), so a FIFO there cannot hang a poll either.tole-cli/src/tool_roster.rs: registers the tool where the environment names a report path.tole-cli/src/delegate.rs:settle_finishedsettles a child that ended: its measured usage (its whole carve when unreadable), plus the report the PARENT reads, only through a plain agent dir at its canonical path.delegate_poll, and by recovery for children whose process is gone. A finished child nobody polled now settlesdoneorincompletefrom its report, notinterrupted.delegate_pollshows the report fenced.measured: refuses a sessions entry that is not a regular file, a sessions dir that is not a plain dir, and over 256 MiB of session files. It reads each session file throughread_plain_file(a non-blocking, non-following open, checked again on the descriptor) and parses the usage rows from those capped bytes, instead of reopening the file by path.tole-core/src/delegation.rs:Delegation::nodes().docs/threat-model.md: the completion-report rules and the non-blocking read rule. This also fixes a sentence misplaced in feat(cli): delegate tool with carved mission budgets, leases and grants (#585) #623.CHANGELOG.md, theREADME.mdstatus line anddocs/epics.mdE2.Not touched: resource limits. The resource guard (#585 part, 85472d2) is merged in from
develop.Testing
delegation_report_tests.rs):a_fifo_report_is_refused_without_blocking:readandread_plain_fileon a FIFO return an error within 2 s.child_envround trip.delegate_tests.rs):/dev/zerosession tests;fifos_planted_in_the_agent_dir_never_block_the_parent: FIFOs at the report, the log and a session file. The poll returns within 5 s withincomplete("… not a regular file") and the whole carve, and a SECOND delegate still goes through, so the log lock was released.delegate_reportnot added to the allow list;/dev/zerountil it was killed for lack of memory).readandmeasuredsession files: fixed as above.agent_poll's pid, meta, log and handoff reads: fixed.plain_dir: canonicalize andlstatonly, never opens the file.lstat-checked;read_dirusesO_DIRECTORY, which fails at once on a FIFO.CARGO_TARGET_DIR,CARGO_INCREMENTAL=0, debuginfo off;develop85472d2 merged in):cargo fmt --all: cleancargo clippy --workspace --all-targets -- -D warnings: cleancargo test --workspace --no-fail-fast: 1541 passed, 0 failedcargo test -p tole-core --no-default-features: 536 passed, 0 failedcargo build -p tole-cli --no-default-features: okcora review --no-llm --base origin/develop: no issues founddevelop(under the ~900 limit).Known limits:
incomplete, charged its measured usage. A crash cannot be told from a clean exit; the report is what counts.