Skip to content

feat(core): delegated children hand in one completion report (#585) - #627

Merged
ajianaz merged 3 commits into
developfrom
feat/delegation-report
Nov 12, 2026
Merged

ajianaz merged 3 commits into
developfrom
feat/delegation-report

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

What

Part 4 of #585 (epic #583), the first of two final PRs (Refs #585; tole audit follows and closes the issue).

A delegated child now hands in one completion report with the harness-owned delegate_report tool. The parent reads it when it settles the child and records it in the delegation log. The run is done only with a complete report; otherwise it is incomplete, with the reasons.

Why

Design docs/profiles-collaboration-secrets.md A8.2: a delegated run cannot settle done without a completion report (what changed, files, diff ref, checks run, open risks). tole_core::delegation already enforced that rule (Report::problems); until now the host passed no report, so every child ended incomplete.

Rules from the review that apply here:

  • Untrusted text: report text is untrusted, so it is capped, control characters are stripped, and it is fenced.
  • Who writes what: the child writes only its own agent dir, never the log.
  • Unknown usage: it is charged in full.
  • The child cannot block or redirect its parent: the parent settles children under the delegation log's exclusive lock, so any file it reads from a child's dir must not block or follow a link.

Changes

  • crates/tole-core/src/delegation_report.rs (new):
    • read_plain_file: reads a file a child can replace. It opens with O_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 with O_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 through read_plain_file with 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 new TOLE_DELEGATION_REPORT. delegation_report(env) trusts only an absolute path named report.json.
  • tole-core/src/agents.rs:
    • a delegated child gets TOLE_DELEGATION_REPORT=<agent dir>/report.json, and exactly delegate_report is added to its allow list (like handoff_submit);
    • agent_poll's reads of the child-writable pid, meta, log and handoff files now go through read_plain_file (log: opened O_NOFOLLOW | O_NONBLOCK and 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_finished settles 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.
    • Poll and recovery: it is used by delegate_poll, and by recovery for children whose process is gone. A finished child nobody polled now settles done or incomplete from its report, not interrupted.
    • delegate_poll shows 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 through read_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:

Not touched: resource limits. The resource guard (#585 part, 85472d2) is merged in from develop.

Testing

  • Core (delegation_report_tests.rs):
    • written once and read back;
    • capped, cleaned and fenced;
    • the parent's read refuses what the child could plant (raw control characters cleaned, oversized refused before parsing, non-JSON and over-cap refused, a symlink neither followed nor written through);
    • a_fifo_report_is_refused_without_blocking: read and read_plain_file on a FIFO return an error within 2 s. child_env round trip.
  • End to end (delegate_tests.rs):
    • the done, incomplete/planted, unpolled, symlinked agent dir and planted /dev/zero session 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 with incomplete ("… not a regular file") and the whole carve, and a SECOND delegate still goes through, so the log lock was released.
  • Red/green:
    • FIFO tests on the previous head: the core FIFO test times out ("blocked: did not return within 2 s") and the end-to-end FIFO test times out ("blocked: did not return within 5 s"). Both pass with the fix.
    • Earlier rows still hold:
      • report not ingested;
      • the read follows a symlink;
      • no cleaning;
      • no size cap;
      • recovery does not settle finished children;
      • delegate_report not added to the allow list;
      • agent-dir plainness not checked;
      • second submission allowed;
      • session file type not checked (the test process read /dev/zero until it was killed for lack of memory).
  • Checked for the same class (child-replaceable paths the parent opens):
    • read and measured session files: fixed as above.
    • agent_poll's pid, meta, log and handoff reads: fixed.
    • plain_dir: canonicalize and lstat only, never opens the file.
    • The sessions dir: lstat-checked; read_dir uses O_DIRECTORY, which fails at once on a FIFO.
    • The drain's queue files and the log live in the data dir, outside the workspace.
  • Commands (private CARGO_TARGET_DIR, CARGO_INCREMENTAL=0, debuginfo off; develop 85472d2 merged in):
    • cargo fmt --all: clean
    • cargo clippy --workspace --all-targets -- -D warnings: clean
    • cargo test --workspace --no-fail-fast: 1541 passed, 0 failed
    • cargo test -p tole-core --no-default-features: 536 passed, 0 failed
    • cargo build -p tole-cli --no-default-features: ok
    • cora review --no-llm --base origin/develop: no issues found
  • Size: 13 files, +818/-38 against develop (under the ~900 limit).

Known limits:

  • A crashed child: a child that crashes without a report settles incomplete, charged its measured usage. A crash cannot be told from a clean exit; the report is what counts.
  • The report is the child's own claim: it is recorded and shown as data, never trusted as instructions or as proof that checks passed.

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.
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

🔍 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.
@ajianaz
ajianaz merged commit 98f157d into develop Nov 12, 2026
19 of 20 checks passed
@ajianaz
ajianaz deleted the feat/delegation-report branch November 20, 2026 08:36
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.

3 participants