pi-durable-subagents 1.4.0 → 1.4.2
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 +17 -1
- package/README.md +5 -2
- package/dist/agent/main/snapshots.js +12 -6
- package/dist/orchestrator/evaluator-client.js +1 -1
- package/dist/orchestrator/snapshot.js +87 -11
- package/dist/ui/view.js +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.4.2
|
|
4
|
+
|
|
5
|
+
- Memory: a main session's polling no longer keeps every earlier pass alive. Each workflow entry's lazy `entries`
|
|
6
|
+
getter was created inside the polling function and closed over that call's context, which held the preceding pass;
|
|
7
|
+
so each pass kept the one before it, with its listing of the workflows directory, ledger state and digests. A
|
|
8
|
+
long-running pi grew by about 0.25 GB per hour while its subagents worked and ran out of heap after about 12 hours.
|
|
9
|
+
A pass now keeps only the latest result.
|
|
10
|
+
- Memory: `status`, every `send` and the resume check no longer keep a digest of every settled workflow on the
|
|
11
|
+
machine. They keep only each settled journal's identity and owner, and read the few finished workflows they show
|
|
12
|
+
from the cache. On a home with 7,800 workflows a pi process kept about 220 MB after its first `status`; it keeps
|
|
13
|
+
about 26 MB. The output is unchanged.
|
|
14
|
+
|
|
15
|
+
## 1.4.1
|
|
16
|
+
|
|
17
|
+
- Docs, tests and fixtures use neutral example names and paths; no behaviour change.
|
|
18
|
+
|
|
3
19
|
## 1.4.0
|
|
4
20
|
|
|
5
21
|
- Model slots inside a provider: `providers.<p>.models` maps a model id to `{ "slots": N }`. A call on `p/id` holds a
|
|
@@ -465,7 +481,7 @@ Measured on a copy of a real home (2084 workflows, 51k orchestrator ledger entri
|
|
|
465
481
|
subagent's builds and tests had read, which looked like the orchestrator
|
|
466
482
|
reading gigabytes per second.
|
|
467
483
|
- A workflow started without `name` is shown by its label values
|
|
468
|
-
(`
|
|
484
|
+
(`nightly-qa c4811f14`) in the dock, `/subagents`, the watch view and the
|
|
469
485
|
completion notice, instead of by its agent name.
|
|
470
486
|
|
|
471
487
|
## 1.0.32
|
package/README.md
CHANGED
|
@@ -532,7 +532,7 @@ session's workflows (sessions are independent), working ones first (newest
|
|
|
532
532
|
first), every subagent with its model, what it is doing and for how long, and
|
|
533
533
|
its latest line. Finished ones follow, most recently ended first, dimmed, with
|
|
534
534
|
their conclusion. A workflow's only subagent is named after the workflow (its
|
|
535
|
-
`name`, else its label values, e.g. `
|
|
535
|
+
`name`, else its label values, e.g. `nightly-qa c4811f14`); in a
|
|
536
536
|
fan-out, a generated key (`tasks:0`) shows as its agent (`worker 1`,
|
|
537
537
|
`reviewer`). The key remains the address for `send` and the CLI. A session's workflows include runs started
|
|
538
538
|
through the CLI by a process this session launched (a background driver, a
|
|
@@ -1034,6 +1034,9 @@ for at most five seconds. Turn boundaries check immediately for late attention.
|
|
|
1034
1034
|
Ledger changes force a journal check;
|
|
1035
1035
|
final sessions are also rechecked within five seconds. Only an explicitly
|
|
1036
1036
|
opened final call keeps its transcript. Prune removes the workflow's caches.
|
|
1037
|
+
A `status` or `send` covers every workflow of the machine but keeps in memory
|
|
1038
|
+
only the identity of a settled journal that no poller holds; the few finished
|
|
1039
|
+
workflows it shows are read from the cache each time.
|
|
1037
1040
|
`DSA_CACHE_HOME=<directory>` places the derived cache under that directory
|
|
1038
1041
|
instead of `DSA_HOME`, without changing where authoritative data is read.
|
|
1039
1042
|
|
|
@@ -1330,7 +1333,7 @@ State lives in `~/.pi/durable-subagents`; set `DSA_HOME` to move it.
|
|
|
1330
1333
|
It is snapshotted when each child execution starts: changing it affects
|
|
1331
1334
|
executions started afterwards, not a child already running; a resumed
|
|
1332
1335
|
execution receives the current setting. False keeps question-only asks valid.
|
|
1333
|
-
- **Quota notices in a successful answer:** `"exhaustedPatterns": ["
|
|
1336
|
+
- **Quota notices in a successful answer:** `"exhaustedPatterns": ["quota exhausted"]` on a
|
|
1334
1337
|
provider treats a message that says the usage window is used up as a quota
|
|
1335
1338
|
failure, even when the gateway answered with HTTP 200. Each entry is a
|
|
1336
1339
|
JavaScript regular expression, matched case-insensitively against an
|
|
@@ -31,6 +31,17 @@ export class PendingOutboxReader {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
const passes = new Map();
|
|
34
|
+
/** One workflow of a pass. Built here, not inside workflows(): a getter created there closes over that call's whole
|
|
35
|
+
* context, which holds the preceding pass (`prior`, `old`), so every result entry kept the pass before it alive and,
|
|
36
|
+
* through that pass's own entries, every earlier one (each with its listing of w/, ledger state and digests). */
|
|
37
|
+
function mainWorkflow(wid, origin, digest, path) {
|
|
38
|
+
return { wid, origin, ...(digest.settled ? { settled: digest.settled } : {}), get entries() {
|
|
39
|
+
const entries = readJournalSnapshot(path);
|
|
40
|
+
if (digest.settled)
|
|
41
|
+
forgetJournalSnapshot(path);
|
|
42
|
+
return entries;
|
|
43
|
+
} };
|
|
44
|
+
}
|
|
34
45
|
export function workflows(home, origin, fresh = false) {
|
|
35
46
|
const { record, names, checked: listed } = readerWorkflowListing(home, fresh), ix = record.state, mark = readerLedgerIdentity(record), now = Date.now();
|
|
36
47
|
let byOrigin = passes.get(home);
|
|
@@ -59,12 +70,7 @@ export function workflows(home, origin, fresh = false) {
|
|
|
59
70
|
continue;
|
|
60
71
|
}
|
|
61
72
|
digests.set(wid, digest);
|
|
62
|
-
changes.set(wid,
|
|
63
|
-
const entries = readJournalSnapshot(path);
|
|
64
|
-
if (digest.settled)
|
|
65
|
-
forgetJournalSnapshot(path);
|
|
66
|
-
return entries;
|
|
67
|
-
} });
|
|
73
|
+
changes.set(wid, mainWorkflow(wid, from, digest, path));
|
|
68
74
|
}
|
|
69
75
|
const result = ids.map(wid => changes.get(wid) ?? old.get(wid)).filter((w) => !!w);
|
|
70
76
|
const same = prior && prior.result.length === result.length && result.every((w, i) => w === prior.result[i]);
|
|
@@ -83,7 +83,7 @@ export class EvaluatorClient {
|
|
|
83
83
|
}
|
|
84
84
|
this.child = undefined;
|
|
85
85
|
}
|
|
86
|
-
/** A2, P10: Fence a previous host, commit launch intent, and attach
|
|
86
|
+
/** A2, P10: Fence a previous host, commit launch intent, and attach the message-channel readers. */
|
|
87
87
|
async start(message, death) {
|
|
88
88
|
await this.retire();
|
|
89
89
|
const exec = `eval:${ulid()}`;
|
|
@@ -766,6 +766,69 @@ export function workflowDigest(home, wid, ledger) {
|
|
|
766
766
|
}
|
|
767
767
|
return digest;
|
|
768
768
|
}
|
|
769
|
+
/** Settled journals a status listing checked without keeping their digest: the journal's identity and who owns the
|
|
770
|
+
* workflow. A listing covers every workflow of the machine (thousands) but shows only a few finished ones; keeping
|
|
771
|
+
* all their digests in `digests` cost each pi process hundreds of MB from its first `status` or `send`. */
|
|
772
|
+
const settledMarks = new Map();
|
|
773
|
+
/** Replace a settled digest that no poller held before (`held`) by its mark: the next reader takes it from disk. */
|
|
774
|
+
function markSettled(path) {
|
|
775
|
+
const memo = digests.get(path);
|
|
776
|
+
if (!memo?.digest.settled) {
|
|
777
|
+
settledMarks.delete(path);
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
const { origin, session } = memo.digest.snapshot;
|
|
781
|
+
settledMarks.set(path, { dev: memo.dev, ino: memo.ino, size: memo.size, ...(origin !== undefined ? { origin } : {}), ...(session !== undefined ? { session } : {}) });
|
|
782
|
+
digests.delete(path);
|
|
783
|
+
folds.delete(path);
|
|
784
|
+
forgetJournalSnapshot(path);
|
|
785
|
+
releasable.delete(path);
|
|
786
|
+
}
|
|
787
|
+
/** Whether a workflow's journal is settled as it is now, with the origin and session of its snapshot; decided without
|
|
788
|
+
* keeping its digest in memory unless a poller already holds it. Undefined: not settled (or not readable). */
|
|
789
|
+
function settledFacts(home, wid) {
|
|
790
|
+
const path = pathsOf(home, wid).journal;
|
|
791
|
+
if (digests.has(path)) {
|
|
792
|
+
const digest = workflowDigest(home, wid);
|
|
793
|
+
settledMarks.delete(path);
|
|
794
|
+
return digest.settled ? { origin: digest.snapshot.origin, session: digest.snapshot.session } : undefined;
|
|
795
|
+
}
|
|
796
|
+
let dev, ino, size;
|
|
797
|
+
try {
|
|
798
|
+
({ dev, ino, size } = statSync(path));
|
|
799
|
+
}
|
|
800
|
+
catch (error) {
|
|
801
|
+
if (error.code !== "ENOENT")
|
|
802
|
+
throw error;
|
|
803
|
+
settledMarks.delete(path);
|
|
804
|
+
return undefined;
|
|
805
|
+
}
|
|
806
|
+
const mark = settledMarks.get(path);
|
|
807
|
+
if (mark && mark.dev === dev && mark.ino === ino && mark.size === size)
|
|
808
|
+
return mark;
|
|
809
|
+
const stored = storedDigest(home, wid, dev, ino, size);
|
|
810
|
+
if (stored) {
|
|
811
|
+
const { origin, session } = stored.snapshot;
|
|
812
|
+
const facts = { ...(origin !== undefined ? { origin } : {}), ...(session !== undefined ? { session } : {}) };
|
|
813
|
+
settledMarks.set(path, { dev, ino, size, ...facts });
|
|
814
|
+
return facts;
|
|
815
|
+
}
|
|
816
|
+
// No usable stored digest: fold the journal once (this also stores its digest when settled), then keep only the mark.
|
|
817
|
+
const digest = workflowDigest(home, wid);
|
|
818
|
+
markSettled(path);
|
|
819
|
+
return digest.settled ? { origin: digest.snapshot.origin, session: digest.snapshot.session } : undefined;
|
|
820
|
+
}
|
|
821
|
+
/** `read` (one snapshot of a settled workflow) without keeping its digest in memory unless a poller already held it. */
|
|
822
|
+
function unretained(home, wid, read) {
|
|
823
|
+
const path = pathsOf(home, wid).journal, held = digests.has(path);
|
|
824
|
+
try {
|
|
825
|
+
return read();
|
|
826
|
+
}
|
|
827
|
+
finally {
|
|
828
|
+
if (!held)
|
|
829
|
+
markSettled(path);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
769
832
|
/** Last journal identity check of the current digest. Reuse never renews this timestamp. */
|
|
770
833
|
export function workflowDigestChecked(home, wid) {
|
|
771
834
|
return digests.get(pathsOf(home, wid).journal)?.checked ?? -Infinity;
|
|
@@ -906,6 +969,7 @@ function forgetRemovedWorkflows(home, names, pruned) {
|
|
|
906
969
|
for (const [wid, p] of paths)
|
|
907
970
|
if (pruned.has(wid) || !present.has(wid)) {
|
|
908
971
|
digests.delete(p.journal);
|
|
972
|
+
settledMarks.delete(p.journal);
|
|
909
973
|
folds.delete(p.journal);
|
|
910
974
|
forgetJournalSnapshot(p.journal);
|
|
911
975
|
firstOrigins.delete(p.journal);
|
|
@@ -1291,12 +1355,22 @@ function origins(home) {
|
|
|
1291
1355
|
}
|
|
1292
1356
|
/** Every workflow with its origin and hold, own session first, then newest first. */
|
|
1293
1357
|
function snapshots(home, origin) {
|
|
1294
|
-
const
|
|
1358
|
+
const owned = (w) => !!origin && ownedBy(w, origin);
|
|
1295
1359
|
const { since, held, labels, session } = heldWorkflows(home);
|
|
1296
|
-
const
|
|
1297
|
-
const wf = labelled(workflowSnapshot(home, wid), labels(wid), session(wid)), withOrigin = wf.origin === undefined &&
|
|
1360
|
+
const full = (wid, ledgerOrigin) => {
|
|
1361
|
+
const wf = labelled(workflowSnapshot(home, wid), labels(wid), session(wid)), withOrigin = wf.origin === undefined && ledgerOrigin !== undefined ? { ...wf, origin: ledgerOrigin } : wf;
|
|
1298
1362
|
return isLive(withOrigin) && held(wid) ? { ...withOrigin, paused: true } : withOrigin;
|
|
1299
|
-
}
|
|
1363
|
+
};
|
|
1364
|
+
const all = [...origins(home)].sort(([a], [b]) => a < b ? 1 : a > b ? -1 : 0).map(([wid, ledgerOrigin]) => {
|
|
1365
|
+
const facts = settledFacts(home, wid);
|
|
1366
|
+
if (facts) {
|
|
1367
|
+
let wf;
|
|
1368
|
+
return { wid, settled: true, own: owned({ origin: facts.origin ?? ledgerOrigin, session: session(wid) || facts.session }),
|
|
1369
|
+
snapshot: () => wf ??= unretained(home, wid, () => full(wid, ledgerOrigin)) };
|
|
1370
|
+
}
|
|
1371
|
+
const wf = full(wid, ledgerOrigin);
|
|
1372
|
+
return { wid, settled: settled(wf), own: owned(wf), snapshot: () => wf };
|
|
1373
|
+
}).sort((a, b) => Number(b.own) - Number(a.own));
|
|
1300
1374
|
return { all, ...(since !== undefined ? { since } : {}) };
|
|
1301
1375
|
}
|
|
1302
1376
|
/** P25, T10: Compact status of all workflows: own session first, then newest first; finished ones beyond the first `keep` collapse into a count. */
|
|
@@ -1304,9 +1378,9 @@ export function statusView(home, options = {}) {
|
|
|
1304
1378
|
const keep = options.keep ?? 10;
|
|
1305
1379
|
const { all, since } = snapshots(home, options.origin), leases = leaseState(home), byCall = leaseCalls(leases);
|
|
1306
1380
|
let finished = 0;
|
|
1307
|
-
const shown = all.filter(w => !settled
|
|
1381
|
+
const shown = all.filter(w => !w.settled || ++finished <= keep).map(w => w.snapshot());
|
|
1308
1382
|
const hidden = all.length - shown.length;
|
|
1309
|
-
const paused = all.filter(w => w.paused).length;
|
|
1383
|
+
const paused = all.filter(w => !w.settled && w.snapshot().paused).length;
|
|
1310
1384
|
return { workflows: shown.map(w => compactWorkflow(w, byCall)), ...(hidden ? { olderFinished: hidden, hint: "status wid=<wid> shows any workflow in detail" } : {}),
|
|
1311
1385
|
...(paused ? { paused: `${paused} workflow${paused > 1 ? "s" : ""} paused (stop-all, drain or a quit pi) since ${new Date(since).toISOString()}; resume continues them (new runs are not affected)` } : {}),
|
|
1312
1386
|
...slotsView(home), ...(leases.length ? { leases: leaseLines(leases) } : {}), ...runningStats(home) };
|
|
@@ -1460,7 +1534,7 @@ export function slotsView(home, now = Date.now()) {
|
|
|
1460
1534
|
* The full view (every call's last line and usage) ran to tens of thousands of tokens on a busy home. */
|
|
1461
1535
|
export function statusBrief(home, options = {}) {
|
|
1462
1536
|
const keep = options.keep ?? 5, now = options.now ?? Date.now(), origin = options.origin;
|
|
1463
|
-
const { all } = snapshots(home, origin), leases = leaseState(home), byCall = leaseCalls(leases, now);
|
|
1537
|
+
const { all: listed } = snapshots(home, origin), leases = leaseState(home), byCall = leaseCalls(leases, now);
|
|
1464
1538
|
const mine = (w) => !origin || ownedBy(w, origin);
|
|
1465
1539
|
const line = (w) => {
|
|
1466
1540
|
const p = progressOf(w), notOk = latestCalls(w).filter(c => c.result && !c.result.ok).length;
|
|
@@ -1492,15 +1566,16 @@ export function statusBrief(home, options = {}) {
|
|
|
1492
1566
|
progress: `${p.done}/${p.total}${p.plus ? "+" : ""}`, tokens: tokens(w.usage), calls,
|
|
1493
1567
|
...(asking.length ? { asking } : {}), ...(alerts.length ? { alerts } : {}) };
|
|
1494
1568
|
};
|
|
1495
|
-
const active =
|
|
1496
|
-
|
|
1569
|
+
const active = listed.filter(w => !w.settled).map(w => w.snapshot());
|
|
1570
|
+
// Snapshotted for its line only when shown (the first `keep`); the rest is a count.
|
|
1571
|
+
const finished = listed.filter(w => w.settled && (!origin || w.own));
|
|
1497
1572
|
const others = active.filter(w => !mine(w));
|
|
1498
1573
|
const heldMine = active.filter(w => mine(w) && w.paused).length, heldOthers = others.filter(w => w.paused);
|
|
1499
1574
|
const paused = [heldMine ? `${heldMine} workflow${heldMine > 1 ? "s" : ""} of this session ${heldMine > 1 ? "are" : "is"} paused (stop-all, drain or a quit pi); resume continues ${heldMine > 1 ? "them" : "it"}` : "",
|
|
1500
1575
|
heldOthers.length ? `${heldOthers.length} workflow${heldOthers.length > 1 ? "s" : ""} of other sessions paused (${heldOthers.slice(0, 8).map(w => w.wid).join(", ")}); resume wid=<wid> continues one` : ""].filter(Boolean).join("; ");
|
|
1501
1576
|
return {
|
|
1502
1577
|
active: active.filter(mine).map(brief), ...(others.length ? { otherSessions: others.slice(0, 10).map(line) } : {}),
|
|
1503
|
-
finished: finished.slice(0, keep).map(line), ...(finished.length > keep ? { olderFinished: finished.length - keep } : {}),
|
|
1578
|
+
finished: finished.slice(0, keep).map(w => line(w.snapshot())), ...(finished.length > keep ? { olderFinished: finished.length - keep } : {}),
|
|
1504
1579
|
...(paused ? { paused } : {}), ...slotsView(home, now), ...(leases.length ? { leases: leaseLines(leases, now) } : {}),
|
|
1505
1580
|
hint: "status wid=<wid> shows one workflow (outputs clipped); add key=<key> for one call's full result, or full:true for everything",
|
|
1506
1581
|
};
|
|
@@ -1535,7 +1610,8 @@ export function statusText(home, value) {
|
|
|
1535
1610
|
}
|
|
1536
1611
|
/** Running workflows of other sessions that a pause holds, as "wid" or "wid (name)": a session's own resume skips them. */
|
|
1537
1612
|
export function pausedElsewhere(home, origin) {
|
|
1538
|
-
return snapshots(home, origin).all.filter(w => w.
|
|
1613
|
+
return snapshots(home, origin).all.filter(w => !w.settled).map(w => w.snapshot()).filter(w => w.paused && w.origin !== origin)
|
|
1614
|
+
.map(w => w.name ? `${w.wid} (${w.name})` : w.wid);
|
|
1539
1615
|
}
|
|
1540
1616
|
/** "<rid>" or "<rid>/<rest>" of a run request that created a workflow → the same address with its wid; else unchanged.
|
|
1541
1617
|
* A run replies {submitted:{rid}} when its workflow is not created within 10 s, so the rid is all the caller has. */
|
package/dist/ui/view.js
CHANGED
|
@@ -18,7 +18,7 @@ export function modelLabel(model, find, aliases = {}) {
|
|
|
18
18
|
const matched = /claude|gpt|gemini|deepseek|glm|opus|sonnet|haiku/i.exec(`${id} ${name}`)?.[0]?.toLowerCase();
|
|
19
19
|
const family = matched && ["opus", "sonnet", "haiku"].includes(matched) ? "claude" : matched;
|
|
20
20
|
const suffix = family && provider.toLowerCase().endsWith(`-${family}`) ? provider.slice(0, -family.length - 1) : provider;
|
|
21
|
-
// A display name that already names its provider ("GLM-5.3 (
|
|
21
|
+
// A display name that already names its provider ("GLM-5.3 (acme)") is never suffixed again.
|
|
22
22
|
const named = (word) => Boolean(word) && new RegExp(`(^|[^a-z0-9])${word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}([^a-z0-9]|$)`, "i").test(name);
|
|
23
23
|
return suffix.toLowerCase() === family || named(provider) || named(suffix) ? name : `${name} (${suffix})`;
|
|
24
24
|
}
|
|
@@ -171,7 +171,7 @@ const GENERATED = /^(?:tasks|chain):(\d+)$/;
|
|
|
171
171
|
/** UI §2: How a person knows a call. A workflow's only agent goes by the workflow's name; a generated key (tasks:0) by
|
|
172
172
|
* its agent, numbered when the workflow runs that agent more than once; a named key as is. "@2" marks a later
|
|
173
173
|
* generation. The key stays the address for tools and the CLI; only the UI shows this name. */
|
|
174
|
-
/** A workflow's display name: its run name, else its label values ("
|
|
174
|
+
/** A workflow's display name: its run name, else its label values ("nightly-qa c4811f14"), else undefined. */
|
|
175
175
|
export function workflowName(w) {
|
|
176
176
|
if (w.name)
|
|
177
177
|
return w.name;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-durable-subagents",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Subagents for pi that never lose work and never do it twice. Crash-safe workflows, automatic recovery, and a live view just like the main agent.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|