pi-durable-subagents 1.0.25 → 1.0.28
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 +73 -0
- package/README.md +135 -15
- package/dist/agent/child.js +7 -2
- package/dist/agent/main/schema.js +4 -1
- package/dist/agent/main/tool.js +42 -8
- package/dist/agent/main.js +62 -12
- package/dist/cli/doctor.js +4 -3
- package/dist/cli/drill/index.js +287 -0
- package/dist/cli/drill/provider.js +25 -0
- package/dist/cli/hold.js +42 -17
- package/dist/cli/main.js +50 -11
- package/dist/cli/requests.js +105 -19
- package/dist/events/derive.js +7 -3
- package/dist/kernel/journal.js +99 -15
- package/dist/kernel/mailbox.js +1 -1
- package/dist/orchestrator/engine.js +157 -12
- package/dist/orchestrator/evaluator-client.js +18 -3
- package/dist/orchestrator/executor/digest.js +80 -0
- package/dist/orchestrator/executor/index.js +47 -37
- package/dist/orchestrator/executor/observe.js +21 -7
- package/dist/orchestrator/executor/session.js +4 -2
- package/dist/orchestrator/notes.js +20 -0
- package/dist/orchestrator/restart.js +5 -3
- package/dist/orchestrator/snapshot.js +144 -21
- package/dist/orchestrator/stats.js +49 -0
- package/dist/platform/containment.js +35 -11
- package/dist/platform/lease.js +53 -11
- package/dist/platform/proctable.js +16 -3
- package/dist/requests.js +31 -0
- package/dist/ui/session.js +2 -2
- package/dist/ui/view.js +5 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,78 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.28
|
|
4
|
+
|
|
5
|
+
- Lower orchestrator cost. A finished workflow's journal is closed about a
|
|
6
|
+
second after its last write and reopened on demand, so finished workflows
|
|
7
|
+
cost nothing while nothing touches them (before: one open file and periodic
|
|
8
|
+
work per workflow ever run). Live calls now look only at session entries
|
|
9
|
+
appended since the last check instead of rescanning the whole session every
|
|
10
|
+
second, and the process scan indexes the process table once per pass.
|
|
11
|
+
Measured in an isolated home: idle with 300 finished workflows about 0.006
|
|
12
|
+
core (was 0.03); 3 live calls with 20 MB sessions about 0.03 core (was 0.07,
|
|
13
|
+
growing with session size).
|
|
14
|
+
- `status --json` and `doctor --json` include `orchestratorStats` (workflows,
|
|
15
|
+
live workflows, open journals, intake passes per second, bytes read); text
|
|
16
|
+
`status` shows it on one line.
|
|
17
|
+
- `send kind:"notify"` tells a call a decision without disturbing it: a
|
|
18
|
+
running call gets it at its next safe point (`steered`), a call waiting on
|
|
19
|
+
its question gets it after the answer (`held-until-answer`), and a call that
|
|
20
|
+
is not running starts nothing: the note is recorded (`noted`) and its next
|
|
21
|
+
follow-up opens with every pending note, once. Restart the orchestrator after
|
|
22
|
+
upgrading before using it; an older orchestrator makes the client refuse it.
|
|
23
|
+
- `to` may list several calls for `steer`, `notify`, `follow-up` and `model`
|
|
24
|
+
(CLI: repeated `--to`); each target is decided on its own and the reply has
|
|
25
|
+
one entry per target. A retry with the same request id and list is
|
|
26
|
+
idempotent; another list under that id is a `request-conflict`.
|
|
27
|
+
- `hold <name> --slots N -- <cmd>` is a counted lease: at most N holders at a
|
|
28
|
+
time, FIFO, with the same release and visibility as other leases;
|
|
29
|
+
`leases`, `status` and restart refusals show `held k/N`. A granted ticket is
|
|
30
|
+
never treated as blocked afterwards.
|
|
31
|
+
- `pi-durable-subagents drill failover` rehearses pool failover in an isolated
|
|
32
|
+
home with a scripted provider (about 30 s, offline): a call moves from a
|
|
33
|
+
used-up provider to the next candidate, new calls avoid the provider, and it
|
|
34
|
+
is used again after a probe. Interrupting it cleans up.
|
|
35
|
+
- `events <wid>` names the target model of a model switch, and `failover:` the
|
|
36
|
+
provider it left when the switch was a failover.
|
|
37
|
+
- `run`: with `tasks`/`chain`, a top-level `agent` is the default agent of
|
|
38
|
+
every step. A run reply names calls that start queued behind another call's
|
|
39
|
+
writer lock (`writerWait`).
|
|
40
|
+
- `status`: run labels show on each workflow line and in the list.
|
|
41
|
+
`status <wid>` takes `tail: N` and `grep: "<regex>"` (CLI `--tail`,
|
|
42
|
+
`--grep`) to return just the last or matching lines of each call's result.
|
|
43
|
+
|
|
44
|
+
## 1.0.27
|
|
45
|
+
|
|
46
|
+
- `hold --no-wait` (or `--max-wait 0`) takes the lease at once or exits 75
|
|
47
|
+
without ever being queued: the decision is made under the resource's lock
|
|
48
|
+
and a refused request writes nothing, so `leases`, `status` and other
|
|
49
|
+
waiters never see it. Before, `--max-wait 0` queued a ticket, checked, and
|
|
50
|
+
removed it. A no-wait request also no longer ends processes left by a
|
|
51
|
+
killed holder (a queued waiter still does); it is refused while they remain.
|
|
52
|
+
- Release check: `pack:smoke` waits for its orchestrator to exit before
|
|
53
|
+
removing its temporary directory, and a failed removal is a warning. The
|
|
54
|
+
1.0.26 release stopped at this step on macOS (`ENOTEMPTY` after
|
|
55
|
+
`pack-smoke ok`), so 1.0.26 was never published; 1.0.27 includes its
|
|
56
|
+
changes.
|
|
57
|
+
|
|
58
|
+
## 1.0.26
|
|
59
|
+
|
|
60
|
+
- A daily quota message in Chinese ("remaining quota is 0, resets at 00:00 the
|
|
61
|
+
next day") is a used-up usage window: a pool call moves to its next candidate
|
|
62
|
+
and a single-model call waits, instead of failing at once as a balance error
|
|
63
|
+
(the word for "balance" occurs inside "remaining quota"). Checked against the 7,941 provider errors
|
|
64
|
+
recorded on a working machine: this was the only usage-window text misread,
|
|
65
|
+
and no rate limit or transient error is read as one.
|
|
66
|
+
- `answered.by` is `call:<wid>/<key>` for a subagent answering through the CLI
|
|
67
|
+
(the CLI now sends its `DSA_CALL` as `caller`). The caller is provenance and
|
|
68
|
+
not part of `spec_digest`: retrying a request id with or without it is the
|
|
69
|
+
same request. A pi session still running an older extension computes the
|
|
70
|
+
digest with the caller included and would see such a retry as a conflict.
|
|
71
|
+
- Tests: an end-to-end pool failover through the CLI and a detached
|
|
72
|
+
orchestrator; the effects fixtures use a unique workflow id, since gate
|
|
73
|
+
processes are found by tag across the whole machine and parallel test files
|
|
74
|
+
shared one; the CI runner also reruns files reported in nested tests.
|
|
75
|
+
|
|
3
76
|
## 1.0.25
|
|
4
77
|
|
|
5
78
|
- `restart` refusals show what a fence would cut short: each lease a running
|
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ the npx cache, so `install-service` refuses to run from there.
|
|
|
55
55
|
| You steer a subagent while it is asking you a question | Your message reaches it, in order. Nothing is rejected or lost. |
|
|
56
56
|
| Two steers arrive out of order and the second replaces the first | Only the second one applies. |
|
|
57
57
|
| A step is refused, or a dependency fails | The workflow stops that branch cleanly. Nothing is retried in vain. |
|
|
58
|
-
| A provider's usage window runs out (`No available accounts`, usage limit, quota exceeded) | 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. |
|
|
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. The question survives orchestrator restarts (also forced ones) and crashes, including one that hits before the subagent released its slot. |
|
|
61
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. |
|
|
@@ -73,13 +73,24 @@ subagents({ tasks: [{ agent: "scout", task: "…" }, { agent: "reviewer", task:
|
|
|
73
73
|
subagents({ chain: [{ agent: "worker", task: "…" }, { agent: "reviewer", task: "Review: {previous}" }] })
|
|
74
74
|
subagents({ workflow: "./batch.js", args: { … }, usageBudget: { costUsd: 20 } })
|
|
75
75
|
subagents({ action: "send", to: "<wid>/<key>", kind: "steer", message: "Don't touch the tests yet" })
|
|
76
|
+
subagents({ action: "send", to: ["<wid>/a", "<wid>/b"], kind: "notify", message: "Config is TOML from now on" })
|
|
76
77
|
subagents({ action: "status" })
|
|
77
78
|
```
|
|
78
79
|
|
|
79
80
|
`status` without a wid is brief: what runs, what asks (with the address to
|
|
80
|
-
answer) or failed, and one line per finished workflow
|
|
81
|
+
answer) or failed, and one line per finished workflow, each with its run
|
|
82
|
+
`labels` clipped to 60 characters (the `/subagents` list shows them on a
|
|
83
|
+
workflow's row when they fit). `status` with a wid
|
|
81
84
|
shows one workflow with outputs clipped; add `key` for one call's full result,
|
|
82
|
-
or `full: true` for everything.
|
|
85
|
+
or `full: true` for everything. `tail: N` gives the last N lines of each call's
|
|
86
|
+
result instead, and `grep: "<regex>"` only its lines matching a case-sensitive
|
|
87
|
+
JavaScript regular expression (both: grep first, then the last N); either is
|
|
88
|
+
unclipped up to 4000 characters per call, which suits a receipt on the last
|
|
89
|
+
line of each output. An invalid regex is an error. The regex runs in the
|
|
90
|
+
process that asks (the pi session or the CLI), so avoid nested quantifiers
|
|
91
|
+
such as `(a+)+`, which can take seconds on one line; to bound its cost it
|
|
92
|
+
tests only the first 2000 characters of a line and the last 5000 lines of an
|
|
93
|
+
output (the reply then starts with `[n earlier lines not searched]`). When a run replies `{submitted: {rid}}`
|
|
83
94
|
(its workflow was not created within 10 s), the rid works wherever a wid does.
|
|
84
95
|
A call's `model` in `status` is the model its last provider request used; a
|
|
85
96
|
requested switch not used yet shows as `switching`, a refused one as
|
|
@@ -87,10 +98,17 @@ requested switch not used yet shows as `switching`, a refused one as
|
|
|
87
98
|
(`next-request`, `next-execution` or `next-generation`).
|
|
88
99
|
A provider's refusal of the content (terms of service, usage policy) fails the
|
|
89
100
|
call at once with that error instead of retrying it.
|
|
90
|
-
With `tasks` or `chain`, top-level `model`, `timeoutMs`, `budget`,
|
|
91
|
-
`context`, `tools`, `skills` and `
|
|
92
|
-
|
|
93
|
-
|
|
101
|
+
With `tasks` or `chain`, top-level `agent`, `model`, `timeoutMs`, `budget`,
|
|
102
|
+
`isolation`, `context`, `tools`, `skills`, `once` and `writer` apply to every
|
|
103
|
+
step that does not set its own, e.g.
|
|
104
|
+
`{ tasks: [{ task: "…" }, { task: "…" }], agent: "reviewer" }`. A top-level
|
|
105
|
+
`task` beside a list is refused (agent + task is a single call); other call
|
|
106
|
+
fields there, and any of them beside a workflow script, are refused rather
|
|
107
|
+
than ignored.
|
|
108
|
+
When a call of a new run already waits for its worktree's writer lock as the
|
|
109
|
+
run reply is written, the reply names it: `writerWait: ["<wid>/<key> held by
|
|
110
|
+
<wid>/<key> (<root>)"]` with a hint that `writer: false` or
|
|
111
|
+
`isolation: "worktree"` opts out. The reply does not wait for this.
|
|
94
112
|
|
|
95
113
|
Every run is asynchronous. The agent is woken once, when the workflow
|
|
96
114
|
finishes (the notice carries each subagent's result) or when a subagent asks
|
|
@@ -100,12 +118,47 @@ it something. Each verb means one thing, and a refusal says what would work:
|
|
|
100
118
|
|---|---|---|
|
|
101
119
|
| `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. |
|
|
102
120
|
| `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. |
|
|
121
|
+
| `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). |
|
|
103
122
|
| `send follow-up` | a finished subagent | Continues the same session as a new generation (`key@2`). With `model` (a model or a pool's name), that generation runs on it. |
|
|
104
123
|
| `send answer` | an open question | Answers it once. |
|
|
105
124
|
| `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. |
|
|
106
125
|
| `stop` | a subagent or a workflow | Final: `stopped`, usage kept, edits left as they are. |
|
|
107
126
|
| `drain` / `resume` | existing workflows | A reversible hold; runs started later are not held. |
|
|
108
127
|
|
|
128
|
+
Notes recorded for a call that is not running are durable and pending until
|
|
129
|
+
its next follow-up, whose opening message carries all of them, in order, before
|
|
130
|
+
its own message:
|
|
131
|
+
|
|
132
|
+
```text
|
|
133
|
+
Notes recorded after your last turn:
|
|
134
|
+
- Config is TOML from now on
|
|
135
|
+
- Keep the old parser for one release
|
|
136
|
+
|
|
137
|
+
<the follow-up's message>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Each note is delivered once, also across orchestrator restarts and retried
|
|
141
|
+
requests. A notify accepted for a running call that seals before it gets the
|
|
142
|
+
note becomes a pending note too. `status` shows them on the call
|
|
143
|
+
(`b@1 ok "..." · 2 notes pending`; JSON `notesPending`).
|
|
144
|
+
|
|
145
|
+
`to` may list several calls for `steer`, `notify`, `follow-up` and `model`
|
|
146
|
+
(`answer` takes one). Each call gets its own request and is decided on its
|
|
147
|
+
own: an unknown or refused target does not affect the others, and the reply
|
|
148
|
+
has one entry per target (`targets`, plus a `summary` line each). With
|
|
149
|
+
`request: "<id>"`, the target at position i (1-based, in the order given) is
|
|
150
|
+
sent as `<id>:<i>`, so a retry with the same list gets the same outcomes and
|
|
151
|
+
sends nothing twice. Each of those requests records the whole list, so another
|
|
152
|
+
message, another list (longer, shorter or reordered) or a single send under
|
|
153
|
+
that id is a `request-conflict`, and nothing of it is sent. The list is compared
|
|
154
|
+
as written: retry with the same addresses (the same run id or `wid/key` form),
|
|
155
|
+
or the retry is a conflict too.
|
|
156
|
+
|
|
157
|
+
`notify` is new in 1.0.28: after upgrading, restart the orchestrator
|
|
158
|
+
(`pi-durable-subagents restart` or the tool's restart action) before using it.
|
|
159
|
+
While an older orchestrator runs, a notify is refused with that advice and
|
|
160
|
+
nothing is sent (an older orchestrator would accept it and drop it).
|
|
161
|
+
|
|
109
162
|
### Workflow scripts
|
|
110
163
|
|
|
111
164
|
A workflow is a plain script. These are the globals it can use:
|
|
@@ -233,7 +286,11 @@ unchanged, with zero edited lines.
|
|
|
233
286
|
```text
|
|
234
287
|
pi-durable-subagents smoke check this machine and this pi (offline, < 60 s)
|
|
235
288
|
pi-durable-subagents chaos run the fault suite (offline, about 2 minutes)
|
|
289
|
+
pi-durable-subagents drill failover [--keep] [--json]
|
|
290
|
+
rehearse pool failover in a temporary home (offline, about 30 s)
|
|
236
291
|
pi-durable-subagents status [wid] [--json]
|
|
292
|
+
pi-durable-subagents status <wid> [--tail <n>] [--grep <regex>] [--json]
|
|
293
|
+
each call's last n lines and/or its lines matching regex
|
|
237
294
|
pi-durable-subagents events <wid> [--json] the meaningful timeline of one workflow
|
|
238
295
|
pi-durable-subagents events --all [--since <cursor>] [--limit <n>] [--json]
|
|
239
296
|
milestones of every workflow, read with a cursor (see below)
|
|
@@ -244,7 +301,7 @@ pi-durable-subagents drain hold existing workflows: running calls f
|
|
|
244
301
|
pi-durable-subagents stop <wid|call>
|
|
245
302
|
pi-durable-subagents run --request <id> --spec <file|-> [--labels <json>] [--cwd <dir>] [--json] [--wait-ms <n>]
|
|
246
303
|
start a run under a caller-chosen id; safe to retry (see below)
|
|
247
|
-
pi-durable-subagents send --request <id> --to <run-id|wid/key> --kind follow-up|answer|steer|model
|
|
304
|
+
pi-durable-subagents send --request <id> --to <run-id|wid/key> [--to ...] --kind follow-up|answer|steer|notify|model
|
|
248
305
|
[--call <key>] [--qid <qid> --rev <n>] --message <text|@file> [--model <m>] [--json]
|
|
249
306
|
pi-durable-subagents stop --request <id> <run-id|wid|wid/key|call> [--json]
|
|
250
307
|
pi-durable-subagents describe --key <run-id> | <wid> [--json]
|
|
@@ -254,7 +311,7 @@ pi-durable-subagents stop-all pause every existing workflow now; journ
|
|
|
254
311
|
pi-durable-subagents prune [wid] [--older-than <days>]
|
|
255
312
|
delete finished workflows (done, failed, stopped); prints count and bytes freed
|
|
256
313
|
pi-durable-subagents restart [--force <token> --reason <text>] switch to the installed version (see "Updating Durable Subagents")
|
|
257
|
-
pi-durable-subagents hold <resource> [--shared] [--max-wait <s>] [--note <text>] -- <command…>
|
|
314
|
+
pi-durable-subagents hold <resource> [--shared | --slots <n>] [--max-wait <s> | --no-wait] [--note <text>] -- <command…>
|
|
258
315
|
run one command while holding a resource lease (see below)
|
|
259
316
|
pi-durable-subagents leases [--json] who holds and who waits for each resource
|
|
260
317
|
pi-durable-subagents doctor [--json] read-only health check; exits 1 when something needs you
|
|
@@ -287,7 +344,7 @@ session and is rejected.
|
|
|
287
344
|
|
|
288
345
|
| exit | meaning | `--json` reply |
|
|
289
346
|
| --- | --- | --- |
|
|
290
|
-
| 0 | decided and applied (a retry gets the same answer) | run: `{request, wid, created, spec_digest}
|
|
347
|
+
| 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}` |
|
|
291
348
|
| 1 | decided and rejected (`reason`), or refused before submission (usage error, invalid spec, unknown agent: this invocation submitted nothing) | `{request, applied: false, reason, spec_digest?}` (`spec_digest` once the content could be hashed) |
|
|
292
349
|
| 3 | `request-conflict`: the id already names other content; nothing was sent | `{request, error, wid?, spec_digest, state}` (the original's digest and state) |
|
|
293
350
|
| 75 | not decided yet: submitted but undecided in `--wait-ms` (default 60 s), submitted and then a later step failed (`reason` says which), or a lock was busy (`reason: "busy"`); an id already recorded is never refused again (the same content gets its first outcome, its agents are not rechecked; other content is a conflict); retry with the same id | `{request, pending: true, reason?}` |
|
|
@@ -298,6 +355,14 @@ tombstone keeps the final status, the id and the digest. Any sender's retry
|
|
|
298
355
|
completes a submission another one recorded but did not publish (it died in
|
|
299
356
|
between), so a retry with the same content always converges.
|
|
300
357
|
|
|
358
|
+
A send with several `--to` (not for `answer`) sends `<id>:1` ... `<id>:n`, one
|
|
359
|
+
per target in the order given, and prints one line per target (`--json`:
|
|
360
|
+
`{request, targets: [{to, request, applied, ...}]}`). The same id with another
|
|
361
|
+
message or list (also a longer one) is a conflict and sends nothing. Its exit code is 3 when the
|
|
362
|
+
id or one target names other content, else 75 when one target is not decided
|
|
363
|
+
yet, else 1 when one was rejected, else 0. A notify's reply adds `delivery`
|
|
364
|
+
(`steered`, `held-until-answer` or `noted`) and a `note` that says what it means.
|
|
365
|
+
|
|
301
366
|
From the `subagents` tool, `request` works the same, with one difference: a
|
|
302
367
|
run's origin session (what `context: "fork"` copies, and where notices go) is
|
|
303
368
|
not part of the digest. A retry of the same id from another session therefore
|
|
@@ -361,9 +426,9 @@ Every event has `id`, `cursor`, `ts` (when the milestone happened), `type`,
|
|
|
361
426
|
|
|
362
427
|
Readers must ignore types they do not know (`waiting`/`moving` follow).
|
|
363
428
|
`by` is the sender of the answer: `session:<id>` for a pi session (with
|
|
364
|
-
`via: "ui"` when it came from the subagent list), `
|
|
365
|
-
|
|
366
|
-
`unknown`. `fenced` is emitted when the call's next execution begins (right
|
|
429
|
+
`via: "ui"` when it came from the subagent list), `call:<wid>/<key>` for a
|
|
430
|
+
subagent answering through the CLI (its `DSA_CALL`; provenance, not
|
|
431
|
+
authority), `cli:<user>@<host>` for any other CLI use, else `unknown`. `fenced` is emitted when the call's next execution begins (right
|
|
367
432
|
after recovery, before it waits for a slot) and only when the fence
|
|
368
433
|
interrupted work, exactly as `describe`'s `lastFence`: a turn that had ended,
|
|
369
434
|
a hibernated question, an answer's resume or a seal are no `fenced`. A `once`
|
|
@@ -455,6 +520,25 @@ never comes back. `doctor` shows disk use, workflows by status, the largest
|
|
|
455
520
|
journals, parked work, old open questions, and leftovers; each finding
|
|
456
521
|
comes with one command to fix it.
|
|
457
522
|
|
|
523
|
+
Finished workflows cost the orchestrator nothing while nobody touches them:
|
|
524
|
+
once a workflow has ended (or parked) with no follow-up or execution open,
|
|
525
|
+
its journal file is closed and nothing reads it periodically. A follow-up,
|
|
526
|
+
resume, revise, stop or prune reopens it as needed. `status` and `doctor`
|
|
527
|
+
show what the running orchestrator costs on one line,
|
|
528
|
+
|
|
529
|
+
```text
|
|
530
|
+
orchestrator: 1.0.28 (pid 4242) · 3 live / 190 workflows, 3 journals open, 0.4 passes/s, read 12 MB
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
and `status --json` / `doctor --json` carry it as `orchestratorStats`:
|
|
534
|
+
`workflows` (not pruned), `liveWorkflows` (with work still open),
|
|
535
|
+
`openJournals` (journal files held open), `passesPerSecond` (intake passes
|
|
536
|
+
that ran, averaged over the last minute; an idle orchestrator runs almost
|
|
537
|
+
none), `readBytes` (bytes the process read since it started, from
|
|
538
|
+
`/proc/self/io`; absent where there is none), `pid` and `at` (when it was
|
|
539
|
+
written). The orchestrator writes these to `orchestrator-stats.json` every
|
|
540
|
+
10 s; they are shown only while that process runs.
|
|
541
|
+
|
|
458
542
|
### Resource leases
|
|
459
543
|
|
|
460
544
|
Benchmarks, timing measurements and big builds need the machine to
|
|
@@ -465,6 +549,7 @@ command:
|
|
|
465
549
|
pi-durable-subagents hold machine -- make bench # exclusive
|
|
466
550
|
pi-durable-subagents hold machine --shared -- npm test # with other shared holders, never with an exclusive one
|
|
467
551
|
pi-durable-subagents hold machine --max-wait 600 --note "profile" -- ./measure.sh
|
|
552
|
+
pi-durable-subagents hold build --slots 4 -- cargo test # at most 4 at a time
|
|
468
553
|
```
|
|
469
554
|
|
|
470
555
|
- The lease covers one command, not a whole call: a subagent that thinks
|
|
@@ -473,6 +558,24 @@ pi-durable-subagents hold machine --max-wait 600 --note "profile" -- ./measure.s
|
|
|
473
558
|
everything before it, and keeps later shared requests out (no starvation).
|
|
474
559
|
A waiting `hold` prints who holds the resource; `--max-wait` gives up with
|
|
475
560
|
exit 75 without running the command.
|
|
561
|
+
- `--slots N` (an integer of at least 1; not with `--shared`) makes the
|
|
562
|
+
resource a counting semaphore: a request runs once fewer than N holders
|
|
563
|
+
(slot or shared) hold it, no exclusive request is ahead of it, and no
|
|
564
|
+
earlier request of any kind still waits, so it never overtakes a waiter.
|
|
565
|
+
Shared requests are not limited by slots but occupy them, and they do not
|
|
566
|
+
queue behind a slot waiter, so a stream of shared requests can keep it
|
|
567
|
+
waiting; use one mode and one N per resource name. `leases` shows
|
|
568
|
+
``build 3/4 held: pid 123 `cargo test` (slot, 2m), ...; waiting: 2 (first: pid 456, 30s)``,
|
|
569
|
+
`leases --json` adds `slots` and `held` to the resource,
|
|
570
|
+
and a waiting `hold` prints its position and `held k/N`.
|
|
571
|
+
- `--no-wait` (same as `--max-wait 0`) takes the lease now or not at all.
|
|
572
|
+
It decides under the resource's lock. If it can run now, its request is
|
|
573
|
+
written already granted. Otherwise nothing is written, and it exits 75
|
|
574
|
+
naming who holds or waits, without running the command. It is never
|
|
575
|
+
listed as a waiter, even for a moment, so it can probe a resource whose
|
|
576
|
+
owner treats any queued request as interference. It also leaves the
|
|
577
|
+
resource alone: unlike a queued waiter, it does not end processes left
|
|
578
|
+
by a holder whose `hold` was killed, and is refused while they remain.
|
|
476
579
|
- The command runs without a shell (write `-- sh -c '…'` for one) in its
|
|
477
580
|
own process group; signals to `hold` go to it and its exit status is
|
|
478
581
|
returned. When it exits, whatever it left in its process group is ended
|
|
@@ -514,7 +617,8 @@ State lives in `~/.pi/durable-subagents`; set `DSA_HOME` to move it.
|
|
|
514
617
|
}
|
|
515
618
|
```
|
|
516
619
|
|
|
517
|
-
- **Pools:** a model can name a pool
|
|
620
|
+
- **Pools:** a model can name a pool (the `model` of a call, a `run --spec`
|
|
621
|
+
file or a model send). The first candidate with a free slot is
|
|
518
622
|
used, and a candidate that keeps failing is skipped for 10 minutes. The
|
|
519
623
|
order is the preference: list the provider you want to use first.
|
|
520
624
|
- **A used-up provider** is not sent new calls until its next try, 15 minutes
|
|
@@ -522,7 +626,23 @@ State lives in `~/.pi/durable-subagents`; set `DSA_HOME` to move it.
|
|
|
522
626
|
time goes to it, so finding out costs no extra request. A call that moved to
|
|
523
627
|
another provider stays there for the rest of its generation (switching back
|
|
524
628
|
mid-task would lose the prompt cache); a follow-up starts on the first
|
|
525
|
-
candidate again. `status` lists each used-up provider with its next try
|
|
629
|
+
candidate again. `status` lists each used-up provider with its next try,
|
|
630
|
+
and `events <wid>` shows the move as a model `forward` naming the target
|
|
631
|
+
(`model=<provider>/<id>`) and the provider it left (`failover=<provider>`);
|
|
632
|
+
a model you send shows only its target.
|
|
633
|
+
- **Rehearsing failover:** `pi-durable-subagents drill failover` runs the
|
|
634
|
+
real CLI, orchestrator and subagent pi processes in a temporary home, with
|
|
635
|
+
two offline providers in a pool: the first refuses with a used-up window
|
|
636
|
+
(`503 ... No available accounts`), the second answers. It checks, step by
|
|
637
|
+
step, that a call moves to the second provider, that `status` lists the
|
|
638
|
+
first with its next try, that a second call starts on the second provider,
|
|
639
|
+
that after the probe interval (25 s here) the next call probes the first
|
|
640
|
+
provider and finds it available, and that this call ends on it. Each step
|
|
641
|
+
prints pass/fail and its time; the exit code is 0 only when all pass. Your
|
|
642
|
+
home, providers and credentials are not used. `--json` prints the result as
|
|
643
|
+
one object; `--keep` keeps the temporary directory and prints its path.
|
|
644
|
+
Interrupted (Ctrl-C), it stops what it started and cleans up the same way
|
|
645
|
+
(exit 130, or 143 for SIGTERM).
|
|
526
646
|
- **Provider slots:** never exceeded, including while a model switch is in
|
|
527
647
|
progress.
|
|
528
648
|
- **Memory:** new subagents wait while memory is short. Running ones are
|
package/dist/agent/child.js
CHANGED
|
@@ -10,7 +10,7 @@ import { openness } from "../kernel/guards.js";
|
|
|
10
10
|
import { recover } from "./child/history.js";
|
|
11
11
|
import { validate } from "./child/schema.js";
|
|
12
12
|
import { registerLive } from "./child/live.js";
|
|
13
|
-
const MESSAGES = ['task', 'steer', 'follow-up', 'continue'];
|
|
13
|
+
const MESSAGES = ['task', 'steer', 'notify', 'follow-up', 'continue'];
|
|
14
14
|
/** P31, P33, P37: Usage of this call only — assistant messages in segments opened by this call's executions,
|
|
15
15
|
* deduplicated by entry id. Context inherited from an earlier generation or a forked origin is not charged. */
|
|
16
16
|
export function usage(entries, call) {
|
|
@@ -78,7 +78,7 @@ export function registerChild(pi) {
|
|
|
78
78
|
if (!active || (mode === 'idle' && !ctx.isIdle()))
|
|
79
79
|
return [];
|
|
80
80
|
let delivered = false;
|
|
81
|
-
const plans = planDecisions(state.records, candidates, req => {
|
|
81
|
+
const plans = planDecisions(state.records, candidates, (req, view) => {
|
|
82
82
|
if (req.to !== call)
|
|
83
83
|
return { action: 'reject', reason: 'wrong-recipient' };
|
|
84
84
|
if ([...MESSAGES, 'answer'].includes(req.kind) && typeof req.body?.message !== 'string')
|
|
@@ -105,6 +105,11 @@ export function registerChild(pi) {
|
|
|
105
105
|
if (MESSAGES.includes(req.kind)) {
|
|
106
106
|
if ((mode === 'idle' && delivered) || (req.kind === 'follow-up' && mode === 'boundary'))
|
|
107
107
|
return { action: 'defer' };
|
|
108
|
+
// A notify never interrupts a question: while an answer waits to be delivered (a hibernated asker resumes with
|
|
109
|
+
// its answer as a continue) it goes after it, at the next safe point. In ask mode it was deferred above.
|
|
110
|
+
if (req.kind === 'notify' && candidates.some(other => !view.resolved.has(other.rid) && !view.tombstones.has(other.rid) &&
|
|
111
|
+
(other.kind === 'answer' && !state.answered.has(`${other.cond?.qid}@${other.cond?.rev}`) || other.kind === 'continue' && other.cond?.qid !== undefined)))
|
|
112
|
+
return { action: 'defer' };
|
|
108
113
|
delivered = true;
|
|
109
114
|
return { action: 'apply' };
|
|
110
115
|
}
|
|
@@ -10,7 +10,8 @@ export const parameters = Type.Object({
|
|
|
10
10
|
chain: Type.Optional(Type.Array(Type.Any(), { description: `Sequential calls ({previous} = previous output). ${stepsDoc}` })),
|
|
11
11
|
agent: Type.Optional(Type.String()), task: Type.Optional(Type.String()), model: Type.Optional(Type.String()),
|
|
12
12
|
cwd: Type.Optional(Type.String({ description: "Run directory (default: this session's). Relative workflow, inputs and call cwd paths resolve against it." })),
|
|
13
|
-
to: Type.Optional(Type.String()
|
|
13
|
+
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
|
+
kind: Type.Optional(Type.Union([Type.Literal("steer"), Type.Literal("notify"), Type.Literal("follow-up"), Type.Literal("answer"), Type.Literal("model")])),
|
|
14
15
|
message: Type.Optional(Type.String()), qid: Type.Optional(Type.String()), rev: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
15
16
|
replaces: Type.Optional(Type.Array(Type.String())), target: Type.Optional(Type.String()), wid: Type.Optional(Type.String()),
|
|
16
17
|
usageBudget: Type.Optional(Type.Object({ tokens: Type.Optional(Type.Number()), costUsd: Type.Optional(Type.Number()) })),
|
|
@@ -19,6 +20,8 @@ export const parameters = Type.Object({
|
|
|
19
20
|
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." })),
|
|
20
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." })),
|
|
21
22
|
key: Type.Optional(Type.String({ description: "A single agent/task run: the call's key. status with wid: that call's full result." })),
|
|
23
|
+
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
|
+
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)." })),
|
|
22
25
|
full: Type.Optional(Type.Boolean({ description: "status: with wid, the complete workflow detail including every output." })),
|
|
23
26
|
force: Type.Optional(Type.Union([Type.String(), Type.Boolean()], { description: "restart: the token shown by a refusal. Show the user the list and obtain explicit approval first; boolean true is refused. Subagents cannot force a restart (an environment-based rail against accidents, not a security boundary)." })),
|
|
24
27
|
reason: Type.Optional(Type.String({ description: "restart: non-empty reason, at most 500 characters; required with force." })),
|
package/dist/agent/main/tool.js
CHANGED
|
@@ -4,7 +4,7 @@ import { validateCallSpec } from "../../compat/spec.js";
|
|
|
4
4
|
import { compileFanout } from "../../compat/fanout.js";
|
|
5
5
|
import { checkLabels } from "../../events/labels.js";
|
|
6
6
|
/** Call fields a tasks/chain run applies to every step that does not set its own. */
|
|
7
|
-
export const stepDefaults = ["model", "timeoutMs", "budget", "isolation", "context", "tools", "skills", "once", "writer"];
|
|
7
|
+
export const stepDefaults = ["agent", "model", "timeoutMs", "budget", "isolation", "context", "tools", "skills", "once", "writer"];
|
|
8
8
|
function string(args, name) {
|
|
9
9
|
if (typeof args[name] !== "string" || !args[name])
|
|
10
10
|
throw new Error(`${name} is required`);
|
|
@@ -35,21 +35,51 @@ export function checkAgents(body, available) {
|
|
|
35
35
|
* at its next provider request), `next-execution` (a call with no live execution launches on it) or `next-generation`
|
|
36
36
|
* (a follow-up's new generation runs on it). From the orchestrator ledger's `send-note`. */
|
|
37
37
|
export function sendReceipt(ledger, rid) {
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
// The latest one counts: a replayed notify corrects what an interrupted first decision recorded.
|
|
39
|
+
const note = ledger.findLast(e => e.type === "send-note" && e.rid === rid);
|
|
40
|
+
if (!note)
|
|
41
|
+
return {};
|
|
42
|
+
if (typeof note.delivery === "string")
|
|
43
|
+
return { delivery: note.delivery, note: DELIVERY_NOTE[note.delivery] ?? note.delivery };
|
|
44
|
+
return { model: String(note.model), effect: String(note.effect), ...(note.pool ? { pool: String(note.pool) } : {}) };
|
|
40
45
|
}
|
|
46
|
+
/** The internal argument through which a send to several calls passes its `batch` (not a tool parameter). */
|
|
47
|
+
export const BATCH = Symbol("batch");
|
|
48
|
+
/** One line of a reply per target: applied (with how a notify went), rejected with its reason, or not decided yet. */
|
|
49
|
+
export function outcomeLine(r) {
|
|
50
|
+
if (r.applied === true)
|
|
51
|
+
return `applied${r.delivery ? ` (${String(r.delivery)}: ${String(r.note)})` : r.effect ? ` (model ${String(r.model)}, ${String(r.effect)})` : ""}`;
|
|
52
|
+
if (r.applied === false)
|
|
53
|
+
return `rejected ${String(r.reason)}`;
|
|
54
|
+
if (r.submitted)
|
|
55
|
+
return `submitted, not decided yet (${String(r.submitted.rid)})`;
|
|
56
|
+
return JSON.stringify(r);
|
|
57
|
+
}
|
|
58
|
+
export const DELIVERY_NOTE = {
|
|
59
|
+
steered: "the call is running; it gets the note at its next safe point",
|
|
60
|
+
"held-until-answer": "the call waits on its question; it gets the note after the answer",
|
|
61
|
+
noted: "the call is not running: recorded as a pending note for its next follow-up (nothing was started)",
|
|
62
|
+
};
|
|
41
63
|
export function request(args, cwd) {
|
|
42
64
|
// v12 §2: Infer run only when one launch form is present; never guess a control verb.
|
|
43
|
-
|
|
65
|
+
// A top-level agent without a task beside tasks/chain is the steps' default agent, not a launch form of its own.
|
|
66
|
+
const listRun = args.tasks !== undefined || args.chain !== undefined;
|
|
67
|
+
// A task beside tasks/chain is refused with what to do, before the launch form is inferred (with or without action).
|
|
68
|
+
if ((args.action === undefined || args.action === "run") && listRun && args.task !== undefined)
|
|
69
|
+
throw new Error(`task cannot be set beside ${args.tasks !== undefined ? "tasks" : "chain"}: agent+task is a single call; give each step its own task (a top-level agent alone is the default agent of every step)`);
|
|
70
|
+
const launchForms = [args.task !== undefined || args.agent !== undefined && !listRun, args.tasks !== undefined,
|
|
44
71
|
args.chain !== undefined, args.workflow !== undefined, args.source !== undefined];
|
|
45
72
|
const action = args.action === undefined && launchForms.filter(Boolean).length === 1 ? "run" : args.action;
|
|
46
73
|
if (typeof action !== "string" || !action)
|
|
47
74
|
throw new Error("action is required: run, agents, send, stop, revise, status, resume, drain, restart");
|
|
48
75
|
if (action === "run") {
|
|
49
76
|
const { action: _, workflow, source, tasks, chain, args: inputs, name, usageBudget, maxCalls, inputs: files, labels, by: _by, request: _request, ...spec } = args;
|
|
50
|
-
const
|
|
77
|
+
const steps = tasks !== undefined || chain !== undefined;
|
|
78
|
+
// With tasks/chain a top-level agent (no task) is the default agent of every step, like model or timeoutMs.
|
|
79
|
+
const single = spec.task !== undefined || spec.agent !== undefined && !steps;
|
|
80
|
+
const choices = [workflow, source, tasks, chain, single ? spec : undefined];
|
|
51
81
|
if (choices.filter(v => v !== undefined).length !== 1)
|
|
52
|
-
throw new Error("run requires exactly one of workflow, source, tasks, chain, or agent/task");
|
|
82
|
+
throw new Error("run requires exactly one of workflow, source, tasks, chain, or agent/task (with tasks/chain, a top-level agent without task is the steps' default agent)");
|
|
53
83
|
// A top-level cwd on a workflow/tasks/chain/source run is the run's directory: relative paths (the workflow file,
|
|
54
84
|
// inputs, per-call cwd) resolve against it and calls default to it. It used to be ignored, so a relative
|
|
55
85
|
// workflow path was looked up in the session's directory instead.
|
|
@@ -110,11 +140,15 @@ export function request(args, cwd) {
|
|
|
110
140
|
}
|
|
111
141
|
if (action === "send") {
|
|
112
142
|
const kind = string(args, "kind");
|
|
113
|
-
if (!["steer", "follow-up", "answer", "model"].includes(kind))
|
|
143
|
+
if (!["steer", "notify", "follow-up", "answer", "model"].includes(kind))
|
|
114
144
|
throw new Error("Unsupported send kind");
|
|
145
|
+
if (Array.isArray(args.to))
|
|
146
|
+
throw new Error("to names one call here; several targets are sent one request each");
|
|
115
147
|
// follow-up may name the model its continuation runs on (P37); other kinds ignore one.
|
|
116
148
|
const model = kind === "model" || kind === "follow-up" && args.model !== undefined ? { model: string(args, "model") } : {};
|
|
117
|
-
|
|
149
|
+
// `batch` is set by a send to several calls (see manyIds in src/requests.ts), never by a caller.
|
|
150
|
+
const body = { to: string(args, "to"), kind, ...model, ...(kind === "model" ? {} : { message: string(args, "message") }), ...(args.by === "user" ? { by: "user" } : {}),
|
|
151
|
+
...(typeof args[BATCH] === "string" ? { batch: args[BATCH] } : {}) };
|
|
118
152
|
const cond = {};
|
|
119
153
|
if (kind === "answer") {
|
|
120
154
|
cond.qid = string(args, "qid");
|