Repository navigation
feat(core): delegation tree with budget carve, depth cap, write lease and report (#585) - #618
Merged
Merged
Conversation
… and report (#585) New tole-core module delegation: an append-only, auditable tree of one goal, with the orchestrator at depth 0 and delegated profiles below. A child's tokens and steps are carved from its parent's remaining budget and its deadline never passes the parent's: a running child keeps its whole carve reserved and a settled one is charged what its subtree spent, so any number of children share one pot. Depth defaults to 2 and can never exceed 3. The child allowlist is the profile patterns a parent pattern covers, plus every deny; a consult node cannot spawn an executor or write. An execute node takes a write lease per path; a lease on the same path, an ancestor or a descendant conflicts, and the first in log order wins a race. max_live_processes only queues. An ok run settles done only with a completion report (summary; changed files need a diff ref and the checks run) and no unsettled children, else incomplete with the reasons. A terminal record is never overwritten. Recovery settles dead processes interrupted and queued orphans cancelled; render_tree prints the audit view. The delegate tool, tole audit and the profile wiring follow.
# Conflicts: # README.md
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
| if path.is_empty() || !path.starts_with('/') { | ||
| return Err(DelegationError::Invalid(format!( | ||
| "lease path {path:?} must be absolute" | ||
| ))); |
lease_write only checked for a leading slash and compared paths by component, so /w/src/../src/a.rs, /w/src/./a.rs or //w/src/a.rs did not conflict with a lease on /w/src/a.rs and two children could write one file. lease_write and release now refuse any path that is not absolute and lexically normal (no empty, . or .. component, no trailing slash), and the fold ignores a forged lease record with such a path. The module does no filesystem access; the host canonicalizes first.
# Conflicts: # CHANGELOG.md
recover() settled a running node whose process was gone with zero usage, so its whole carve went back to the parent and spawn+crash cycles could spend past the goal's budget. A dead node is now charged its whole carve unless the host passes a measured value (lower measured usage still refunds the difference); only a queued node that never started refunds everything. A budget stop is charged its whole carve, a settle never goes below the node's reported own spend, and delegate() refuses an own spend lower than one the node reported before (kept in the spawn record).
This was referenced Nov 11, 2026
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 1 of #585 (epic #583): a new
tole-coremodule,delegation. It keeps one goal as an append-only, auditable tree: the orchestrator at depth 0 and delegated profiles below it. Every delegation cap is enforced inside it:Nothing is wired yet.
agent_startkeeps its depth-1 cap until the follow-up PR, which adds the delegate tool,tole auditand the profile and secret wiring.Why
Design
docs/profiles-collaboration-secrets.mdA6, A8 and A10, with the owner decisions in force:max_live_processes: only a machine guard.Putting every cap in one module means no caller (tool,
@mentionrouting, cron as a profile) can skip one.Changes
crates/tole-core/src/delegation.rs(new):goal,spawn,start,write_lease,releaseandsettleover the existingLedgerStore(the same append, fold and torn-tail rules as the cron ledger). Unknown kinds are skipped, and a newer version of a known kind is refused. Nothing reads a clock, spawns or touches the filesystem:now, process liveness and measured usage are passed in. The host holds a lock around every mutating call, as for the cron ledger.begin(&Goal, now): opens the root (the orchestrator) with the root budget, its allowlist,max_depth(1 to 3; anything else is refused) andmax_live.delegate(parent, &DelegateRequest, own_spend, now) -> Handle:Invalid), also after reopening the log.BudgetExhausted).max_depthcannot delegate (DepthCap).may_delegatetells the host where to register the tool.approval::list_covers, the ruleagent_startalready uses), plus every deny of both. Uncovered patterns are dropped and recorded.consultnode can only spawnconsultnodes.g.1.2.start(node, process lease, session, now): a spawn is recordedqueued. It starts unless the goal already hasmax_livedelegated processes running (Queued { live, max }, which the host can show).next_queuedgives the next one to start.lease_write/release:executenode may take a lease./a/bor/: no empty,.or..component, no//, no trailing slash). Any other spelling is refused withInvalid, never rewritten, so/w/src/../src/a.rscannot dodge a lease on/w/src/a.rs. The host canonicalizes first (symlinks, case folding): this module does no filesystem access.settle(node, outcome, used, report, reason, now):Outcome::Okbecomesdoneonly with a completeReportand no unsettled children. Otherwise it becomesincomplete, with the reasons recorded.usedmust be the node's measured own usage, for every outcome. It is what the parent is charged, and the rest of the carve goes back to the parent. It is never taken below the node's highest reported own spend.Outcome::Budgetis always charged the whole carve. A host that cannot measure passes the whole carve (Spend::all_of).recover(now, alive, measured):interrupted. Its usage is unknown, so it is charged its whole carve unlessmeasuredreturns what it really spent (a lower measured value refunds the difference). A crash can never refund a budget it may have burned.cancelledand refunds in full, since it never started.tree/render_tree: the audit view, one line per node, indented by depth: profile, status, mode, charged/carved tokens and steps, allowlist, workspace, session, report summary and reason.crates/tole-core/src/delegation_tests.rs(new): the unit tests.docs/threat-model.md: a new "Delegation tree (feat(core): delegation — budget carve, depth 2 (max 3), write lease and mandatory report #585)" section. It covers the lease-path rule, that the host must canonicalize, the full-charge rule for unknown usage, and that the depth-1 rule stays in force until the wiring PR.README.mdstatus line,docs/epics.mdE2 andCHANGELOG.md.Testing
17 unit tests in
delegation_tests.rs, covering:BudgetExhaustedafter exactly 10 cycles of a 1000-token goal;Each cap was broken on purpose; the matching tests went red, and green again once restored:
okalwaysdone(report not mandatory)/(the previous code)Budgetcharged only what was passedThe new budget tests need the new
recover(now, alive, measured)signature, so they cannot compile against the previous code. The red evidence there is the break row "a dead node settles with zero usage", which puts the previous behavior back into the new code.Commands (private
CARGO_TARGET_DIR,CARGO_INCREMENTAL=0, debuginfo off;developmerged in):cargo fmt --all: cleancargo clippy --workspace --all-targets -- -D warnings: cleancargo test --workspace: 1474 passed, 0 failedcargo test -p tole-core --no-default-features: 505 passed, 0 failedcargo build -p tole-cli --no-default-features: okcora review --no-llm --base origin/develop: no issues foundKnown limits and choices to confirm:
Profile::granted, withSecretSetfrom feat(core): SecretSet — known-value redaction at every egress sink, child minimum env #595), thedelegation.*config keys, and the mailbox result flow. They belong to the wiring PR.