pi-durable-subagents 1.5.0 → 1.5.1
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,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.5.1
|
|
4
|
+
|
|
5
|
+
- A worktree on an unexpected branch or detached HEAD can no longer block unrelated workflows during startup recovery. If the call already succeeded, recovery keeps its result and files and records one notice that survives restarts. The notice identifies the call, path, expected branch and actual checkout (#10).
|
|
6
|
+
|
|
3
7
|
## 1.5.0
|
|
4
8
|
|
|
5
9
|
- The `durable-subagents:activity` event includes `costUsd`, the sum of recorded costs for the session's retained workflows, including finished runs. Status bars receive a new event when spend changes (#6).
|
|
@@ -56,6 +56,27 @@ async function branchHead(cwd, branch) {
|
|
|
56
56
|
throw error;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
/** What a registered worktree holds now, for a person: its branch (or a detached HEAD) and its commit. */
|
|
60
|
+
function holdText(tree) {
|
|
61
|
+
const at = tree.HEAD ? ` at ${tree.HEAD}` : "";
|
|
62
|
+
return tree.branch ? `${tree.branch.replace(/^refs\/heads\//, "")}${at}` : tree.detached !== undefined ? `a detached HEAD${at}` : `no branch${at}`;
|
|
63
|
+
}
|
|
64
|
+
/** P32: An identity mismatch names the call, the workflow, the path and both identities, so a person can repair the path;
|
|
65
|
+
* this process never moves a worktree, a branch or a file to make them agree. */
|
|
66
|
+
function identityConflict(t, path, branch, head, tree) {
|
|
67
|
+
return `Worktree identity conflict: ${t.callId} (workflow ${t.wid}) needs its worktree ${path} on ${branch}${head ? ` at ${head}` : ""}, ` +
|
|
68
|
+
`but the path holds ${holdText(tree)}`;
|
|
69
|
+
}
|
|
70
|
+
/** P32: What to advise a person. It names the path and the branch but never spells out a shell command: either may hold
|
|
71
|
+
* spaces or characters a shell would interpret, so the operator repairs the path with their own quoting. */
|
|
72
|
+
function repairAdvice(path, branch, kept) {
|
|
73
|
+
const inspect = `Check what ${path} holds and keep anything you need`;
|
|
74
|
+
return kept
|
|
75
|
+
? `${inspect}. The worktree and its branch were kept, nothing was removed, and this call's sealed result is unchanged; ` +
|
|
76
|
+
`restore the path on ${branch} (or remove that worktree once its changes are preserved) and this note is no longer needed`
|
|
77
|
+
: `${inspect}. The call failed and the path, its files and its branches were left untouched: restore the path on ${branch}, ` +
|
|
78
|
+
`or remove that worktree once its changes are preserved, and run the call again`;
|
|
79
|
+
}
|
|
59
80
|
/** P32: Commit creation intent and reconcile Git's worktree registry and branch identity. */
|
|
60
81
|
export async function prepareWorktree(t) {
|
|
61
82
|
if (t.spec.isolation !== "worktree")
|
|
@@ -84,8 +105,11 @@ export async function prepareWorktree(t) {
|
|
|
84
105
|
return path;
|
|
85
106
|
const tree = (await worktree(t.cwd, path)), head = await branchHead(t.cwd, branch);
|
|
86
107
|
if (tree) {
|
|
108
|
+
// A path someone else moved fails this call only, before anything runs: the worktree is never re-created or moved
|
|
109
|
+
// over what it holds (its files and branch stay for the person to repair).
|
|
87
110
|
if (tree.branch !== `refs/heads/${branch}` || tree.HEAD !== head)
|
|
88
|
-
throw new Error(
|
|
111
|
+
throw new Error(`${identityConflict(t, path, branch, head, tree)}. ` +
|
|
112
|
+
`${repairAdvice(path, branch, false)}`);
|
|
89
113
|
}
|
|
90
114
|
else {
|
|
91
115
|
if (head) {
|
|
@@ -112,8 +136,16 @@ export async function cleanWorktree(t) {
|
|
|
112
136
|
await t.journal.append("wt-removed", { call: t.callId });
|
|
113
137
|
return;
|
|
114
138
|
}
|
|
115
|
-
|
|
116
|
-
|
|
139
|
+
const head = await branchHead(t.cwd, String(intent.branch));
|
|
140
|
+
if (tree.branch !== `refs/heads/${intent.branch}` || tree.HEAD !== head) {
|
|
141
|
+
// The call already sealed ok: its result is final, and removing or moving anything would discard what the path
|
|
142
|
+
// holds, while throwing here would fail this call's recovery on every start. The note is an `unknown` item (like a
|
|
143
|
+
// dirty keep), not a `conflict` reminder: no cross-call contention is open, so it does not hold the workflow open.
|
|
144
|
+
await attention(t, "worktree-conflict", `${identityConflict(t, path, String(intent.branch), head, tree)}. ` +
|
|
145
|
+
`${repairAdvice(path, String(intent.branch), true)}`);
|
|
146
|
+
await t.journal.append("wt-kept", { call: t.callId });
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
117
149
|
if (await git(path, "status", "--porcelain", "--untracked-files=all")) {
|
|
118
150
|
await attention(t, "worktree", `Dirty worktree kept: ${path}`);
|
|
119
151
|
await t.journal.append("wt-kept", { call: t.callId });
|
|
@@ -53,7 +53,7 @@ import { availableMemory } from "./memory.js";
|
|
|
53
53
|
import { reached, sessionUsage, totalUsage } from "./usage.js";
|
|
54
54
|
import { indexSweep, seededSweep, recordFenceFailure, resolveFenceAttention, serialContainment, skipLostCandidate, sweepExecutions } from "./sweep.js";
|
|
55
55
|
import { gateRetired } from "./effects/gate.js";
|
|
56
|
-
import { WorktreeIndex, worktreeCalls, worktreeLabel, worktreePair, worktreeRoots } from "./worktree.js";
|
|
56
|
+
import { WorktreeIndex, isWorktreeConflict, worktreeCalls, worktreeLabel, worktreePair, worktreeRoots } from "./worktree.js";
|
|
57
57
|
import { failedModel, modelFailures, MODEL_RETRY_MS, parentPinned, spillCandidates } from "./pool.js";
|
|
58
58
|
import { PENDING_NOTE, UNDELIVERED_FOLLOW_UP } from "../notes.js";
|
|
59
59
|
import { COMMAND_LOG, exitMeaning, readExitRecord, readTail, spawnCommand } from "../../platform/command.js";
|
|
@@ -531,6 +531,10 @@ export default function createExecutor(ledgers, options = {}) {
|
|
|
531
531
|
for (const { item } of attentionEntries(journal.entries())) {
|
|
532
532
|
if (item.kind === "finished" || item.id === `unknown:${call}` || item.id.startsWith("fence:"))
|
|
533
533
|
continue;
|
|
534
|
+
// P32: the identity-conflict note reports what a kept worktree holds; the call ending repairs nothing, so a seal or a
|
|
535
|
+
// recovery leaves it open for the person to see and act on.
|
|
536
|
+
if (isWorktreeConflict(item.id, call))
|
|
537
|
+
continue;
|
|
534
538
|
if (item.call === call && !journal.entries().some(r => r.type === JT.attentionResolved && r.id === item.id && r.rev === item.rev))
|
|
535
539
|
await journal.append(JT.attentionResolved, { id: item.id, rev: item.rev, resolution: "retired" });
|
|
536
540
|
}
|
|
@@ -63,6 +63,12 @@ export function worktreeRoots() {
|
|
|
63
63
|
}
|
|
64
64
|
/** Pair identity is durable; it also lets readers and seal recovery identify both participants. */
|
|
65
65
|
export const worktreePair = (a, b) => `worktree:${[a, b].sort().join("|")}`;
|
|
66
|
+
/** P32: The id of the one durable note a successful call's kept worktree records when its path holds another identity
|
|
67
|
+
* (effects/prepare.ts writes it; the seal's retirement, the recovery predicate and the digest read it). */
|
|
68
|
+
export const worktreeConflictId = (call) => `worktree-conflict:${call}`;
|
|
69
|
+
/** P32: Whether an attention id is exactly `call`'s identity-conflict note. That note reports what the kept path holds
|
|
70
|
+
* for a person; the call ending does not settle it (nothing was repaired), so only its repair does. */
|
|
71
|
+
export const isWorktreeConflict = (id, call) => id === worktreeConflictId(call);
|
|
66
72
|
export const worktreeCalls = (id) => id.startsWith("worktree:") ? id.slice(9).split("|") : [];
|
|
67
73
|
export const worktreeLabel = (call) => call.replace(/@\d+\//, "/").replace(/@\d+$/, "");
|
|
68
74
|
const callOf = (exec) => exec.slice(0, exec.lastIndexOf("#"));
|
|
@@ -13,7 +13,7 @@ import { heldOn, isModelPool, modelLimit, modelPool, slotsFull } from "./slots.j
|
|
|
13
13
|
import {} from "./ledger.js";
|
|
14
14
|
import { awaitingRuns, readerHold, readerLedger, readerLedgerIdentity } from "./reader-ledger.js";
|
|
15
15
|
import { packageVersion } from "../version.js";
|
|
16
|
-
import { worktreeCalls, worktreeLabel } from "./executor/worktree.js";
|
|
16
|
+
import { worktreeCalls, worktreeLabel, isWorktreeConflict } from "./executor/worktree.js";
|
|
17
17
|
import { leaseCalls, leaseLines, leaseState } from "../platform/lease.js";
|
|
18
18
|
import { labelsOf } from "../events/derive.js";
|
|
19
19
|
import { PENDING_NOTE, generationRids, UNDELIVERED_FOLLOW_UP } from "./notes.js";
|
|
@@ -668,12 +668,14 @@ export function pendingRecovery(wid, entries) {
|
|
|
668
668
|
return true;
|
|
669
669
|
}
|
|
670
670
|
}
|
|
671
|
-
// Retirement, fence repair, and cross-workflow conflict resolution can still close these items.
|
|
671
|
+
// Retirement, fence repair, and cross-workflow conflict resolution can still close these items. A call's
|
|
672
|
+
// identity-conflict note (a kept worktree) is like `unknown:<call>`: a durable diagnostic of a sealed call that it writes
|
|
673
|
+
// once and never retires, so an open one is no recovery work due and does not hold the digest back.
|
|
672
674
|
for (const { item } of attention)
|
|
673
675
|
if (!resolved.has(JSON.stringify([item.id, item.rev]))) {
|
|
674
676
|
if (item.id.startsWith("fence:") || item.kind === "conflict")
|
|
675
677
|
return true;
|
|
676
|
-
if (item.call && seals.has(item.call) && item.kind !== "finished" && item.id !== `unknown:${item.call}`)
|
|
678
|
+
if (item.call && seals.has(item.call) && item.kind !== "finished" && item.id !== `unknown:${item.call}` && !isWorktreeConflict(item.id, item.call))
|
|
677
679
|
return true;
|
|
678
680
|
}
|
|
679
681
|
return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-durable-subagents",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
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",
|