Repository navigation
Subagents: subagent.run tool with depth and child limits (ATO-1670) - #1733
Draft
sosidudku1 wants to merge 18 commits into
Draft
sosidudku1 wants to merge 18 commits into
sosidudku1 wants to merge 18 commits into
Conversation
Worker metadata now carries depth: the operator session is 0, a worker it spawns is 1, a worker spawned by a worker is parent depth + 1. createFusionWorkerSession stamps it (default 1), readFusionWorkerMeta reads a missing or malformed depth as 1 without rejecting the record, and readSessionDepth / childFusionWorkerDepth give the depth of any session and of its next child. The s-w- id prefix is unchanged.
…ubagent-tool # Conflicts: # src/tools/fusion/worker-runner.ts
… check (ATO-1670) The core runner options take an optional depth, stamped on every worker session; absent it stays 1, so Fusion is unchanged. The task tree's depth and node caps become one exported check, treeLimitBreach, which the split check and the proposal refusals now use and the subagent tool will reuse.
…1670) Runs up to 4 tasks per call and 24 per turn as worker turns on the session's own model, under the subagent origin, with the worker tool policy plus a profile's allowlist. Only a depth-0 session may call it: the depth is read from the caller's session data and a worker id counts as depth 1 even with a broken stamp. The tool is also hidden from workers. Caps go through the task tree's treeLimitBreach.
…og gates (ATO-1670) Descriptor and args schema next to fusion.delegate, compact form, grammar rule, approval_gated solo class, a live gate that hides it while Fusion is effective, registration beside fusion.delegate with the same profile loader, and a record of minted worker sessions so the depth check reads their own stamp. Shared catalog tests updated deliberately.
…670-subagent-tool
ToolContext gains turnId, one value per agent turn, and model, the chat model a pinned turn asks its link for (the desktop's per-project model). Both flow from the agent loop through the step and batch contexts.
…1670) Optional approvalRefusal on the shared runner core options. Absent, the worker session policy keeps Fusion's texts unchanged.
…ing tasks check (ATO-1670) - The per-turn child count keys on ToolContext.turnId, one entry per session and a bounded number of sessions. - A turn that asked its link for a model runs its subagents on it and their rows name it. - A task may declare files: the person is asked once per call under the fusion_fanout category, and a yes lets the subagents write there. Subagents get their own refusal texts, naming no orchestrator. - Unknown task keys are refused also when tasks arrive as a JSON string.
…670) resolveUserPath leaves an absolute path as written, so files: ["/a/../b"] gave the directory "/a/..", which passed the breadth check and then covered the whole disk. Every path is resolved before dirname, and collapseScope resolves each directory before judging it.
…is per directory (ATO-1670) Outside Fusion nothing clears the gate's turn grant at turn start, so subagent.run remembers the turn each session's grant came from and clears it before reading it in any other turn, or without a turn id. The descriptor and README now say a yes covers the directories of the listed files and the working directory.
…unt (ATO-1670) ToolContext.turnSpend carries the turn's cost ceiling, the spend so far and a way to add to it, only when a ceiling is set. What a tool adds goes into the same turn spend the loop checks before every step.
…e options (ATO-1670) Type-only: the runner already read them. A subagent run now passes them.
…p on its cap (ATO-1670) Under a ceiling, each subagent completion is priced with the resolver Fusion workers use and added to the turn's spend. No subagent starts once the ceiling is reached, a running one is stopped through its signal, and the rows say so with Fusion's wording. Without a ceiling nothing changes.
… Fusion (ATO-1670) - A call made once the ceiling is reached is refused before any approval question and before it counts toward the per-turn cap. - A stopped run ends its output with the stop line and what to do. - Every row the ceiling cut gets the note, whatever status it ended in. - A cloud leg with no price says on its rows that the ceiling was not applied to it. - onTaskFinished moves into the shared runner core options (type only).
…and flag only cloud legs as unpriced (ATO-1670) - The Stopped line and details.stoppedBy appear only when a row was cut or not started by the ceiling. A run whose last completion crossed it but finished gets a neutral line and details.ceilingReached. - The unpriced note uses the provider's own local check (llama-server or a local server URL), not slot affinity.
…op note match (ATO-1670)
This branch has not been deployed
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.
Stacked on #1728 (ATO-1669, shared worker runner, itself on #1560). Also contains a merge of #1722 (ATO-1666, worker session depth). Retarget to
mainonce those are merged.Linear: ATO-1670. Also fixes ATO-1682 (a
..path in declaredfileswidened the write grant to the whole disk, in Fusion too).What changes
A new tool,
subagent.run, lets the agent hand one or more tasks to subagents in normal mode (not only in Fusion), on the shared worker runner. A subagent runs on the session's current model with the worker tool policy; a profile (explore,review,research, or one from files/settings) narrows its tools and adds its prompt.Decisions copied from precedents:
SUBAGENT_MAX_DEPTH, a constant, no setting yet). Precedent: Claude Code subagents cannot spawn subagents; Codex multi-agent defaults to max depth 1.s-w-worker id as depth 1 even with a missing or broken stamp (fail closed). It is also hidden from workers (WORKER_EXCLUDED_TOOLS) and blocked by the worker tool filter at dispatch.DEFAULT_FUSION_CLOUD_WORKERS), 24 per turn (DEFAULT_FUSION_TASK_TREE_MAX_NODES). The limits are an extension of the task tree: a newtreeLimitBreachintask-tree.tsis used bycanSplitAt, bothvalidateSplitProposalrefusals (same results, same messages) and bysubagent.run.subagent.run(repo'sfamily.verb, likeverify.run; Claude Code "Task", Codexspawn_agent). Hooks written for Claude'sTaskalso match it.ToolContextgains optionalmodelandturnId. A profile's model or role resolves exactly as in Fusion.files; the person is asked once per call (same fan-out approval asfusion.delegate), and a yes lets the subagents write in the directories of those files and the working directory for this turn only. Withoutfilesa subagent cannot write below the trust level that would allow it anyway, and its refusal text tells the model to declarefilesor do the edit itself.fusion.delegate).fusion-delegate.tsis untouched.Spend ceiling
Subagents stop on the parent turn's spend ceiling the way Fusion workers stop on its cap.
ToolContextgains an optionalturnSpendseam (ceilingUsd,spentUsd(),add(usd)).agent-loopsets it only when the turn'scostCeilingUsd > 0;addgoes throughrecordCompactionSpend, so subagent spend lands inturn.spendUsdand the normal ceiling check stops the parent after the tool returns.step-contract,step-executor,batch-contract,batch-scheduleronly pass the field through. No ceiling, no change.subagent.runprices each child completion with the same resolver asfusion.delegate(resolveWorkerPricing+estimateUsageCostUsd), adds it to the turn, starts no new task once the ceiling is reached and aborts running ones when usage crosses it.Stopped:line and an instruction not to retry only when the ceiling actually cut or held back a task; if every task finished and the last usage crossed the ceiling, a neutral "Spend budget for this turn is now reached." line instead. Rows cut by the ceiling get the cap note whatever status the runner gave them.llama-server, not a local URL, same rule as the session readout). Local legs stay silent.shouldStart,onWorkerUsageandonTaskFinishedmoved type-only from the Fusion extras intoWorkerRunnerCoreOptions; Fusion behaviour unchanged.Duplication left for ATO-1671
Profile loading, per-task leg notes and row model labels, the local-leg width rule and the ceiling wiring (
ceilingStop,ceilingAbort,shouldStart,onWorkerUsage) are copied fromfusion-delegate.ts;fusion.delegate's own guard still checks only the id prefix. ATO-1671 movesfusion.delegateonto this path once #605 and #1560 are merged or closed.Known limits
MintedSessionMetadataonly changes outcomes once max depth goes above 1 (commented).Tests
New
src/tools/subagent/*.test.ts(refusals by depth stamp and bys-w-id with a broken stamp, run from depth 0 stamps the child depth 1 with originsubagent, caps per call and per turn by turn id, profile tools, unknown profile, Fusion refused, turn model used, declared files ask once at approval level 1 with a real gate, a grant does not carry into the next turn, stringtaskskey check). Plustask-tree,fanout-paths(..normalised),worker-runner-core(depth option),agent-loop-fusion-seams(turn id and model reach tools; the seam exists only under a ceiling and spend added by a tool stops the turn withcost_ceiling), spend ceiling insubagent-run.test.ts(refused up front with no prompt and no ledger count, stop mid-run with theStopped:line, cap note on a cutfailedrow, neutral line when nothing was cut, unpriced cloud vs local legs, no change without a ceiling), and deliberate pin updates:worker-tool-policyexact list, conformance (119 descriptors), catalog, filter gate, resource class, hooks,/toolslisting, feed line.Verification
tasksskipping the key check (85). Fixed in round 1...infileswidened the grant (pre-existing, ATO-1682). Fixed in round 2. Final re-check: no findings.Stopped:line, cap note on every cut row, unpriced note, tests); round 2 reported a stop only when something was cut and used the real local-provider rule. Final re-check: minors only, listed under Known limits.agent-loop.ts,step-executor.ts,batch-scheduler.ts,step-contract.ts,batch-contract.ts,turn-spend.ts): optional pass-through fields plus the smallturnSpendblock inagent-loop. Open PRs on those files: ATO-1432, ATO-1435: report what the engine wait decided on and why the engine is gone #1284 ATO-1434: stop waiting after 90 s when the engine lock is held and no model process exists #1520 Wait before re-asking after an empty model answer (ATO-1676) #1723 Count native tool schemas in the local prompt budget (ATO-1678) #1726 (agent-loop), Log why a model reply was empty: finish reason, tokens, provider, model, request size (ATO-1572) #1613 Wait before re-asking after an empty model answer (ATO-1676) #1723 (step-executor), TUI: step cost in /why and saved /verbose choice (ATO-34) #1709 (turn-spend). Shared registries (compact forms, resource class, filter gate, grammar,/tools) are also touched by Screen capture on Windows and Linux (ATO-527) #1675 Browser: Take over, the user finishes a step and hands back (ATO-508) #1679 Screen control: numbered app elements and background press (ATO-998, ATO-530) #1680 Browser scenarios: record once, replay without the model (ATO-960) #1691 My files: index chosen folders, progress routes and files.search with page citations (ATO-1621) #1697 fix(browser): keep the Annotate note box out of the page's reach (ATO-1543) #1608 Tables and charts in os.fs.write_pptx, shared OOXML zip helper (ATO-537) #1713 Word lists, tables, pictures and tracked changes; Excel charts (ATO-541) #1720: additive entries.npx vitest run src/tools/subagent src/tools/fusion src/tools/tool-contract-conformance.test.ts src/tools/tool-roles.test.ts src/tools/tool-output-spill.test.ts src/runtime src/agent src/hooks src/tui/commands, typecheck,imports:check, a grammar check. In the app: normal mode, ask for a subagent with profileexplore, see the worker row in the feed.Not yet checked on the second Mac.