Repository navigation
feat(cli): delegate tool with carved mission budgets, leases and grants (#585) - #623
Merged
Merged
Conversation
…ts (#585) The CLI faces (run, chat, mission) get delegate and delegate_poll over tole_core::delegation. delegate carves the child's budget from the session's node and starts it as tole mission with the carve as its step, minute and token caps, optionally as a profile, with --allow = parent intersect profile; the child keeps its provider keys plus the parent grant intersect the profile's grants. An execute child takes a write lease on the canonicalized directory it works in, checked before it spawns. A child gets the tool again only while above the goal's depth. delegate_poll charges a settled child its measured session usage, or its whole carve when the records cannot be read, and so does recovery. Past max_live_processes spawns queue and start on a later delegate or poll. agent_start and agent_poll stay one release as aliases; tole serve keeps the classic depth-1 tools. agents::agent_dir now refuses ids that are not one plain path component and child_env::delegation refuses node ids with a leading, trailing or doubled dot (#621 review).
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
A queued spawn kept its whole launch spec, allow list, budget and secret names included, in a file next to the log, and drain launched from it. A child that can write that file could widen a queued sibling. The file now keeps only what carries no authority (role, artifacts to read, mailbox choice); allow list, budget, depth, mode, task, workspace and profile are read back from the node the tree recorded and the secrets are recomputed as parent grant intersect the profile's grants.
…ut of the workspace (#585) The host launches what the delegation log records, and the log lived in <workspace>/tole-agents/, where an execute child's file tools could append a spawn with allow ["*"] or a huge budget for the next drain to start. The fold now ignores any spawn whose parent is unknown or settled, whose id is not the parent's next, whose depth passes the goal's limit, that runs execute under a consult parent, whose allow list is not covered by the parent's (or drops a parent deny), or whose budget or deadline passes what the parent can still carve at that point of the log. A settle is never charged below the node's reported own spend, and a budget stop always its whole carve. The log, its lock and the queue now live in the tole data dir, <codecora home>/tole/delegation/<hash of the canonical workspace root>/, outside every workspace; children keep getting its absolute path in TOLE_DELEGATION_LOG.
…heck (#585) In worktree mode the pre-check asked lease_conflict for <workspace>/.tole-worktrees, which also matches every lease BELOW that dir, so a second execute child was refused while the first held its own worktree, against the refusal message and the threat model. A new core query, lease_ancestor_conflict, reports only a lease on the path itself or an ancestor; the worktree pre-check uses it, and the in-place check keeps lease_conflict, where a lease anywhere inside the workspace must block a whole-workspace writer.
| "budget": {"tokens": h.budget.tokens, "steps": h.budget.steps, | ||
| "deadline": h.budget.deadline}, | ||
| "allow": h.allow, "dropped": h.dropped, | ||
| }); |
| "node": n.id, "status": n.status, "reason": n.reason, | ||
| "used": n.used.map(|u| json!({"tokens": u.tokens, "steps": u.steps})), | ||
| "started_from_queue": started, | ||
| }))) |
Delegator::for_session kept the session root as given while the log recorded children under the canonical root, so with a symlinked or .. workspace path a poll looked up the wrong agent dir and never settled the child. The root is now canonicalized once and every key uses it. delegate never drained the queue, so a slot freed by recovery went to the new spawn ahead of older queued ones. A new spawn now joins the queue and the queue drains in log order (Node::seq) on every delegate and poll; a queued writer whose workspace lease is taken holds the queue. An exited but unreaped child (a zombie) no longer counts as alive, so its slot frees without a poll, and goal ids are unique per process.
This was referenced Nov 12, 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 3 of #585 (epic #583): the
delegate/delegate_polltools for the CLI faces (run,chat,mission), built ontole_core::delegation(#618) and the launch contract and limits from #621. Each delegated child runs as a budgetedtole mission, optionally as a profile. Its authority, secrets, budget and write access all come from the delegation tree, which also re-checks every spawn in its fold. The log lives outside every workspace.agent_start/agent_pollstay one release as deprecated aliases.The completion report, settle-on-report and
tole auditfollow in part (b), which opens after this merges.Why
Design
docs/profiles-collaboration-secrets.mdA6 and A8, with the owner rules and the review's hard rules in force:Changes
crates/tole-core/src/delegation.rs:State::spawn_allowed): live parent, the next id, depth within the goal's limit, the consult rule, allow covered by the parent's (parent denies kept), and a non-empty budget and deadline within what the parent can still carve. Anything else is ignored.Node::seq: log order. Queued nodes start in that order (next_queued), so ties within one second keep their order.lease_conflict: any overlap, for a whole-workspace writer.lease_ancestor_conflict: the path or an ancestor only, for a writer that will get a fresh directory under the path.liveandby_session.crates/tole-cli/src/delegate.rs(new):Delegator::for_sessioncanonicalizes the session root once; a root that cannot be canonicalized gets no tool. That one value keys the log path, the agents dir, the agent dirs recorded as sessions, the poll tool's root and everyagent_dirlookup, so a symlinked or..workspace path still settles its children.<codecora home>/tole/delegation/<hash of the canonical root>/(delegate::log_path), outside every workspace. Children get the absolute path throughTOLE_DELEGATION_LOG.may_delegate(node)holds. A classic depth-1agent_startchild gets none.delegate {task|prompt, profile?, mode?, budget?, allow?, role?, consumes?, keep_mailbox?}, under the log's exclusive lock:executechild is refused when its workspace lease is taken.--agents-worktree, only a lease on.tole-worktreesor above it refuses it; sibling worktree writers run in parallel.max_live_processesallows. A new spawn never starts ahead of an older queued one, and the reply says whether it started or isqueued, plus what started from the queue.tole mission --max-steps S --max-minutes M --max-tokens T [--profile P] --allow …at the node's depth. The child keeps its provider keys plusProfile::granted(held).cancelled(zero spent), and keeps going past a failed launch.delegate_poll {agent}: settles the polled child first (measured session usage, or the whole carve), then recovers the others and drains. Until part (b), anokchild settlesincomplete.g-<secs>-<pid>-<n>).ledger_file.rs:lease_alivecounts an exited but unreaped child (a zombie,/procstateZ) as gone, so a finished detached child frees its slot on the next delegate without a poll.tool_roster.rs/main.rs: the poll tool is rooted at the host's canonical root.tole servekeeps the classic depth-1agent_startfor now.agents::agent_dir(root, id)returnsOptionand refuses empty,.,.., leading-dot and separator-bearing ids.child_env::delegation()refuses node ids with a leading, trailing or doubled dot.docs/threat-model.md(fold validation, file locations, what a child can still write, the in-place vs worktree pre-check, one canonical root, strict FIFO and zombies, the known limit below);CHANGELOG.md(Added, plus Deprecatedagent_start/agent_poll);README.md;docs/epics.md.Testing
delegation_tests.rs, 20 tests): the fold ignores forged spawns, a raw settle cannot charge below the rules, and the ancestor check ignores leases below the path.delegate_tests.rs, 9 tests, with a faketolebinary):a_symlinked_or_dotted_root_still_settles_its_children: through a symlinked root and through areal/../realroot, a finished child is polled, settled and charged its measured 50 tokens / 1 step. (A relative root is not expressed, because the test harness cannot change the cwd safely in parallel tests; it is canonicalized the same way.)a_new_delegate_never_starts_ahead_of_an_older_queued_one: withmax_live_processes = 1, A runs and B is queued. A exits, nobody polls, and the nextdelegateC starts B first and queues C.with_worktrees_two_writers_run_in_parallel_each_on_its_own_lease;the_log_is_outside_the_workspace_and_forged_spawns_launch_nothing;ledger_file:an_unreaped_exited_child_is_not_alive.agent_dir/delegation()id checks.CARGO_TARGET_DIR,CARGO_INCREMENTAL=0, debuginfo off;develop8aa231c merged in):cargo fmt --all: cleancargo clippy --workspace --all-targets -- -D warnings: cleancargo test --workspace --no-fail-fast: 1509 passed, 0 failedcargo test -p tole-core --no-default-features: 511 passed, 0 failedcargo build -p tole-cli --no-default-features: okcora review --no-llm --base origin/develop: no issues foundKnown limits
tole servekeeps the classic depth-1agent_start/agent_poll.<workspace>/tole-agents/<id>/, so it could understate its usage within its carve. A child with an approvedrun_commandcan write the data dir like any path outside the jail; the fold still refuses any spawn wider than its parent.interrupted, charged their measured usage. A polled child settles as a run (incompleteuntil part (b) adds the report).cancelledwith its measured usage or whole carve. It is reachable only by a race between the pre-check and the lease, so no test drives it.