pi-durable-subagents 1.0.43 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,111 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.0
4
+
5
+ - Caller wakes: a subagent can run `run --request <id> --wake caller -- <program> [args…]`, then end its turn. The
6
+ durable command keeps running; each workflow completion sends the caller a follow-up with workflow and call
7
+ statuses, durations, command exit codes or signals, and an output tail (at most 20 call lines and 4000 characters
8
+ total). A sealed caller opens a new generation; a running one gets the existing forwarded-follow-up behaviour,
9
+ including reopening after an undelivered turn. Retries and recovery reuse each completion's first wake decision.
10
+ - Wake admission and limits: `--wake` accepts only `caller` and needs a valid `DSA_CALL`; without it the CLI refuses
11
+ before submitting anything. The caller must be an agent call in an existing, unpruned workflow's current revision;
12
+ invalid callers are rejected with `wake caller: …` and no workflow is created. The main-session tool has no wake
13
+ option. A stopped caller is skipped (`caller stopped`); a pruned or retired caller or broken pins can reject
14
+ delivery. These outcomes are durable and final; holds and the ordinary follow-up rules still apply.
15
+ - Command shorthand and version: `run --request <id> -- <program> [args…]` submits an argv command call without a spec
16
+ file; `--timeout-ms` (positive integer milliseconds) and `--name` apply only to that form. `--spec` and `--` are
17
+ mutually exclusive; both forms accept `--wake caller`, `--cwd`, labels and the existing request-id options. Arguments
18
+ after `--` are literal; use `-- sh -c '…'` for shell syntax. `version` and `--version` print the package version.
19
+ - Read-only fields: `describe` adds top-level `wake: {to, state, rev?, generation?, reason?}` (`pending`, `applied`,
20
+ `skipped`, `rejected`). Each caller's `awaiting: [{request, wid?, state}]` is admission-ordered, limited to its current
21
+ revision and absent when empty; states are `pending` (admitted, no workflow), `running`, and `finished` (wake
22
+ undecided). `status <wid> --json` carries it too. A described sealed call has `sealedAt`, its latest generation's seal
23
+ timestamp in milliseconds; an unsealed one omits it. Pending wakes prevent prune and lazy settlement; prune after
24
+ delivery keeps the wake receipt. `wake` participates in the request digest; `caller` is provenance, excluded, so
25
+ retries from another generation of the same caller keep their identity. Requests without wake keep their digests.
26
+ - Agent process lifecycle and diagnostics: every derived agent system prompt ends with a reminder to use a durable
27
+ command call for work that must outlive the turn. Agent fences record best-effort `ended` entries before signalling
28
+ SIGKILL to targets other than the direct pi child: at most 20 pid/command pairs per entry, `more` for the rest,
29
+ command lines clipped to 200 characters (empty when unreadable). Linux reads `/proc`, macOS uses `ps`. `describe`
30
+ projects these as `endedAtSeal` (at most 20 across the latest generation) and `endedAtSealMore`, absent when empty.
31
+ This records signal targets, not proof of death; identity rechecks can prevent a signal after recording. Recording
32
+ has a total 500 ms budget per fence and never prevents cleanup. Crash recovery without a persisted child identity
33
+ omits roots, including orphaned descendants, from diagnostics but still fences them. Command calls and gates are
34
+ not recorded. Command arguments may be sensitive; processes that clear their tag and escape the tree before
35
+ tracking can still evade containment.
36
+ - Command PATH: after merging `env`, command calls append `$DSA_HOME/bin` once as the last PATH entry, so they can find
37
+ the CLI shim while custom and inherited tools keep precedence. Empty entries and earlier copies of that directory
38
+ are removed; an explicitly empty PATH contains only the shim directory. Agent PATH is unchanged.
39
+ - Lease priorities: `hold --priority <n>` accepts integers -100..100 (default 0). Waiters rank by higher priority, then
40
+ sequence; incompatible granted holders always block. Exclusive requests wait behind every ranked-ahead waiter,
41
+ shared behind exclusive waiters, counted behind every ranked-ahead waiter and until its slot limit permits a grant.
42
+ Every final grant is checked under the resource lock. Equal priorities keep the existing rules; lower priorities
43
+ can starve. `--no-wait` can pass lower-priority waiters, never incompatible holders or blockers of equal or higher priority,
44
+ and creates no waiting ticket.
45
+ - Yield and expected duration: `hold --yield` stops its command and descendants for a live waiter it blocks, even one
46
+ with lower priority, releases the lease and exits 75; detection is within the poll interval plus one second.
47
+ Compatible waiters and no-wait probes do not trigger it; the command is not resumed or retried. `--expect` accepts
48
+ whole seconds, optionally `s`, `m` or `h` (`90`, `90s`, `25m`, `2h`), from one second through seven days; it is only an
49
+ estimate, not a timeout or reservation. Holder text shows `3m of ~25m`, waiters `expects 25m`; `leases --json` includes
50
+ optional ticket fields `priority`, `yield: true` and `expectMs`. Exit 75 with
51
+ `hold: <resource> is not free now (…); not running the command (exit 75)`,
52
+ `hold: <resource> still held by … after …; not running the command (exit 75)` or
53
+ `hold: yielded <resource> to <who> after <age>; the command was stopped (exit 75)` is a stable program interface:
54
+ the first two never ran the command, the third stopped it, and none is a completed check verdict.
55
+ - Lease process cleanup: held commands inherit `DSA_HOLD=<resource>:<seq>` without changing `DSA_EXEC` or `DSA_CALL`.
56
+ Before release on exit, yield or wrapper cleanup, hold ends the command group and exact-tagged descendants with
57
+ TERM, grace, KILL and rescans, bounded to five seconds; surviving tags produce a warning and the lease is released
58
+ anyway. After a killed wrapper's command ends, group or tagged leftovers keep the ticket live until a queued waiter
59
+ reclaims and ends them (with the same bound). Linux finds tags in `/proc/<pid>/environ`, including detached sessions;
60
+ macOS uses `ps` when it exposes tags, otherwise falls back to group-only cleanup. Clearing the tag and leaving the
61
+ group can escape; tags are cooperative, not a security boundary. Separate homes should use distinct resource names
62
+ to avoid identical tags.
63
+ - Upgrade: caller wakes need a 1.1.0 orchestrator. With the 1.1.0 CLI, a new wake request to a live 1.0.45 orchestrator
64
+ exits 1 before recording anything, with `the running orchestrator 1.0.45 predates run --wake (new in 1.1.0)` and
65
+ restart guidance, not a silently ignored flag. The gate applies only when the running version predates both 1.1.0
66
+ and the loaded CLI; already recorded requests retain their first outcome. Lease priorities and yield take effect
67
+ once every hold wrapper for the resource runs 1.1.0; upgrading the orchestrator alone does not update wrappers.
68
+
69
+ ## 1.0.45
70
+
71
+ - 1.0.44 was tagged but never published: its release checks failed on macOS. 1.0.45 is the first release with
72
+ command calls; on macOS, too, an argv whose program path does not exist ends with 127.
73
+ - Command calls: a call spec with `command` (an argv array, or a string for `/bin/sh -c`) instead of `agent`/`task`
74
+ runs the command without a model, a provider slot or tokens, and wakes the session that started it like any finished
75
+ call. Use it for a long build, a test suite or a wait that should not keep an agent busy. It works in every launch
76
+ form (single call, `tasks`, `chain`, `runs.run` in a script, `run --request`) and takes `cwd`, `timeoutMs`
77
+ (wall-clock from its start), `env` (added to the orchestrator's environment; `DSA_*` is reserved), `rerun` and
78
+ `writer` (default `false`). See README, "Command calls".
79
+ - An argv array runs a program, never shell syntax: its first element is looked up on the command's `PATH` (127 when
80
+ no program has it, 126 when the file is not executable), and a shell builtin name such as `exit` is not run as a
81
+ builtin. A string runs through `/bin/sh -c`. The wrapper that records the exit status works under any `env` the
82
+ command gets (`PATH` unset or bogus, `IFS`, locale).
83
+ - Result: exit 0 is `ok`, another status `failed`, past `timeoutMs` `timeout`, `stop` `stopped`; `data` is
84
+ `{exitCode, signal, durationMs}` and `output` the last 16 KiB of the interleaved stdout/stderr log. Stop and timeout
85
+ end the whole process tree, including detached descendants. Steer, follow-up, answer, model and notify are refused
86
+ with one reason, from the tool and the CLI alike (an `answer` without `qid` included).
87
+ - The timeout counts from the command's start, also while no orchestrator runs: a command that ended in time is `ok`
88
+ or `failed` even when its result is recorded later, and one that ended after its deadline is `timeout` (its exit
89
+ status still in `data`).
90
+ - A command outlives the orchestrator: a restart (also a forced one), an idle exit, a crash, a quitting pi session or
91
+ `stop-all` leaves it running; the next orchestrator takes it over, or records its result if it ended meanwhile. It
92
+ never runs twice at once. A process gone without an exit record ends `unknown`, or with `rerun: true` starts once
93
+ more. Restart refusals do not count command calls as busy and say how many keep running.
94
+ - A hold (`drain`, `stop-all`, a quitting pi) prevents a command call from starting and never stops one that started.
95
+ One not started yet (also one waiting for its worktree's writer lock, and the one `rerun`) starts after `resume`.
96
+ One that started runs to its end and its result is delivered as without the hold, also after an orchestrator
97
+ restart: a held workflow with a running command counts as pending work, so `start` and a pi session start an
98
+ orchestrator for it, and a workflow that is then complete finishes and sends its notice. A call it wants next waits
99
+ for `resume`.
100
+ - In a chain, a command step gets no `{previous}` substitution; an agent step after it gets its output.
101
+ - Status, describe and the subagent view show a command call's command, pid, attempt, elapsed time and log path
102
+ instead of a model.
103
+ - Fixed: an orchestrator started from inside a call (a subagent or a command running the CLI) inherited that call's
104
+ identity (`DSA_EXEC`, `DSA_CALL` and the other per-call variables), so the end or stop of that call could also end
105
+ the orchestrator. It now starts without them.
106
+ - Downgrade: once a command call has run, an older version is unsupported. Its orchestrator exits at startup with
107
+ `Unknown pinned agent: undefined` and changes nothing; installing 1.0.44 again recovers.
108
+
3
109
  ## 1.0.43
4
110
 
5
111
  Steady-state cost no longer grows with history. Behaviour, file formats and recorded decisions are unchanged.
package/README.md CHANGED
@@ -58,7 +58,7 @@ the npx cache, so `install-service` refuses to run from there.
58
58
  | A provider's usage window runs out (`No available accounts`, usage limit, quota exceeded, a daily quota at 0) | Found at the second refusal in a row, while pi is still retrying. A call in a pool continues **in the same session** on the pool's next model (within pi's next retry or two); new calls skip that provider. After 15 minutes the next call that wants it tries it once; when it answers, new calls and new generations use it again. A call with a single model waits for it instead of failing. Billing errors (402, insufficient balance) still fail at once. |
59
59
  | Two subagents would write in the same worktree | Only one runs there at a time. A call that can write (its tools include `edit` or `write`, which pi's default tools do) holds its git worktree's writer lock from its launch until it ends, also while it waits for an answer. Another writer for that worktree waits in order, and status shows `waiting for writer lock: <root> held by <wid>/<key>`. `writer: false` (a call that does not write there), `isolation: "worktree"` and `"writerLock": "off"` opt out. |
60
60
  | A subagent waits for an answer for a long time | It releases its model slot and memory, then resumes exactly once when you answer. A forwarded answer prevents planned hibernation. If an execution was stopped after consuming the answer, recovery continues the same session without another answer. The question survives orchestrator restarts (also forced ones) and crashes, including one that hits before the subagent released its slot. |
61
- | A subagent's work ends (finished, stopped, or cut off) | Every process its tools started ends with that execution, also ones started with `nohup`, `setsid` or `&`: they carry the execution's tag (see the limit below). Anything that must outlive the subagent has to be started by you or the parent session. A command run under `hold` is no exception: a forced restart stops it and its lease is released. |
61
+ | A subagent's work ends (finished, stopped, or cut off) | Every process its tools started ends with that execution, also ones started with `nohup`, `setsid` or `&`: they carry the execution's tag (see the limit below). For work that must outlive its turn, the subagent can start a durable command call with `run --wake caller -- …` (below). A `hold` run directly by its tools is no exception: a forced restart stops it and its lease is released. |
62
62
  | A subagent runs in a worktree you made (`isolation: "none"`, the default, with `cwd`) | Durable Subagents never creates, cleans, moves or deletes that directory or its branch, also not on `prune`; `prune` deletes only its own state and the worktrees it created for `isolation: "worktree"`. |
63
63
 
64
64
  ## Use it
@@ -69,6 +69,7 @@ the agent calls it:
69
69
  ```text
70
70
  subagents({ action: "agents" })
71
71
  subagents({ agent: "worker", task: "Fix the flaky lease test" })
72
+ subagents({ command: ["npm", "test"], cwd: "./repo", timeoutMs: 1800000 })
72
73
  subagents({ tasks: [{ agent: "scout", task: "…" }, { agent: "reviewer", task: "…" }] })
73
74
  subagents({ chain: [{ agent: "worker", task: "…" }, { agent: "reviewer", task: "Review: {previous}" }] })
74
75
  subagents({ workflow: "./batch.js", args: { … }, usageBudget: { costUsd: 20 } })
@@ -103,10 +104,12 @@ call at once with that error instead of retrying it.
103
104
  With `tasks` or `chain`, top-level `agent`, `model`, `timeoutMs`, `budget`,
104
105
  `isolation`, `context`, `tools`, `skills`, `once` and `writer` apply to every
105
106
  step that does not set its own, e.g.
106
- `{ tasks: [{ task: "…" }, { task: "…" }], agent: "reviewer" }`. A top-level
107
- `task` beside a list is refused (agent + task is a single call); other call
108
- fields there, and any of them beside a workflow script, are refused rather
109
- than ignored.
107
+ `{ tasks: [{ task: "…" }, { task: "…" }], agent: "reviewer" }`. A command
108
+ step takes only `timeoutMs` and `writer` of them, plus `env` and `rerun`,
109
+ which apply to command steps only (see [Command calls](#command-calls)). A
110
+ top-level `task` or `command` beside a list is refused (each is a single
111
+ call; put it in a step); other call fields there, and any of them beside a
112
+ workflow script, are refused rather than ignored.
110
113
  When a call of a new run already waits for its worktree's writer lock as the
111
114
  run reply is written, the reply names it: `writerWait: ["<wid>/<key> held by
112
115
  <wid>/<key> (<root>)"]` with a hint that `writer: false` or
@@ -118,13 +121,13 @@ it something. Each verb means one thing, and a refusal says what would work:
118
121
 
119
122
  | Verb | Applies to | Effect |
120
123
  |---|---|---|
121
- | `run` | — | Start one subagent, `tasks` in parallel, a `chain`, or a workflow script. An unknown agent name is refused before anything starts, with the list of agents. |
124
+ | `run` | — | Start one subagent, a command call, `tasks` in parallel, a `chain`, or a workflow script. An unknown agent name is refused before anything starts, with the list of agents. |
122
125
  | `send steer` | a running subagent | Reaches it at its next safe point. To a finished one: refused, use `follow-up`; To one waiting on its question: it interrupts the question, and the subagent usually asks again; `answer` answers it. |
123
126
  | `send notify` | any subagent | Tells it a decision without disturbing it. The reply's `delivery` says how: `steered` (running: it gets the note at its next safe point, like a steer), `held-until-answer` (waiting on its question: never interrupts it; it gets the note at the first safe point after the answer) or `noted` (not running: nothing starts; the note is recorded, and the call's next follow-up opens with it). |
124
127
  | `send follow-up` | any subagent | A finished one continues in the same session as a new generation (`key@2`); the reply names it (`generation`, `call`). A running one gets it after its current turn; the reply says `delivery: forwarded` and names the running generation (`call: <wid>/<key>@<gen>`). With `model` (a model or a pool's name), the generation that takes it runs on it. |
125
128
  | `send answer` | an open question | Answers it once, at the first chance: as the result of the question it waits on, or (when it no longer waits on that question, say after a steer) as a message at its next safe point. An answer to an earlier question while it waits on a later one ends the later one: that question is withdrawn (`superseded`, the subagent is told to ask again if it still needs it) and takes no answer. |
126
129
  | `send model` | any subagent | A running one switches at its next request; one asking, hibernated or waiting for a slot launches on it when it runs again. A pool's name picks its first model that is not used up (and, for a running call, has a free slot); the reply names the model picked, and a call from that pool stays in it. |
127
- | `stop` | a subagent or a workflow | Final: `stopped`, usage kept, edits left as they are. |
130
+ | `stop` | a subagent or a workflow | Final: `stopped`, usage kept, edits left as they are. A command call's whole process tree ends. |
128
131
  | `drain` / `resume` | existing workflows | A reversible hold; runs started later are not held. |
129
132
 
130
133
  Notes recorded for a call that is not running are durable and pending until
@@ -195,6 +198,9 @@ single file: it cannot `import` or `require` other modules.
195
198
  - `writer` (`false`: the call does not write in its cwd's worktree, so it does
196
199
  not take that worktree's writer lock; `true`: it does, whatever its tools).
197
200
 
201
+ A spec with `command` instead of `agent` and `task` is a
202
+ [command call](#command-calls).
203
+
198
204
  The result has `ok`, `status`, the full `output` text and the structured
199
205
  `data`.
200
206
 
@@ -202,6 +208,107 @@ A script is replayed after a crash. Finished calls are not run again, and a
202
208
  changed script is detected rather than silently mixed. Keep scripts
203
209
  deterministic: use `now()`/`random()`, not `Date`/`Math.random`.
204
210
 
211
+ ### Command calls
212
+
213
+ A command call runs a command instead of an agent: no model, no provider slot,
214
+ no tokens. It is a call like any other: it has a key and an address
215
+ (`<wid>/<key>`), it can be a step of `tasks` or `chain` or a `runs.run` of a
216
+ script, and when it ends it wakes the session that started it like any
217
+ finished call. Use it for a long build, a test suite or a wait that should not
218
+ keep an agent (and its slot) busy.
219
+
220
+ ```text
221
+ subagents({ command: ["npm", "test"], cwd: "./repo" })
222
+ subagents({ command: "make -j8 && ./bench > bench.txt", timeoutMs: 3600000, env: { CI: "1" } })
223
+ subagents({ chain: [{ command: ["npm", "test"] }, { agent: "worker", task: "Fix what failed:\n{previous}" }] })
224
+ ```
225
+
226
+ | Field | Meaning |
227
+ |---|---|
228
+ | `command` | An array runs a program with those arguments, never shell syntax: its first element is looked up in the command's `PATH` (exit 127 when there is none), and a shell builtin is not run as a builtin (`["exit", "7"]` looks for a program named `exit`). A string runs through `/bin/sh -c`. |
229
+ | `cwd` | Its directory, resolved like an agent call's. |
230
+ | `timeoutMs` | Wall-clock time from its start, including time the orchestrator was down (see the result table). |
231
+ | `env` | Variables added to the environment (`DSA_*` names are reserved). |
232
+ | `rerun` | `true`: when the process vanished without an exit record (the machine restarted), start it once more instead of ending `unknown`. For idempotent commands. |
233
+ | `writer` | `true`: take its worktree's writer lock (default `false`). |
234
+ | `key` | Its key in `tasks`/`chain`, as for agent steps. |
235
+
236
+ Other call fields (`agent`, `task`, `model`, `tools`, `schema`, `gate`, …)
237
+ are refused in a command call, and `env`/`rerun` in an agent call. stdin is
238
+ empty; stdout and stderr go, interleaved, to `output.log` in the attempt's
239
+ directory. The command sees the orchestrator's environment plus `env`,
240
+ `DSA_CALL` (its call id), `DSA_EXEC` (its attempt) and `DSA_HOME`, so a
241
+ `pi-durable-subagents` command inside it (`hold`, `run`, `send`) addresses
242
+ the same home; it cannot force a restart. After merging `env`, the command's
243
+ `PATH` is `env.PATH`, else the orchestrator's `PATH`, with `$DSA_HOME/bin`
244
+ appended once as the last entry. Custom and inherited tools keep precedence,
245
+ and the CLI shim is still found. Empty entries and earlier copies of the
246
+ shim directory are removed; an explicitly empty PATH searches only that
247
+ directory, not the current directory or system tools. Agent PATH is unchanged
248
+ (the shim stays first).
249
+
250
+ | The command | Result |
251
+ |---|---|
252
+ | exits 0 | `ok` |
253
+ | exits with another status or is killed by a signal | `failed`, error `Command exited <status>` / `Command killed by <SIG>` |
254
+ | ends after its deadline (start + `timeoutMs`), or still runs then | `timeout`, error `Command timed out after <ms> ms` |
255
+ | is stopped (`stop`) | `stopped` |
256
+ | vanished without an exit record, no `rerun` | `unknown`, error `Command ended without an exit record` |
257
+
258
+ `data` is `{exitCode, signal, durationMs}` and `output` the last 16 KiB of
259
+ `output.log`. Only `stop` controls a command call (it ends the whole process
260
+ tree); `steer`, `follow-up`, `answer`, `model` and `notify` are refused with
261
+ `command call: <kind> is not supported (stop it, or start a new call)`.
262
+
263
+ The deadline counts from the command's start, also while no orchestrator
264
+ runs: a command that ended in time is `ok` (or `failed`) even when the
265
+ orchestrator records it later, and one that ended after its deadline is
266
+ `timeout` (with its exit in `data`) although nothing had to stop it.
267
+
268
+ A command outlives the orchestrator: a restart (also a forced one), an idle
269
+ exit or a crash leaves it running, and the next orchestrator takes it over or
270
+ records its result if it ended meanwhile. The restart busy list does not count
271
+ it.
272
+
273
+ A subagent can start a command that must outlive its own turn, then end the
274
+ turn instead of waiting in a tool:
275
+
276
+ ```sh
277
+ pi-durable-subagents run --request build-42 --wake caller -- npm test
278
+ ```
279
+
280
+ When the workflow ends, the caller gets a follow-up with its status, each
281
+ call's status and duration, command exit code or signal when known, and an
282
+ output tail. Its first line is:
283
+
284
+ ```text
285
+ Durable run build-42 (<wid>) that you started with --wake caller finished: done.
286
+ ```
287
+
288
+ A sealed caller continues as a new generation; a running one gets the usual
289
+ forwarded follow-up, reopened after its turn if it did not take it.
290
+ Each workflow completion has one durable wake decision, reused
291
+ after retries and crashes. The ordinary finished notice to the CLI origin
292
+ is unchanged. Every derived agent system prompt includes this lifecycle
293
+ reminder; the pinned agent definition is not changed.
294
+
295
+ A hold (`drain`, `stop-all`, a quit pi) prevents starting, never stops what
296
+ started. A command call that has not started yet (also one waiting for its
297
+ worktree's writer lock) waits while its workflow is held and starts after
298
+ `resume`. One that has started runs to its end; its result is recorded and
299
+ delivered to its workflow as without the hold, also after an orchestrator
300
+ restart (`start` and the pi session's starter start an orchestrator for it):
301
+ a workflow that is then complete finishes and sends its notice, and a call it
302
+ wants next waits for `resume`. The one `rerun` of a lost command is a new
303
+ start, so under a hold it waits for `resume` too.
304
+
305
+ In a chain, a command step gets no `{previous}` (its command is not changed);
306
+ an agent step after a command step gets the command's output as `{previous}`.
307
+ `status`, `describe` and the `/subagents` view show a running command call
308
+ with `command: <command>`, its pid and how long it runs instead of a model;
309
+ `describe` also names its `output.log`. A finished one shows its status and
310
+ exit code.
311
+
205
312
  ### Watch any subagent like the main agent
206
313
 
207
314
  While subagents work, a small dock sits above the editor: one quiet row per
@@ -316,6 +423,7 @@ unchanged, with zero edited lines.
316
423
  ## Command line
317
424
 
318
425
  ```text
426
+ pi-durable-subagents version print pi-durable-subagents <package version> (also --version)
319
427
  pi-durable-subagents smoke check this machine and this pi (offline, < 60 s)
320
428
  pi-durable-subagents chaos run the fault suite (offline, about 2 minutes)
321
429
  pi-durable-subagents drill failover [--keep] [--json]
@@ -331,7 +439,8 @@ pi-durable-subagents start start the orchestrator if work is pendin
331
439
  pi-durable-subagents resume [wid] continue unfinished or parked work (undoes drain / stop-all)
332
440
  pi-durable-subagents drain hold existing workflows: running calls finish, nothing new starts in them
333
441
  pi-durable-subagents stop <wid|call>
334
- pi-durable-subagents run --request <id> --spec <file|-> [--labels <json>] [--session <id>] [--cwd <dir>] [--json] [--wait-ms <n>]
442
+ pi-durable-subagents run --request <id> [--wake caller] --spec <file|-> [--labels <json>] [--session <id>] [--cwd <dir>] [--json] [--wait-ms <n>]
443
+ pi-durable-subagents run --request <id> [--wake caller] [--cwd <dir>] [--timeout-ms <n>] [--name <text>] [--labels <json>] [--session <id>] [--json] [--wait-ms <n>] -- <program> [args…]
335
444
  start a run under a caller-chosen id; safe to retry (see below)
336
445
  pi-durable-subagents send --request <id> --to <run-id|wid/key> [--to ...] --kind follow-up|answer|steer|notify|model
337
446
  [--call <key>] [--qid <qid> --rev <n>] --message <text|@file> [--model <m>] [--json]
@@ -343,7 +452,7 @@ pi-durable-subagents stop-all pause every existing workflow now; journ
343
452
  pi-durable-subagents prune [wid] [--older-than <days>]
344
453
  delete finished workflows (done, failed, stopped); prints count and bytes freed
345
454
  pi-durable-subagents restart [--force <token> --reason <text>] switch to the installed version (see "Updating Durable Subagents")
346
- pi-durable-subagents hold <resource> [--shared | --slots <n>] [--max-wait <s> | --no-wait] [--note <text>] -- <command…>
455
+ pi-durable-subagents hold <resource> [--shared | --slots <n>] [--priority <n>] [--yield] [--expect <duration>] [--max-wait <s> | --no-wait] [--note <text>] -- <command…>
347
456
  run one command while holding a resource lease (see below)
348
457
  pi-durable-subagents leases [--json] who holds and who waits for each resource
349
458
  pi-durable-subagents doctor [--json] read-only health check; exits 1 when something needs you
@@ -370,10 +479,37 @@ answers, the question id and revision). Persist the exact spec bytes you
370
479
  submit and retry with those bytes: the run's `cwd` is part of the content
371
480
  (`spec.cwd`, else `--cwd`, else the current directory, made absolute), so
372
481
  retry from the same place or pass it explicitly. The `spec` file is the
373
- `subagents` tool's run form (`{agent, task, model?, schema?, …}` or
482
+ `subagents` tool's run form (`{agent, task, model?, schema?, …}`,
483
+ `{command, cwd?, timeoutMs?, env?, rerun?}` or
374
484
  `{tasks: […], name?, usageBudget?, maxCalls?}`); `context: "fork"` needs a pi
375
485
  session and is rejected.
376
486
 
487
+ The `run -- …` shorthand submits `{command: [program, ...args], timeoutMs?,
488
+ name?}` through the same normalizer. Arguments after `--` are literal; use
489
+ `-- sh -c 'make && make test'` for shell syntax. `--spec` and `--` are mutually
490
+ exclusive. `--timeout-ms` (positive integer milliseconds) and `--name` require
491
+ the argv form; `--cwd`, labels, session display and request-id exit codes
492
+ work as before.
493
+
494
+ `--wake` takes only `caller` and needs a valid `DSA_CALL`, supplied inside a
495
+ subagent call. Without it, the CLI refuses before submitting anything:
496
+ `--wake caller needs DSA_CALL: run it from inside a subagent call`.
497
+ The caller must be an agent call in an existing, unpruned workflow's current
498
+ revision; invalid callers are rejected with `wake caller: …`, with no new
499
+ workflow. A command call cannot receive a wake; the main-session `subagents`
500
+ tool has no wake option. The stored `RunBody.wake: {to: "<wid>/<key>"}` is
501
+ part of the digest; `RunBody.caller` (the full `DSA_CALL`) is provenance, not
502
+ part of it. Retrying from another generation of the same caller therefore
503
+ keeps the request identity. Requests without wake keep their digests.
504
+
505
+ Caller wakes need a 1.1.0 orchestrator. After upgrading the CLI, restart a
506
+ still-running 1.0.45 orchestrator: a new wake request exits 1 before recording
507
+ anything, with `the running orchestrator 1.0.45 predates run --wake (new in 1.1.0)`
508
+ and restart guidance, not a silently ignored flag. This gate applies
509
+ when the running version predates both 1.1.0 and the loaded CLI; an already
510
+ recorded request retains its first outcome. With no running orchestrator,
511
+ the next one starts on the installed version.
512
+
377
513
  | exit | meaning | `--json` reply |
378
514
  | --- | --- | --- |
379
515
  | 0 | decided and applied (a retry gets the same answer) | run: `{request, wid, created, spec_digest, writerWait?, hint?}` (`writerWait: [{call, heldBy, cwd}]`: calls already queued behind a writer lock); send/stop: `{request, applied, generation?, call?, spec_digest}` |
@@ -412,7 +548,9 @@ full text, `qid`, `rev` and the `to` address to answer), `sealed` (finished:
412
548
  `status` plus every call's unclipped `output`, `error` and schema `data`) or
413
549
  `pruned` (`pruned: {status, endedAt}`; workflows pruned before 1.0.21 have
414
550
  only `endedAt`), with `wid`, `request` and
415
- `spec_digest`, and `labels` when the run has any. Live calls also show what
551
+ `spec_digest`, and `labels` when the run has any. A command call has
552
+ `command` (its command on one line, clipped), `attempt`, `log` (its
553
+ `output.log`) and, while it runs, `pid` and `elapsed`. Live calls also show what
416
554
  they wait for (slot, writer lock, lease, exhausted provider; see "Labels and
417
555
  why a call does not move"). `lastFence: {at, exec, reason}` appears only
418
556
  when an execution was cut off: it had not ended its turn when it was fenced,
@@ -424,6 +562,33 @@ is. The reason is a best-effort reading of the journals: `restart-force` when a
424
562
  `orchestrator-crash` when the orchestrator died uncleanly while it ran, else
425
563
  `process-died`.
426
564
 
565
+ A wake run's `describe` adds `wake: {to, state, rev?, generation?, reason?}`:
566
+ `state` is `pending`, `applied`, `skipped` or `rejected`; `rev` counts workflow
567
+ completions and `generation` names the delivery generation when known. A
568
+ stopped caller is skipped (`caller stopped`); a pruned or retired caller or
569
+ broken pins can reject delivery. Skips and rejections are final. A pending
570
+ wake prevents prune (`wake pending`) and lazy settlement; pruning after
571
+ delivery keeps its receipt.
572
+
573
+ Each described caller call, and each call in `status <wid> --json`, can have
574
+ `awaiting: [{request, wid?, state}]`: `pending` means admitted but no workflow
575
+ yet, `running` means not completed, `finished` means completed with the wake
576
+ still undecided. Entries are ordered by admission, limited to the caller's
577
+ current revision and removed once the latest wake is decided; absent when
578
+ empty. Reading this indexes caller addresses in the ledger and reads only
579
+ matching run journals, not every workflow.
580
+ A sealed described call also has `sealedAt`, its latest generation's seal
581
+ timestamp in milliseconds; an unsealed generation omits it.
582
+
583
+ For an agent call, `describe` can show `endedAtSeal: [{pid, command}]`, the
584
+ SIGKILL targets recorded by fences of its latest generation, in journal
585
+ order, at most 20, and `endedAtSealMore` for the rest. Each `ended` journal
586
+ entry lists at most 20 targets plus optional `more`; command lines are
587
+ clipped to 200 characters, empty when unreadable (Linux `/proc`, macOS `ps`).
588
+ The direct pi child is excluded; command calls and gates have no such
589
+ records. These fields are absent when nothing was recorded. They diagnose
590
+ signal targets, not proof of death (see the limits below).
591
+
427
592
  ```sh
428
593
  pi-durable-subagents run --request build-42 --spec build-42.json --json
429
594
  # exit 75: retry later with the same id and bytes
@@ -681,18 +846,24 @@ pi-durable-subagents hold machine -- make bench # exclusive
681
846
  pi-durable-subagents hold machine --shared -- npm test # with other shared holders, never with an exclusive one
682
847
  pi-durable-subagents hold machine --max-wait 600 --note "profile" -- ./measure.sh
683
848
  pi-durable-subagents hold build --slots 4 -- cargo test # at most 4 at a time
849
+ pi-durable-subagents hold machine --priority 50 --expect 25m -- ./measure.sh
850
+ pi-durable-subagents hold machine --shared --yield -- ./advisory-check.sh
684
851
  ```
685
852
 
686
853
  - The lease covers one command, not a whole call: a subagent that thinks
687
854
  or waits for an answer holds nothing.
688
- - Requests are served strictly in order. An exclusive request waits for
689
- everything before it, and keeps later shared requests out (no starvation).
690
- A waiting `hold` prints who holds the resource; `--max-wait` gives up with
691
- exit 75 without running the command.
855
+ - Waiters rank by `--priority N` (integer -100..100, default 0), higher
856
+ first, then sequence. Incompatible granted holders always block. An
857
+ exclusive request waits behind every ranked-ahead waiter; a shared one
858
+ behind exclusive waiters. Higher priorities can overtake lower waiters,
859
+ never incompatible holders; equal priorities keep the existing FIFO
860
+ rules. Low priorities can starve. Every final grant is checked under the
861
+ resource lock. A waiting `hold` prints who holds the resource; `--max-wait`
862
+ gives up with exit 75 without running the command.
692
863
  - `--slots N` (an integer of at least 1; not with `--shared`) makes the
693
864
  resource a counting semaphore: a request runs once fewer than N holders
694
- (slot or shared) hold it, no exclusive request is ahead of it, and no
695
- earlier request of any kind still waits, so it never overtakes a waiter.
865
+ (slot or shared) hold it, no exclusive holder blocks it, and no
866
+ ranked-ahead request of any kind still waits.
696
867
  Shared requests are not limited by slots but occupy them, and they do not
697
868
  queue behind a slot waiter, so a stream of shared requests can keep it
698
869
  waiting; use one mode and one N per resource name. `leases` shows
@@ -704,17 +875,35 @@ pi-durable-subagents hold build --slots 4 -- cargo test # at most 4 at a time
704
875
  written already granted. Otherwise nothing is written, and it exits 75
705
876
  naming who holds or waits, without running the command. It is never
706
877
  listed as a waiter, even for a moment, so it can probe a resource whose
707
- owner treats any queued request as interference. It also leaves the
878
+ owner treats any queued request as interference. It can pass lower-priority
879
+ waiters; equal- or higher-priority waiters block it by the same mode rules
880
+ (a counted request waits behind every such waiter). It also leaves the
708
881
  resource alone: unlike a queued waiter, it does not end processes left
709
882
  by a holder whose `hold` was killed, and is refused while they remain.
883
+ - `--yield` makes a holder stop its command and descendants when a live
884
+ waiter is blocked by it, even a lower-priority one. Compatible waiters
885
+ and no-wait probes do not trigger it. Detection is within the poll
886
+ interval plus one second; cleanup runs before release, then `hold` exits
887
+ 75. The command is not resumed or retried.
888
+ - `--expect` records an estimate, not a timeout or reservation: whole
889
+ seconds, optionally `s`, `m` or `h` (`90`, `90s`, `25m`, `2h`), from one
890
+ second through seven days (`604800s` or `168h`). Holder text shows
891
+ `3m of ~25m`, waiter text `expects 25m` (the first waiter for counted
892
+ listings). `leases --json` includes optional ticket fields `priority`,
893
+ `yield: true` and `expectMs`; unused fields stay absent, old priority is 0.
710
894
  - The command runs without a shell (write `-- sh -c '…'` for one) in its
711
- own process group; signals to `hold` go to it and its exit status is
712
- returned. When it exits, whatever it left in its process group is ended
713
- before the lease passes on.
895
+ own process group, with `DSA_HOLD=<resource>:<seq>`; `DSA_EXEC` and
896
+ `DSA_CALL` are unchanged. Signals to `hold` go to its group, and the exit
897
+ status passes through unless it yields. Before release on command exit,
898
+ yield, a forwarded signal followed by exit, or wrapper cleanup, the group
899
+ and exact-tagged descendants are ended: TERM, grace, KILL and rescans,
900
+ bounded to five seconds. If tags survive, it releases anyway and prints
901
+ `hold: <n> processes tagged <tag> survived; releasing`.
714
902
  - The lease lives as long as the `hold` process or its command lives, so a
715
903
  killed `hold` does not hand the machine over while the command still
716
904
  runs. If `hold` is killed and its command has exited, processes the
717
- command left in its group still hold the lease; the next waiter ends them
905
+ command left in its group or with its tag still hold the lease; the next
906
+ queued waiter ends them before proceeding, with the same cleanup bound
718
907
  (on macOS, a process that took over the command's pid is waited for, not
719
908
  ended). State is one small file per request under
720
909
  `$DSA_HOME/leases/<resource>/`; no orchestrator is needed, and the user's
@@ -729,8 +918,27 @@ pi-durable-subagents hold build --slots 4 -- cargo test # at most 4 at a time
729
918
  `(holds lease machine)` / `(waiting for lease machine 3m)` on call lines.
730
919
  Tell a subagent in its task to run measurements under
731
920
  `pi-durable-subagents hold machine -- …`.
732
- - Leases are cooperative: processes started without `hold` are not held
733
- back, and a daemon that leaves the process group is not covered.
921
+ - Linux finds tags in `/proc/<pid>/environ`, including descendants in new
922
+ groups or sessions. macOS uses `ps` when it exposes the tag, otherwise
923
+ falls back to group-only cleanup. Clearing the tag and leaving the group
924
+ can escape. Tags are not a security boundary; separate DSA homes should
925
+ use distinct resource names to avoid identical tags.
926
+ - Priorities and yield take effect once every hold wrapper for the resource
927
+ runs 1.1.0; upgrading the orchestrator alone does not update wrappers.
928
+ Leases remain cooperative: processes started without `hold` are not held
929
+ back.
930
+
931
+ Programs may treat exit 75 with any of these stable line forms as no check
932
+ verdict (identity and duration text in the middle varies):
933
+
934
+ ```text
935
+ hold: <resource> is not free now (…); not running the command (exit 75)
936
+ hold: <resource> still held by … after …; not running the command (exit 75)
937
+ hold: yielded <resource> to <who> after <age>; the command was stopped (exit 75)
938
+ ```
939
+
940
+ The first two never started the command; the yield line stopped it, so its
941
+ partial output is not a completed result.
734
942
 
735
943
  ## Configuration
736
944
 
@@ -909,8 +1117,9 @@ subagent is a pi process the orchestrator drives over its stdin and stdout, and
909
1117
  those pipes end with the old process. A crash is no different: the successor
910
1118
  fences every execution that still runs (an execution that had already ended is
911
1119
  not counted as interrupted). Work that must survive a forced restart, such as a
912
- long measurement, belongs outside the subagent's processes (for example
913
- `systemd-run --user … pi-durable-subagents hold machine -- …`), with the
1120
+ long measurement, belongs outside the subagent's processes: use a durable
1121
+ command call (`run --wake caller -- …`) or an external launcher such as
1122
+ `systemd-run --user … pi-durable-subagents hold machine -- …`, with the
914
1123
  subagent only watching it.
915
1124
  The restart ledger records the reason and initiator; after the next start,
916
1125
  `status` shows who forced it and why for 24 hours.
@@ -969,7 +1178,25 @@ loads the old extension; start a new one.
969
1178
  - After a crash, the model call that was in flight is paid for again.
970
1179
  - Process containment uses process tags plus a 1-second tracker. A process
971
1180
  that clears its tag and leaves the process tree within its first second
972
- cannot be found.
1181
+ cannot be found. Lease tag discovery on macOS depends on `ps` exposing
1182
+ environments; otherwise only the command's group is covered. Even on
1183
+ Linux, lease cleanup releases after five seconds with a warning if tagged
1184
+ processes survive.
1185
+ - Caller wakes use ordinary follow-up delivery, not a stronger guarantee:
1186
+ durable storage and an available orchestrator are needed, a held caller
1187
+ waits for resume, and stop, retired revisions or broken pins can prevent
1188
+ delivery. A wake lists at most 20 calls (then `… N more`), with at most
1189
+ 4000 characters total, dropping earlier output to fit; agent results never get invented exit
1190
+ codes. `describe` and `status` retain the command result's last 16 KiB,
1191
+ not its whole output; read the command's log for the full interleaved text.
1192
+ - Ended-process diagnostics are best effort, with a total 500 ms budget per
1193
+ fence; failed or timed-out recording does not prevent cleanup. A record
1194
+ lists SIGKILL targets, not proof of death: a process may exit or its pid
1195
+ may be reused before signalling, and identity rechecks can skip it.
1196
+ An append already in progress can finish after the budget expires.
1197
+ Recovery without a persisted direct-child identity omits roots (including
1198
+ orphaned descendants) from diagnostics but still fences them. Command
1199
+ lines can contain sensitive arguments, like other workflow diagnostics.
973
1200
  - Model and tool behaviour belong to the models and tools you use.
974
1201
 
975
1202
  ## License
@@ -1,7 +1,8 @@
1
1
  // The subagents tool's parameter schema. Kept apart from tool.ts because it needs the optional pi peer
2
2
  // package, which the CLI (sharing tool.ts) must not import: it runs from the package directory.
3
3
  import { Type } from "@earendil-works/pi-ai";
4
- const stepsDoc = "Call specs {agent, task, model?, cwd?, timeoutMs?, output?, schema?, gate?, isolation?, context?, budget?, once?, tools?, skills?, writer?, key?}; " +
4
+ const stepsDoc = "Call specs {agent, task, model?, cwd?, timeoutMs?, output?, schema?, gate?, isolation?, context?, budget?, once?, tools?, skills?, writer?, key?} " +
5
+ "or command specs {command, cwd?, timeoutMs?, env?, rerun?, writer?, key?}; " +
5
6
  "each call is addressed as '<wid>/<key>', where key is the step's own unique key or else 'tasks:<i>' / 'chain:<i>'.";
6
7
  export const parameters = Type.Object({
7
8
  action: Type.Optional(Type.Union(["run", "agents", "send", "stop", "revise", "status", "resume", "drain", "restart"].map(v => Type.Literal(v)))),
@@ -9,6 +10,9 @@ export const parameters = Type.Object({
9
10
  tasks: Type.Optional(Type.Array(Type.Any(), { description: `Parallel calls. ${stepsDoc}` })),
10
11
  chain: Type.Optional(Type.Array(Type.Any(), { description: `Sequential calls ({previous} = previous output). ${stepsDoc}` })),
11
12
  agent: Type.Optional(Type.String()), task: Type.Optional(Type.String()), model: Type.Optional(Type.String()),
13
+ command: Type.Optional(Type.Union([Type.String(), Type.Array(Type.String())], { description: "A command call instead of agent+task: an argv array runs a program (PATH lookup, no shell: a builtin is not a builtin), a string runs through /bin/sh -c. No model or slot; it survives restarts. Result data {exitCode, signal, durationMs}, output = the last 16 KiB of stdout+stderr." })),
14
+ env: Type.Optional(Type.Record(Type.String(), Type.String(), { description: "Command calls: variables added to the environment (DSA_* reserved)." })),
15
+ rerun: Type.Optional(Type.Boolean({ description: "Command calls: start the command once more when it vanished without an exit record (machine restart) instead of sealing unknown; for idempotent commands." })),
12
16
  cwd: Type.Optional(Type.String({ description: "Run directory (default: this session's). Relative workflow, inputs and call cwd paths resolve against it." })),
13
17
  to: Type.Optional(Type.Union([Type.String(), Type.Array(Type.String())], { description: "send: '<wid>/<key>', or a list of them for steer, notify, follow-up and model (one request per call; answer takes one)." })),
14
18
  kind: Type.Optional(Type.Union([Type.Literal("steer"), Type.Literal("notify"), Type.Literal("follow-up"), Type.Literal("answer"), Type.Literal("model")])),
@@ -18,7 +22,7 @@ export const parameters = Type.Object({
18
22
  maxCalls: Type.Optional(Type.Integer({ minimum: 1 })), inputs: Type.Optional(Type.Record(Type.String(), Type.String())),
19
23
  name: Type.Optional(Type.String()),
20
24
  labels: Type.Optional(Type.Record(Type.String(), Type.String(), { description: "run: your labels, e.g. {node, attempt}: at most 32 keys [A-Za-z0-9_.:-]{1,64}, string values of at most 256 characters, 4096 bytes of JSON; part of the request's content (spec_digest), shown by describe and on its events." })),
21
- timeoutMs: Type.Optional(Type.Number({ description: "Per-call limit on active time in milliseconds (a number). Omit unless a hard limit is needed; prefer budgets." })),
25
+ timeoutMs: Type.Optional(Type.Number({ description: "Per-call limit on active time in milliseconds (a number; a command call: wall-clock time since it started). Omit unless a hard limit is needed; prefer budgets." })),
22
26
  key: Type.Optional(Type.String({ description: "A single agent/task run: the call's key. status with wid: that call's full result." })),
23
27
  tail: Type.Optional(Type.Integer({ minimum: 1, description: "status with wid: the last N lines of each call's result (unclipped, at most 4000 characters per call)." })),
24
28
  grep: Type.Optional(Type.String({ description: "status with wid: only the lines of each call's result matching this case-sensitive JS regular expression, run in-process: avoid nested quantifiers such as (a+)+; it tests the first 2000 characters of a line and the last 5000 lines (with tail: grep first, then the last N)." })),