pi-subagents 0.89.1 → 0.90.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/bundle/agents.js +4 -4
- package/bundle/child-tool-plan.js +3 -3
- package/bundle/{chunk-SG3NCWZW.js → chunk-2LEBXCLU.js} +29 -19
- package/bundle/{chunk-UUW7P6KJ.js → chunk-37EJGDYO.js} +2 -2
- package/bundle/{chunk-IGZTXGPG.js → chunk-4DA22WRU.js} +59 -30
- package/bundle/{chunk-77VQEATI.js → chunk-5J2RTMKW.js} +2 -2
- package/bundle/{chunk-7J4ZXMY7.js → chunk-72334PEI.js} +6 -4
- package/bundle/{chunk-F6PTAPQ3.js → chunk-7HPZIT4W.js} +13 -13
- package/bundle/{chunk-SWGB2P5J.js → chunk-7Y4IJMCW.js} +1 -1
- package/bundle/{chunk-TRN65L4F.js → chunk-ACTHBJUI.js} +1 -1
- package/bundle/{chunk-6D54VW3E.js → chunk-AJWRYQPH.js} +145 -76
- package/bundle/{chunk-TXC7WIPL.js → chunk-C45WQQZX.js} +1 -1
- package/bundle/{chunk-YJIU5WF4.js → chunk-CPWZN5KM.js} +1 -1
- package/bundle/{chunk-BERAWSQQ.js → chunk-DNJ2GHSI.js} +7 -7
- package/bundle/{chunk-CASL47ST.js → chunk-EBGTTJKP.js} +6 -6
- package/bundle/{chunk-LWH7IGI3.js → chunk-F4NSLXB2.js} +8 -6
- package/bundle/{chunk-URKQZHVH.js → chunk-G43SW4BT.js} +29 -19
- package/bundle/{chunk-Q4VH72JI.js → chunk-KNVQTRSY.js} +2 -2
- package/bundle/{chunk-5TXWZB73.js → chunk-P2M6RIVX.js} +1 -1
- package/bundle/{chunk-ROJH7KPK.js → chunk-PSB3VLMH.js} +2 -2
- package/bundle/{chunk-VEEUXJDO.js → chunk-PTN7XAXI.js} +2 -2
- package/bundle/{chunk-TDXVQPZW.js → chunk-RIBMW6V3.js} +69 -15
- package/bundle/{chunk-KCDPTXHT.js → chunk-SIB2GQHL.js} +238 -200
- package/bundle/{chunk-JEZOSEWG.js → chunk-SRWJIAIP.js} +2 -0
- package/bundle/{chunk-OUM6SEVD.js → chunk-UC22RDXP.js} +8 -4
- package/bundle/{chunk-W2BZS6UC.js → chunk-VMJGZHUL.js} +9 -5
- package/bundle/{chunk-MIX3MCIF.js → chunk-WANQBKAZ.js} +12 -7
- package/bundle/{chunk-LUNVS6KP.js → chunk-WHHRG32M.js} +27 -20
- package/bundle/{chunk-C22YEYFZ.js → chunk-XIQKWTFY.js} +5 -5
- package/bundle/{chunk-YLU5JFW2.js → chunk-XYIVVS3A.js} +7 -3
- package/bundle/{chunk-R3NH5XAL.js → chunk-YVDKGAEO.js} +5 -4
- package/bundle/{chunk-4FFKVLBG.js → chunk-ZWGOHOGI.js} +5 -5
- package/bundle/control-channel.js +3 -3
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +3 -3
- package/bundle/preflight.js +13 -11
- package/bundle/project-panes.js +5 -5
- package/bundle/shared-types.js +1 -1
- package/bundle/workflow-resources.js +1 -1
- package/docs/configuration.md +12 -3
- package/docs/models.md +1 -1
- package/docs/observability.md +10 -2
- package/docs/tool-reference.md +5 -2
- package/docs/watchdog.md +3 -2
- package/docs/workflows.md +1 -1
- package/package.json +1 -1
- package/skills/pi-subagents/SKILL.md +1 -1
- package/src/agents/agents.d.ts +2 -0
- package/src/agents/agents.js +4 -0
- package/src/api/preflight.d.ts +1 -0
- package/src/api/preflight.js +2 -1
- package/src/extension/config.js +3 -0
- package/src/extension/public-execution.js +4 -2
- package/src/extension/reply-workflow-script.js +10 -1
- package/src/extension/schemas.d.ts +1 -0
- package/src/extension/schemas.js +2 -0
- package/src/extension/subagent-options.d.ts +2 -0
- package/src/extension/subagent-options.js +10 -4
- package/src/inspectors/herdr/project-panes.d.ts +2 -0
- package/src/inspectors/herdr/project-panes.js +7 -1
- package/src/inspectors/shell-command.d.ts +2 -1
- package/src/inspectors/shell-command.js +7 -5
- package/src/runs/background/active-async-capacity.js +2 -1
- package/src/runs/background/active-run-index.d.ts +1 -0
- package/src/runs/background/active-run-index.js +3 -0
- package/src/runs/background/async-execution.d.ts +2 -0
- package/src/runs/background/async-execution.js +6 -3
- package/src/runs/background/async-retention.js +48 -12
- package/src/runs/background/async-status.js +32 -17
- package/src/runs/background/process-terminal.d.ts +6 -0
- package/src/runs/background/process-terminal.js +34 -2
- package/src/runs/background/retained-children.js +1 -1
- package/src/runs/background/run-status.js +2 -1
- package/src/runs/background/stale-run-reconciler.d.ts +8 -0
- package/src/runs/background/stale-run-reconciler.js +38 -8
- package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
- package/src/runs/background/workflow-terminal-proof.js +4 -4
- package/src/runs/foreground/execution.js +7 -9
- package/src/runs/foreground/subagent-executor.d.ts +2 -0
- package/src/runs/foreground/subagent-executor.js +129 -45
- package/src/runs/shared/fast-mode-extension.d.ts +2 -1
- package/src/runs/shared/fast-mode-extension.js +5 -3
- package/src/runs/shared/herdr-pane-host.js +10 -2
- package/src/runs/shared/mcp-config-sources.d.ts +1 -0
- package/src/runs/shared/mcp-config-sources.js +1 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.js +1 -0
- package/src/shared/capacity-resilient-json.d.ts +7 -3
- package/src/shared/capacity-resilient-json.js +8 -6
- package/src/shared/disabled-features.d.ts +4 -0
- package/src/shared/disabled-features.js +1 -0
- package/src/shared/types.d.ts +19 -0
- package/src/shared/types.js +2 -0
- package/src/tui/fleet-transcript.js +21 -9
- package/src/tui/fleet.js +1 -0
- package/src/watchdog/runtime.d.ts +4 -0
- package/src/watchdog/runtime.js +50 -12
- package/src/watchdog/turn-delta.d.ts +2 -0
- package/src/watchdog/turn-delta.js +21 -0
- package/src/workflows/structured-workflow-scripts.js +6 -4
- package/src/workflows/workflow-resources.js +4 -2
- package/src/workflows/workflow-revival.d.ts +6 -0
- package/src/workflows/workflow-revival.js +1 -1
|
@@ -7,7 +7,7 @@ import { Worker } from "node:worker_threads";
|
|
|
7
7
|
import { writeAtomicJson } from "../../shared/atomic-json.js";
|
|
8
8
|
import { readMissionBinding } from "../../missions/lifecycle.js";
|
|
9
9
|
import { MissionNotFoundError, readMission } from "../../missions/store.js";
|
|
10
|
-
import { REVIVAL_ORIGIN_FILE } from "../../workflows/workflow-revival.js";
|
|
10
|
+
import { projectWorkflowKeyRevival, REVIVAL_LINK_FILE, REVIVAL_ORIGIN_FILE } from "../../workflows/workflow-revival.js";
|
|
11
11
|
import { ACTIVE_RUN_INDEX_DIR } from "./active-run-index.js";
|
|
12
12
|
import { encodeIndexSegment } from "./index-segment.js";
|
|
13
13
|
import { reconcileAsyncRun } from "./stale-run-reconciler.js";
|
|
@@ -149,6 +149,50 @@ function missionReferenceBlocksReclaim(runDir, resultsDir, runId) {
|
|
|
149
149
|
return !(error instanceof MissionNotFoundError);
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
|
+
// A run is kept by its own state: live, waited on, recent, resumable, or unreadable. A missing run keeps nothing.
|
|
153
|
+
function runKept(input, runId) {
|
|
154
|
+
const runDir = path.join(input.asyncDirRoot, runId);
|
|
155
|
+
if (!fs.existsSync(runDir))
|
|
156
|
+
return false;
|
|
157
|
+
const status = readStatus(runDir);
|
|
158
|
+
if (status?.runId !== runId || !TERMINAL_STATES.has(status.state))
|
|
159
|
+
return true;
|
|
160
|
+
if (input.protectedRunIds.has(runId) || input.waitRunIds.has(runId) || activeMarkerExists(input.asyncDirRoot, runId))
|
|
161
|
+
return true;
|
|
162
|
+
const timestamp = statusTimestamp(status, runDir);
|
|
163
|
+
return timestamp === undefined || timestamp > input.cutoff || (timestamp > input.resumableCutoff && hasResumableContract(runDir, status));
|
|
164
|
+
}
|
|
165
|
+
// A workflow, its children and their revivals are reclaimed together: each is kept while any of them is.
|
|
166
|
+
function workflowTreeKept(input, workflow) {
|
|
167
|
+
return (workflow.steps ?? []).some((step) => {
|
|
168
|
+
if (!step.runId || !validRunId(step.runId))
|
|
169
|
+
return false;
|
|
170
|
+
const revived = step.workflowKey ? projectWorkflowKeyRevival(input.asyncDirRoot, workflow.runId, step.workflowKey, step.runId)?.revivedRunIds ?? [] : [];
|
|
171
|
+
const chain = [step.runId, ...revived];
|
|
172
|
+
// The chain ends at a link it could not follow when that link file is still there.
|
|
173
|
+
return fs.existsSync(path.join(input.asyncDirRoot, chain.at(-1), REVIVAL_LINK_FILE)) || chain.some((runId) => runKept(input, runId));
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
// Only the workflow checks its tree; its children wait for its folder to go, then are judged on their own.
|
|
177
|
+
// An invalid workflow id names no folder to wait for, so it keeps them too.
|
|
178
|
+
function workflowKeepsChildren(asyncDirRoot, workflowRunId) {
|
|
179
|
+
return !validRunId(workflowRunId) || fs.existsSync(path.join(asyncDirRoot, workflowRunId));
|
|
180
|
+
}
|
|
181
|
+
function workflowReferenceBlocksReclaim(input, runDir, status) {
|
|
182
|
+
if (status.mode === "workflow" && workflowTreeKept(input, status))
|
|
183
|
+
return true;
|
|
184
|
+
let workflowRunId = status.parentWorkflowRunId;
|
|
185
|
+
// A revived workflow child is a link in its key's revival chain and belongs to that workflow.
|
|
186
|
+
if (fs.existsSync(path.join(runDir, REVIVAL_ORIGIN_FILE))) {
|
|
187
|
+
const origin = readJson(path.join(runDir, REVIVAL_ORIGIN_FILE));
|
|
188
|
+
if (typeof origin?.workflowRunId !== "string")
|
|
189
|
+
return true;
|
|
190
|
+
workflowRunId = origin.workflowRunId;
|
|
191
|
+
}
|
|
192
|
+
if (workflowRunId === undefined)
|
|
193
|
+
return status.workflowKey !== undefined;
|
|
194
|
+
return workflowKeepsChildren(input.asyncDirRoot, workflowRunId);
|
|
195
|
+
}
|
|
152
196
|
function runTombstoneMarkerPath(maintenanceRoot, runId) {
|
|
153
197
|
return path.join(maintenanceRoot, RUN_TOMBSTONE_MARKERS_DIR, `${encodeIndexSegment(runId)}.json`);
|
|
154
198
|
}
|
|
@@ -234,10 +278,7 @@ function runSkipReason(input) {
|
|
|
234
278
|
return "active-index";
|
|
235
279
|
if (!TERMINAL_STATES.has(status.state))
|
|
236
280
|
return "non-terminal";
|
|
237
|
-
if (
|
|
238
|
-
return "workflow-reference";
|
|
239
|
-
// A revived workflow child is a link in its key's revival chain; deleting it would cut off later revivals.
|
|
240
|
-
if (fs.existsSync(path.join(runDir, REVIVAL_ORIGIN_FILE)))
|
|
281
|
+
if (workflowReferenceBlocksReclaim(input, runDir, status))
|
|
241
282
|
return "workflow-reference";
|
|
242
283
|
if (hasNestedReferences(status))
|
|
243
284
|
return "nested-reference";
|
|
@@ -450,11 +491,6 @@ function hasUnresolvedResultHandoff(data) {
|
|
|
450
491
|
const manifestPath = data.parallelHandoff.path;
|
|
451
492
|
return typeof manifestPath !== "string" || !manifestPath || unresolvedHandoff(manifestPath);
|
|
452
493
|
}
|
|
453
|
-
function completionMode(data) {
|
|
454
|
-
return data.completion && typeof data.completion === "object" && !Array.isArray(data.completion)
|
|
455
|
-
? data.completion.mode
|
|
456
|
-
: undefined;
|
|
457
|
-
}
|
|
458
494
|
function resultSkipReason(input) {
|
|
459
495
|
if (!input.data)
|
|
460
496
|
return "invalid-result";
|
|
@@ -473,7 +509,8 @@ function resultSkipReason(input) {
|
|
|
473
509
|
return "run-present";
|
|
474
510
|
if (missionObserverIndexExists(input.resultsDir, runId))
|
|
475
511
|
return "mission-reference";
|
|
476
|
-
|
|
512
|
+
// The run dir is gone here, so a workflow's own result is an orphan; a child's result waits for its workflow's folder.
|
|
513
|
+
if (typeof input.data.parentWorkflowRunId === "string" ? workflowKeepsChildren(input.asyncDirRoot, input.data.parentWorkflowRunId) : typeof input.data.workflowKey === "string")
|
|
477
514
|
return "workflow-reference";
|
|
478
515
|
if (hasUnresolvedResultHandoff(input.data))
|
|
479
516
|
return "handoff-reference";
|
|
@@ -833,7 +870,6 @@ export async function cleanupAsyncRetention(options) {
|
|
|
833
870
|
continue;
|
|
834
871
|
}
|
|
835
872
|
fs.rmSync(tombstone, { recursive: true });
|
|
836
|
-
// Retention never deletes a workflow run, so this removes only a single run's recovery descriptor.
|
|
837
873
|
fs.rmSync(runLaunchDir(options.asyncDirRoot, status.runId), { recursive: true, force: true });
|
|
838
874
|
removeRunTombstoneMarker(maintenanceRoot, status.runId);
|
|
839
875
|
result.deletedRuns += 1;
|
|
@@ -170,7 +170,7 @@ function deriveAsyncActivityState(asyncDir, status) {
|
|
|
170
170
|
?? (status.mode === "workflow" ? undefined : currentStep?.startedAt ?? status.startedAt),
|
|
171
171
|
};
|
|
172
172
|
}
|
|
173
|
-
function statusToSummary(asyncDir, status, nestedWarnings = []
|
|
173
|
+
function statusToSummary(asyncDir, status, nestedWarnings = []) {
|
|
174
174
|
const statusPath = path.join(asyncDir, "status.json");
|
|
175
175
|
validateAsyncStatusLaneMetadata(status, `Invalid async status '${statusPath}'`);
|
|
176
176
|
const workflowChildren = parseWorkflowChildSummary(status.workflowChildren);
|
|
@@ -188,7 +188,6 @@ function statusToSummary(asyncDir, status, nestedWarnings = [], nestedRoute) {
|
|
|
188
188
|
const { activityState, lastActivityAt } = deriveAsyncActivityState(asyncDir, status);
|
|
189
189
|
const processTerminal = readProcessTerminal(asyncDir, { runId: status.runId, runnerProcessInstanceId: status.processTerminal?.runnerProcessInstanceId })
|
|
190
190
|
?? sanitizeProcessTerminal(status.processTerminal, { runId: status.runId, runnerProcessInstanceId: status.processTerminal?.runnerProcessInstanceId }, path.join(asyncDir, "status.json"));
|
|
191
|
-
const nestedProjectionAllowed = nestedWarnings.length === 0;
|
|
192
191
|
// Degrade to the status-stored snapshot when the persisted budget is unavailable (e.g. removed
|
|
193
192
|
// by OS temp cleanup) instead of failing the whole run list; admission paths stay strict.
|
|
194
193
|
let runFanoutBudget = status.runFanoutBudget;
|
|
@@ -203,17 +202,6 @@ function statusToSummary(asyncDir, status, nestedWarnings = [], nestedRoute) {
|
|
|
203
202
|
const steps = status.steps ?? [];
|
|
204
203
|
const chainStepCount = status.chainStepCount ?? steps.length;
|
|
205
204
|
const parallelGroups = normalizeParallelGroups(status.parallelGroups, steps.length, chainStepCount);
|
|
206
|
-
let nestedChildren = [];
|
|
207
|
-
if (nestedProjectionAllowed && nestedRoute) {
|
|
208
|
-
try {
|
|
209
|
-
// The route is resolved by the caller via buildNestedRouteIndex, so this
|
|
210
|
-
// avoids a fresh scan of the nested-events directory per run.
|
|
211
|
-
nestedChildren = projectNestedEvents(nestedRoute)?.children ?? [];
|
|
212
|
-
}
|
|
213
|
-
catch (error) {
|
|
214
|
-
nestedWarnings.push(`Nested status unavailable: ${getErrorMessage(error)}`);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
205
|
const summarizedSteps = steps.map((step, index) => {
|
|
218
206
|
const stepActivityState = step.activityState;
|
|
219
207
|
const stepLastActivityAt = step.lastActivityAt;
|
|
@@ -289,7 +277,7 @@ function statusToSummary(asyncDir, status, nestedWarnings = [], nestedRoute) {
|
|
|
289
277
|
...(step.children?.length ? { children: step.children } : {}),
|
|
290
278
|
};
|
|
291
279
|
});
|
|
292
|
-
attachRootChildrenToSteps(status.runId || path.basename(asyncDir), summarizedSteps,
|
|
280
|
+
attachRootChildrenToSteps(status.runId || path.basename(asyncDir), summarizedSteps, undefined);
|
|
293
281
|
return {
|
|
294
282
|
id: status.runId || path.basename(asyncDir),
|
|
295
283
|
asyncDir,
|
|
@@ -326,7 +314,6 @@ function statusToSummary(asyncDir, status, nestedWarnings = [], nestedRoute) {
|
|
|
326
314
|
...(hostSteps.length ? { hostSteps } : {}),
|
|
327
315
|
...(status.mode === "workflow" && status.workflowGraph ? { workflowGraph: status.workflowGraph } : {}),
|
|
328
316
|
steps: summarizedSteps,
|
|
329
|
-
...(nestedChildren.length ? { nestedChildren } : {}),
|
|
330
317
|
...(nestedWarnings.length ? { nestedWarnings } : {}),
|
|
331
318
|
...(processTerminal ? { processTerminal } : {}),
|
|
332
319
|
...(runFanoutBudget ? { runFanoutBudget } : {}),
|
|
@@ -352,6 +339,24 @@ function statusToSummary(asyncDir, status, nestedWarnings = [], nestedRoute) {
|
|
|
352
339
|
export function summarizeAsyncStatus(asyncDir, status) {
|
|
353
340
|
return statusToSummary(asyncDir, status);
|
|
354
341
|
}
|
|
342
|
+
/** Projects nested children onto summaries built without them. It never reconciles descendants. */
|
|
343
|
+
function attachNestedChildren(runs, resolveRoute = (run) => findNestedRouteForRootId(run.id)) {
|
|
344
|
+
for (const run of runs) {
|
|
345
|
+
let nestedChildren;
|
|
346
|
+
try {
|
|
347
|
+
const route = resolveRoute(run);
|
|
348
|
+
nestedChildren = route ? projectNestedEvents(route).children : [];
|
|
349
|
+
}
|
|
350
|
+
catch (error) {
|
|
351
|
+
run.nestedWarnings = [...(run.nestedWarnings ?? []), `Nested status unavailable: ${getErrorMessage(error)}`];
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
if (!nestedChildren.length)
|
|
355
|
+
continue;
|
|
356
|
+
run.nestedChildren = nestedChildren;
|
|
357
|
+
attachRootChildrenToSteps(run.id, run.steps, nestedChildren);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
355
360
|
function sortRuns(runs) {
|
|
356
361
|
const rank = (state) => {
|
|
357
362
|
switch (state) {
|
|
@@ -433,6 +438,7 @@ export function listAsyncRuns(asyncDirRoot, options = {}, observeStatus) {
|
|
|
433
438
|
// load-time restoration (which only wants queued/running runs) skips it
|
|
434
439
|
// entirely when no active runs match.
|
|
435
440
|
let nestedRouteIndex;
|
|
441
|
+
const reconciledRoutes = new Map();
|
|
436
442
|
const resolveNestedRoute = (rootRunId) => {
|
|
437
443
|
if (!includeNested)
|
|
438
444
|
return undefined;
|
|
@@ -505,11 +511,13 @@ export function listAsyncRuns(asyncDirRoot, options = {}, observeStatus) {
|
|
|
505
511
|
catch (error) {
|
|
506
512
|
observeStatus?.(null);
|
|
507
513
|
nestedWarnings.push(`Nested status unavailable: ${getErrorMessage(error)}`);
|
|
514
|
+
// Children that failed to reconcile are not projected.
|
|
515
|
+
nestedRoute = undefined;
|
|
508
516
|
}
|
|
509
517
|
}
|
|
510
518
|
let summary;
|
|
511
519
|
try {
|
|
512
|
-
summary = statusToSummary(asyncDir, status, nestedWarnings
|
|
520
|
+
summary = statusToSummary(asyncDir, status, nestedWarnings);
|
|
513
521
|
}
|
|
514
522
|
catch (error) {
|
|
515
523
|
observeStatus?.(null);
|
|
@@ -519,9 +527,16 @@ export function listAsyncRuns(asyncDirRoot, options = {}, observeStatus) {
|
|
|
519
527
|
continue;
|
|
520
528
|
}
|
|
521
529
|
runs.push(summary);
|
|
530
|
+
if (nestedRoute)
|
|
531
|
+
reconciledRoutes.set(summary, nestedRoute);
|
|
522
532
|
}
|
|
523
533
|
const sorted = sortRuns(runs);
|
|
524
|
-
|
|
534
|
+
const listed = options.limit !== undefined ? sorted.slice(0, options.limit) : sorted;
|
|
535
|
+
// Project nested children only for the runs returned. A non-reconciling read
|
|
536
|
+
// (FleetView polls one) looks up each run's own route-index directory.
|
|
537
|
+
if (includeNested)
|
|
538
|
+
attachNestedChildren(listed, options.reconcile === false ? undefined : (run) => reconciledRoutes.get(run));
|
|
539
|
+
return listed;
|
|
525
540
|
}
|
|
526
541
|
function formatActivityFacts(input) {
|
|
527
542
|
const facts = [];
|
|
@@ -8,6 +8,12 @@ export interface RunnerCloseObservation {
|
|
|
8
8
|
signal: string | null;
|
|
9
9
|
}
|
|
10
10
|
export declare function processTerminalPath(asyncDir: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* A status reader's verdict that a finished run's runner died with no Pi watching it. It is a separate file so a
|
|
13
|
+
* reader can never overwrite the proof the launching Pi writes when it does see the close; it shows only while
|
|
14
|
+
* process-terminal.json is still pending for the same runner.
|
|
15
|
+
*/
|
|
16
|
+
export declare function unobservedRunnerExitPath(asyncDir: string): string;
|
|
11
17
|
/** Establish ownership before authorizing a runner to start any child session. */
|
|
12
18
|
export declare function initializeProcessTerminal(asyncDir: string, runId: string, runnerProcessInstanceId: string): void;
|
|
13
19
|
export declare function sanitizeProcessTerminal(value: unknown, fallback: {
|
|
@@ -9,6 +9,14 @@ export { processTerminalCandidatePath, readProcessTerminalCandidate, writeProces
|
|
|
9
9
|
export function processTerminalPath(asyncDir) {
|
|
10
10
|
return path.join(asyncDir, "process-terminal.json");
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* A status reader's verdict that a finished run's runner died with no Pi watching it. It is a separate file so a
|
|
14
|
+
* reader can never overwrite the proof the launching Pi writes when it does see the close; it shows only while
|
|
15
|
+
* process-terminal.json is still pending for the same runner.
|
|
16
|
+
*/
|
|
17
|
+
export function unobservedRunnerExitPath(asyncDir) {
|
|
18
|
+
return path.join(asyncDir, "process-terminal-unobserved.json");
|
|
19
|
+
}
|
|
12
20
|
function errorMessage(error) {
|
|
13
21
|
return error instanceof Error ? error.message : String(error);
|
|
14
22
|
}
|
|
@@ -84,11 +92,33 @@ export function sanitizeProcessTerminal(value, fallback, label = "status") {
|
|
|
84
92
|
return unknownProof(fallback.runId ?? label, fallback.runnerProcessInstanceId ?? "unknown", "proof-write-failed", errorMessage(error));
|
|
85
93
|
}
|
|
86
94
|
}
|
|
95
|
+
/** Throws for an unreadable or invalid file, like the sidecar it stands in for. */
|
|
96
|
+
function readUnobservedRunnerExit(asyncDir, pending) {
|
|
97
|
+
const filePath = unobservedRunnerExitPath(asyncDir);
|
|
98
|
+
let raw;
|
|
99
|
+
try {
|
|
100
|
+
raw = JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
if (error.code === "ENOENT")
|
|
104
|
+
return undefined;
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
// Left behind by an earlier runner instance of this run.
|
|
108
|
+
if (isRecord(raw) && (raw.runId !== pending.runId || raw.runnerProcessInstanceId !== pending.runnerProcessInstanceId))
|
|
109
|
+
return undefined;
|
|
110
|
+
validateProof(raw, filePath);
|
|
111
|
+
const proof = raw;
|
|
112
|
+
if (proof.state !== "unknown" || proof.reason !== "observer-unavailable")
|
|
113
|
+
throw new Error(`Invalid unobserved runner exit in '${asyncDir}'.`);
|
|
114
|
+
return proof;
|
|
115
|
+
}
|
|
87
116
|
export function readProcessTerminal(asyncDir, fallback) {
|
|
88
117
|
try {
|
|
89
118
|
const raw = JSON.parse(fs.readFileSync(processTerminalPath(asyncDir), "utf-8"));
|
|
90
119
|
validateProof(raw, asyncDir, fallback);
|
|
91
|
-
|
|
120
|
+
const proof = raw;
|
|
121
|
+
return proof.state === "pending" ? readUnobservedRunnerExit(asyncDir, proof) ?? proof : proof;
|
|
92
122
|
}
|
|
93
123
|
catch (error) {
|
|
94
124
|
if (error.code === "ENOENT")
|
|
@@ -136,7 +166,9 @@ export function finalizeProcessTerminal(asyncDir, runId, runnerClose) {
|
|
|
136
166
|
if (existing && fs.existsSync(processTerminalPath(asyncDir))) {
|
|
137
167
|
if (existing.state === "observed" && existing.runId === runId && existing.runnerProcessInstanceId === runnerClose.processInstanceId)
|
|
138
168
|
return existing;
|
|
139
|
-
|
|
169
|
+
// A status reader that saw the runner pid dead before this close event fired settled the proof as
|
|
170
|
+
// observer-unavailable; this process did observe the close, so it computes the full proof.
|
|
171
|
+
if (existing.state === "unknown" && existing.reason !== "observer-unavailable") {
|
|
140
172
|
// A sticky runner-published unknown proof keeps its reason; only add the observed exit. Unreadable or mismatched sidecars read back as proof-write-failed and stay untouched.
|
|
141
173
|
if (existing.instances?.length || existing.reason === "proof-write-failed")
|
|
142
174
|
return existing;
|
|
@@ -69,7 +69,7 @@ function boundedTaskSummary(value) {
|
|
|
69
69
|
: normalized;
|
|
70
70
|
}
|
|
71
71
|
export function listRetainedChildren(asyncDirRoot, sessionId) {
|
|
72
|
-
const children = listAsyncRuns(asyncDirRoot, { sessionId, states: ["complete", "failed", "paused", "stopped"], entryLimit: MAX_RETAINED_CHILD_CANDIDATES, reconcile: false })
|
|
72
|
+
const children = listAsyncRuns(asyncDirRoot, { sessionId, states: ["complete", "failed", "paused", "stopped"], entryLimit: MAX_RETAINED_CHILD_CANDIDATES, reconcile: false, includeNested: false })
|
|
73
73
|
.flatMap((run) => {
|
|
74
74
|
if (!run.parentWorkflowRunId || run.steps.length !== 1)
|
|
75
75
|
return [];
|
|
@@ -14,7 +14,7 @@ import { readStatus } from "../../shared/utils.js";
|
|
|
14
14
|
import { resolveSubagentIntercomTarget } from "../../intercom/intercom-bridge.js";
|
|
15
15
|
import { normalizeExternalCliRunnerStatus } from "../shared/external-cli-contract.js";
|
|
16
16
|
import { resolveSubagentResultStatus } from "../../intercom/result-intercom.js";
|
|
17
|
-
import { readProcessTerminal, sanitizeProcessTerminal } from "./process-terminal.js";
|
|
17
|
+
import { readProcessTerminal, sanitizeProcessTerminal, unobservedRunnerExitPath } from "./process-terminal.js";
|
|
18
18
|
import { readWorkflowTerminalProof } from "./workflow-terminal-proof.js";
|
|
19
19
|
import { formatWaitSubscriptions } from "./wait-subscriptions.js";
|
|
20
20
|
import { resolveAsyncRunLocation } from "./async-resume.js";
|
|
@@ -89,6 +89,7 @@ function formatRunLifecycleDebug(input) {
|
|
|
89
89
|
`Status file: ${path.join(asyncDir, "status.json")}`,
|
|
90
90
|
status.workflowReceiptPath ? `Workflow receipt: ${status.workflowReceiptPath}` : undefined,
|
|
91
91
|
`Process terminal file: ${path.join(asyncDir, "process-terminal.json")}`,
|
|
92
|
+
`Unobserved runner exit file: ${unobservedRunnerExitPath(asyncDir)}`,
|
|
92
93
|
`Session: ${status.sessionId ?? "unknown"}`,
|
|
93
94
|
`State: ${status.state}`,
|
|
94
95
|
`Mode: ${status.mode}`,
|
|
@@ -58,5 +58,13 @@ export interface RecordedPidObservation {
|
|
|
58
58
|
* macOS host reading a Linux container's runs must not compare their boot ids.
|
|
59
59
|
*/
|
|
60
60
|
export declare function checkRecordedPidLiveness(recorded: RecordedPid, observation?: RecordedPidObservation): PidLiveness;
|
|
61
|
+
/**
|
|
62
|
+
* Only the Pi process that spawned a runner sees it close and writes its process-terminal proof. When that
|
|
63
|
+
* process is gone, a finished run whose runner is confirmed dead would report a `pending` proof forever.
|
|
64
|
+
* Record it as unknown, never observed: nobody saw the exit. A workflow's pid is its host Pi, not a runner.
|
|
65
|
+
* The verdict goes to its own file, never process-terminal.json, so a close the launching Pi observes after the
|
|
66
|
+
* pending read above still wins.
|
|
67
|
+
*/
|
|
68
|
+
export declare function settleUnobservedRunnerExit(asyncDir: string, status: AsyncStatus, observation?: RecordedPidObservation): void;
|
|
61
69
|
export declare function reconcileAsyncRun(asyncDir: string, options?: ReconcileAsyncRunOptions, observeStatus?: RawDrainStatusObserver): ReconcileAsyncRunResult;
|
|
62
70
|
export {};
|
|
@@ -2,8 +2,8 @@ import * as fs from "node:fs";
|
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import { writeAtomicJson } from "../../shared/atomic-json.js";
|
|
4
4
|
import { resultFilePath, resultPayloadPathForSessionRun, writeAsyncResultFile } from "./result-files.js";
|
|
5
|
-
import { updateActiveRunIndex } from "./active-run-index.js";
|
|
6
|
-
import { readProcessTerminal } from "./process-terminal.js";
|
|
5
|
+
import { isTerminalAsyncState, updateActiveRunIndex } from "./active-run-index.js";
|
|
6
|
+
import { readProcessTerminal, unobservedRunnerExitPath } from "./process-terminal.js";
|
|
7
7
|
import { OWNING_SESSION_COMPLETION_OWNER } from "../../shared/completion-owner.js";
|
|
8
8
|
import { readStatus } from "../../shared/utils.js";
|
|
9
9
|
import { DIRS } from "../../shared/types.js";
|
|
@@ -14,7 +14,6 @@ import { assertWorkflowGraphHostSteps } from "../shared/host-step-status.js";
|
|
|
14
14
|
import { currentPidNamespaceScope } from "./pid-namespace.js";
|
|
15
15
|
import { currentBootId } from "./boot-id.js";
|
|
16
16
|
import { WORKFLOW_STOP_CAUSE_OWNER_EXITED } from "../../workflows/workflow-stop-cause.js";
|
|
17
|
-
import { isTerminalAsyncState } from "./workflow-terminal-proof.js";
|
|
18
17
|
function getErrorMessage(error) {
|
|
19
18
|
return error instanceof Error ? error.message : String(error);
|
|
20
19
|
}
|
|
@@ -427,6 +426,38 @@ export function checkRecordedPidLiveness(recorded, observation = { observedScope
|
|
|
427
426
|
: checkPidLiveness(recorded.pid, observation.kill, scopeVerified);
|
|
428
427
|
return liveness === "dead" && scopeMismatch ? "unknown" : liveness;
|
|
429
428
|
}
|
|
429
|
+
/**
|
|
430
|
+
* Only the Pi process that spawned a runner sees it close and writes its process-terminal proof. When that
|
|
431
|
+
* process is gone, a finished run whose runner is confirmed dead would report a `pending` proof forever.
|
|
432
|
+
* Record it as unknown, never observed: nobody saw the exit. A workflow's pid is its host Pi, not a runner.
|
|
433
|
+
* The verdict goes to its own file, never process-terminal.json, so a close the launching Pi observes after the
|
|
434
|
+
* pending read above still wins.
|
|
435
|
+
*/
|
|
436
|
+
export function settleUnobservedRunnerExit(asyncDir, status, observation = { observedScope: currentPidNamespaceScope(), observedBootId: currentBootId() }) {
|
|
437
|
+
const runnerProcessInstanceId = status.processTerminal?.runnerProcessInstanceId;
|
|
438
|
+
if (!terminal(status.state) || status.mode === "workflow" || status.processTerminal?.state !== "pending" || !runnerProcessInstanceId)
|
|
439
|
+
return;
|
|
440
|
+
if (typeof status.pid !== "number" || status.pidNamespaceScope !== observation.observedScope)
|
|
441
|
+
return;
|
|
442
|
+
if (readProcessTerminal(asyncDir, { runId: status.runId, runnerProcessInstanceId })?.state !== "pending")
|
|
443
|
+
return;
|
|
444
|
+
if (checkRecordedPidLiveness({ pid: status.pid, pidNamespaceScope: status.pidNamespaceScope, bootId: status.bootId }, observation) !== "dead")
|
|
445
|
+
return;
|
|
446
|
+
try {
|
|
447
|
+
const proof = {
|
|
448
|
+
version: 1,
|
|
449
|
+
state: "unknown",
|
|
450
|
+
runId: status.runId,
|
|
451
|
+
runnerProcessInstanceId,
|
|
452
|
+
reason: "observer-unavailable",
|
|
453
|
+
diagnostic: `Runner PID ${status.pid} is gone and no Pi recorded its exit.`,
|
|
454
|
+
};
|
|
455
|
+
writeAtomicJson(unobservedRunnerExitPath(asyncDir), proof);
|
|
456
|
+
}
|
|
457
|
+
catch {
|
|
458
|
+
// The proof stays pending; the next status read tries again.
|
|
459
|
+
}
|
|
460
|
+
}
|
|
430
461
|
export function reconcileAsyncRun(asyncDir, options = {}, observeStatus) {
|
|
431
462
|
const now = options.now?.() ?? Date.now();
|
|
432
463
|
const status = readStatus(asyncDir);
|
|
@@ -453,11 +484,10 @@ export function reconcileAsyncRun(asyncDir, options = {}, observeStatus) {
|
|
|
453
484
|
const staleAfterMs = options.staleAlivePidMs ?? 24 * 60 * 60 * 1000;
|
|
454
485
|
const lastUpdate = effectiveStatus.lastUpdate ?? effectiveStatus.startedAt;
|
|
455
486
|
const observedScope = options.pidNamespaceScope ? options.pidNamespaceScope() : currentPidNamespaceScope();
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
});
|
|
487
|
+
const observation = { kill: options.kill, observedScope, observedBootId: options.bootId ? options.bootId() : currentBootId() };
|
|
488
|
+
const runnerLiveness = (pid) => checkRecordedPidLiveness({ pid, pidNamespaceScope: effectiveStatus.pidNamespaceScope, bootId: effectiveStatus.bootId }, observation);
|
|
489
|
+
if (status)
|
|
490
|
+
settleUnobservedRunnerExit(asyncDir, status, observation);
|
|
461
491
|
if (existingResultPath) {
|
|
462
492
|
// A live runner writes its result before its final status; repairing in that window would replace
|
|
463
493
|
// its pending exit proof with a placeholder. Only a confirmed-alive pid defers: a result is better
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AsyncStatus, ProcessTerminal, WorkflowChildSummary, WorkflowTerminalProof } from "../../shared/types.ts";
|
|
2
|
-
export declare function isTerminalAsyncState(state: AsyncStatus["state"]): state is Exclude<AsyncStatus["state"], "queued" | "running" | "paused">;
|
|
3
2
|
/**
|
|
4
3
|
* The model an async workflow child reports for itself. Workflow lane records keep only
|
|
5
4
|
* launch identity, so display projections fall back to the child's own status step.
|
|
@@ -2,10 +2,9 @@ import * as fs from "node:fs";
|
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import { readStatus } from "../../shared/utils.js";
|
|
4
4
|
import { readProcessTerminal } from "./process-terminal.js";
|
|
5
|
+
import { isTerminalAsyncState } from "./active-run-index.js";
|
|
6
|
+
import { settleUnobservedRunnerExit } from "./stale-run-reconciler.js";
|
|
5
7
|
const TERMINAL_WORKFLOW_STATES = new Set(["completed", "failed", "stopped"]);
|
|
6
|
-
export function isTerminalAsyncState(state) {
|
|
7
|
-
return state !== "queued" && state !== "running" && state !== "paused";
|
|
8
|
-
}
|
|
9
8
|
/**
|
|
10
9
|
* The model an async workflow child reports for itself. Workflow lane records keep only
|
|
11
10
|
* launch identity, so display projections fall back to the child's own status step.
|
|
@@ -83,13 +82,14 @@ export function readWorkflowChildEvidence(workflowAsyncDir, step) {
|
|
|
83
82
|
if (recorded.state === "not-started" && recorded.runId === step.runId && typeof childStatus.error === "string" && childStatus.error) {
|
|
84
83
|
return { state: "resolved", proof: recorded };
|
|
85
84
|
}
|
|
85
|
+
settleUnobservedRunnerExit(childDir, childStatus);
|
|
86
86
|
const proof = readProcessTerminal(childDir, { runId: step.runId, runnerProcessInstanceId: recorded.runnerProcessInstanceId });
|
|
87
87
|
if (proof?.state !== "observed" || proof.runId !== step.runId) {
|
|
88
88
|
const proofState = proof?.state ?? "missing";
|
|
89
89
|
const bound = childStatus.runId === step.runId && typeof recorded.runnerProcessInstanceId === "string";
|
|
90
90
|
return {
|
|
91
91
|
state: !proof || proof.state === "pending" ? "pending" : "unknown",
|
|
92
|
-
reason: `async workflow child ${label} process-terminal proof is ${proofState}`,
|
|
92
|
+
reason: `async workflow child ${label} process-terminal proof is ${proofState}${proof?.state === "unknown" && proof.reason ? ` (${proof.reason})` : ""}`,
|
|
93
93
|
...(bound ? { unresolvedProof: { status: childStatus, proofState } } : {}),
|
|
94
94
|
};
|
|
95
95
|
}
|
|
@@ -248,8 +248,8 @@ function isCompleteUsageCounter(value) {
|
|
|
248
248
|
return typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
249
249
|
}
|
|
250
250
|
const STOPPED_BEFORE_COMPLETION_ERROR = "Subagent stopped before completion.";
|
|
251
|
-
|
|
252
|
-
const
|
|
251
|
+
// Kept off the result so the object returned in tool details stays plain JSON.
|
|
252
|
+
const attemptRecoveryState = new WeakMap();
|
|
253
253
|
async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared) {
|
|
254
254
|
const effectiveThinking = options.thinkingOverride ?? agent.thinking;
|
|
255
255
|
const modelArg = applyThinkingSuffix(model, effectiveThinking, options.thinkingOverride !== undefined);
|
|
@@ -259,7 +259,7 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
259
259
|
// Display name for the child session: applied inside the child through its
|
|
260
260
|
// runtime config and echoed back on the result payload so hosts can label
|
|
261
261
|
// this run without reading the child's session file.
|
|
262
|
-
const childSessionName = deriveChildSessionName({ agent: agent.name, task: shared.originalTask ?? task });
|
|
262
|
+
const childSessionName = deriveChildSessionName({ agent: agent.name, task: shared.originalTask ?? task, label: options.label });
|
|
263
263
|
const watchdogConfig = resolveWatchdogConfig(options.cwd ?? runtimeCwd);
|
|
264
264
|
const childWatchdog = watchdogConfig.ok
|
|
265
265
|
? resolveChildWatchdogConfig({
|
|
@@ -1480,9 +1480,7 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1480
1480
|
result.exitCode = exitCode;
|
|
1481
1481
|
result.providerDiagnostics = clearProviderRetry(result.providerDiagnostics);
|
|
1482
1482
|
progress.providerDiagnostics = result.providerDiagnostics;
|
|
1483
|
-
|
|
1484
|
-
result[AFTER_COMPACTION_SETTLEMENT] = true;
|
|
1485
|
-
result[REMAINING_TIMEOUT_MS] = remainingTimeoutMs;
|
|
1483
|
+
attemptRecoveryState.set(result, { afterCompactionSettlement, remainingTimeoutMs });
|
|
1486
1484
|
if (interruptedByControl) {
|
|
1487
1485
|
result.exitCode = 0;
|
|
1488
1486
|
result.interrupted = true;
|
|
@@ -1695,7 +1693,7 @@ async function runSyncCompletionInner(runtimeCwd, agents, agentName, task, optio
|
|
|
1695
1693
|
...options,
|
|
1696
1694
|
capabilityCeiling: intersectSubagentCapabilityCeilings(options.capabilityCeiling ?? resolveCurrentSubagentCapabilityCeiling(options.parentSessionId), options.childRuntime?.capabilityCeiling),
|
|
1697
1695
|
};
|
|
1698
|
-
const childSessionName = deriveChildSessionName({ agent: agentName, task });
|
|
1696
|
+
const childSessionName = deriveChildSessionName({ agent: agentName, task, label: options.label });
|
|
1699
1697
|
const agent = agents.find((a) => a.name === agentName);
|
|
1700
1698
|
if (!agent) {
|
|
1701
1699
|
const diagnosticContext = options.unknownAgentDiagnosticContext
|
|
@@ -1955,12 +1953,12 @@ async function runSyncCompletionInner(runtimeCwd, agents, agentName, task, optio
|
|
|
1955
1953
|
structuredOutputFailed: attemptResult.structuredOutputFailed,
|
|
1956
1954
|
acceptanceFailed: false,
|
|
1957
1955
|
currentTool: attemptResult.progress?.currentTool,
|
|
1958
|
-
afterCompactionSettlement: attemptResult
|
|
1956
|
+
afterCompactionSettlement: attemptRecoveryState.get(attemptResult)?.afterCompactionSettlement,
|
|
1959
1957
|
});
|
|
1960
1958
|
if (recovery.action === "resume") {
|
|
1961
1959
|
recoveryPrompt = recovery.prompt;
|
|
1962
1960
|
// The retry gets the budget the first attempt left, so that attempt's supervisor waits stay uncounted.
|
|
1963
|
-
const remainingMs = attemptResult
|
|
1961
|
+
const remainingMs = attemptRecoveryState.get(attemptResult)?.remainingTimeoutMs;
|
|
1964
1962
|
if (remainingMs !== undefined)
|
|
1965
1963
|
attemptOptions.deadlineAt = Date.now() + remainingMs;
|
|
1966
1964
|
attemptNotes.push("[abort-recovery] compaction abort after useful progress; resuming the retained child session once on the same model.");
|
|
@@ -79,6 +79,8 @@ export interface SubagentParamsLike {
|
|
|
79
79
|
/** Internal workflow ownership metadata; not part of the public schema. */
|
|
80
80
|
workflowParentRunId?: string;
|
|
81
81
|
workflowKey?: string;
|
|
82
|
+
/** Top-level `label` or a workflow child's `runs.run` label; names the child's own session instead of a task excerpt. */
|
|
83
|
+
label?: string;
|
|
82
84
|
lane?: import("../../shared/types.ts").WorkflowLaneMetadata;
|
|
83
85
|
/** Set by the scheduler so this run's completion can name the schedule that produced it. */
|
|
84
86
|
scheduleOrigin?: ScheduleOrigin;
|