Files
pi-subagent/research/pi-durable-async-subagents.md
alex 4deccb95ef Turn the subagent extension into the pi-subagent Pi package
Move the extension from ~/.pi/agent/extensions/subagent into this repo
and package it for pi install:

- Sources under src/, entry exposed via the pi manifest in package.json
- Host packages (@earendil-works/*, typebox) stay peer dependencies
- Tests, TLA+ spec, and research notes move along unchanged in behavior
- Gates (.pi/verify.json): typecheck, tests, tlc, smoke — all green
- Install: pi install git:git.rwiesner.com/alex/pi-subagent or local path
2026-11-25 13:40:16 +00:00

47 KiB
Raw Permalink Blame History

pi-durable as a foundation for async subagents

Pinned upstream commit: e2cb38ac149b440560e1f66da26613bf25f42937 (2026-11-25). All upstream line references below are against this commit.

Host examined: installed @earendil-works/pi-coding-agent 1.6.0. The installed tree does not contain @earendil-works/pi-durable; the package is published separately (npm latest is 1.6.0), but it is not bundled with the coding agent.

Assumption: “Option C” means embedding a pi-durable Harness inside the Pi extension process to run async jobs while the parent Pi session remains the UI/model loop. It does not mean replacing the Pi CLI with pi-durable. If C instead means replacing Pi, the fidelity gaps below become larger, not smaller.

Executive summary

  • @earendil-works/pi-durable is a complete durable in-process agent harness, not a subprocess supervisor. It owns conversations, model turns, tool calls, submissions, tasks, compaction, and crash recovery, using pi-ai for model access and Chord for documents (README:3-7, registry.ts:10).
  • Its genuinely useful capabilities for this problem are the task state machine, ownership/abort tree, explicit waits, park/signal mechanism, task graph, bounded tool output, and crash/restart accounting. It already has production-shaped implementations and a large test suite for these.
  • It cannot run or supervise the extension’s existing pi --mode json -p --no-session children as first-class jobs. It can spawn a command through its NodeExecutionEnv/bash tool, but it has no JSON-event supervisor, no per-process job record, and no external-process reconciliation. Its own agent runs in-process.
  • Reusing current behavior would require substantial glue: a Models adapter, a tool adapter (durable supplies only read, write, edit, bash, powershell), MCP bridging, Pi-extension bridging, prompt/context-file reconstruction, TUI work, and usage reshaping. These are not “drop-in” APIs.
  • Two settled design decisions conflict directly with durable’s model: the four-process global scheduler (durable allows one writer per storage and has no cross-process locking) and session-bound kill-on-reload (durable is designed to resume interrupted work after a process restart).
  • Recommendation: Option A. Keep the subprocess design and borrow durable’s state-machine ideas. Do not add pi-durable as a dependency now. Option B adds a second store without solving scheduling; Option C replaces the behavior the extension exists to preserve.

Findings

1. What pi-durable actually provides

Capability What exists Important limit
Execution Harness over one Storage; conversations, submissions, built-in pi.generation, pi.tool, and pi.compaction tasks; hooks, code mode, compaction (README:92-113, registry.ts:10) In-process. It calls models.streamSimple() itself (generation.ts:811).
Persistence Atomic commits of entries, documents, task records, and submissions; Memory, IndexedDB, SQLite, JSONL, Cloudflare DO backends; reopen and resume (README:115-138, README:1020-1051) One writer per storage; no cross-process locking (README:1051).
Cancellation Conversation.abort(), Submission.abort(), Harness.abortTask(); abort cascades bottom-up through owned tasks; parked tools get cancel() (README:882-884, README:918-952, README:427) No forced termination of non-cooperative in-process code; it is an explicit non-goal (spec.md:7291-7303).
Waiting Submission.wait(), waitForIdle(), waitForTask(); task waits with allSettled, failFast, any; sleeps and signals; tools can park instead of holding a process (README:214-261, README:392-432, README:929-954) Waiting is process-local unless the task parks; external processes are not automatically waited on.
Task graph watchTaskGraph() exposes every live task with owner edge, status, background/abort marks, and owned conversations (README:956-971) Live tasks only. Completed records are queried through getTask and transaction scans (tx.scanTasks); inspect reports live tasks. I found no task-delete/prune API.
Subagents Patterns and runnable examples: a foreground tool creates a task-owned child conversation and waits for its submission (21-subagent-foreground.ts:41-78); a background manager uses an anchor task plus reporter tasks (22-subagent-background.ts:57-72, 22-subagent-background.ts:133-212) There is no built-in named-subagent manager. It is example/product code built from conversations, tasks, and SubmissionSettled signals (README:924-927). The background example’s reporter auto-posts answers to the parent; that is optional product code, not a primitives requirement. An explicit get/list/wait API can omit it.
Crash resume Open turns surviving running tasks back to pending, counts restarts, retries model requests with backoff, and ends repeated crash loops at restartLimit (scheduler.ts:478-518, README:263-267) This is recovery of its own tasks, not of external subprocesses. A custom tool that spawns a process must implement its own idempotency/reconciliation; replay policy only decides whether the tool reruns (README:336).
Process execution NodeExecutionEnv can spawn programs, stream stdout/stderr, and kill process trees (env/node.ts:829-836, env/node.ts:303-327) It is a command environment for tools, not a job supervisor. No JSONL pi event parsing, process registry, or orphan reconciliation.

The test suite is substantial: 107 *.test.ts files under packages/durable/test, including ownership/abort, task graph, task recovery, nested tools, read-only sessions, and a replay-safe subagent recovery test (harness-ownership.test.ts:1298-1345). That supports the scheduler/state-machine parts; it does not establish parity with Pi’s agent runtime.

2. Can it run the existing pi --mode json -p --no-session subprocesses?

No, not as a supported or first-class capability.

pi-durable executes an independent in-process agent harness. Its built-in generation task resolves a model from HarnessOptions.models and calls runtime.models.streamSimple(...) (generation.ts:208-224, generation.ts:811). Its built-in task list is pi.generation, pi.tool, pi.compaction; there is no process/task supervisor task (registry.ts:10).

You could write a custom durable tool that spawns pi --mode json -p --no-session, parses its JSONL, and returns the final answer. But that gives you only:

  • a durable pi.tool task around the call, with replay policy and output limits;
  • no durable record of the child process identity, no process registry, no session-bound ownership, no automatic orphan cleanup;
  • on a crash, either the tool reruns (if replay: "safe") or the model gets an interrupted result (README:336); the child process itself is outside durable’s state machine.

So durable can host a subprocess-spawning tool, but it does not supervise the extension’s subprocess jobs. The extension would still own the process registry, JSON event parsing, cancellation, result bounding, and reload cleanup.

3. What reuse would require: APIs present versus glue

Current behavior pi-durable API present Glue / gap Assessment
Agent markdown discovery (~/.pi/agent/agents, project .pi/agents) None. Durable has no agent-file loader. Keep agents.ts discovery and map AgentConfig to AgentChange (instructions, model, thinkingLevel, tools, cwd) (types.ts:556-577). Small/medium glue. Semantics of instructions differ from --append-system-prompt.
Parent model/provider selection ModelRef { provider, modelId }; parent ctx.model supplies both (README:481-505). HarnessOptions.models requires a full pi-ai Models, not Pi’s ModelRegistry (types.ts:796-803). Pi exposes ctx.modelRegistry (a facade with streamSimple, complete, find, auth methods) but not the private ModelRuntime implements Models (model-registry.d.ts:18-45, model-runtime.d.ts:35-36). Model ref is easy; the Models bridge is real glue and an unsupported private-API risk.
Thinking level AgentState.thinkingLevel; generation sends reasoning unless "off"; thinkingBudgets exists in stream options (types.ts:556-559, types.ts:650-664). Map ctx.thinkingLevel; preserve the current rule that explicit agent models do not inherit the parent thinking level (index.ts:299-304). Small glue, but behavior must be specified.
Coding tools read, write, edit, bash, and optionally powershell (README:294-296, tools/index.ts:28-36). Pi also has ls, find, grep, and its own tool semantics/renderers. Durable’s built-ins are separate implementations, not Pi’s tools. Medium/large gap for exact behavior.
MCP None. Durable mentions MCP tools only as possible registered tools (tool_search, code mode); @earendil-works/pi-durable does not depend on pi-mcp (package.json:166-173). Connect via @earendil-works/pi-mcp, adapt each server/tool to ToolRegistration, handle auth, deferred tools, reconnection, naming, images. Large glue; current child gets MCP automatically.
Pi extensions Durable has its own Extension shape (tools, sections, hooks, wraps, tasks) (types.ts:512-526). Pi extensions are ExtensionAPI modules with a different lifecycle/context. No adapter exists. Large glue; custom tools, permission hooks, providers, and UI extensions would not just work.
Context files / skills / system prompt Durable’s prompt is sections plus instructions (README:471-479). Pi publicly exports loadProjectContextFiles() (resource-loader.d.ts:65-71); buildSystemPrompt() exists in an internal module but is not a root export (system-prompt.d.ts:25-70, index.d.ts:19). You would have to render context files into durable sections and reproduce Pi’s tool snippets/guidelines/skills. Medium/large glue; exact prompt parity is unlikely without a shared builder.
UI / progress Durable has Conversation.watch(), watchTaskGraph(), pi.live docs, and api.details() (README:578-628, README:956-968). Build a new TUI job panel/renderers; current code renders child JSON events and tool activity (index.ts:721-763). Medium/large UI work.
Usage pi.usage per conversation (provider/model, tool name), harness.usage() aggregate (README:1012-1018, usage.ts:1-45). Current extension parses child message_end events into input/output/cache/cost/contextTokens/turns (index.ts:360-378). Map durable’s Usage shape and compute context/turns separately. Small/medium glue.
CWD AgentState.cwd; environment built per call (README:531-545). Translate the extension’s per-task cwd. Small.
Recursion disabled Child conversations can remove the subagent extension: configure({ extensions: { remove: [Subagent] } }) (21-subagent-foreground.ts:58-61). In the current subprocess path there is no explicit removal: it only passes --tools when the agent markdown lists tools (index.ts:305). “Recursion disabled” is a design requirement, not an implemented guarantee today. Small in durable; must be added to subprocess path.
Bounded results Tool output limits default to 2000 lines / 50 KB (truncate.ts:12-13); details can be larger if the tool stores them. Current extension caps parallel summary at 50 KB but keeps full messages in details (index.ts:37, index.ts:147-170). Durable’s default aligns with the agreed cap; still need an explicit details bound.

Bottom line: durable has the right vocabulary for jobs (agent state, model ref, thinking, cwd, tool filters, ownership, task graph, usage), but not Pi’s runtime. The missing pieces are exactly the ones that make the current extension valuable: full Pi agent boot, MCP, extensions, context files, coding tools, and TUI. The current child is also ephemeral (--no-session); durable persists a conversation transcript, which is a feature difference as well as a storage difference (index.ts:298).

4. Package maturity, dependencies, storage, multi-process rules, and importability

Maturity and versioning

  • The package is explicitly Experimental: “The API changes without notice between releases” (README:3).
  • package.json says 1.6.0, but the CHANGELOG at the pinned commit has an Unreleased section with breaking changes to tool parks, wraps, hook results, admit, signal state, and commit results (CHANGELOG.md:1-12). The v1.6.0 tag is faac585884ae2c013a6b1400f3e9e77f10b34bac; published 1.6.0 does not include those Unreleased changes.
  • The README is not fully synchronized with source at this commit: the hook example at README:785 still shows the old { sleep: { ... } } shape, while ToolPark is tagged { kind: "sleep" | "wait" } (types.ts:265-279). Treat examples as version-specific.
  • Test coverage is broad (107 test files), including storage conformance, scheduler recovery, read-only views, task graph, child tasks, and subagent recovery. This is meaningful engineering, but the API churn is real.

Maturity judgment: engineering maturity is high for task/storage semantics; API maturity is low because the package labels itself experimental and is still making breaking changes on main after the 1.6.0 release.

Engines, dependencies, exports

  • Node >=22.19.0 (package.json:163-165); the host has the same engine floor.
  • Runtime dependencies are pinned exactly: @earendil-works/chord, pi-ai, pi-codemode, pi-schema, pi-telemetry at 1.6.0, plus @silvia-odwyer/photon and diff (package.json:166-173). No peerDependencies; npm treats Pi packages as ordinary dependencies and may install separate copies under the extension tree.
  • Exports include the root, /tools, /env, /env/node, /codemode, /tool-search, /images/*, /storage/memory, /storage/indexeddb, /storage/jsonl, /storage/jsonl/node, /storage/sqlite, /storage/sqlite/node, /storage/sqlite/cloudflare, and /testing (package.json:8-123). Published files are dist, README, and CHANGELOG (package.json:125-130).

Storage options and constraints

Backend Use Caveat
Memory MemoryStorage Nothing persisted. Good for a session-bound prototype, but no crash recovery.
IndexedDB Browser One owner at a time; use a Web Lock.
SQLite openNodeSqliteStorage(file) WAL + synchronous = NORMAL; commits survive process crashes, newest may be lost on power/host failure.
JSONL openNodeJsonlStorage(dir) Append-only; fsync optional; read-only viewer mode; keeps whole history in memory. Not for long-running agents.
Cloudflare DO DO SQLite Only inside a Durable Object.

Source: README:1020-1051.

Multi-process ownership

  • “One process writes a storage at a time; there is no cross-process locking” (README:1051).
  • Read-only viewing is supported: HarnessOptions.readOnly refuses writes and scheduling (types.ts:852-859); JSONL must also be opened with storage-level readOnly because a writable open repairs files (README:127, README:1051).
  • The scheduler is a TaskScheduler owned by one Harness (scheduler.ts:318). I found no lease, worker registry, or cross-process ownership API.

Can a normal Pi extension import it?

Mechanically, yes, as a normal npm dependency:

  • Pi’s host-provided list is pi-ai, pi-agent-core, pi-coding-agent, pi-tui, typebox; pi-durable is not on it (packages.md:104-116).
  • Pi docs say npm dependencies work if you add a package.json next to the extension and run npm install; imports from node_modules/ resolve (extensions.md:168-170).
  • The current subagent implementation files are only index.ts and agents.ts (plus this research/ directory); there is no package.json/node_modules. Adding the dependency is a packaging change.

But it is not a supported host API, and there is a real module-identity risk:

  • Pi maps only exact host-provided specifiers, including @earendil-works/pi-ai, @earendil-works/pi-ai/models, @earendil-works/pi-ai/compat, and typebox (loader.js:65-88).
  • pi-durable imports @earendil-works/pi-ai/utils/validation, /utils/uuid, /utils/retry, /session-resources, and similar subpaths that are not in that alias map (tool.ts:13, provider.ts:2, harness.ts:5, generation.ts:13-16). Those will resolve from its installed dependency tree, potentially a second pi-ai copy in the same process.
  • Pi’s docs warn: “Installed packages load with separate module roots. Do not rely on two packages sharing one dependency instance” (packages.md:116).
  • pi-durable pins pi-ai and chord to exact 1.6.0, so the extension becomes version-locked to the host release. A host upgrade can strand the extension.

Judgment: import is allowed but integration is not first-class. A spike would be required to prove that the duplicate pi-ai/chord module identities do not break session-resource cleanup, model streaming, or storage. I did not run that spike.

5. Options and their consequences

Criterion A. Subprocess design + borrowed durable ideas B. pi-durable for job metadata/history only C. Rebuild async around pi-durable Harness/tasks
Current sync subagent Preserved exactly Preserved exactly Could stay, but creates two execution engines
Async execution Subprocess per task Subprocess per task In-process pi-durable agent
Current agent markdown, model inheritance, MCP, extensions, context files, TUI Inherited from child Pi Inherited from child Pi Must rebuild/adapt most of it
One job per single/parallel/chain invocation Custom job record Custom job record + durable records Durable task tree; needs an umbrella job task
Explicit get/list/wait/cancel, no auto model turn Custom Custom + durable queries Durable APIs fit
Session-bound, killed on reload/replacement Natural Natural if store is cleaned Conflicts with durable’s resume model
Four-process global scheduler Custom, compatible Custom; durable’s single-writer store blocks shared metadata Incompatible with one durable store; needs coordinator or separate stores
Bounded metadata/results + Pi custom-entry history Preserved Dual history or durable-only history Durable transcript + Pi history duplicated
Recursion disabled Must add explicit removal to subprocess args Same Easy via extension removal
Verification TLA+ scheduler + fake-process tests Plus storage conformance/dual-store tests Upstream durable tests + fidelity/integration tests; loses fake-process execution coverage
Dependency/operational risk Lowest High Highest

The capability facts in the table are sourced above; the trade-offs and risk rankings are judgment.

Option A — keep subprocess execution, borrow durable ideas

Preserves: every settled decision in the brief: sync subagent unchanged; add subagent_async and subagent_jobs; one job per invocation; explicit get/list/wait/cancel with no automatic model turn; jobs survive a turn but are session-bound and killed on reload/session replacement; four-process global scheduler; bounded metadata/results and Pi custom-entry history; subprocess-per-task with current Pi markdown/model/cwd/tools/MCP/extension behavior; recursion disabled; TLA+ and deterministic fake-process tests. Two implementation gaps in the current sync path still need closing: an explicit recursion guard and a hard details/result bound (see §3).

What to borrow (ideas, not the dependency):

  • A durable job record with a stable ID, idempotency/request ID, parent/child edges, explicit state enum, bounded summary, artifact path, and append-only event history.
  • Ownership-tree cancellation: cancel parent → cancel children bottom-up; one job per invocation; background jobs opt out of parent turn-abort but are reachable by an explicit “cancel all” operation.
  • Explicit waits and parked states: queued/running/waiting/succeeded/failed/cancelled/interrupted, with wait/get reading committed state rather than relying on in-memory promises.
  • Restart/restart-limit accounting for the scheduler, and a session epoch marker so stale jobs are killed rather than resumed after a reload.
  • Process-tree kill (durable’s NodeExecutionEnv is a useful reference) and orphan reconciliation by PID/start token.
  • Bounded tool output: durable’s 2000-line/50 KB default matches the agreed result cap.

New failure modes / operational requirements: orphaned child processes after a host crash, PID reuse, process-group kill on POSIX/Windows, async cleanup in session_shutdown, a job index that is crash-consistent with Pi custom entries, and a cross-process scheduler lock/lease. These are already implicit in the agreed design; durable does not remove them. The current sync path already sends SIGTERM, then SIGKILL after 5 s, to the direct child only (index.ts:408-418); async jobs need a process-tree kill.

Verification: TLA+ model remains applicable; deterministic fake-process tests remain the primary execution test; add tests for SIGTERM→SIGKILL escalation, process-tree kill, reload/session-replacement cleanup, stale-job reconciliation, and job-store crash recovery.

Option B — durable only for metadata/history

Preserves: subprocess execution, current fidelity, sync tool, session-bound semantics, four-process scheduler (as a custom component), bounded results, recursion guard.

Changes/invalidates: the single-source-of-truth history. You would either keep Pi custom entries and mirror to durable (dual write) or move history to durable and lose Pi-native rendering. Durable’s one-writer rule means the four processes cannot all write its store; only a coordinator could, so it does not solve the shared scheduler. If you use MemoryStorage, it does not survive a crash; if you use SQLite/JSONL, you add migration, cleanup, and version-lock obligations.

New failure modes: dual-store divergence, durable store migration/version skew, stale metadata after crash, cleanup on reload, extra disk, duplicate pi-ai/chord modules, and a second set of IDs. The lower-level createSession() API can store documents without a Harness/models, but it provides no scheduler, so it is essentially a storage library (session.ts:143-163).

Verification: durable’s storage conformance suite plus consistency tests between Pi entries and durable docs; still needs all fake-process tests. TLA+ must model both stores or prove one is derived.

Judgment: B is only defensible if there is a concrete requirement for durable’s queryable history/task graph that Pi custom entries plus a small sidecar index cannot meet. It adds a large dependency for a metadata problem.

Option C — rebuild async around pi-durable Harness/tasks

Preserves: explicit job semantics, cancellation/ownership tree, waiting/parking, task graph, bounded output, recursion removal, usage accounting, and stronger-than-session persistence if you let it persist.

Invalidates or puts at risk:

  • Subprocess-per-task; the agent runs in the Pi extension process. A tool crash/OOM can take down the parent. Durable explicitly does not force-terminate non-cooperative in-process code (spec.md:7303).
  • Current agent markdown/model/MCP/extension/context/UI fidelity; all require adapters or reimplementation (see §3).
  • Four-process global scheduler; durable has one writer per storage and no cross-process locking (README:1051). You would need a single coordinator or per-process stores, either of which changes the agreed scheduler.
  • Session-bound kill-on-reload; durable’s purpose is to resume after a process dies (README:5, README:115-127). Keeping session-bound semantics requires abort/cleanup on shutdown plus a session epoch that prevents reopen-resume; that is a custom layer on top of durable. Using MemoryStorage avoids the store mismatch but discards durable’s crash-resume, leaving only its in-process scheduler.
  • Pi custom-entry history; durable has its own transcript/store. You would either duplicate or replace Pi history.
  • Fake-process tests; execution is no longer a process, so those tests no longer cover the async path. You would need fake models/timers/storage plus integration tests.

New failure modes: event-loop starvation, in-process memory growth, model/provider auth mismatch, MCP/extension/context gaps, TUI rewrite, usage double-counting (durable warns against reporting a child’s usage in the parent result, since the child’s pi.usage already counts it — spec.md:7131), durable store growth with no prune API, API churn, and duplicate pi-ai copies.

Verification: upstream durable’s tests cover its scheduler/storage; they do not cover Pi fidelity. You would need golden tests comparing child Pi vs durable output for tool set, system prompt, MCP, extension hooks, usage, and cancellation; provider/auth parity tests; and session-shutdown tests. TLA+ could model the wrapper, but durable’s internal scheduler is upstream’s responsibility.

Recommendation

Adopt Option A. Keep the agreed subprocess design, and borrow durable’s state-machine discipline rather than its package.

This is judgment, based on the sourced facts above:

  • The extension’s value is fidelity to a real Pi child: markdown agents, model/provider inheritance, thinking, cwd, tools, MCP, extensions, context files, and TUI. Durable does not provide that runtime; it provides a different one.
  • The settled four-process scheduler and session-bound job lifetime are structurally opposed to durable’s single-writer, resume-after-crash model. Bending durable to those decisions costs more than implementing the job state machine directly.
  • Durable’s best ideas are portable: request IDs, explicit task states, ownership/abort trees, parks/signals, bounded output, restart limits, task graph views. These can live in a small Pi-native job store and Pi custom entries.

Concretely, for Option A:

  1. Keep the current subagent tool and agents.ts discovery unchanged.
  2. Add a Pi-native job record/index with jobId, requestId, parent/child edges, mode (single|parallel|chain), state, timestamps, bounded summary, result artifact path, and error/cancel reason.
  3. Implement subagent_async to create one job per invocation and spawn children exactly as today; implement subagent_jobs as explicit get/list/wait/cancel over committed records, with no automatic model turn.
  4. Add a session epoch and session_shutdown cleanup that kills the process tree and marks jobs interrupted; on startup, reconcile stale jobs instead of resuming them.
  5. Add explicit recursion guard: never pass the subagent/subagent_async tools to a child, even when the markdown file omits tools.
  6. Add a job-event log and task-graph-style view for the TUI, but store it in Pi custom entries plus a small sidecar index, not in a second durable store. Pi custom entries are explicitly durable and do not enter LLM context (extensions.md:1683-1699).
  7. Keep the TLA+ scheduler model and fake-process tests; add process-tree kill, reload, orphan, and job-store crash tests.

Revisit Option C only if the product accepts in-process execution and the loss of subprocess isolation, Pi exposes a supported in-process agent harness plus a public Models bridge, and the four-process/session-bound constraints are relaxed or replaced by a single-writer coordinator. Until then, C is a rewrite with a large fidelity regression surface. Option B is not recommended unless a concrete queryable-history requirement emerges; even then, start with the lower-level Session/documents API or a plain SQLite job table, not the full Harness.

Facts that could not be established

  • Whether pi-durable can be loaded through Pi’s jiti alias map without a second pi-ai/chord copy causing runtime problems. No spike was run.
  • Whether a complete Models adapter can be built from the public ModelRegistry without private APIs. No public Models instance is exposed to extensions; ModelRuntime implements Models but is private (model-runtime.d.ts:35-36).
  • Exact behavioral parity between durable’s read/write/edit/bash and Pi’s tools; not exhaustively diffed.
  • The exact API diff between the published 1.6.0 tarball and the pinned main commit. Main has Unreleased breaking changes, so they are not identical; I did not enumerate every difference.
  • Whether Pi awaits session_shutdown handlers through every exit path (including SIGKILL); docs define the event but not a hard guarantee for uncatchable termination (extensions.md:601-610).
  • Whether durable task records are ever pruned. I found scanTasks/getTask but no delete/prune API; not exhaustively audited.
  • Performance/memory of embedding durable in the Pi process for many concurrent jobs. No benchmark was run.
  • Whether a custom durable tool can reliably supervise pi --mode json process trees on all platforms without additional process-registry code. Durable’s environment has tree-kill logic, but no job-level reconciliation.
  • Whether the current child actually offers the subagent tool when the agent markdown omits tools. The current code has no explicit removal, but I did not run a child to observe its tool loadout.

Files and sources

Upstream pi-durable at e2cb38ac149b440560e1f66da26613bf25f42937

Host Pi 1.6.0 (installed)

  • /home/alex/.pi/agent/install/releases/1.6.0/node_modules/@earendil-works/pi-coding-agent/docs/extensions.md
    • lifecycle/shutdown: L390-393, L601-610
    • available imports/dependencies: L155-170
    • pi.appendEntry: L1683-1699
  • /home/alex/.pi/agent/install/releases/1.6.0/node_modules/@earendil-works/pi-coding-agent/docs/packages.md
    • host-provided packages and dependency rules: L100-116
  • /home/alex/.pi/agent/install/releases/1.6.0/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/loader.js
    • jiti aliases: L65-88
  • /home/alex/.pi/agent/install/releases/1.6.0/node_modules/@earendil-works/pi-coding-agent/dist/core/model-registry.d.ts
    • ModelRegistry facade: L18-45
  • /home/alex/.pi/agent/install/releases/1.6.0/node_modules/@earendil-works/pi-coding-agent/dist/core/model-runtime.d.ts
    • ModelRuntime implements Models: L35-36
  • /home/alex/.pi/agent/install/releases/1.6.0/node_modules/@earendil-works/pi-coding-agent/dist/core/resource-loader.d.ts
    • loadProjectContextFiles: L65-71
  • /home/alex/.pi/agent/install/releases/1.6.0/node_modules/@earendil-works/pi-coding-agent/dist/core/system-prompt.d.ts
    • prompt/context/skills options: L25-70 (internal module, not a root export)
  • /home/alex/.pi/agent/install/releases/1.6.0/node_modules/@earendil-works/pi-coding-agent/dist/index.d.ts
    • public exports (includes loadProjectContextFiles, not buildSystemPrompt): L19-20
  • /home/alex/.pi/agent/install/releases/1.6.0/node_modules/@earendil-works/pi-coding-agent/docs/mcp.md
    • MCP configuration/behavior: L1-100
  • /home/alex/.pi/agent/install/releases/1.6.0/node_modules/@earendil-works/pi-coding-agent/docs/cli-integration.md
    • JSON/print mode: L3-40

Current extension

  • /home/alex/.pi/agent/extensions/subagent/index.ts
    • concurrency/result caps: L34-37
    • child args/model/thinking/tools: L298-305
    • temp system prompt and task: L331-339
    • spawn/JSON parsing/usage: L344-386
    • abort/kill: L408-418
    • parent model/thinking capture: L483-486
    • project-agent trust UI: L518-544
    • TUI renderers: L721-763
  • /home/alex/.pi/agent/extensions/subagent/agents.ts
    • AgentConfig: L11-18
    • markdown discovery: L128-140
  • /home/alex/.pi/agent/extensions/subagent implementation files: index.ts and agents.ts (plus this research/ report); no package.json or node_modules.

Other primary sources

Answer

Option A. pi-durable is an excellent source of durable job-state ideas, but it is a different agent runtime, not a supervisor for pi --mode json children. Keep the subprocess design, borrow request IDs, explicit task states, ownership/abort trees, bounded results, restart accounting, and a task-graph-style view; implement them in Pi custom entries plus a small job index. Do not adopt durable for execution (C) or metadata (B) unless the four-process/session-bound decisions and the current Pi fidelity requirements are deliberately renegotiated.