Dropped the pi- prefix from crate directories (crates/pi-X -> crates/X) and renamed the packages to omp-X. pi-walker and pi-watch are now one crate, omp-xfs, with the watcher nested as omp_xfs::watch. omp-natives keeps lib name pi_natives so the shipped pi_natives.<platform>.node addons and their loader, CI, Nix and Docker paths are unchanged.
54 KiB
task
Spawn subagents — one per call, or a
tasks[]batch per call (task.batch, default on). Withasync.enabled=true, ordinary spawns run in the background; otherwise the call blocks until they finish. Execution mode is per item: an item whose custom agent type declaresblocking: trueruns inline while non-blocking items in the same call still spawn as background jobs. No bundled agent currently declaresblocking: true.
Source
- Entry:
packages/coding-agent/src/task/index.ts - Model-facing prompt:
packages/coding-agent/src/prompts/tools/task.md - Key collaborators:
packages/coding-agent/src/task/types.ts— dynamic schema, agent definitions, output caps.packages/tui/src/tools/task.ts— progress/result and tool-details types.packages/coding-agent/src/task/structured-subagent.ts— shared task/eval preflight, model/schema policy, artifact retention, execution.packages/coding-agent/src/task/isolation-runner.ts— isolation capture, merge, recovery, and lifecycle ownership.packages/coding-agent/src/task/eval-tools.ts— expose parent-kernel tools to a child.packages/coding-agent/src/task/discovery.ts— discover project/user/plugin/bundled agents.packages/coding-agent/src/task/agents.ts— bundled agent definitions and frontmatter parsing.packages/coding-agent/src/task/executor.ts— create child sessions, run subagents, collect output, hand finished sessions to the lifecycle manager.packages/coding-agent/src/thread/— subagent worker threads: worker pool (subagent-worker.ts), main↔worker RPC (rpc.ts), run routing (executor-routing.ts), main-side mirrors of worker-homed sessions (remote-agent-session.ts), and one bridge per shared main-thread service (services/).packages/coding-agent/src/registry/agent-lifecycle.ts— idle-TTL parking and revival of finished subagents.packages/coding-agent/src/registry/agent-registry.ts— process-global agent directory (running | idle | parked | aborted).packages/coding-agent/src/async/job-manager.ts— background job registration, progress, and result delivery.packages/coding-agent/src/task/parallel.ts—Semaphoreused for the session-scoped concurrency bound.@oh-my-pi/pi-natives(crates/iso) — isolation PAL:isoResolve/isoStart/isoStopbackend resolution and fallback.packages/coding-agent/src/task/worktree.ts— isolation backend mapping (parseIsolationBackend) and lifecycle (ensureIsolation/cleanupIsolation), patch capture, branch merge.packages/coding-agent/src/task/output-manager.ts— session-scopedagent://id allocation.packages/coding-agent/src/task/name-generator.ts— default AdjectiveNoun agent ids.packages/coding-agent/src/internal-urls/agent-protocol.ts— resolveagent://<id>to saved subagent output.packages/coding-agent/src/internal-urls/history-protocol.ts— resolvehistory://<id>to a concise transcript.packages/coding-agent/src/tools/index.ts— tool registration and recursion-depth gating.packages/coding-agent/src/sdk.ts— child-session router/tool wiring and per-subagentAgentOutputManager.docs/task-agent-discovery.md— deeper discovery and precedence notes.
Inputs
The wire schema is shape-swapped by task.batch (default on). One unit of work is { name?, agent?, model?, task, solutionSpace, effort?, outputSchema?, schemaMode?, tools?, isolated? }. isolated exists only when task.isolation.enabled is true and plan mode is disabled; effort requires task.enableEffort=true (default off), and tools requires eval.tools.enabled (default on).
task.steps (default off) swaps task for steps: string[] in the wire schema and tool description, in either shape: the model sees only one of the two. Runtime accepts either (internal callers, stale transcripts) but rejects an item carrying both.
- Batch shape (
task.batchon):{ context, tasks: item[] }— one subagent per item, all run under the same fan-out rules; there is no top-level agent field.contextis required shared background rendered into every spawned subagent's system prompt (CONTEXTsection);agent,outputSchema, andschemaModeare per item.effortis added only when its setting enables it;isolatedadditionally requires plan mode to be disabled. - Flat shape (
task.batchoff):{ ...item }— exactly one spawn per call. Shared background goes into alocal://file (e.g.local://ctx.md) that each spawn'staskreferences; subagents share the parent'slocal://root.
| Field | Type | Required | Description |
|---|---|---|---|
context |
string |
Yes (batch) | Shared background prepended to every spawn of the call via the subagent system prompt. Rejected when task.batch is off. |
tasks |
array |
Yes (batch) | One task item per subagent. Provided names must be unique within the call (case-insensitive). Rejected when task.batch is off. |
name |
string |
No | Stable agent name — becomes the registry/IRC id. The prompt requests CamelCase, at most 32 characters; the wire schema only requires a string. Defaults to a generated AdjectiveNoun name and is uniquified per session by AgentOutputManager. Item field in batch shape, top-level in flat shape. |
agent |
string |
No | Agent type to run this item (e.g. scout). Defaults to the spawn policy's default agent (usually task); items in one batch call may use different agent types. Item field in batch shape, top-level in flat shape. |
model |
string |
No | Per-call model: one exact provider/model-id[@upstream][:level], accepted only when task.perCallModel is on and limited to operator-approved models; otherwise the call fails preflight (see Per-call model). @upstream is an aggregator-only route pin and part of the model identity. Present in the schema only when task.perCallModel is on; an unadvertised model still reaches preflight instead of being dropped. An empty string is treated as omitted. Item field in batch shape, top-level in flat shape. |
task |
string |
Yes, unless task.steps is on |
Complete, self-contained instructions. Empty-after-trim is rejected. Item field in batch shape, top-level in flat shape. |
steps |
string[] |
Yes, when task.steps is on |
Replaces task: ordered stages for one subagent, each non-empty. The first is the initial prompt; each later one is sent once the subagent delivered the previous (terminal yield, or its final message without yield). More than MAX_STEPS (4) steps share prompts, earlier prompts taking the extra (5 → 2-1-1-1). What the subagent delivers for each earlier prompt reaches its spawner as an IRC progress note (a busy spawner reads it at its next step boundary, an idle one wakes, a wait keeps waiting); the last prompt's result is the spawn's result. A failed yield or a budget stop ends the chain early. Item field in batch shape, top-level in flat shape. |
solutionSpace |
string |
Yes | How open-ended the child's problem is: whether the fix or design is given, or which causes or designs remain open (e.g. one fix: rename, names given; deadlock cause open, no repro). Volume of work does not widen it. Rides the child's first prompt into the auto thinking classifier as its sole input — the judge sees this field, not the task text; ignored when the child's thinking selector is not auto or effort overrides it. Blank or missing values fall back to classifying the task text: the schema advertises it as required, but the tool's lenient argument validation still spawns a call that omits it. Item field in batch shape, top-level in flat shape. |
effort |
"lo" | "med" | "hi" |
No | Present only with task.enableEffort=true. Per-spawn thinking effort, mapped onto the resolved model's supported range (lowest/middle/highest level it tops out at, e.g. high/xhigh/max). Overrides the agent's default selector, including auto, except for a mention agent whose tag names a level, which ignores it; omitting it keeps the agent's configured selector — automatic per-prompt classification only for agents configured auto (e.g. the bundled task); scout/sonic configure medium. Item field in batch shape, top-level in flat shape. |
outputSchema |
JSON Schema (object | boolean | string | null at the coarse wire-validation layer) |
No | Invocation-specific structured-output contract. Takes precedence over agent frontmatter output and the inherited parent session schema. Item field in batch shape, top-level in flat shape. |
schemaMode |
"permissive" | "strict" |
No | Validation mode for the effective output schema. Overrides the parent mode; defaults to permissive. After schema-retry exhaustion, permissive mode can accept invalid payloads with a warning; strict mode fails. Invalid caller schemas fail preflight in either mode. |
tools |
string[] |
No | Named tools already defined in the parent's Python or JS eval kernel. Present when eval.tools.enabled=true; child calls execute in the parent kernel, not the child's. Rejected in plan mode. Item field in batch shape, top-level in flat shape. |
isolated |
boolean |
No | Run in an isolated workspace and capture patches/branch changes. Present only when task.isolation.enabled is true and plan mode is disabled. Kept-alive task agents retain their workspace through idle/parked transitions and can be revived; release captures final changes and cleans the workspace. |
There is no wire label field: the one-line UI label shown in the TUI/registry is generated automatically from the task text by the tiny/title model (fire-and-forget), so callers never provide it.
With task.steps on, an item reads { "name": "Implement", "steps": ["Add the parser in src/parse.ts.", "Wire it into the CLI.", "Cover both with tests."], "solutionSpace": "…" }. Each step's text reaches the subagent trimmed, with LF line endings and its interior whitespace kept. The run records the prompts it sent as task-steps session entries, so omp --restore sends the ones an interrupted subagent had left after resuming its turn.
Users can tag models with ^ in the composer. The resulting session-local m1, m2, … pseudonyms are accepted as agent by task, eval agent(), and workpool(); each uses the bundled task template pinned to the tagged selector. A ^provider/model:level tag also sets the agent's initial effort, which the effort hint does not override. A user-tagged ^provider/model agent without a level grants its tagged model for per-call selection, subject to task.perCallModelAllow; a per-call model for a level-tagged agent is a conflict error. See user-tagged model agents for persistence, boundaries, and precedence.
When per-call selection is enabled for a surface, the task/eval tool descriptions list approved role models from the operator's settings and the narrowing allowlist; project settings never add a model and can only narrow the list.
Runtime stays permissive: the flat form is accepted even while task.batch is on (internal callers such as the commit flow's analyze_files, and stale transcripts). The model only ever sees one shape.
Batch calls reject a top-level agent rather than silently discarding a specialist selector and spawning the default agent. Put agent on each tasks[] item when selecting reviewer, scout, or a custom agent; the agent name is not inferred from the task text.
There is no legacy per-call schema parameter. Use outputSchema and optional schemaMode; when absent, structured output falls back to the agent definition's output frontmatter and then the inherited parent session schema.
Outputs
The tool returns one text block plus details: TaskToolDetails.
A stepped spawn's assignment (on details.progress items and details.results entries) lists every step as one Markdown brief; task is the initial prompt, carrying only the first.
When async.enabled=true, the Task tool description supplies the delivery rules: results auto-deliver, blocked callers can use wait if the tool is active, and a completed result's claimed artifacts are unverified. The job-lifecycle reference (read proc://<id> inspects without consuming delivery, write proc://<id>/kill cancels, how long results and job IDs live, write agent://<id> when peer messaging is enabled) rides the first spawn result of each TaskTool instance only; later acknowledgments do not repeat it.
Extensions that replace task inherit this guidance (the native tool's delegationGuidance) in their description for calls delegated through ctx.invokeTool, while keeping their own calling instructions and input schema.
Background response (async.enabled=true):
content:Spawned agent `<id>` (job `<jobId>`).(the first spawn result of the session continues with the job-lifecycle reference). A batch call instead returnsSpawned N background agents using <agent types>. ...(the deduped per-item agent types, comma-joined) with a per-agent-(job)listing.details:{ projectAgentsDir, results, totalDurationMs, progress: [<AgentProgress per spawn>], async: { state, jobId, type: "task" } }. The call keeps one sharedprogress[]snapshot;async.jobIdis the first started job andasync.stateaggregates over the async spawns ("running" until every job settles, "failed" if any spawn failed) — jobs that settled before the call returned are already reflected. A mixed call'sresultscarries the blocking spawns' inlineSingleResults (pure background calls returnresults: []).- Live progress streams into the same tool block via
onUpdate(...); final results arrive as async-result injections. Non-isolated completions get an idle/follow-up hint when messaging is enabled. Aborted agents that can be resumed get a resume hint; isolated runs point at the transcript. The currenttask-follow-up.mdtemplate still labels isolated runs non-resumable, despite the retained-workspace lifecycle described below.
Settled response (async.enabled=false, no job manager, every item's agent blocking: true, or async job body):
content: summary rendered frompackages/coding-agent/src/prompts/tools/task-summary.md; output up to 11500 chars is inline whole, longer output shows a 5000-char preview andagent://<id>holds the full output. A sync batch concatenates the per-spawn summaries.details.results: oneSingleResultper spawn;usage,outputPathspopulated (aggregated across spawns for a sync batch).
SingleResult includes:
- identity:
index,id,agent,agentSource,task,description, optionalassignment(internal payload names; the wire fields arename/agent/task) - status:
exitCode, optionalerror, optionalaborted, optionalabortReason, optionalretryFailure - output:
output,stderr,truncated,durationMs,tokens,requests, optionalcontextTokens/contextWindow,usage - model: optional
modelOverride,modelRole,resolvedModel,resolvedModelIdentity,resolvedThinkingLevel,resolvedModelIsFallback,resolvedModelRoute,advisor - structured result: optional
structuredOutputwith schema source/mode, validation status, parseddata, and validationerror - artifact metadata:
outputPath?,isolated?,patchPath?,hasRootChanges?,branchName?,branchBaseSha?,nestedPatches?,nestedPatchPaths?,outputMeta? - extracted tool data:
extractedToolData?from registered subprocess tool handlers such asyield
Artifacts and side channels:
- Every subagent with an artifacts dir writes
<id>.md;agent://<id>resolves to that file. - Structured payloads with a
datavalue also write<id>.json, even when schema-invalid. JSON-path reads prefer this sidecar and fall back to parsing<id>.md; a later output without structured data removes a stale sidecar. - A subagent's own children are dot-qualified (
<id>.<child>);agent://<id>.<child>reads that nested output. A slash path is always JSON extraction:agent://<id>/<key>/<index>/…extracts that value from a JSON output (e.g.agent://<id>.<child>/reports/0/data). - Each subagent gets
<id>.jsonlsession history when the parent persists artifacts;history://<id>renders it as a concise transcript (works for live and parked agents). - Isolated patch mode writes
<id>.patchbefore merge; nested changes write<id>.nested-<n>-<path>.patchfiles in both merge modes.
Flow
TaskTool.create(...)discovers agents through a process-level memo keyed by resolved cwd and effective extension roots (discoverAgentsForCreate).refreshAgentDiscovery(...)replaces the matching description snapshot after explicit reloads.execute(...)repairs inline prose (repairTaskParams), then validates:schemais always rejected;tasks/contextare rejected unlesstask.batchis on; batch calls need a non-emptytasks, unique provided names, a non-empty sharedcontext, and no top-leveltaskorstepsalongsidetasks. Each item or flat call needs a non-emptytaskor a non-emptystepslist, not both. The call is normalized into its spawn list (resolveSpawnItems) before normal dispatch starts any spawn. Eval-tool names and every item's effective spawn policy are preflighted before normal dispatch registers jobs. Unknown/disabled agents, invalid caller schemas, depth/spawn-policy violations, and unavailable plan-mode controls fail the call before dispatch.- Per-item execution split: items whose agent type declares
blocking: truerun inline; the rest become background jobs. The whole call runs sync whenasync.enabled=false, the session has noAsyncJobManager(orphaned host), or every item is blocking; inline spawns run asSpawnRuns (src/task/spawn-run.ts), each holding a session-scoped semaphore permit until it settles. - Background execution (any non-blocking item with
async.enabled=trueand anAsyncJobManager):- agent ids are allocated up front via
AgentOutputManager.allocate(...)— each item'sname, or a generated AdjectiveNoun name — one per spawn; - one
type: "task"job per spawn is registered withsession.asyncJobManager(id= agent id,queued: true,ownerId= caller agent id) and the tool returns immediately; - each job body starts — or adopts, after a speculative launch — a
SpawnRun, which acquires the session-scopedSemaphore(one perTaskToolinstance, resized in place from the livetask.maxConcurrencysetting before every acquire and release); the job is marked running once the permit is held and reports progress through the sharedbuildAsyncDetails/onUpdate; - a failed or aborted run throws
TaskJobErrorso the job landsfailed, but the agent itself stays registered and interrogable. - a mixed call registers the async jobs first, then runs its blocking items inline and returns once they settle — the text combines the inline summaries with the spawned-job listing, and the block keeps rendering the still-running background rows beside the inline results.
- agent ids are allocated up front via
- Each
SpawnRuncalls#runSpawn→runStructuredSubagent(...). Shared policy resolution reloads settings and rediscovers agents from disk, so runtime resolution can differ from the create-time description. - It resolves the requested agent, enforces depth/spawn policy and
PI_BLOCKED_AGENTself-recursion prevention, validates the effective output schema, and appliesbefore_subagent_spawnrouting/blocking hooks. - Model priority:
task.agentModelOverrides→ agent frontmatter → configured task role/session fallback. An approved per-callmodelreplaces the last two; for an agent with atask.agentModelOverridesentry or a level-tagged mention agent it is a conflict error. Output schema priority: per-calloutputSchema→ agent frontmatteroutput→ inherited parent session schema. - Plan mode supplies
read,grep,glob,web_search, and any configuredast_grep, replaces the agent's spawn/prewalk controls, and disables LSP/IRC. Eval-defined tools and isolation/apply/merge controls are rejected. - If
isolated, it requires a git repo (getRepoRoot(...)/captureBaseline(...)) and opens the run's workspace (openWorkspace): by default it mapsisolation.backendto a backend-kind hint (parseIsolationBackend) and materializes the workspace via the natives PAL (nativeWorkspace→ensureIsolation→isoResolve/isoStart), walking the candidate list when a backend is unavailable; whenisolation.backendisautoand ovnfs is found (ovnfsCommand), it opens an ovnfs checkout instead (ovnfsWorkspace,task/ovnfs.ts). - Artifacts dir comes from the parent session file when available, otherwise a temp dir. When the session is executing an approved plan, the plan reference is handed to the subagent.
- Non-isolated spawns call
runSubprocess(...)with parent cwd. Isolated spawns run in their workspace and capture root/nested patches or a branch. Successful changes apply only whentask.isolation.apply=true; failed capture/merge paths preserve recovery artifacts. Kept-alive runs transfer workspace cleanup to the lifecycle owner rather than tearing it down at completion. runSubprocess(...)creates a child agent session with an isolated settings snapshot (parent settings inherited —async.enabledandbash.autoBackground.enabledare inherited from the parent, not force-disabled;tier.openai/tier.anthropic/tier.googleare first re-resolved throughtier.subagent, then the child session resolves an exacttask.agentServiceTierOverrides[agentName]entry handed over by task/eval dispatch against its final model and persists the result;tools.approvalModeis forced toyolobecause headless subagents have no UI to confirm prompts against;advisor.enabledis forced off unless the spawn opts in per agent; per-spawn overrides may disable read summarization and clear extra workspace roots for isolated runs), childagentIdequal to the allocated id, child internal URL router/AgentOutputManager, output schema, the sharedcontext(batch calls) in the system prompt'sCONTEXTsection, and the IRC peer roster in the system prompt. An exacttask.agentAccountPools[agentName]entry is installed on the child's provider session right after the parent's account affinity is copied, and the child's model registry enforces it on every key lookup, so for each listed provider the child, its side requests, and subagents it spawns without their own entry authenticate only with those OAuth accounts; vibe workers and revived agents take the live entry. See Task agent discovery.- Child tool availability starts from explicit
agent.toolswhen provided; auto-addtaskfor declared spawns below the depth limit. Explicit lists containingtask/bashgainwaitunless restricted, and the registry still requires an async/IRC/service wake source.execexpands tobashplusevalwhen a backend is enabled. Outbound messaging requires explicitwrite, while inbound steering does not. Parent-ownedtodois stripped unless prewalk is armed. - The child must finish through the hidden
yieldtool; up to 3 reminder prompts, the last forcingtoolChoice = yieldwhen supported.finalizeSubprocessOutput(...)reconciles raw text,yieldpayloads, structured schemas, and abort states. - End-of-run lifecycle (keep-alive, in the run finalizer):
- caller signal, user interrupt, wall-clock timeout, or soft-request-budget abort on a kept-alive agent with a reviver → only the run stops: the agent becomes
idleand may receive a follow-up/revival; - explicit kill (Agent Hub, RPC
cancel_subagent, collab, vibe), or an aborted agent without a reviver → registry statusaborted, session disposed, kill tombstone written; a later message or Hub revive reopens the transcript as a freshparkedgeneration, removes the tombstone, and revives it; - manager shutdown → dispose/unregister the process-local session without a kill tombstone;
- isolated kept-alive run → follows the same idle/parking/revival path while retaining its workspace; explicit release captures final patches/branch state and cleans the isolation handle;
- everything else (success and failure alike) → status
idlewith the live session attached, andAgentLifecycleManager.global().adopt(id, { idleTtlMs, revive })arms the park timer. The reviver reopens the session JSONL.
- caller signal, user interrupt, wall-clock timeout, or soft-request-budget abort on a kept-alive agent with a reviver → only the run stops: the agent becomes
- Lifecycle thereafter:
idleagents are parked aftertask.agentIdleTtlMs(session disposed;AgentRef+ session file retained);write agent://<id>or the Agent Hub revives parked and killed agents back toidle."Main"is never parked.
Modes / Variants
- Execution mode
- Background job —
async.enabled=true; non-blocking spawns go throughAsyncJobManager. - Sync inline —
async.enabled=false, no job manager, or the item's agent declaresblocking: true(per item: a mixed call runs both modes).
- Background job —
- Thread (
task.workerThreads, default4: the most worker threads used; omp CLI and compiled binary only)- Placement — workers are used only when enough subagents run at once. With
nsubagent runs in flight that the main thread placed (its own in-process runs and follow-up turns plus runs on workers, counting the spawn being placed),W(n) = 0forn < 9(SUBAGENT_WORKER_THRESHOLDinsrc/thread/subagent-worker.ts), elsemin(task.workerThreads, floor(log2(n / 9)) + 1): 1–8 runs stay on the main thread, 9–17 add one worker, 18–35 two, 36–71 three, 72+ four. Each top-level spawn and each cold revival goes to whichever of the main thread and the firstW(n)worker slots has the fewest runs in flight, starting a worker for an empty slot; ties prefer an existing worker over the main thread (which also drives the TUI), and the main thread over starting a worker. Kept-alive idle subagents do not count as running. - Worker — a spawn placed on a worker runs its whole
runSubprocess(...)(child session, tools, monitor, lifecycle finalization) there; spawns made inside a subagent stay in that subagent's thread and do not count toward the main thread'sn. Follow-up turns and warm revivals run on the agent's home thread (its worker, or the main thread); a cold revival is placed like a fresh spawn. - On demand — a worker boots ahead of time only when the spawns being streamed (the in-flight count plus the
tasks[]items of the streamingtaskcall seen so far, or 1; anevalcall whose code callsagent(/workpool(counts as 1) reach a bracket whose worker slot is empty; otherwise the placement that needs it starts it. A worker lives while it runs a subagent or holds a live (idle, kept-alive) subagent session, and exits 60 s after it has neither, releasing its memory; whenndrops, existing workers are not stopped early. - Main — fewer than 9 concurrent subagents,
task.workerThreads: 0, SDK embedding, andbun testrun subagents on the main thread. - Shared state stays single-owned on the main thread and reaches workers by RPC: agent registry, lifecycle, IRC bus, async jobs, cost gate, event buses, artifact ids, agent storage, auth storage (pins, account pools, OAuth refresh), MCP connections, Hindsight/Mnemopi state, telemetry spans, and logs. Workers get live mirrors of the parent settings and build their own model catalog over main's auth storage. The main thread sees a worker-homed subagent as a mirrored session that the Agent Hub, focus view,
agent://,history://,proc://, and RPC mode use like a local one. - Extensions — workers re-import file-backed prepared extensions; inline factories (
<inline-N>) cannot cross threads, so worker-hosted subagents run without them and the main thread logs a warning (Extension loading). - A worker that exits mid-run fails that run with an error naming the worker; its agents are detached as
parked(with a transcript) oraborted, and a revival is placed like a fresh spawn.
- Placement — workers are used only when enough subagents run at once. With
- Batch mode (
task.batch, default on)- on —
{ context, tasks[] }: one independent spawn per item, requiredcontextshared across the call's spawns, withagent,outputSchema, andschemaModeper item.effortappears only when its setting enables it;isolatedalso requires plan mode to be disabled. Lifecycle, revival, and concurrency semantics match N parallel single calls. - off — single spawn per call;
tasks/contextare rejected and removed from the schema, with the same conditionaleffort/isolatedfields.
- on —
- Speculative launch (
task.speculativeLaunch, default on; batch mode only) — while a{ context, tasks[] }call streams, the tool's stream session (src/task/speculative-launch.ts) starts each item'sSpawnRunas soon as that item's JSON object closes (contextmust already have closed), and starts the remainder when the call finishes streaming. Dispatch adopts runs whose normalized spawn params still match; an invalid finished call, launched items that differ from the finished call, a blocking hook, or an aborted turn aborts every launched run. Launches need host authorization (authorizeLaunch): auto-allowedtaskapproval and no extensiontool_call/tool_result/approval lifecycle handlers. - Isolation is available when
task.isolation.enabledis true: each task must setisolated: trueto use a separate checkout; omitted orfalsetasks share the parent checkout.isolation.backendselectsauto,apfs,btrfs,zfs,reflink,overlayfs,projfs,block-clone, orrcopy, and the PAL resolves the actual backend with fallback;autouses ovnfs for isolated subagents when it is found (below). - ovnfs (active whenever the binary is found —
ovnfs.path, defaultovnfson PATH): the system prompt gains a "Separate checkouts" section telling agents to open ovnfs checkouts (ovnfs new,diff,apply,land,pull,rm) instead ofgit worktree add,git cloneorcp -r. Whentask.isolation.enabledalso allows isolated tasks andisolation.backendisauto, each isolated subagent works in an ovnfs checkout — a copy-on-write view of the repo with a private git dir, served by the ovnfs daemon — instead of a native clone. omp runsovnfs --json startto make sure the daemon runs and learn its admin socket, then opens (new) and removes (rm) one checkout per run over that Unix socket. Capture, merge and apply are the same as for native workspaces. The run's task-isolation dir records the checkout (.omp-ovnfs-checkout.json) soomp worktree clearremoves checkouts of crashed runs; a checkout whose changes could not be captured is kept like a native workspace. Without the binary, isolation stays native; once ovnfs is found there is no fallback: if it fails, the isolated task fails and says so. - Isolation merge strategy:
task.isolation.mergeselects patch mode (capture/apply root patches) or branch mode (commit toomp/task/<id>, cherry-pick into parent).task.isolation.apply=falseretains captured changes without applying them; nested repositories get separate patch artifacts. - Eval-defined tools:
toolsresolves names across the parent's retained Python/JS kernels. Unknown names, disabled sharing, or the same name defined in both kernels fail preflight; these tools are not available in plan mode. - Agent source precedence is first-wins by exact name: project
.omp/agents; user.omp/agent/agents; OMP extension-packageagents/roots in CLI → project settings → user settings → installed npm/link plugin order; Claude marketplace plugin agents (project before user); then bundled (scout,reviewer,security-reviewer,task,sonic). - Prewalk: agent frontmatter
prewalkortask.agentPrewalk[agentName]can start on the normal model and hand off to a cheaper resolved model at the first edit/write.task.prewalk(default off) arms this behavior for the bundled generictaskagent. Missing/unconfigured targets and exact model+effort no-ops skip the handoff rather than failing the spawn. - Auto-prewalk:
task.agentPrewalkAuto[agentName]("on"/"off"/ model pattern) lets the native judge decide per assignment whether an agent with no unconditional prewalk hands off;"on"usesprewalk.autoTarget, any other value the given target. An unconditional prewalk from frontmatter,task.prewalkortask.agentPrewalkwins and is never judged, and skipped spawns, unavailable targets or a judge failure leave the spawn without prewalk. - Advisor: agent frontmatter
advisorortask.agentAdvisor[agentName]("on"/"off"/ model pattern) pairs the child session with an advisor; an explicit pattern lands on the child'smodelRoles.advisor. Subagents default to no advisor.
Side Effects
- Filesystem
- Writes
<id>.jsonland<id>.mdunder the session artifacts dir or a temp task dir; isolated patch mode writes<id>.patch. - Creates/removes worktrees or overlay mount directories; branch mode creates temporary worktrees and task branches.
- Writes
- Network
- Child sessions may use whichever networked tools/models their active tool set permits.
- MCP proxy tools reuse parent connections and their configured transport deadlines, including
OMP_MCP_TIMEOUT_MSoverrides andtimeout: 0; no separate subagent deadline caps a tool call.
- Subprocesses / native bindings
- Isolation backends run through the
omp-nativesPAL (crates/iso): kerneloverlaywithfuse-overlayfs/fusermount[3]fallback on Linux, APFS/Btrfs/ZFS/reflink clones, ProjFS on Windows, recursive copy as last resort. - Git operations for baseline capture, patch apply, worktrees, branches, stash, cherry-pick, commits.
- Isolation backends run through the
- Session state (transcript, memory, jobs, checkpoints, registries)
- Creates child
AgentSessioninstances with isolated settings snapshots; finished sessions stay registered in the process-globalAgentRegistryasidle/parkeduntil process teardown or explicit release. - With
async.enabled=true, registers one async job per spawn insession.asyncJobManager; completion is injected into the parent as an async-result message. - Arms idle-TTL timers in
AgentLifecycleManager(unref'd; they never hold the process open). - Emits
task:subagent:event,task:subagent:progress, andtask:subagent:lifecycleon the parent event bus. - Allocates session-scoped output ids through
AgentOutputManagersoagent://stays unique across invocations. - Shares the parent
local://root andArtifactManagerwith subagents.
- Creates child
- Background work / cancellation
write proc://<jobId>/kill(emptycontent) or parent tool-call abort cancels background jobs; parent tool-call abort cancels sync runs through the call signal. A cancelled run stops but its agent staysidleand resumable. An owned running subagent without a job can be cancelled throughproc://<agentId>/kill, which aborts and releases its session.- Missing-
yieldrecovery sends up to three internal reminder prompts to the child session.
Limits & Caps
- Tool mode:
approval="exec",strict=false,lenientArgValidation=true,loadMode="essential". - Stepped spawns are opt-in:
task.stepsdefaults tofalse; at mostMAX_STEPS = 4prompts per spawn (packages/coding-agent/src/task/steps.ts). - Per-spawn effort is opt-in:
task.enableEffortdefaults tofalse; when false,effortis omitted from the dynamic model-facing schema. - Concurrency:
task.maxConcurrencydefaults to32;0means unlimited. One session-scopedSemaphoreis resized from the live setting before every acquire/release and bounds everySpawnRunacross task calls, including sync and speculative runs. - Isolation baseline: each repository's uncommitted snapshot is capped at
1 GiB(ISOLATION_BASELINE_MAX_CONTENT_BYTESintask/worktree.ts). Oversized snapshots fail before spawning rather than buffering unbounded content. - Idle TTL:
task.agentIdleTtlMs, default420_000ms (7 min);<= 0disables parking and keeps idle sessions live until exit. - Worker threads:
task.workerThreads, default4(the most used);0keeps subagents on the main thread. Fewer than 9 concurrent subagents (SUBAGENT_WORKER_THRESHOLD) never use a worker; then one worker per doubling (9, 18, 36, 72). A worker with no running subagent and no open session exits after 60 s idle, the last one included. - Per-subagent output truncation:
MAX_OUTPUT_BYTES = 500_000andMAX_OUTPUT_LINES = 5000inpackages/coding-agent/src/task/types.ts(overridable viaPI_TASK_MAX_OUTPUT_BYTES/PI_TASK_MAX_OUTPUT_LINES). Full raw output is still written to<id>.md. - Progress coalescing:
PROGRESS_COALESCE_MS = 150; recent-output tail:RECENT_OUTPUT_TAIL_BYTES = 8 * 1024(last 8 non-empty lines). - Missing-
yieldreminder retries:MAX_YIELD_RETRIES = 3inpackages/coding-agent/src/task/executor.ts. - Soft request budget:
task.softRequestBudgetdefaults to 200 requests (0disables). Crossing it injects a wrap-up notice whentask.softRequestBudgetNoticeis enabled; at 1.5× the budget the run is force-stopped to yield partial findings. Bundled scout/sonic agents cap it at 100; the setting can lower that cap but not raise it. An exact-nametask.agentSoftRequestBudgetentry (lead: 400) replaces both for that agent, in either direction;0there disables its guard. - Hard wall clock:
task.maxRuntimeMsapplies to every spawn; default0disables it. - Recursion depth:
task.maxRecursionDepthdefaults to2; negative values disable the cap. The tool registry and shared preflight enforce it, andrunSubprocess(...)strips childtaskaccess at max depth. - Inline summaries carry output up to
INLINE_OUTPUT_CHARS(11500) characters whole (packages/coding-agent/src/task/result-summary.ts), keeping the envelope under async delivery'sASYNC_INLINE_RESULT_MAX_CHARS(12000); an envelope that a long<error>or<merge-summary>would push past that cap, and any longer output, gets aPREVIEW_CHARS = 5000head instead, which requires a full output artifact.agent://<id>points to that artifact.
Errors
- Shape/preflight failures return
isError: true, explanatory text, and emptyresults:schema(never accepted)tasks/contextwhiletask.batchis disabled- batch calls: missing/empty
tasks, duplicate provided names, missing sharedcontext, top-leveltaskorstepsalongsidetasks - any item or flat call: neither or both of
taskandsteps, empty task text, or an emptystepslist or step - invalid effort, unknown/settings-disabled agents, depth/spawn-policy denial, invalid caller output schemas, disabled isolation, or isolation/eval-tool controls in plan mode
- unknown eval tools, disabled eval sharing, or a name defined in both parent kernels
- per-call
model:task.perCallModeldoes not allow this invocation kind (reported before selector validation); an invalid exact selector; both hostmodeland per-callmodelsupplied through the SDK; a conflictingtask.agentModelOverridesentry; or a mention agent whose^provider/model:leveltag names a level, even whenmodelrepeats the tagged selector - a per-call model is non-chat, unavailable, unapproved by the current grants or excluded by
task.perCallModelAllow - a per-call model has no supported effort at or below
task.maxEffort
- Isolation preparation failures return
Isolated subagent execution could not be prepared: .... They distinguish missing Git repositories, pure Jujutsu workspaces without colocated Git, and oversized snapshots. Unavailable backends fall back through the PAL candidate list; other setup/capture failures preserve available output and recovery artifacts. - Job registration failure returns
Failed to start background task job(s): ...; a batch that schedules only some jobs reports the failed ids in the immediate text and keeps the started ones running. - Child failures surface as
SingleResult.exitCode = 1withstderr/errorpopulated; the async job is marked failed but the delivery text still carries the output plus a follow-up/transcript hint. - Per-call workers also fail if credentials are unavailable or a later main-loop request loses approval or cannot honor the requested-effort cap; they do not drop
modelor use an automatic model fallback. A Factory response served by another model, or carrying a fallback handoff block, fails the worker: the request omits Factory's refusal chain, so a handoff is a violation rather than an answer. Cold revival refuses legacy per-call records without the canonicalperCallModelIdentityand savedperCallThinkingLevel, an unavailable exact saved route, a model no longer granted (a removed/disabled agent or a non-live real parent grants nothing), or an effort floor above the livetask.maxEffort. Revival waits for a model-registry refresh already in flight before the exact lookup; it does not start one, so a cold registry fails the revival withCannot revive subagent "<id>": its per-call model <provider/model-id> is no longer available. A per-call worker revives only on its exact saved model. - If the child omits
yield,finalizeSubprocessOutput(...)injects warnings such asSYSTEM WARNING: Subagent exited without calling yield tool after 3 reminders. agent://<id>reads report unavailable sessions/artifact directories, missing ids, or invalid JSON for field extraction.agent://allis write-only; message targets cannot carry JSON-path suffixes.
Notes
- Parallelism is parallel
taskcalls in one assistant message — or, withtask.batch, atasks[]batch in one call; either way the session-scoped semaphore bounds the fan-out. Withasync.enabled=true, each spawn is an independent background job. - Shared background convention without batch mode: write it once to a
local://file and reference that path in each spawn'stask— subagents share the parent'slocal://root. Withtask.batch, the requiredcontextparameter carries the shared background directly into each spawn's system prompt. - Prefer messaging an existing agent via
write agent://<id>over a fresh spawn for follow-up work: it already holds the relevant context. Barehistory://discovers registered transcripts; messaging a parked agent revives it.history://<id>shows what an agent has done. - Peer-messaging availability is derived, not configured (
isIrcEnabledin the messaging helper): it requires a caller withwriteand someone to message — the session can spawn subagents, or it is a subagent itself. Without peer messaging, the follow-up hint does not suggest it. - A subagent's result (its
yield, or its last report turn for a message result) answers its parent. A message from anyone but its parent or its own subagents, or anyagent://allbroadcast, that is still queued when it ends a turn without tool calls gets a wake turn of its own once the result is out; so does such a message that finds its run (first run or follow-up) idle, waiting on background work included. A direct sender receives that turn's reply, a broadcaster nothing. Messages that arrive while the subagent works still reach it at the next tool-call boundary, and messages from its parent or its own subagents are answered within the run. - Agent discovery precedence is first-wins by exact name: project
.ompagents before user.omp, then OMP extension-package roots, Claude marketplace plugin agents (project before user), and bundled agents. Direct.claude/agents,.codex/agents, and.gemini/agentsroots are skipped. Create-time discovery is memoized per cwd/effective extension roots; execution-time discovery stays fresh. - Child sessions do not inherit conversation history. Built-in carry-over is the workspace tree/skills/rules, the parent's context files except those named
AGENTS.md(other names and@-imported text pass through), the sharedlocal://root, and the approved-plan reference when one exists. Without worktree isolation, the child also gets the parent's additional workspace roots and rediscovers each root's context files, again without any file namedAGENTS.md. - When the parent passes
mcpManager, child sessions disable standalone MCP discovery and get proxy tools that reuse parent connections. - Branch-mode merge temporarily stashes the parent repo before cherry-picking; a stash-pop conflict leaves the landed commits on HEAD and preserves the stash, reported as
stashConflict. Patch mode usesrepo.canApplyPatch(...)before applying the root patch; reverse-only applicability is treated as already applied, while failed forward checks retain the artifact for recovery. - Nested git repos are diffed independently inside isolated workspaces and merged separately with
applyNestedPatches(...). agent://ids are name-based (Taskfirst,Task-2/Task-3only when the name repeats, nested likeParent.Child) byAgentOutputManager; this is what prevents artifact collisions across repeated or nested invocations.
Auto-parallel
task.autoParallel (off default, suggest, on) asks the native judge which parts of each new top-level prompt can run concurrently. Ownership: auto-parallel/planner.ts (segmentation, judgment, partition), session/auto-parallel.ts (mode, notice, hint), questions in prompts/judge/auto-parallel.json.
- Judged: typed, user-authored prompts and queued follow-ups in the main session, never steering, skill prompts, subagents, or plan mode. The
tasktool must be enabled and thejudgerole must resolve first to a native backend (thefind.enabled: autocondition). - Items: each top-level list entry and each line outside a list is one item; nested entries, lines indented to an entry's text, and fenced blocks stay with their item. Prompts with fewer than 2 or more than 16 items are not judged.
- Plan: one judgment asks each item's role (
context: background and list lead-ins, sent to every subtask;task;wrapup: checks, commits, changelog done after all subtasks) and whether each pair of items is coupled (same file or component, one needs the other's result, design, or API, a rename one touches, or one refines the other). Task items joined by a pair at P(coupled) ≥ 0.35 share a subtask, transitively. The threshold sits low because a missed split only costs time, while a wrong one puts two workers on coupled code. suggestreportsAuto-parallel: 3 subtasks: … | … | …orAuto-parallel: no splitper judged prompt and changes nothing.on: a split into two or more subtasks adds a hidden reminder to the prompt listing the subtasks, the shared context, and the wrap-up items, and tells the agent to settle cross-subtask contracts, then delegate the subtasks in one paralleltaskcall. A prompt that does not split gets nothing.
Like auto-prewalk, it fails open: a missing native judge, a judge error or malformed answer, the 4-second timeout, an abort, or a superseded prompt leave the turn unchanged. Judgments are journaled as model usage under the purpose auto-parallel.