pi-durable-subagents 1.0.45 → 1.2.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,121 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.0
4
+
5
+ - Structured asks: the child `ask` tool keeps required `question: string` and adds optional `decision_needed` (one
6
+ sentence naming the decision), `options: [{label, scope?, cost?, risk?, preferred?}]`, `facts: string[]`,
7
+ `tried: string[]` and `classification_candidates: [{label, evidence?: string[], unproven?: string[]}]`.
8
+ Option scope/cost/risk and candidate evidence/unproven distinguish costs, evidence and explanations not yet proved.
9
+ Parent-facing asking notices, agent-tool status and CLI status/describe text show the decision first, numbered
10
+ option labels second (preferred marked), then the original question. Plain questions display as before.
11
+ - Ask limits and refusal: any supplied structured field requires a nonblank `decision_needed`. Structured asks limit
12
+ every string, including `question`, to 2000 characters; options and classification candidates to 9 items each;
13
+ facts and tried to 20 each. At most one option may be preferred. Nested evidence/unproven arrays have no additional
14
+ item-count limit. Empty arrays are allowed; text is preserved, not trimmed or coerced; omitted fields stay absent.
15
+ Wrong types, exceeded limits, multiple preferred options or a missing decision produce `ask refused:` before any
16
+ question entry, attention item, waiter or revision is created, and the child can correct it and ask again. The
17
+ missing-decision text is `ask refused: decision_needed is required (one sentence naming the decision you need), then options`.
18
+ Under default settings, question-only asks keep their 1.1.0 behaviour, including no new question-length limit.
19
+ - Ask configuration: `askRequireDecision` is a boolean `config.json` key, default false, validated and included in the
20
+ orchestrator config hash. True requires a decision on every ask and applies structured-ask string limits. The
21
+ setting reaches a child when its execution starts: a live config change affects executions started afterwards,
22
+ not a child already running; a resumed execution receives the current setting.
23
+ - Ask storage and JSON: supplied fields survive session entries, digests, attention and orchestrator restarts.
24
+ `describe --key <request> --json`, `describe <wid> --json` and the program `describe()` API add them to each
25
+ `questions[]` item alongside `qid`, `rev`, `to`, `call` and `text`; text stays the original question. Full status
26
+ JSON attention retains metadata; compact status clips the decision like question text. Agent-tool brief `asking[]`
27
+ adds clipped `decision_needed` and `rev` only for structured entries, including mixed lists. Plain-question JSON
28
+ keeps its previous shape and serialization, without defaults. The qid formula, answer, steer and hibernation
29
+ semantics are unchanged; machine JSON stays separate from rendered text.
30
+ - Sticky model switches: an accepted manual `send kind:model` becomes the logical call's choice for later follow-up
31
+ generations (g+1, g+2, …), including calls initially launched from a pool. Another accepted manual switch or a
32
+ follow-up specifying `model` replaces it. Refused, withdrawn or replaced requests never become choices; automatic
33
+ failover never becomes one. A concrete `provider/id[:thinking]` remains concrete; a pool choice remains a pool,
34
+ resolved again at each generation launch using current configuration and existing availability, slot, skip and
35
+ failover rules. Concrete choices keep the 1.1 explicit-model path: an exhausted provider waits for availability,
36
+ probing and slots, with no fallback pool invented. Live-switch admission and reservations are unchanged.
37
+ - Sealed model switches: `send kind:model` records a sealed call's choice with `effect: "next-generation"`, creating
38
+ no generation, starting no child and reserving no slot. A follow-up continues it. Status keeps the last actual
39
+ `model` and shows the unused choice as `switching`; opening the next generation consumes the indicator, not the
40
+ persistent choice. The existing sealed follow-up acceptance path applies, including done and stopped workflows;
41
+ address, stale-revision, command-call and pin-validation refusals remain. A model send alone does not resume work.
42
+ - Model durability and upgrade: choices persist before the applied reply and survive restarts; retried request ids
43
+ return their first outcome. New live manual `forward` records have optional `choice` retaining the original model
44
+ or pool; sealed choices use `model-choice {rid, call, model}`; new `generation` records carry optional `choice` and
45
+ write it into `spec.model` (concrete choices also use the existing generation model override). Call/revision scope
46
+ prevents leakage. Existing forwards without `choice` retain their 1.1 execution-only semantics; old journals,
47
+ request digests and decisions keep their meaning. Restart the orchestrator on 1.2.0 and start a new pi session to
48
+ load the new extension before relying on the new behaviour; an already running child's ask setting is unchanged.
49
+ - Test-tail repair: the three live-session helpers in `test/pi/executor/executor.test.ts` parse only complete JSONL
50
+ lines (`revisions()` in reaskedBeforeFence, `rows()` in P28, `receipts()` in P7). An incomplete final write waits for
51
+ its newline; a malformed complete line still throws. Settled-session assertions are unchanged.
52
+
53
+ ## 1.1.0
54
+
55
+ - Caller wakes: a subagent can run `run --request <id> --wake caller -- <program> [args…]`, then end its turn. The
56
+ durable command keeps running; each workflow completion sends the caller a follow-up with workflow and call
57
+ statuses, durations, command exit codes or signals, and an output tail (at most 20 call lines and 4000 characters
58
+ total). A sealed caller opens a new generation; a running one gets the existing forwarded-follow-up behaviour,
59
+ including reopening after an undelivered turn. Retries and recovery reuse each completion's first wake decision.
60
+ - Wake admission and limits: `--wake` accepts only `caller` and needs a valid `DSA_CALL`; without it the CLI refuses
61
+ before submitting anything. The caller must be an agent call in an existing, unpruned workflow's current revision;
62
+ invalid callers are rejected with `wake caller: …` and no workflow is created. The main-session tool has no wake
63
+ option. A stopped caller is skipped (`caller stopped`); a pruned or retired caller or broken pins can reject
64
+ delivery. These outcomes are durable and final; holds and the ordinary follow-up rules still apply.
65
+ - Command shorthand and version: `run --request <id> -- <program> [args…]` submits an argv command call without a spec
66
+ file; `--timeout-ms` (positive integer milliseconds) and `--name` apply only to that form. `--spec` and `--` are
67
+ mutually exclusive; both forms accept `--wake caller`, `--cwd`, labels and the existing request-id options. Arguments
68
+ after `--` are literal; use `-- sh -c '…'` for shell syntax. `version` and `--version` print the package version.
69
+ - Read-only fields: `describe` adds top-level `wake: {to, state, rev?, generation?, reason?}` (`pending`, `applied`,
70
+ `skipped`, `rejected`). Each caller's `awaiting: [{request, wid?, state}]` is admission-ordered, limited to its current
71
+ revision and absent when empty; states are `pending` (admitted, no workflow), `running`, and `finished` (wake
72
+ undecided). `status <wid> --json` carries it too. A described sealed call has `sealedAt`, its latest generation's seal
73
+ timestamp in milliseconds; an unsealed one omits it. Pending wakes prevent prune and lazy settlement; prune after
74
+ delivery keeps the wake receipt. `wake` participates in the request digest; `caller` is provenance, excluded, so
75
+ retries from another generation of the same caller keep their identity. Requests without wake keep their digests.
76
+ - Agent process lifecycle and diagnostics: every derived agent system prompt ends with a reminder to use a durable
77
+ command call for work that must outlive the turn. Agent fences record best-effort `ended` entries before signalling
78
+ SIGKILL to targets other than the direct pi child: at most 20 pid/command pairs per entry, `more` for the rest,
79
+ command lines clipped to 200 characters (empty when unreadable). Linux reads `/proc`, macOS uses `ps`. `describe`
80
+ projects these as `endedAtSeal` (at most 20 across the latest generation) and `endedAtSealMore`, absent when empty.
81
+ This records signal targets, not proof of death; identity rechecks can prevent a signal after recording. Recording
82
+ has a total 500 ms budget per fence and never prevents cleanup. Crash recovery without a persisted child identity
83
+ omits roots, including orphaned descendants, from diagnostics but still fences them. Command calls and gates are
84
+ not recorded. Command arguments may be sensitive; processes that clear their tag and escape the tree before
85
+ tracking can still evade containment.
86
+ - Command PATH: after merging `env`, command calls append `$DSA_HOME/bin` once as the last PATH entry, so they can find
87
+ the CLI shim while custom and inherited tools keep precedence. Empty entries and earlier copies of that directory
88
+ are removed; an explicitly empty PATH contains only the shim directory. Agent PATH is unchanged.
89
+ - Lease priorities: `hold --priority <n>` accepts integers -100..100 (default 0). Waiters rank by higher priority, then
90
+ sequence; incompatible granted holders always block. Exclusive requests wait behind every ranked-ahead waiter,
91
+ shared behind exclusive waiters, counted behind every ranked-ahead waiter and until its slot limit permits a grant.
92
+ Every final grant is checked under the resource lock. Equal priorities keep the existing rules; lower priorities
93
+ can starve. `--no-wait` can pass lower-priority waiters, never incompatible holders or blockers of equal or higher priority,
94
+ and creates no waiting ticket.
95
+ - Yield and expected duration: `hold --yield` stops its command and descendants for a live waiter it blocks, even one
96
+ with lower priority, releases the lease and exits 75; detection is within the poll interval plus one second.
97
+ Compatible waiters and no-wait probes do not trigger it; the command is not resumed or retried. `--expect` accepts
98
+ whole seconds, optionally `s`, `m` or `h` (`90`, `90s`, `25m`, `2h`), from one second through seven days; it is only an
99
+ estimate, not a timeout or reservation. Holder text shows `3m of ~25m`, waiters `expects 25m`; `leases --json` includes
100
+ optional ticket fields `priority`, `yield: true` and `expectMs`. Exit 75 with
101
+ `hold: <resource> is not free now (…); not running the command (exit 75)`,
102
+ `hold: <resource> still held by … after …; not running the command (exit 75)` or
103
+ `hold: yielded <resource> to <who> after <age>; the command was stopped (exit 75)` is a stable program interface:
104
+ the first two never ran the command, the third stopped it, and none is a completed check verdict.
105
+ - Lease process cleanup: held commands inherit `DSA_HOLD=<resource>:<seq>` without changing `DSA_EXEC` or `DSA_CALL`.
106
+ Before release on exit, yield or wrapper cleanup, hold ends the command group and exact-tagged descendants with
107
+ TERM, grace, KILL and rescans, bounded to five seconds; surviving tags produce a warning and the lease is released
108
+ anyway. After a killed wrapper's command ends, group or tagged leftovers keep the ticket live until a queued waiter
109
+ reclaims and ends them (with the same bound). Linux finds tags in `/proc/<pid>/environ`, including detached sessions;
110
+ macOS uses `ps` when it exposes tags, otherwise falls back to group-only cleanup. Clearing the tag and leaving the
111
+ group can escape; tags are cooperative, not a security boundary. Separate homes should use distinct resource names
112
+ to avoid identical tags.
113
+ - 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
114
+ exits 1 before recording anything, with `the running orchestrator 1.0.45 predates run --wake (new in 1.1.0)` and
115
+ restart guidance, not a silently ignored flag. The gate applies only when the running version predates both 1.1.0
116
+ and the loaded CLI; already recorded requests retain their first outcome. Lease priorities and yield take effect
117
+ once every hold wrapper for the resource runs 1.1.0; upgrading the orchestrator alone does not update wrappers.
118
+
3
119
  ## 1.0.45
4
120
 
5
121
  - 1.0.44 was tagged but never published: its release checks failed on macOS. 1.0.45 is the first release with
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
@@ -126,7 +126,7 @@ it something. Each verb means one thing, and a refusal says what would work:
126
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). |
127
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. |
128
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. |
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. |
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 sealed one records a choice for its next follow-up, without starting anything or reserving a slot. An accepted manual choice persists across later generations until another manual choice replaces it (see [Model switching](#model-switching)). |
130
130
  | `stop` | a subagent or a workflow | Final: `stopped`, usage kept, edits left as they are. A command call's whole process tree ends. |
131
131
  | `drain` / `resume` | existing workflows | A reversible hold; runs started later are not held. |
132
132
 
@@ -172,6 +172,96 @@ or the retry is a conflict too.
172
172
  While an older orchestrator runs, a notify is refused with that advice and
173
173
  nothing is sent (an older orchestrator would accept it and drop it).
174
174
 
175
+ ### Asking the parent
176
+
177
+ A child uses `ask` to ask its parent a question and wait for an answer or
178
+ steering message. `{question: string}` still works by default. For a decision
179
+ that the parent can act on, name the decision, options and evidence:
180
+
181
+ ```json
182
+ {
183
+ "question": "The local repair is verified; should I keep this scope?",
184
+ "decision_needed": "Choose the repair scope.",
185
+ "options": [
186
+ {"label": "Local fix", "scope": "ask projection", "cost": "one verification run", "risk": "low", "preferred": true},
187
+ {"label": "Defer the repair"}
188
+ ],
189
+ "facts": ["commit 5ad9ee3", "run AK", "log sha abc"],
190
+ "tried": ["reproduced the projection loss"],
191
+ "classification_candidates": [
192
+ {"label": "projection loss", "evidence": ["digest drops fields"], "unproven": ["restart path"]}
193
+ ]
194
+ }
195
+ ```
196
+
197
+ `question` is always required and must be a string. The optional fields are:
198
+
199
+ - `decision_needed`: one sentence naming the decision you need; required and
200
+ nonblank whenever any structured field is present.
201
+ - `options`: at most 9 objects with required `label` and optional `scope`,
202
+ `cost`, `risk` (strings) and `preferred` (boolean). At most one may be
203
+ preferred; the parent sees numbered labels, with `(preferred)` on that one.
204
+ - `facts` and `tried`: at most 20 strings each; give durable evidence (commit,
205
+ run id, log sha) and what you have already tried.
206
+ - `classification_candidates`: at most 9 objects with required `label` and
207
+ optional `evidence` and `unproven` arrays of strings, separating evidence
208
+ from explanations not yet proved. These nested arrays have no additional
209
+ item-count limit.
210
+
211
+ Every string in a structured ask, including `question`, is at most 2000
212
+ characters. An ask is structured when any optional field above is present,
213
+ or when `askRequireDecision` is true (see [Configuration](#configuration)).
214
+ Default question-only asks keep the 1.1.0 behaviour, including no new
215
+ question-length limit. Empty arrays are allowed; omitted fields stay absent,
216
+ and text is preserved, not trimmed or coerced.
217
+
218
+ Wrong types, exceeded limits, multiple preferred options or a missing decision
219
+ produce a tool error starting `ask refused:` before any question entry,
220
+ attention item, waiter or revision is created. A missing decision says exactly:
221
+
222
+ ```text
223
+ ask refused: decision_needed is required (one sentence naming the decision you need), then options
224
+ ```
225
+
226
+ The child can correct it and ask again. Parent-facing asking notices, the
227
+ agent tool's status text, and CLI status/describe text show the decision first,
228
+ then numbered option labels, then the original question. Plain questions still
229
+ display as before. The supplied fields survive sessions, digests, attention
230
+ and orchestrator restarts; question identity (`qid`, based on execution and
231
+ question text), answer, steer and hibernation semantics are unchanged. JSON
232
+ fields are described under [Driving dsa from a program](#driving-dsa-from-a-program).
233
+
234
+ ### Model switching
235
+
236
+ In 1.2.0, an accepted manual `send kind:model` becomes the logical call's
237
+ choice for every later follow-up generation (g+1, g+2, …), including calls
238
+ initially launched from a pool. Another accepted manual model switch, or a
239
+ follow-up specifying `model`, replaces it. Refused, withdrawn or replaced
240
+ requests never become choices; automatic failover never becomes a choice.
241
+
242
+ A concrete `provider/id[:thinking]` remains concrete. A pool name remains a
243
+ pool choice, resolved again at each generation's launch using the current pool
244
+ configuration. Pool availability, slot, skip and failover rules still apply.
245
+ A concrete choice follows the existing 1.1 explicit-model launch path: it has
246
+ no pool to widen into, so an exhausted provider waits for availability/probing
247
+ and provider slots, not an invented fallback pool. Live-switch capacity
248
+ admission and reservations are unchanged.
249
+
250
+ To a sealed call, `send kind:model` records the choice and replies with
251
+ `model` and `effect: "next-generation"`; it creates no generation, starts no
252
+ child and reserves no slot. Send a follow-up to continue. Until then, `status`
253
+ retains the last actual `model` and shows the pending choice as `switching`.
254
+ Opening the next generation consumes the pending indicator, not the choice.
255
+ Sealed model requests use the existing sealed follow-up acceptance path,
256
+ including done and stopped workflows; address, stale-revision, command-call
257
+ and pin-validation refusals still apply. This does not resume a stopped
258
+ workflow by itself.
259
+
260
+ The choice is persisted before the applied reply and survives orchestrator
261
+ restarts; a retry with the same request id returns the first outcome. Legacy
262
+ model forwards without the new optional `choice` retain their 1.1
263
+ execution-only semantics; upgrading does not make an old switch sticky.
264
+
175
265
  ### Workflow scripts
176
266
 
177
267
  A workflow is a plain script. These are the globals it can use:
@@ -239,7 +329,13 @@ empty; stdout and stderr go, interleaved, to `output.log` in the attempt's
239
329
  directory. The command sees the orchestrator's environment plus `env`,
240
330
  `DSA_CALL` (its call id), `DSA_EXEC` (its attempt) and `DSA_HOME`, so a
241
331
  `pi-durable-subagents` command inside it (`hold`, `run`, `send`) addresses
242
- the same home; it cannot force a restart.
332
+ the same home; it cannot force a restart. After merging `env`, the command's
333
+ `PATH` is `env.PATH`, else the orchestrator's `PATH`, with `$DSA_HOME/bin`
334
+ appended once as the last entry. Custom and inherited tools keep precedence,
335
+ and the CLI shim is still found. Empty entries and earlier copies of the
336
+ shim directory are removed; an explicitly empty PATH searches only that
337
+ directory, not the current directory or system tools. Agent PATH is unchanged
338
+ (the shim stays first).
243
339
 
244
340
  | The command | Result |
245
341
  |---|---|
@@ -264,6 +360,28 @@ exit or a crash leaves it running, and the next orchestrator takes it over or
264
360
  records its result if it ended meanwhile. The restart busy list does not count
265
361
  it.
266
362
 
363
+ A subagent can start a command that must outlive its own turn, then end the
364
+ turn instead of waiting in a tool:
365
+
366
+ ```sh
367
+ pi-durable-subagents run --request build-42 --wake caller -- npm test
368
+ ```
369
+
370
+ When the workflow ends, the caller gets a follow-up with its status, each
371
+ call's status and duration, command exit code or signal when known, and an
372
+ output tail. Its first line is:
373
+
374
+ ```text
375
+ Durable run build-42 (<wid>) that you started with --wake caller finished: done.
376
+ ```
377
+
378
+ A sealed caller continues as a new generation; a running one gets the usual
379
+ forwarded follow-up, reopened after its turn if it did not take it.
380
+ Each workflow completion has one durable wake decision, reused
381
+ after retries and crashes. The ordinary finished notice to the CLI origin
382
+ is unchanged. Every derived agent system prompt includes this lifecycle
383
+ reminder; the pinned agent definition is not changed.
384
+
267
385
  A hold (`drain`, `stop-all`, a quit pi) prevents starting, never stops what
268
386
  started. A command call that has not started yet (also one waiting for its
269
387
  worktree's writer lock) waits while its workflow is held and starts after
@@ -395,6 +513,7 @@ unchanged, with zero edited lines.
395
513
  ## Command line
396
514
 
397
515
  ```text
516
+ pi-durable-subagents version print pi-durable-subagents <package version> (also --version)
398
517
  pi-durable-subagents smoke check this machine and this pi (offline, < 60 s)
399
518
  pi-durable-subagents chaos run the fault suite (offline, about 2 minutes)
400
519
  pi-durable-subagents drill failover [--keep] [--json]
@@ -410,7 +529,8 @@ pi-durable-subagents start start the orchestrator if work is pendin
410
529
  pi-durable-subagents resume [wid] continue unfinished or parked work (undoes drain / stop-all)
411
530
  pi-durable-subagents drain hold existing workflows: running calls finish, nothing new starts in them
412
531
  pi-durable-subagents stop <wid|call>
413
- pi-durable-subagents run --request <id> --spec <file|-> [--labels <json>] [--session <id>] [--cwd <dir>] [--json] [--wait-ms <n>]
532
+ pi-durable-subagents run --request <id> [--wake caller] --spec <file|-> [--labels <json>] [--session <id>] [--cwd <dir>] [--json] [--wait-ms <n>]
533
+ 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…]
414
534
  start a run under a caller-chosen id; safe to retry (see below)
415
535
  pi-durable-subagents send --request <id> --to <run-id|wid/key> [--to ...] --kind follow-up|answer|steer|notify|model
416
536
  [--call <key>] [--qid <qid> --rev <n>] --message <text|@file> [--model <m>] [--json]
@@ -422,7 +542,7 @@ pi-durable-subagents stop-all pause every existing workflow now; journ
422
542
  pi-durable-subagents prune [wid] [--older-than <days>]
423
543
  delete finished workflows (done, failed, stopped); prints count and bytes freed
424
544
  pi-durable-subagents restart [--force <token> --reason <text>] switch to the installed version (see "Updating Durable Subagents")
425
- pi-durable-subagents hold <resource> [--shared | --slots <n>] [--max-wait <s> | --no-wait] [--note <text>] -- <command…>
545
+ pi-durable-subagents hold <resource> [--shared | --slots <n>] [--priority <n>] [--yield] [--expect <duration>] [--max-wait <s> | --no-wait] [--note <text>] -- <command…>
426
546
  run one command while holding a resource lease (see below)
427
547
  pi-durable-subagents leases [--json] who holds and who waits for each resource
428
548
  pi-durable-subagents doctor [--json] read-only health check; exits 1 when something needs you
@@ -454,6 +574,32 @@ retry from the same place or pass it explicitly. The `spec` file is the
454
574
  `{tasks: […], name?, usageBudget?, maxCalls?}`); `context: "fork"` needs a pi
455
575
  session and is rejected.
456
576
 
577
+ The `run -- …` shorthand submits `{command: [program, ...args], timeoutMs?,
578
+ name?}` through the same normalizer. Arguments after `--` are literal; use
579
+ `-- sh -c 'make && make test'` for shell syntax. `--spec` and `--` are mutually
580
+ exclusive. `--timeout-ms` (positive integer milliseconds) and `--name` require
581
+ the argv form; `--cwd`, labels, session display and request-id exit codes
582
+ work as before.
583
+
584
+ `--wake` takes only `caller` and needs a valid `DSA_CALL`, supplied inside a
585
+ subagent call. Without it, the CLI refuses before submitting anything:
586
+ `--wake caller needs DSA_CALL: run it from inside a subagent call`.
587
+ The caller must be an agent call in an existing, unpruned workflow's current
588
+ revision; invalid callers are rejected with `wake caller: …`, with no new
589
+ workflow. A command call cannot receive a wake; the main-session `subagents`
590
+ tool has no wake option. The stored `RunBody.wake: {to: "<wid>/<key>"}` is
591
+ part of the digest; `RunBody.caller` (the full `DSA_CALL`) is provenance, not
592
+ part of it. Retrying from another generation of the same caller therefore
593
+ keeps the request identity. Requests without wake keep their digests.
594
+
595
+ Caller wakes need a 1.1.0 orchestrator. After upgrading the CLI, restart a
596
+ still-running 1.0.45 orchestrator: a new wake request exits 1 before recording
597
+ anything, with `the running orchestrator 1.0.45 predates run --wake (new in 1.1.0)`
598
+ and restart guidance, not a silently ignored flag. This gate applies
599
+ when the running version predates both 1.1.0 and the loaded CLI; an already
600
+ recorded request retains its first outcome. With no running orchestrator,
601
+ the next one starts on the installed version.
602
+
457
603
  | exit | meaning | `--json` reply |
458
604
  | --- | --- | --- |
459
605
  | 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}` |
@@ -506,6 +652,44 @@ is. The reason is a best-effort reading of the journals: `restart-force` when a
506
652
  `orchestrator-crash` when the orchestrator died uncleanly while it ran, else
507
653
  `process-died`.
508
654
 
655
+ For structured asks, each `describe` `questions[]` item adds the supplied
656
+ `decision_needed`, `options`, `facts`, `tried` and `classification_candidates`
657
+ alongside `qid`, `rev`, `to`, `call` and `text`; `text` remains the original
658
+ question, not a rendered summary. This applies to both CLI describe forms
659
+ and the program `describe()` API. Full `status <wid> --json` attention items
660
+ retain the metadata; compact status clips `decision_needed` like question
661
+ text. The agent tool's brief `asking[]` adds clipped `decision_needed` and
662
+ `rev` only for structured questions, even in a mixed list. Plain-question JSON
663
+ keeps its 1.1.0 shape and serialization, without inserted defaults. Machine
664
+ JSON stays separate from the decision-first text rendering.
665
+
666
+ A wake run's `describe` adds `wake: {to, state, rev?, generation?, reason?}`:
667
+ `state` is `pending`, `applied`, `skipped` or `rejected`; `rev` counts workflow
668
+ completions and `generation` names the delivery generation when known. A
669
+ stopped caller is skipped (`caller stopped`); a pruned or retired caller or
670
+ broken pins can reject delivery. Skips and rejections are final. A pending
671
+ wake prevents prune (`wake pending`) and lazy settlement; pruning after
672
+ delivery keeps its receipt.
673
+
674
+ Each described caller call, and each call in `status <wid> --json`, can have
675
+ `awaiting: [{request, wid?, state}]`: `pending` means admitted but no workflow
676
+ yet, `running` means not completed, `finished` means completed with the wake
677
+ still undecided. Entries are ordered by admission, limited to the caller's
678
+ current revision and removed once the latest wake is decided; absent when
679
+ empty. Reading this indexes caller addresses in the ledger and reads only
680
+ matching run journals, not every workflow.
681
+ A sealed described call also has `sealedAt`, its latest generation's seal
682
+ timestamp in milliseconds; an unsealed generation omits it.
683
+
684
+ For an agent call, `describe` can show `endedAtSeal: [{pid, command}]`, the
685
+ SIGKILL targets recorded by fences of its latest generation, in journal
686
+ order, at most 20, and `endedAtSealMore` for the rest. Each `ended` journal
687
+ entry lists at most 20 targets plus optional `more`; command lines are
688
+ clipped to 200 characters, empty when unreadable (Linux `/proc`, macOS `ps`).
689
+ The direct pi child is excluded; command calls and gates have no such
690
+ records. These fields are absent when nothing was recorded. They diagnose
691
+ signal targets, not proof of death (see the limits below).
692
+
509
693
  ```sh
510
694
  pi-durable-subagents run --request build-42 --spec build-42.json --json
511
695
  # exit 75: retry later with the same id and bytes
@@ -763,18 +947,24 @@ pi-durable-subagents hold machine -- make bench # exclusive
763
947
  pi-durable-subagents hold machine --shared -- npm test # with other shared holders, never with an exclusive one
764
948
  pi-durable-subagents hold machine --max-wait 600 --note "profile" -- ./measure.sh
765
949
  pi-durable-subagents hold build --slots 4 -- cargo test # at most 4 at a time
950
+ pi-durable-subagents hold machine --priority 50 --expect 25m -- ./measure.sh
951
+ pi-durable-subagents hold machine --shared --yield -- ./advisory-check.sh
766
952
  ```
767
953
 
768
954
  - The lease covers one command, not a whole call: a subagent that thinks
769
955
  or waits for an answer holds nothing.
770
- - Requests are served strictly in order. An exclusive request waits for
771
- everything before it, and keeps later shared requests out (no starvation).
772
- A waiting `hold` prints who holds the resource; `--max-wait` gives up with
773
- exit 75 without running the command.
956
+ - Waiters rank by `--priority N` (integer -100..100, default 0), higher
957
+ first, then sequence. Incompatible granted holders always block. An
958
+ exclusive request waits behind every ranked-ahead waiter; a shared one
959
+ behind exclusive waiters. Higher priorities can overtake lower waiters,
960
+ never incompatible holders; equal priorities keep the existing FIFO
961
+ rules. Low priorities can starve. Every final grant is checked under the
962
+ resource lock. A waiting `hold` prints who holds the resource; `--max-wait`
963
+ gives up with exit 75 without running the command.
774
964
  - `--slots N` (an integer of at least 1; not with `--shared`) makes the
775
965
  resource a counting semaphore: a request runs once fewer than N holders
776
- (slot or shared) hold it, no exclusive request is ahead of it, and no
777
- earlier request of any kind still waits, so it never overtakes a waiter.
966
+ (slot or shared) hold it, no exclusive holder blocks it, and no
967
+ ranked-ahead request of any kind still waits.
778
968
  Shared requests are not limited by slots but occupy them, and they do not
779
969
  queue behind a slot waiter, so a stream of shared requests can keep it
780
970
  waiting; use one mode and one N per resource name. `leases` shows
@@ -786,17 +976,35 @@ pi-durable-subagents hold build --slots 4 -- cargo test # at most 4 at a time
786
976
  written already granted. Otherwise nothing is written, and it exits 75
787
977
  naming who holds or waits, without running the command. It is never
788
978
  listed as a waiter, even for a moment, so it can probe a resource whose
789
- owner treats any queued request as interference. It also leaves the
979
+ owner treats any queued request as interference. It can pass lower-priority
980
+ waiters; equal- or higher-priority waiters block it by the same mode rules
981
+ (a counted request waits behind every such waiter). It also leaves the
790
982
  resource alone: unlike a queued waiter, it does not end processes left
791
983
  by a holder whose `hold` was killed, and is refused while they remain.
984
+ - `--yield` makes a holder stop its command and descendants when a live
985
+ waiter is blocked by it, even a lower-priority one. Compatible waiters
986
+ and no-wait probes do not trigger it. Detection is within the poll
987
+ interval plus one second; cleanup runs before release, then `hold` exits
988
+ 75. The command is not resumed or retried.
989
+ - `--expect` records an estimate, not a timeout or reservation: whole
990
+ seconds, optionally `s`, `m` or `h` (`90`, `90s`, `25m`, `2h`), from one
991
+ second through seven days (`604800s` or `168h`). Holder text shows
992
+ `3m of ~25m`, waiter text `expects 25m` (the first waiter for counted
993
+ listings). `leases --json` includes optional ticket fields `priority`,
994
+ `yield: true` and `expectMs`; unused fields stay absent, old priority is 0.
792
995
  - The command runs without a shell (write `-- sh -c '…'` for one) in its
793
- own process group; signals to `hold` go to it and its exit status is
794
- returned. When it exits, whatever it left in its process group is ended
795
- before the lease passes on.
996
+ own process group, with `DSA_HOLD=<resource>:<seq>`; `DSA_EXEC` and
997
+ `DSA_CALL` are unchanged. Signals to `hold` go to its group, and the exit
998
+ status passes through unless it yields. Before release on command exit,
999
+ yield, a forwarded signal followed by exit, or wrapper cleanup, the group
1000
+ and exact-tagged descendants are ended: TERM, grace, KILL and rescans,
1001
+ bounded to five seconds. If tags survive, it releases anyway and prints
1002
+ `hold: <n> processes tagged <tag> survived; releasing`.
796
1003
  - The lease lives as long as the `hold` process or its command lives, so a
797
1004
  killed `hold` does not hand the machine over while the command still
798
1005
  runs. If `hold` is killed and its command has exited, processes the
799
- command left in its group still hold the lease; the next waiter ends them
1006
+ command left in its group or with its tag still hold the lease; the next
1007
+ queued waiter ends them before proceeding, with the same cleanup bound
800
1008
  (on macOS, a process that took over the command's pid is waited for, not
801
1009
  ended). State is one small file per request under
802
1010
  `$DSA_HOME/leases/<resource>/`; no orchestrator is needed, and the user's
@@ -811,8 +1019,27 @@ pi-durable-subagents hold build --slots 4 -- cargo test # at most 4 at a time
811
1019
  `(holds lease machine)` / `(waiting for lease machine 3m)` on call lines.
812
1020
  Tell a subagent in its task to run measurements under
813
1021
  `pi-durable-subagents hold machine -- …`.
814
- - Leases are cooperative: processes started without `hold` are not held
815
- back, and a daemon that leaves the process group is not covered.
1022
+ - Linux finds tags in `/proc/<pid>/environ`, including descendants in new
1023
+ groups or sessions. macOS uses `ps` when it exposes the tag, otherwise
1024
+ falls back to group-only cleanup. Clearing the tag and leaving the group
1025
+ can escape. Tags are not a security boundary; separate DSA homes should
1026
+ use distinct resource names to avoid identical tags.
1027
+ - Priorities and yield take effect once every hold wrapper for the resource
1028
+ runs 1.1.0; upgrading the orchestrator alone does not update wrappers.
1029
+ Leases remain cooperative: processes started without `hold` are not held
1030
+ back.
1031
+
1032
+ Programs may treat exit 75 with any of these stable line forms as no check
1033
+ verdict (identity and duration text in the middle varies):
1034
+
1035
+ ```text
1036
+ hold: <resource> is not free now (…); not running the command (exit 75)
1037
+ hold: <resource> still held by … after …; not running the command (exit 75)
1038
+ hold: yielded <resource> to <who> after <age>; the command was stopped (exit 75)
1039
+ ```
1040
+
1041
+ The first two never started the command; the yield line stopped it, so its
1042
+ partial output is not a completed result.
816
1043
 
817
1044
  ## Configuration
818
1045
 
@@ -826,7 +1053,8 @@ State lives in `~/.pi/durable-subagents`; set `DSA_HOME` to move it.
826
1053
  "pools": { "fast": ["anthropic/claude-haiku-4-5", "openai/gpt-5-mini"] },
827
1054
  "providers": { "anthropic": { "slots": 4 } },
828
1055
  "memory": { "reserveMb": 2048, "perChildMb": 300 },
829
- "writerLock": "queue"
1056
+ "writerLock": "queue",
1057
+ "askRequireDecision": false
830
1058
  }
831
1059
  ```
832
1060
 
@@ -867,8 +1095,11 @@ State lives in `~/.pi/durable-subagents`; set `DSA_HOME` to move it.
867
1095
  after it last refused (`"k": { "probeMs": 900000 }`). Then one call at a
868
1096
  time goes to it, so finding out costs no extra request. A call that moved to
869
1097
  another provider stays there for the rest of its generation (switching back
870
- mid-task would lose the prompt cache); a follow-up starts on the first
871
- candidate again. `status` lists each used-up provider with its next try,
1098
+ mid-task would lose the prompt cache). Automatic failover is not a sticky
1099
+ choice: a follow-up starts from pool order again unless a manual choice
1100
+ stands. A manual pool choice resolves that pool again; a concrete choice
1101
+ has no fallback pool and waits for its provider. `status` lists each used-up
1102
+ provider with its next try,
872
1103
  and `events <wid>` shows the move as a model `forward` naming the target
873
1104
  (`model=<provider>/<id>`) and the provider it left (`failover=<provider>`);
874
1105
  a model you send shows only its target.
@@ -906,11 +1137,19 @@ State lives in `~/.pi/durable-subagents`; set `DSA_HOME` to move it.
906
1137
  `"off"` lets them run together and only reminds you of edits seen in the same
907
1138
  worktree. Writes that do not go through a writing call (your own, or a
908
1139
  `writer: false` call's bash) are not constrained.
1140
+ - **Required ask decisions:** `"askRequireDecision": true` requires a nonblank
1141
+ `decision_needed` on every child ask and applies the structured-ask string
1142
+ limits, even when no other metadata is given. This boolean key defaults to
1143
+ false, is validated and participates in the orchestrator config hash.
1144
+ It is snapshotted when each child execution starts: changing it affects
1145
+ executions started afterwards, not a child already running; a resumed
1146
+ execution receives the current setting. False keeps question-only asks valid.
909
1147
  - **onQuit:** `"pause"` (default) pauses a session's running workflows when
910
1148
  you quit that pi; `"continue"` lets them run on in the background.
911
1149
  - **Changes apply without a restart:** the orchestrator re-reads the file
912
- when it changes. A new slot limit, pool or default model applies to the next
913
- slot acquisition; slots already held are kept when a limit drops. An
1150
+ when it changes (`askRequireDecision` reaches a child at execution start,
1151
+ not mid-execution). A new slot limit, pool or default model applies to the
1152
+ next slot acquisition; slots already held are kept when a limit drops. An
914
1153
  invalid change is not applied, and `status` reports it next to the settings
915
1154
  still in effect (`config: <hash> since …`) and the slots held per provider.
916
1155
 
@@ -991,8 +1230,9 @@ subagent is a pi process the orchestrator drives over its stdin and stdout, and
991
1230
  those pipes end with the old process. A crash is no different: the successor
992
1231
  fences every execution that still runs (an execution that had already ended is
993
1232
  not counted as interrupted). Work that must survive a forced restart, such as a
994
- long measurement, belongs outside the subagent's processes (for example
995
- `systemd-run --user … pi-durable-subagents hold machine -- …`), with the
1233
+ long measurement, belongs outside the subagent's processes: use a durable
1234
+ command call (`run --wake caller -- …`) or an external launcher such as
1235
+ `systemd-run --user … pi-durable-subagents hold machine -- …`, with the
996
1236
  subagent only watching it.
997
1237
  The restart ledger records the reason and initiator; after the next start,
998
1238
  `status` shows who forced it and why for 24 hours.
@@ -1026,6 +1266,19 @@ SIGTERM, which is not atomic: a call launched in between is fenced and resumes.
1026
1266
  The old orchestrator cannot record the new audit fields. A pi session started before the update still
1027
1267
  loads the old extension; start a new one.
1028
1268
 
1269
+ ### Upgrading to 1.2.0
1270
+
1271
+ Restart the orchestrator on 1.2.0 and start a new pi session to load the new
1272
+ extension before relying on structured asks or sticky model choices; an
1273
+ already running child keeps its execution-start ask setting. Existing
1274
+ journals, request digests and decisions keep their meaning. Plain asks keep
1275
+ their JSON unchanged, and old model forwards remain execution-only. New live
1276
+ manual model forwards carry optional `choice` (the original model or pool
1277
+ name); sealed choices use `model-choice {rid, call, model}` entries. New
1278
+ generation records carry optional `choice` and put it in `spec.model` (a
1279
+ concrete choice also uses the existing generation `model` override). These
1280
+ records are scoped to the call and revision, not another key or revision.
1281
+
1029
1282
  ## What we do not promise
1030
1283
 
1031
1284
  - Call specs are checked strictly when a call is first proposed: an unknown or
@@ -1051,7 +1304,25 @@ loads the old extension; start a new one.
1051
1304
  - After a crash, the model call that was in flight is paid for again.
1052
1305
  - Process containment uses process tags plus a 1-second tracker. A process
1053
1306
  that clears its tag and leaves the process tree within its first second
1054
- cannot be found.
1307
+ cannot be found. Lease tag discovery on macOS depends on `ps` exposing
1308
+ environments; otherwise only the command's group is covered. Even on
1309
+ Linux, lease cleanup releases after five seconds with a warning if tagged
1310
+ processes survive.
1311
+ - Caller wakes use ordinary follow-up delivery, not a stronger guarantee:
1312
+ durable storage and an available orchestrator are needed, a held caller
1313
+ waits for resume, and stop, retired revisions or broken pins can prevent
1314
+ delivery. A wake lists at most 20 calls (then `… N more`), with at most
1315
+ 4000 characters total, dropping earlier output to fit; agent results never get invented exit
1316
+ codes. `describe` and `status` retain the command result's last 16 KiB,
1317
+ not its whole output; read the command's log for the full interleaved text.
1318
+ - Ended-process diagnostics are best effort, with a total 500 ms budget per
1319
+ fence; failed or timed-out recording does not prevent cleanup. A record
1320
+ lists SIGKILL targets, not proof of death: a process may exit or its pid
1321
+ may be reused before signalling, and identity rechecks can skip it.
1322
+ An append already in progress can finish after the budget expires.
1323
+ Recovery without a persisted direct-child identity omits roots (including
1324
+ orphaned descendants) from diagnostics but still fences them. Command
1325
+ lines can contain sensitive arguments, like other workflow diagnostics.
1055
1326
  - Model and tool behaviour belong to the models and tools you use.
1056
1327
 
1057
1328
  ## License