pi-better-subagents 0.31.0 → 0.32.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/assignment-projection.d.mts +1 -0
- package/assignment-projection.mjs +41 -6
- package/docs/usage.md +14 -0
- package/historical-attention.ts +35 -0
- package/index.ts +80 -41
- package/navigator.mjs +3 -2
- package/package.json +1 -1
- package/worker-waits.ts +14 -13
|
@@ -9,6 +9,7 @@ export interface AssignmentProjection {
|
|
|
9
9
|
verified: boolean;
|
|
10
10
|
}
|
|
11
11
|
export function assignmentFor(meta: object, processStatus?: string, options?: { baseDir?: string | undefined; coordinatorPath?: string; observation?: object }): AssignmentProjection;
|
|
12
|
+
export function createAssignmentProjector(options?: { baseDir?: string | undefined; coordinatorPath?: string; observation?: object }): (meta: object, processStatus?: string) => AssignmentProjection;
|
|
12
13
|
export function projectAssignment(meta: object, processStatus: string, observation?: object): AssignmentProjection;
|
|
13
14
|
export function assignmentDiagnostic(assignment: AssignmentProjection): string;
|
|
14
15
|
export const ASSIGNMENT_STATES: string[];
|
|
@@ -57,18 +57,53 @@ export function projectAssignment(meta, processStatus, observation = { verified:
|
|
|
57
57
|
|
|
58
58
|
/** All consumers use the same lineage and authoritative wait read. Park caches are hints only. */
|
|
59
59
|
export function assignmentFor(meta, processStatus = meta.status, options = {}) {
|
|
60
|
+
return assignmentFromSnapshot(meta, processStatus, options, () => readAttempts(options));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function readAttempts(options) {
|
|
60
64
|
const base = options.baseDir ?? join(tmpdir(), "pi-better-subagents");
|
|
61
|
-
const attempts =
|
|
62
|
-
let current = meta;
|
|
65
|
+
const attempts = [];
|
|
63
66
|
try {
|
|
64
|
-
for (const id of
|
|
67
|
+
for (const id of readdirSync(join(base, "runs"))) {
|
|
65
68
|
try {
|
|
66
69
|
const candidate = JSON.parse(readFileSync(join(base, "runs", id, "meta.json"), "utf8"));
|
|
67
|
-
if (candidate
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
if (candidate && typeof candidate === "object") attempts.push(candidate);
|
|
71
|
+
}
|
|
72
|
+
catch { /* A partial unrelated record must not hide a continuation. */ }
|
|
70
73
|
}
|
|
71
74
|
} catch { /* Registry gaps cannot establish a newer attempt. */ }
|
|
75
|
+
return attempts;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** One synchronous UI refresh shares a snapshot; the next refresh reads disk again. */
|
|
79
|
+
export function createAssignmentProjector(options = {}) {
|
|
80
|
+
let snapshot;
|
|
81
|
+
const readSnapshot = (meta) => {
|
|
82
|
+
if (!snapshot) {
|
|
83
|
+
snapshot = new Map();
|
|
84
|
+
for (const candidate of readAttempts(options)) {
|
|
85
|
+
let workspaces = snapshot.get(candidate.sessionId);
|
|
86
|
+
if (!workspaces) snapshot.set(candidate.sessionId, workspaces = new Map());
|
|
87
|
+
let attempts = workspaces.get(candidate.cwd);
|
|
88
|
+
if (!attempts) workspaces.set(candidate.cwd, attempts = []);
|
|
89
|
+
attempts.push(candidate);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return snapshot.get(meta.sessionId)?.get(meta.cwd) ?? [];
|
|
93
|
+
};
|
|
94
|
+
return (meta, processStatus = meta.status) => assignmentFromSnapshot(meta, processStatus, options,
|
|
95
|
+
() => readSnapshot(meta));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function assignmentFromSnapshot(meta, processStatus, options, readSnapshot) {
|
|
99
|
+
const attempts = new Map([[meta.id, meta]]);
|
|
100
|
+
let current = meta;
|
|
101
|
+
if (meta.operations || meta.park) {
|
|
102
|
+
for (const candidate of readSnapshot()) {
|
|
103
|
+
if (candidate.sessionId === meta.sessionId && candidate.cwd === meta.cwd
|
|
104
|
+
&& (!meta.assignment || candidate.assignment?.assignmentId === meta.assignment.assignmentId)) attempts.set(candidate.id, candidate);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
72
107
|
// Conversation roots survive explicit follow-ups. Only automatic resume edges
|
|
73
108
|
// join attempts into one assignment; manual continuation starts a new one.
|
|
74
109
|
const lineage = new Map([[meta.id, meta]]);
|
package/docs/usage.md
CHANGED
|
@@ -1085,3 +1085,17 @@ Near-term:
|
|
|
1085
1085
|
twice ([#2](https://github.com/1aboveio/pi-better-subagents/issues/2)) — **done**.
|
|
1086
1086
|
- Named agent-definition files (per-agent system prompt + tool allowlist) and
|
|
1087
1087
|
chain/parallel orchestration.
|
|
1088
|
+
# Historical Waits
|
|
1089
|
+
|
|
1090
|
+
`/subagents history` lists retained waits from other sessions in this workspace.
|
|
1091
|
+
Each entry identifies its originating session and offers inspection or explicit
|
|
1092
|
+
cancellation. Inspection does not adopt the assignment, acknowledge its evidence,
|
|
1093
|
+
or start a continuation. Cancellation confirms the durable result; it does not
|
|
1094
|
+
claim that an uncertain writer has stopped. Failures leave the wait available
|
|
1095
|
+
for inspection and retry.
|
|
1096
|
+
|
|
1097
|
+
`/subagents history dismiss` durably dismisses the current historical-attention
|
|
1098
|
+
notice without changing any wait or evidence. A changed wait generation, phase,
|
|
1099
|
+
publication or attention reason can produce a new notice. Ordinary task navigation
|
|
1100
|
+
remains scoped to the active session.
|
|
1101
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { type RunCallbackOrigin } from "./registry.ts";
|
|
5
|
+
import { durableSubagentRoot } from "./session-store.ts";
|
|
6
|
+
import { parkedWaits, type ParkedWait } from "./worker-waits.ts";
|
|
7
|
+
|
|
8
|
+
/** Discovery is not adoption: the captured owner and wait evidence stay untouched. */
|
|
9
|
+
export function historicalWaits(origin: RunCallbackOrigin | undefined): ParkedWait[] {
|
|
10
|
+
if (!origin) return [];
|
|
11
|
+
return parkedWaits().filter(({ record }) => record.ownerWorkspace === origin.cwd
|
|
12
|
+
&& record.ownerSessionId !== origin.sessionId);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function attentionRevision(waits: ParkedWait[]): string {
|
|
16
|
+
return createHash("sha256").update(JSON.stringify(waits.map(({ runId, record }) => [
|
|
17
|
+
runId, record.waitId, record.generation, record.phase, record.heldReason,
|
|
18
|
+
record.cancelReason, record.resumedBy, record.resumeLaunchToken,
|
|
19
|
+
]).sort((a, b) => String(a[0]).localeCompare(String(b[0]))))).digest("hex");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function receiptPath(workspace: string): string {
|
|
23
|
+
return join(durableSubagentRoot(), `historical-attention-${createHash("sha256").update(workspace).digest("hex")}.json`);
|
|
24
|
+
}
|
|
25
|
+
export function attentionDismissed(workspace: string, revision: string): boolean {
|
|
26
|
+
try { return JSON.parse(readFileSync(receiptPath(workspace), "utf8")).revision === revision; }
|
|
27
|
+
catch { return false; }
|
|
28
|
+
}
|
|
29
|
+
export function dismissAttention(workspace: string, revision: string): void {
|
|
30
|
+
mkdirSync(durableSubagentRoot(), { recursive: true });
|
|
31
|
+
const path = receiptPath(workspace);
|
|
32
|
+
const temp = `${path}.${randomUUID()}.tmp`;
|
|
33
|
+
writeFileSync(temp, JSON.stringify({ version: 1, revision }), { mode: 0o600 });
|
|
34
|
+
renameSync(temp, path);
|
|
35
|
+
}
|
package/index.ts
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
* launch is the result · completion posts back · the foreground never blocks
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import { createAssignmentProjector } from "./assignment-projection.mjs";
|
|
15
|
+
import { historicalWaits, attentionRevision, attentionDismissed, dismissAttention } from "./historical-attention.ts";
|
|
15
16
|
import { registerAssignmentAttempt, commitAssignmentTerminal, readOutcome, receiptOutcome, outcomeTranscriptReceipt, inspectOutcome, createOutcomeHost, closeOutcomeHost, claimOutcome, type AssignmentBinding } from "./assignment-outcomes.ts";
|
|
16
17
|
import { currentSandboxPermissions } from "./permission-policy.ts";
|
|
17
18
|
import { requestResumeAdmission } from "./worker-waits.ts";
|
|
@@ -238,6 +239,8 @@ import { defaultUserRoot, type CatalogSnapshot } from "./catalog-store.ts";
|
|
|
238
239
|
import { restrictContextFilesToWorktree } from "./shared-worktree-context.ts";
|
|
239
240
|
|
|
240
241
|
const SUBAGENT_MODE_ACTIONS: readonly AutocompleteItem[] = [
|
|
242
|
+
{ value: "history", label: "history", description: "Inspect or cancel waits from other sessions" },
|
|
243
|
+
{ value: "history dismiss", label: "history dismiss", description: "Dismiss unchanged historical attention notices" },
|
|
241
244
|
{ value: "settings", label: "settings", description: "Open delegation, concurrency, and timing settings" },
|
|
242
245
|
{ value: "cap", label: "cap <number>", description: "Set a positive concurrent subagent limit for this session" },
|
|
243
246
|
{ value: "tool-wait", label: "tool-wait <minutes>", description: "Set the session tool-wait alert time; 0 turns it off" },
|
|
@@ -1388,7 +1391,8 @@ function navigatorRows(visible?: RunMeta[], at?: number) {
|
|
|
1388
1391
|
|
|
1389
1392
|
/** Runs that should advertise/open the left-arrow navigator affordance. */
|
|
1390
1393
|
function navigatorRunningRuns(): RunMeta[] {
|
|
1391
|
-
|
|
1394
|
+
const project = createAssignmentProjector();
|
|
1395
|
+
return sessionVisibleNavigatorRuns(Date.now(), project).filter((m) => ["running", "waiting"].includes(project(m, effectiveStatus(m)).state));
|
|
1392
1396
|
}
|
|
1393
1397
|
|
|
1394
1398
|
function navigatorRunningCount(): number {
|
|
@@ -1400,16 +1404,16 @@ function navigatorRunningCount(): number {
|
|
|
1400
1404
|
* each rebuild still reads owned non-terminal metadata so external status
|
|
1401
1405
|
* changes are visible immediately without a time-based memo.
|
|
1402
1406
|
*/
|
|
1403
|
-
function sessionVisibleNavigatorRuns(now: number = Date.now()): RunMeta[] {
|
|
1407
|
+
function sessionVisibleNavigatorRuns(now: number = Date.now(), project = createAssignmentProjector()): RunMeta[] {
|
|
1404
1408
|
const origin = activeCallbackOrigin;
|
|
1405
1409
|
if (!origin) return [];
|
|
1406
1410
|
return navigatorVisibleRuns(listMetasForOrigin(origin))
|
|
1407
1411
|
.filter(belongsToActiveNavigatorSession)
|
|
1408
|
-
.filter((m) => !isExpiredTerminalNavigatorRun(m, now));
|
|
1412
|
+
.filter((m) => !isExpiredTerminalNavigatorRun(m, now, project));
|
|
1409
1413
|
}
|
|
1410
1414
|
|
|
1411
|
-
function isExpiredTerminalNavigatorRun(meta: RunMeta, now: number): boolean {
|
|
1412
|
-
const status =
|
|
1415
|
+
function isExpiredTerminalNavigatorRun(meta: RunMeta, now: number, project = createAssignmentProjector()): boolean {
|
|
1416
|
+
const status = project(meta, effectiveStatus(meta)).state;
|
|
1413
1417
|
if (!isTerminalNavigatorStatus(status)) return false;
|
|
1414
1418
|
const endedAt = meta.endedAt ?? meta.lostAt;
|
|
1415
1419
|
return typeof endedAt === "number" && now - endedAt >= TERMINAL_NAVIGATOR_RETENTION_MS;
|
|
@@ -1438,20 +1442,22 @@ function navigatorDetail(id: string, now: number = Date.now()) {
|
|
|
1438
1442
|
* Set by the active extension instance: cancel a parked assignment's pending
|
|
1439
1443
|
* wait. Returns false when the run is not parked, so the ordinary stop path runs.
|
|
1440
1444
|
*/
|
|
1441
|
-
let cancelParkedForUi: ((id: string, reason: string) => boolean) | undefined;
|
|
1445
|
+
let cancelParkedForUi: ((id: string, reason: string) => Promise<boolean>) | undefined;
|
|
1442
1446
|
|
|
1443
1447
|
/** Shared #44 stop+dismiss path used by navigator Close (#47). */
|
|
1444
1448
|
function navigatorCloseRun(id: string) {
|
|
1445
1449
|
// A parked attempt's child already exited cleanly, so "close" must cancel the
|
|
1446
1450
|
// pending automatic resume instead of pretending to stop a live process.
|
|
1447
|
-
if (
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1451
|
+
if (parkedWaitForRun(id) && cancelParkedForUi) {
|
|
1452
|
+
void cancelParkedForUi(id, "closed from the navigator; the automatic resume is cancelled")
|
|
1453
|
+
.then((cancelled) => {
|
|
1454
|
+
if (!cancelled) throw new Error("The pending wait changed; inspect it again.");
|
|
1455
|
+
dismissRun(id);
|
|
1456
|
+
uiCtx?.ui.notify(`Cancelled the pending wait of ${id}. Writer termination may remain unproven.`, "info");
|
|
1457
|
+
})
|
|
1458
|
+
.catch((error) => uiCtx?.ui.notify(`Cancellation failed for ${id}: ${String(error)}. The wait remains available for inspection and retry.`, "warning"));
|
|
1459
|
+
// The synchronous navigator must retain the row until the durable operation settles.
|
|
1460
|
+
return { action: "missing", id };
|
|
1455
1461
|
}
|
|
1456
1462
|
const outcome = executeNavigatorClose(id, {
|
|
1457
1463
|
readMeta,
|
|
@@ -2300,18 +2306,21 @@ export default function (pi: ExtensionAPI) {
|
|
|
2300
2306
|
childExtensionPath: childBridgeExtensionPath(selfDir()),
|
|
2301
2307
|
});
|
|
2302
2308
|
let resumeOrchestration: ResumeOrchestration | undefined;
|
|
2309
|
+
const notifyOwnedWait = (message: string, level: "warning" | "info" = "warning") => {
|
|
2310
|
+
try { uiCtx?.ui?.notify?.(message, level); } catch { /* no UI */ }
|
|
2311
|
+
};
|
|
2303
2312
|
/**
|
|
2304
2313
|
* Stop a continuation attempt only when this parent owns it and the token
|
|
2305
2314
|
* published with it matches. A pid is never signalled on a guess.
|
|
2306
2315
|
*/
|
|
2307
2316
|
const stopPublishedAttempt = createOwnedAttemptStopper();
|
|
2308
|
-
cancelParkedForUi = (id, reason) => {
|
|
2317
|
+
cancelParkedForUi = async (id, reason) => {
|
|
2309
2318
|
const parked = parkedWaitForRun(id);
|
|
2310
2319
|
if (!parked) return false;
|
|
2311
|
-
|
|
2312
|
-
.
|
|
2313
|
-
.
|
|
2314
|
-
|
|
2320
|
+
try {
|
|
2321
|
+
await cancelParkedWait(workerOperations.service, parked, reason, { stopAttempt: stopPublishedAttempt });
|
|
2322
|
+
if (parked.meta.assignment) enqueueCompletionCallback(pi, id);
|
|
2323
|
+
} finally { syncHealthTicker(); }
|
|
2315
2324
|
return true;
|
|
2316
2325
|
};
|
|
2317
2326
|
const effectiveSettings = () => {
|
|
@@ -3482,9 +3491,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
3482
3491
|
capacity: resumeCapacity(),
|
|
3483
3492
|
launch: launchParkedResume,
|
|
3484
3493
|
stopAttempt: stopPublishedAttempt,
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
},
|
|
3494
|
+
notifyWhen: (meta) => Boolean(activeCallbackOrigin && belongsToOrigin(meta, activeCallbackOrigin)),
|
|
3495
|
+
notify: notifyOwnedWait,
|
|
3488
3496
|
});
|
|
3489
3497
|
return resumeOrchestration;
|
|
3490
3498
|
}
|
|
@@ -3509,10 +3517,13 @@ export default function (pi: ExtensionAPI) {
|
|
|
3509
3517
|
try {
|
|
3510
3518
|
await reconcileParkedWaits(service, {
|
|
3511
3519
|
resume: (park) => orchestration.resume(park),
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
},
|
|
3520
|
+
notifyWhen: (meta) => Boolean(activeCallbackOrigin && belongsToOrigin(meta, activeCallbackOrigin)),
|
|
3521
|
+
notify: notifyOwnedWait,
|
|
3515
3522
|
});
|
|
3523
|
+
const historical = historicalWaits(activeCallbackOrigin);
|
|
3524
|
+
if (historical.length && activeCallbackOrigin && !attentionDismissed(activeCallbackOrigin.cwd, attentionRevision(historical))) {
|
|
3525
|
+
uiCtx?.ui?.notify?.(`${historical.length} historical subagent waits remain. Inspect or cancel with /subagents history; dismiss this notice with /subagents history dismiss.`, "warning");
|
|
3526
|
+
}
|
|
3516
3527
|
} catch { /* reconciliation retries on the next session start */ }
|
|
3517
3528
|
}
|
|
3518
3529
|
|
|
@@ -3990,23 +4001,25 @@ export default function (pi: ExtensionAPI) {
|
|
|
3990
4001
|
enqueueCompletionCallback(pi, id);
|
|
3991
4002
|
} });
|
|
3992
4003
|
acceptanceStopToolRef = acceptanceStopTool;
|
|
3993
|
-
// A parked
|
|
3994
|
-
//
|
|
3995
|
-
// be continued manually. Without this, stop would report "not running" and
|
|
3996
|
-
// leave the automatic resume armed for the same assignment.
|
|
4004
|
+
// A parked attempt may have exited, but its automatic resume is still armed.
|
|
4005
|
+
// Explicit stop must confirm durable cancellation, not just stop a process.
|
|
3997
4006
|
const acceptanceStopToolWithParked = {
|
|
3998
4007
|
...acceptanceStopTool,
|
|
3999
4008
|
async execute(toolCallId: string, params: unknown, signal?: AbortSignal, onUpdate?: unknown, ctx?: unknown) {
|
|
4000
4009
|
const target = (params as { id?: unknown } | undefined)?.id;
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
+
try {
|
|
4011
|
+
if (typeof target === "string" && await cancelParkedForUi?.(target, "cancelled by subagent_stop; the automatic resume is cancelled")) {
|
|
4012
|
+
renderWidget();
|
|
4013
|
+
syncHealthTicker();
|
|
4014
|
+
return {
|
|
4015
|
+
content: [{
|
|
4016
|
+
type: "text",
|
|
4017
|
+
text: `Durably cancelled the pending wait of parked subagent ${target}. Writer termination may remain unproven; ordinary continuation admission still applies.`,
|
|
4018
|
+
}],
|
|
4019
|
+
};
|
|
4020
|
+
}
|
|
4021
|
+
} catch (error) {
|
|
4022
|
+
return { isError: true, content: [{ type: "text", text: `Cancellation failed for ${target}: ${String(error)}. The retained wait remains available for inspection and retry.` }] };
|
|
4010
4023
|
}
|
|
4011
4024
|
return (acceptanceStopTool.execute as (
|
|
4012
4025
|
id: string, p: unknown, s?: AbortSignal, u?: unknown, c?: unknown,
|
|
@@ -4100,10 +4113,36 @@ export default function (pi: ExtensionAPI) {
|
|
|
4100
4113
|
if (typeof pi.registerCommand === "function") {
|
|
4101
4114
|
agentOperations.registerCommands(pi);
|
|
4102
4115
|
pi.registerCommand("subagents", {
|
|
4103
|
-
description: "[settings|mode manual|adaptive|coordinator|cap <number>|tool-wait <minutes>|stuck <minutes>|save|reset] — Subagent
|
|
4116
|
+
description: "[history [dismiss]|settings|mode manual|adaptive|coordinator|cap <number>|tool-wait <minutes>|stuck <minutes>|save|reset] — Subagent management",
|
|
4104
4117
|
getArgumentCompletions: subagentsArgumentCompletions,
|
|
4105
4118
|
async handler(args, ctx) {
|
|
4106
4119
|
const tokens = args.trim().split(/\s+/).filter(Boolean);
|
|
4120
|
+
if (tokens[0] === "history") {
|
|
4121
|
+
try {
|
|
4122
|
+
const origin = { cwd: ctx.cwd, sessionId: ctx.sessionManager.getSessionId() };
|
|
4123
|
+
const waits = historicalWaits(origin);
|
|
4124
|
+
if (tokens[1] === "dismiss") {
|
|
4125
|
+
dismissAttention(ctx.cwd, attentionRevision(waits));
|
|
4126
|
+
ctx.ui.notify("Historical attention notice dismissed. Waits and evidence are unchanged.", "info");
|
|
4127
|
+
return;
|
|
4128
|
+
}
|
|
4129
|
+
const labels = waits.map((p) => `${p.runId} · session ${p.record.ownerSessionId ?? "unknown"} · ${p.phase}`);
|
|
4130
|
+
const selected = await ctx.ui.select("Historical subagent waits", labels);
|
|
4131
|
+
const park = waits[labels.indexOf(selected ?? "")];
|
|
4132
|
+
if (!park) return;
|
|
4133
|
+
const action = await ctx.ui.select(`${park.runId} · session ${park.record.ownerSessionId ?? "unknown"}`, ["Inspect", "Cancel pending wait"]);
|
|
4134
|
+
if (action === "Inspect") {
|
|
4135
|
+
ctx.ui.notify(JSON.stringify({ runId: park.runId, originatingSession: park.record.ownerSessionId,
|
|
4136
|
+
workspace: park.record.ownerWorkspace, waitId: park.waitId, generation: park.generation,
|
|
4137
|
+
phase: park.phase, reason: park.record.heldReason, cancellation: park.record.cancelReason,
|
|
4138
|
+
resumedBy: park.record.resumedBy, log: park.meta.logPath }), "info");
|
|
4139
|
+
} else if (action === "Cancel pending wait" && await ctx.ui.confirm("Cancel pending wait?", `${park.runId} belongs to session ${park.record.ownerSessionId ?? "unknown"}. This does not prove its writer has stopped.`)) {
|
|
4140
|
+
if (!await cancelParkedForUi?.(park.runId, "explicit cancellation from historical management")) throw new Error("The pending wait changed; inspect it again.");
|
|
4141
|
+
ctx.ui.notify(`Durably cancelled the pending wait of ${park.runId}. Writer termination may remain unproven.`, "info");
|
|
4142
|
+
}
|
|
4143
|
+
} catch (error) { ctx.ui.notify(`Historical wait management failed: ${String(error)}. Inspect or retry with /subagents history.`, "warning"); }
|
|
4144
|
+
return;
|
|
4145
|
+
}
|
|
4107
4146
|
if (tokens.length === 0 || (tokens.length === 1 && tokens[0] === "settings")) {
|
|
4108
4147
|
await openSettings(ctx);
|
|
4109
4148
|
return;
|
|
@@ -4153,7 +4192,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
4153
4192
|
changeTiming(key, minutes);
|
|
4154
4193
|
ctx.ui.notify(`${tokens[0] === "tool-wait" ? "Tool-wait" : "No-progress"} alert: ${minutes} min (current session). Running subagents are unchanged.`, "info");
|
|
4155
4194
|
} else {
|
|
4156
|
-
ctx.ui.notify("Usage: /subagents [settings|mode manual|adaptive|coordinator|cap <number>|tool-wait <minutes>|stuck <minutes>|save|reset]", "warning");
|
|
4195
|
+
ctx.ui.notify("Usage: /subagents [history [dismiss]|settings|mode manual|adaptive|coordinator|cap <number>|tool-wait <minutes>|stuck <minutes>|save|reset]", "warning");
|
|
4157
4196
|
}
|
|
4158
4197
|
refreshBackgroundWorkNavigator(ctx);
|
|
4159
4198
|
},
|
package/navigator.mjs
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* with visible-width-aware truncation.
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
|
-
import { assignmentFor } from "./assignment-projection.mjs";
|
|
27
|
+
import { assignmentFor, createAssignmentProjector } from "./assignment-projection.mjs";
|
|
28
28
|
import {
|
|
29
29
|
formatNavigatorHealthFacts,
|
|
30
30
|
statusThemeColor,
|
|
@@ -190,8 +190,9 @@ export function pendingNavigatorPark(meta) {
|
|
|
190
190
|
|
|
191
191
|
export function buildNavigatorRows(metas, deps) {
|
|
192
192
|
const now = deps.now ?? Date.now();
|
|
193
|
+
const project = createAssignmentProjector();
|
|
193
194
|
return metas.map((m) => {
|
|
194
|
-
const assignment =
|
|
195
|
+
const assignment = project(m, deps.effectiveStatus(m));
|
|
195
196
|
const status = assignment.state;
|
|
196
197
|
const health = typeof deps.healthFor === "function" ? deps.healthFor(m) : undefined;
|
|
197
198
|
const effort = typeof deps.effortFor === "function" ? deps.effortFor(m) : (m.effort ?? m.modelEffort);
|
package/package.json
CHANGED
package/worker-waits.ts
CHANGED
|
@@ -1670,6 +1670,7 @@ export interface ResumeOrchestrationOptions {
|
|
|
1670
1670
|
/** Follow a cancelled generation to the attempt it already published. */
|
|
1671
1671
|
stopAttempt?: StopPublishedAttempt;
|
|
1672
1672
|
notify?(message: string, level: "info" | "warning"): void;
|
|
1673
|
+
notifyWhen?(meta: RunMeta): boolean;
|
|
1673
1674
|
now?: () => number;
|
|
1674
1675
|
}
|
|
1675
1676
|
|
|
@@ -1872,7 +1873,7 @@ export function createResumeOrchestration(options: ResumeOrchestrationOptions):
|
|
|
1872
1873
|
} catch { /* the park record still shows the hold */ }
|
|
1873
1874
|
if (park.meta.assignment) commitAssignmentTerminal({ ...park.meta, status: "failed", failureReason: reason }, true);
|
|
1874
1875
|
try {
|
|
1875
|
-
options.notify?.(`Subagent ${park.runId} wait ${park.waitId} is held: ${reason}`, "warning");
|
|
1876
|
+
if (!options.notifyWhen || options.notifyWhen(park.meta)) options.notify?.(`Subagent ${park.runId} wait ${park.waitId} is held: ${reason}`, "warning");
|
|
1876
1877
|
} catch { /* ignore UI failures */ }
|
|
1877
1878
|
return "held";
|
|
1878
1879
|
};
|
|
@@ -2117,7 +2118,8 @@ export async function cancelParkedWait(
|
|
|
2117
2118
|
const scope = backgroundScopeForMeta(park.meta, park.record);
|
|
2118
2119
|
const at = (options.now ?? Date.now)();
|
|
2119
2120
|
if (park.meta.assignment) {
|
|
2120
|
-
commitAssignmentTerminal({ ...park.meta, status: "killed" });
|
|
2121
|
+
const outcome = commitAssignmentTerminal({ ...park.meta, status: "killed" });
|
|
2122
|
+
if (outcome?.outcome !== "cancelled") throw new Error("The assignment already has a non-cancelled terminal outcome; cancellation was not committed.");
|
|
2121
2123
|
const cancellation = await stopPublishedAttempt(park, reason, options.stopAttempt, options.now);
|
|
2122
2124
|
updateParkRecord(park.runId, { phase: "cancelled", cancelReason: cancellation === "foreign" ? `${reason} (published writer termination remains unproven)` : reason, cancelledAt: at });
|
|
2123
2125
|
return;
|
|
@@ -2130,10 +2132,10 @@ export async function cancelParkedWait(
|
|
|
2130
2132
|
updateParkRecord(park.runId, {
|
|
2131
2133
|
phase: "held",
|
|
2132
2134
|
cancelReason: `${reason} (the durable cancellation failed: ${reasonOf(error)})`,
|
|
2133
|
-
cancelledAt: at,
|
|
2134
2135
|
});
|
|
2135
|
-
|
|
2136
|
+
throw new Error(`Durable cancellation failed: ${reasonOf(error)}`);
|
|
2136
2137
|
}
|
|
2138
|
+
if (view.phase !== "cancelled") throw new Error(`Durable cancellation was not confirmed (wait is ${view.phase}).`);
|
|
2137
2139
|
const settled = readParkRecord(park.runId);
|
|
2138
2140
|
if (settled?.phase === "cancelled" && settled.cancelReason) return;
|
|
2139
2141
|
const cancellation = await stopPublishedAttempt(park, reason, options.stopAttempt, options.now);
|
|
@@ -2148,14 +2150,7 @@ export async function cancelParkedWait(
|
|
|
2148
2150
|
});
|
|
2149
2151
|
return;
|
|
2150
2152
|
}
|
|
2151
|
-
|
|
2152
|
-
updateParkRecord(park.runId, {
|
|
2153
|
-
phase: "cancelled",
|
|
2154
|
-
cancelReason: cancellation === "foreign"
|
|
2155
|
-
? `${reason} (the published continuation could not be attributed to this parent and was left running)`
|
|
2156
|
-
: reason,
|
|
2157
|
-
cancelledAt: at,
|
|
2158
|
-
});
|
|
2153
|
+
throw new Error("Durable cancellation unavailable: the original worker scope and observed-waits service are required.");
|
|
2159
2154
|
}
|
|
2160
2155
|
|
|
2161
2156
|
/**
|
|
@@ -2493,17 +2488,22 @@ export async function settleResumedAttemptExit(input: ResumedAttemptExitInput):
|
|
|
2493
2488
|
|
|
2494
2489
|
export async function reconcileParkedWaits(
|
|
2495
2490
|
service: WorkerOperationService | undefined,
|
|
2496
|
-
|
|
2491
|
+
outerOptions: {
|
|
2497
2492
|
resume(park: ParkedWait): Promise<"resumed" | "held" | "skipped">;
|
|
2498
2493
|
notify?(message: string, level: "warning"): void;
|
|
2494
|
+
notifyWhen?(meta: RunMeta): boolean;
|
|
2499
2495
|
},
|
|
2500
2496
|
): Promise<{ resumed: number; held: number; skipped: number }> {
|
|
2501
2497
|
let resumed = 0;
|
|
2502
2498
|
let held = 0;
|
|
2503
2499
|
let skipped = 0;
|
|
2500
|
+
const options = outerOptions;
|
|
2501
|
+
const scopedOptions = (meta: RunMeta) => ({ ...outerOptions,
|
|
2502
|
+
notify: outerOptions.notifyWhen && !outerOptions.notifyWhen(meta) ? undefined : outerOptions.notify });
|
|
2504
2503
|
if (service?.outageReconciliation === 1) {
|
|
2505
2504
|
try {
|
|
2506
2505
|
for (const report of pendingObservations()) {
|
|
2506
|
+
const options = scopedOptions(report.meta);
|
|
2507
2507
|
try {
|
|
2508
2508
|
const scope = backgroundScopeForMeta(report.meta, report.record);
|
|
2509
2509
|
if (!scope) continue;
|
|
@@ -2569,6 +2569,7 @@ export async function reconcileParkedWaits(
|
|
|
2569
2569
|
}
|
|
2570
2570
|
}
|
|
2571
2571
|
for (const park of parkedWaits()) {
|
|
2572
|
+
const options = scopedOptions(park.meta);
|
|
2572
2573
|
try {
|
|
2573
2574
|
if (park.record.phase === "resuming") {
|
|
2574
2575
|
const attemptId = park.record.resumedBy ?? "";
|