pi-subagents 0.83.1 → 0.85.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 +79 -0
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/{chunk-5YIITCPD.js → chunk-3UZ5FVVJ.js} +322 -110
- package/bundle/{chunk-F4ASL6OV.js → chunk-7MAE3DJV.js} +1 -1
- package/bundle/{chunk-YXFJVCOL.js → chunk-CS4O36CZ.js} +11 -156
- package/bundle/{chunk-AHIFYGR3.js → chunk-DV2NCNPR.js} +22 -11
- package/bundle/{chunk-G2Z6ZH26.js → chunk-GCSLVFCX.js} +1 -1
- package/bundle/{chunk-2S4K53MV.js → chunk-H2NLFTC5.js} +1 -1
- package/bundle/{chunk-MABL3FUM.js → chunk-HFTBF7SG.js} +2 -1
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-UFL7IYCW.js → chunk-IQIWF2VX.js} +190 -1177
- package/bundle/{chunk-NPIYWVOD.js → chunk-JNXT3MPI.js} +15 -6
- package/bundle/{chunk-C7JMPU5F.js → chunk-JO67XSKD.js} +59 -27
- package/bundle/{chunk-UUP372DR.js → chunk-JWYG26RE.js} +223 -93
- package/bundle/{chunk-C5P5CHYK.js → chunk-KDMFBYFM.js} +1 -1
- package/bundle/{chunk-V2BZYLEP.js → chunk-KEY3UQMQ.js} +7 -2
- package/bundle/{chunk-VLFZIN6D.js → chunk-KZ34KQQH.js} +9 -6
- package/bundle/{chunk-ZVOAMTUQ.js → chunk-L2ENOFVZ.js} +76 -58
- package/bundle/{chunk-RNIZLSEA.js → chunk-LGMILZNE.js} +323 -18
- package/bundle/{chunk-UYK5MZWE.js → chunk-LTPH2DXH.js} +247 -153
- package/bundle/{chunk-2D52JFLF.js → chunk-N7B2KD74.js} +41 -117
- package/bundle/{chunk-IPGZMQXV.js → chunk-O7CPL6H4.js} +183 -28
- package/bundle/{chunk-D3JAFGMO.js → chunk-PHZP3KHB.js} +1 -1
- package/bundle/{chunk-2DHZTCOL.js → chunk-PVIVCDG2.js} +2 -2
- package/bundle/{chunk-LFDBD4PW.js → chunk-QO75KJBT.js} +2 -2
- package/bundle/{chunk-SSG7IEP5.js → chunk-RQAUNAWG.js} +2 -2
- package/bundle/{chunk-QP5ZWNIS.js → chunk-RV5OGHLO.js} +6 -3
- package/bundle/chunk-T5V5BRCL.js +1067 -0
- package/bundle/{chunk-LNRJCP2Y.js → chunk-UX4SCV5N.js} +337 -207
- package/bundle/{chunk-F5DBXJ2G.js → chunk-WOVMHDES.js} +234 -182
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +8 -8
- package/bundle/project-panes.js +3 -3
- package/docs/agents.md +17 -2
- package/docs/configuration.md +2 -2
- package/docs/extension-api.md +16 -1
- package/docs/workflows.md +30 -2
- package/package.json +1 -1
- package/src/agents/agent-management.js +27 -11
- package/src/agents/agent-memory.d.ts +1 -4
- package/src/agents/agent-memory.js +1 -4
- package/src/agents/agents.d.ts +1 -3
- package/src/agents/agents.js +7 -6
- package/src/agents/frontmatter.js +1 -8
- package/src/agents/global-npm-root.d.ts +1 -0
- package/src/agents/global-npm-root.js +11 -3
- package/src/agents/skills.d.ts +0 -3
- package/src/agents/skills.js +0 -3
- package/src/extension/config.js +7 -1
- package/src/extension/herdr-pi-bridge.js +10 -2
- package/src/extension/index.d.ts +0 -13
- package/src/extension/index.js +43 -32
- package/src/extension/public-execution.d.ts +1 -0
- package/src/extension/public-execution.js +4 -0
- package/src/extension/reply-workflow-script.js +24 -4
- package/src/extension/schemas.d.ts +8 -3
- package/src/extension/schemas.js +5 -3
- package/src/extension/session-switch.d.ts +25 -0
- package/src/extension/session-switch.js +138 -0
- package/src/extension/subagent-guide.d.ts +1 -1
- package/src/extension/subagent-guide.js +1 -1
- package/src/extension/subagent-launch-tool.d.ts +25 -0
- package/src/extension/subagent-launch-tool.js +48 -0
- package/src/extension/tool-activation.js +25 -11
- package/src/extension/tool-description.js +6 -0
- package/src/inspectors/herdr/actions.d.ts +0 -1
- package/src/inspectors/herdr/actions.js +0 -1
- package/src/inspectors/session-roots-codec.d.ts +0 -1
- package/src/inspectors/session-roots-codec.js +0 -1
- package/src/inspectors/tmux/actions.d.ts +0 -1
- package/src/inspectors/tmux/actions.js +0 -1
- package/src/integrations/herdr-status.js +3 -8
- package/src/intercom/native-supervisor-channel.js +65 -9
- package/src/runs/background/async-execution.d.ts +8 -9
- package/src/runs/background/async-execution.js +77 -27
- package/src/runs/background/async-job-tracker.js +12 -0
- package/src/runs/background/async-resume.d.ts +2 -1
- package/src/runs/background/async-resume.js +112 -39
- package/src/runs/background/async-retention.d.ts +1 -0
- package/src/runs/background/async-retention.js +22 -11
- package/src/runs/background/auto-drain.js +2 -1
- package/src/runs/background/boot-id.d.ts +1 -3
- package/src/runs/background/boot-id.js +1 -3
- package/src/runs/background/completion-batcher.d.ts +3 -4
- package/src/runs/background/completion-batcher.js +2 -3
- package/src/runs/background/control-channel.d.ts +0 -6
- package/src/runs/background/control-channel.js +0 -6
- package/src/runs/background/fleet-view.js +2 -3
- package/src/runs/background/notify.d.ts +0 -2
- package/src/runs/background/notify.js +0 -2
- package/src/runs/background/result-watcher.d.ts +1 -0
- package/src/runs/background/result-watcher.js +59 -29
- package/src/runs/background/resume-guidance.js +4 -2
- package/src/runs/background/retained-children.js +2 -1
- package/src/runs/background/run-child-session.d.ts +2 -1
- package/src/runs/background/run-child-session.js +10 -2
- package/src/runs/background/run-status.js +4 -3
- package/src/runs/background/scheduled-runs.d.ts +3 -1
- package/src/runs/background/scheduled-runs.js +13 -16
- package/src/runs/background/subagent-runner.d.ts +2 -4
- package/src/runs/background/subagent-runner.js +10 -6
- package/src/runs/background/subagent-wait.js +12 -15
- package/src/runs/background/wait-config.d.ts +2 -0
- package/src/runs/background/wait-config.js +17 -3
- package/src/runs/background/wait-tool.js +4 -2
- package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
- package/src/runs/background/workflow-terminal-proof.js +0 -1
- package/src/runs/foreground/execution.d.ts +0 -3
- package/src/runs/foreground/execution.js +17 -9
- package/src/runs/foreground/subagent-executor.d.ts +3 -2
- package/src/runs/foreground/subagent-executor.js +112 -26
- package/src/runs/shared/child-commands.js +15 -2
- package/src/runs/shared/child-hooks.d.ts +1 -7
- package/src/runs/shared/child-hooks.js +13 -5
- package/src/runs/shared/child-launch.js +6 -2
- package/src/runs/shared/child-runtime-config.d.ts +0 -1
- package/src/runs/shared/child-session.d.ts +3 -1
- package/src/runs/shared/child-session.js +22 -2
- package/src/runs/shared/child-tool-plan.d.ts +0 -1
- package/src/runs/shared/child-tool-plan.js +0 -1
- package/src/runs/shared/claude-code-adapter.js +11 -0
- package/src/runs/shared/external-cli-runner.js +26 -6
- package/src/runs/shared/herdr-connection.js +2 -1
- package/src/runs/shared/herdr-pane-host.d.ts +2 -2
- package/src/runs/shared/herdr-pane-host.js +17 -1
- package/src/runs/shared/herdr-placed-run.js +48 -22
- package/src/runs/shared/lane-metadata.d.ts +0 -1
- package/src/runs/shared/lane-metadata.js +0 -1
- package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
- package/src/runs/shared/model-resolution-diagnostic.d.ts +11 -1
- package/src/runs/shared/model-resolution-diagnostic.js +25 -0
- package/src/runs/shared/model-resolution.d.ts +2 -2
- package/src/runs/shared/model-resolution.js +7 -1
- package/src/runs/shared/model-scope.d.ts +1 -5
- package/src/runs/shared/model-scope.js +1 -5
- package/src/runs/shared/mutation-evidence.d.ts +1 -1
- package/src/runs/shared/mutation-evidence.js +52 -7
- package/src/runs/shared/nested-events.d.ts +1 -0
- package/src/runs/shared/nested-events.js +1 -1
- package/src/runs/shared/parallel-utils.d.ts +2 -1
- package/src/runs/shared/permissions.js +5 -3
- package/src/runs/shared/placement-host.d.ts +5 -1
- package/src/runs/shared/rex-pane-host.d.ts +0 -1
- package/src/runs/shared/rex-pane-host.js +0 -2
- package/src/runs/shared/run-launch-folder.d.ts +12 -0
- package/src/runs/shared/run-launch-folder.js +21 -0
- package/src/runs/shared/runner-launcher.d.ts +12 -1
- package/src/runs/shared/runner-launcher.js +16 -0
- package/src/runs/shared/single-output.d.ts +3 -3
- package/src/runs/shared/single-output.js +5 -3
- package/src/runs/shared/structured-output.d.ts +8 -0
- package/src/runs/shared/structured-output.js +30 -2
- package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
- package/src/runs/shared/subagent-prompt-runtime.js +4 -2
- package/src/runs/shared/tool-timeout.js +2 -1
- package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
- package/src/runs/shared/worktree-cleanup-plan.js +0 -1
- package/src/runs/shared/worktree.d.ts +3 -0
- package/src/runs/shared/worktree.js +20 -0
- package/src/shared/capacity-resilient-json.d.ts +1 -1
- package/src/shared/child-cache-retention.d.ts +1 -2
- package/src/shared/child-cache-retention.js +1 -2
- package/src/shared/fleet-transcript-reader.d.ts +51 -0
- package/src/shared/fleet-transcript-reader.js +333 -0
- package/src/shared/formatters.d.ts +0 -18
- package/src/shared/formatters.js +0 -18
- package/src/shared/session-succession.d.ts +16 -1
- package/src/shared/session-succession.js +41 -2
- package/src/shared/session-warnings.d.ts +7 -0
- package/src/shared/session-warnings.js +26 -0
- package/src/shared/settings.d.ts +0 -23
- package/src/shared/settings.js +3 -35
- package/src/shared/types.d.ts +28 -11
- package/src/shared/types.js +0 -12
- package/src/shared/utils.d.ts +0 -14
- package/src/shared/utils.js +0 -22
- package/src/shared/wait-tool-name.d.ts +8 -0
- package/src/shared/wait-tool-name.js +13 -0
- package/src/slash/slash-commands.js +2 -1
- package/src/slash/subagent-cost.d.ts +3 -2
- package/src/slash/subagent-cost.js +22 -3
- package/src/slash/subagents-admin.js +0 -1
- package/src/tui/fleet-status.d.ts +0 -5
- package/src/tui/fleet-status.js +4 -24
- package/src/tui/fleet-transcript.d.ts +1 -44
- package/src/tui/fleet-transcript.js +1 -327
- package/src/tui/fleet.js +6 -4
- package/src/tui/render.d.ts +0 -9
- package/src/tui/render.js +81 -47
- package/src/tui/subagent-messages.js +3 -2
- package/src/watchdog/register-child.d.ts +2 -3
- package/src/watchdog/register-child.js +2 -3
- package/src/watchdog/turn-delta.js +2 -1
- package/src/workflows/scripted-workflow.js +243 -20
- package/src/workflows/workflow-launch-record.d.ts +15 -6
- package/src/workflows/workflow-launch-record.js +30 -12
- package/src/workflows/workflow-resume-claim.js +2 -2
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +11 -8
- package/src/workflows/workflow-script-worker.d.ts +13 -0
- package/src/workflows/workflow-script-worker.js +79 -0
- package/workflow-script-process.cjs +36 -0
- package/workflow-script-worker.cjs +453 -176
|
@@ -13,11 +13,13 @@ import { reconcileAsyncRun } from "./stale-run-reconciler.js";
|
|
|
13
13
|
import { resultFilePath, resultPayloadPathForIndexedRun } from "./result-files.js";
|
|
14
14
|
import { canScanAsyncRunPrefix, MIN_SAFE_ASYNC_RUN_PREFIX_LENGTH } from "./run-id-query.js";
|
|
15
15
|
import { parallelHandoffPath, resolveRetainedWorktreeCwd } from "../shared/parallel-handoff.js";
|
|
16
|
-
import { normalizeWorktreeBaseRef } from "../shared/worktree.js";
|
|
16
|
+
import { findListedWorktreeAgentCwd, findListedWorktreeOnBranch, isComparablePathInside, normalizeWorktreeBaseRef } from "../shared/worktree.js";
|
|
17
17
|
import { intersectThinkingCeilings, parseThinkingLevel } from "../../shared/thinking-ceiling.js";
|
|
18
18
|
import { assertWorkflowGraphHostSteps } from "../shared/host-step-status.js";
|
|
19
19
|
import { validateIntercomBridgeConfig } from "../../intercom/intercom-bridge.js";
|
|
20
20
|
import { validateModelResponseAliases } from "../../shared/model-response-aliases.js";
|
|
21
|
+
import { readWorkflowLaunchRecord } from "../../workflows/workflow-launch-record.js";
|
|
22
|
+
import { recoveryDescriptorPath } from "../shared/run-launch-folder.js";
|
|
21
23
|
function getErrorMessage(error) {
|
|
22
24
|
return error instanceof Error ? error.message : String(error);
|
|
23
25
|
}
|
|
@@ -251,6 +253,7 @@ function normalizeRecoveryAcceptance(value, descriptorPath) {
|
|
|
251
253
|
throw new Error(`Invalid async recovery descriptor '${descriptorPath}': ${errors.join(" ")}`);
|
|
252
254
|
return value;
|
|
253
255
|
}
|
|
256
|
+
/** A workflow-mode target has a ceiling only when its parent-owned launch record exists (resolveAsyncResumeTarget). */
|
|
254
257
|
export function asyncReviveRequiresRecoveryDescriptor(target) {
|
|
255
258
|
if (target.recoveryDescriptor)
|
|
256
259
|
return false;
|
|
@@ -263,10 +266,8 @@ function resumeTargetMode(status, result) {
|
|
|
263
266
|
return result.mode;
|
|
264
267
|
return undefined;
|
|
265
268
|
}
|
|
266
|
-
export function readAsyncRecoveryDescriptor(
|
|
267
|
-
|
|
268
|
-
return undefined;
|
|
269
|
-
const descriptorPath = path.join(asyncDir, "recovery-descriptor.json");
|
|
269
|
+
export function readAsyncRecoveryDescriptor(runsRoot, runId) {
|
|
270
|
+
const descriptorPath = recoveryDescriptorPath(runsRoot, runId);
|
|
270
271
|
if (!fs.existsSync(descriptorPath))
|
|
271
272
|
return undefined;
|
|
272
273
|
let value;
|
|
@@ -284,7 +285,7 @@ export function readAsyncRecoveryDescriptor(asyncDir) {
|
|
|
284
285
|
"subagentOnlyExtensions", "mcpDirectTools", "excludeTools", "mutationTools", "systemPrompt", "systemPromptMode", "inheritProjectContext", "inheritGlobalContext", "inheritSkills", "skills",
|
|
285
286
|
"skillPath", "agentFilePath", "memory", "outputPath", "outputMode", "structuredOutputSchema", "acceptance", "sessionDir", "artifactConfig",
|
|
286
287
|
"artifactsDir", "maxOutput", "controlConfig", "context", "intercomBridge", "absoluteDeadlineAt", "initialTurnBudget", "initialToolBudget", "maxSubagentDepth", "share", "capabilityCeiling",
|
|
287
|
-
"launchResolvedExtensions", "runFanoutBudget", "lane", "baseRef", "launcher",
|
|
288
|
+
"launchResolvedExtensions", "runFanoutBudget", "lane", "baseRef", "launcher", "requiredLauncher", "sessionId", "managedWorktree",
|
|
288
289
|
"extensionBindings",
|
|
289
290
|
"requiredExtensions",
|
|
290
291
|
]);
|
|
@@ -299,8 +300,16 @@ export function readAsyncRecoveryDescriptor(asyncDir) {
|
|
|
299
300
|
}
|
|
300
301
|
if (parsed.version !== 1)
|
|
301
302
|
throw new Error(`Invalid async recovery descriptor '${descriptorPath}': version must be 1.`);
|
|
302
|
-
if (parsed.launcher !== undefined && (typeof parsed.launcher !== "string" || !RUNNER_LAUNCHER_NAME_PATTERN.test(parsed.launcher)))
|
|
303
|
-
throw new Error(`Invalid async recovery descriptor '${descriptorPath}': launcher must be a launcher name.`);
|
|
303
|
+
if (parsed.launcher !== undefined && parsed.launcher !== null && (typeof parsed.launcher !== "string" || !RUNNER_LAUNCHER_NAME_PATTERN.test(parsed.launcher)))
|
|
304
|
+
throw new Error(`Invalid async recovery descriptor '${descriptorPath}': launcher must be a launcher name or null.`);
|
|
305
|
+
if (parsed.requiredLauncher !== undefined) {
|
|
306
|
+
const required = parsed.requiredLauncher;
|
|
307
|
+
if (!required || typeof required !== "object" || Array.isArray(required) || Object.keys(required).some((key) => key !== "name" && key !== "definitionDigest")
|
|
308
|
+
|| typeof required.name !== "string" || !RUNNER_LAUNCHER_NAME_PATTERN.test(required.name)
|
|
309
|
+
|| typeof required.definitionDigest !== "string" || !/^[0-9a-f]{64}$/.test(required.definitionDigest)) {
|
|
310
|
+
throw new Error(`Invalid async recovery descriptor '${descriptorPath}': requiredLauncher must be { name, definitionDigest }.`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
304
313
|
try {
|
|
305
314
|
parsed.runFanoutBudget = validateRunFanoutBudgetDescriptor(parsed.runFanoutBudget);
|
|
306
315
|
}
|
|
@@ -372,7 +381,14 @@ export function readAsyncRecoveryDescriptor(asyncDir) {
|
|
|
372
381
|
}
|
|
373
382
|
if (parsed.systemPrompt !== undefined && typeof parsed.systemPrompt !== "string")
|
|
374
383
|
throw new Error(`Invalid async recovery descriptor '${descriptorPath}': systemPrompt must be a string.`);
|
|
375
|
-
|
|
384
|
+
if (parsed.managedWorktree !== undefined) {
|
|
385
|
+
const worktree = parsed.managedWorktree;
|
|
386
|
+
const valid = !!worktree && typeof worktree === "object" && !Array.isArray(worktree) && ((worktree.provider === "native" && typeof worktree.cwd === "string" && path.isAbsolute(worktree.cwd) && Object.keys(worktree).length === 2)
|
|
387
|
+
|| (worktree.provider === "worktrunk" && typeof worktree.branch === "string" && !!worktree.branch.trim() && Object.keys(worktree).length === 2));
|
|
388
|
+
if (!valid)
|
|
389
|
+
throw new Error(`Invalid async recovery descriptor '${descriptorPath}': managedWorktree is invalid.`);
|
|
390
|
+
}
|
|
391
|
+
for (const field of ["sessionId", "launchContractDigest", "sessionFile", "model", "modelProvider", "thinking", "agentFilePath", "outputPath", "sessionDir", "artifactsDir"]) {
|
|
376
392
|
if (parsed[field] !== undefined && (typeof parsed[field] !== "string" || !parsed[field].trim()))
|
|
377
393
|
throw new Error(`Invalid async recovery descriptor '${descriptorPath}': ${field} must be a non-empty string.`);
|
|
378
394
|
}
|
|
@@ -457,6 +473,27 @@ export function readAsyncRecoveryDescriptor(asyncDir) {
|
|
|
457
473
|
parsed.acceptance = normalizeRecoveryAcceptance(parsed.acceptance, descriptorPath);
|
|
458
474
|
return parsed;
|
|
459
475
|
}
|
|
476
|
+
/**
|
|
477
|
+
* handoff.json sits in the run directory, so its worktree cwd must be the one the launch chose: the
|
|
478
|
+
* native path the parent computed, or a worktree git itself lists on the requested Worktrunk branch.
|
|
479
|
+
*/
|
|
480
|
+
function assertLaunchedWorktreeCwd(runId, launchCwd, launched, handoffCwd) {
|
|
481
|
+
const listed = launched.provider === "native" ? undefined : findListedWorktreeOnBranch(launchCwd, launched.branch);
|
|
482
|
+
const matches = launched.provider === "native"
|
|
483
|
+
? isComparablePathInside(launched.cwd, handoffCwd) && isComparablePathInside(handoffCwd, launched.cwd)
|
|
484
|
+
: listed !== undefined && isComparablePathInside(listed, handoffCwd);
|
|
485
|
+
if (!matches)
|
|
486
|
+
throw new Error(`Async run '${runId}' managed worktree ${handoffCwd} is not the worktree its launch created.`);
|
|
487
|
+
return handoffCwd;
|
|
488
|
+
}
|
|
489
|
+
/** A run launched in a worktree resumes in it, never in the source checkout, even when handoff.json is missing. */
|
|
490
|
+
function launchedWorktreeCwdWithoutHandoff(runId, launchCwd, launched) {
|
|
491
|
+
const cwd = launched.provider === "native" ? launched.cwd : findListedWorktreeAgentCwd(launchCwd, launched.branch);
|
|
492
|
+
if (cwd === undefined || !fs.statSync(cwd, { throwIfNoEntry: false })?.isDirectory()) {
|
|
493
|
+
throw new Error(`Async run '${runId}' ran in a managed worktree (${launched.provider === "native" ? launched.cwd : `branch ${launched.branch}`}) that no longer exists; it cannot resume in the source checkout.`);
|
|
494
|
+
}
|
|
495
|
+
return cwd;
|
|
496
|
+
}
|
|
460
497
|
function validateResumeSessionFile(runId, sessionFile) {
|
|
461
498
|
if (path.extname(sessionFile) !== ".jsonl")
|
|
462
499
|
throw new Error(`Async run '${runId}' session file must be a .jsonl file: ${sessionFile}`);
|
|
@@ -487,20 +524,40 @@ export function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
|
|
|
487
524
|
const requested = params.id ?? params.runId;
|
|
488
525
|
throw new Error(requested ? `Async run not found for '${requested}'.` : "Async run not found. Provide id or dir.");
|
|
489
526
|
}
|
|
527
|
+
// A run directory is always named for its run, so a status file naming another run is refused, and
|
|
528
|
+
// before reconciling: its repair publishes a result under the status file's run id.
|
|
529
|
+
if (location.asyncDir) {
|
|
530
|
+
let recordedRunId;
|
|
531
|
+
try {
|
|
532
|
+
recordedRunId = JSON.parse(fs.readFileSync(path.join(location.asyncDir, "status.json"), "utf-8")).runId;
|
|
533
|
+
}
|
|
534
|
+
catch { /* missing or unreadable: validateStatusForResume reports it */ }
|
|
535
|
+
if (typeof recordedRunId === "string" && recordedRunId !== path.basename(location.asyncDir))
|
|
536
|
+
throw new Error(`Async run '${path.basename(location.asyncDir)}' has a status file for a different run '${recordedRunId}'.`);
|
|
537
|
+
}
|
|
490
538
|
const reconciliation = location.asyncDir
|
|
491
539
|
? reconcileAsyncRun(location.asyncDir, { resultsDir, kill: deps.kill, now: deps.now })
|
|
492
540
|
: undefined;
|
|
493
541
|
const status = reconciliation?.status ?? null;
|
|
494
542
|
validateStatusForResume(status, location.asyncDir ? path.join(location.asyncDir, "status.json") : "status.json");
|
|
495
|
-
|
|
543
|
+
// Records are trusted only for a run folder directly under the runs root: `dir` may name a
|
|
544
|
+
// runs-shaped tree a run built inside its own folder.
|
|
545
|
+
const directRunFolder = location.asyncDir !== null && path.dirname(location.asyncDir) === path.resolve(asyncDirRoot);
|
|
546
|
+
const recoveryDescriptor = directRunFolder ? readAsyncRecoveryDescriptor(asyncDirRoot, path.basename(location.asyncDir)) : undefined;
|
|
496
547
|
const result = location.resultPath ? readResultFile(location.resultPath) : undefined;
|
|
497
|
-
const runId =
|
|
498
|
-
|
|
499
|
-
|
|
548
|
+
const runId = location.asyncDir ? path.basename(location.asyncDir) : result?.runId ?? result?.id ?? location.resolvedId ?? "unknown";
|
|
549
|
+
// Only a single run writes a recovery descriptor. When one exists, the run's identity (agent,
|
|
550
|
+
// session, cwd, model, ceilings) comes from it alone: status.json and the shared results directory
|
|
551
|
+
// are writable by a run behind a runner launcher.
|
|
552
|
+
const mode = recoveryDescriptor ? "single" : resumeTargetMode(status, result);
|
|
553
|
+
const notOwned = recoveryDescriptor
|
|
554
|
+
? !ownsRun(options.sessionId, recoveryDescriptor.sessionId)
|
|
555
|
+
: (status && !ownsRun(options.sessionId, status.sessionId)) || (result && !ownsRun(options.sessionId, result.sessionId));
|
|
556
|
+
if (options.sessionId && notOwned) {
|
|
500
557
|
throw new Error(`Async run '${runId}' was not found in the active session.`);
|
|
501
558
|
}
|
|
502
559
|
if (recoveryDescriptor && recoveryDescriptor.sourceRunId !== runId)
|
|
503
|
-
throw new Error(`Async run '${runId}' has a recovery descriptor for a different source run.`);
|
|
560
|
+
throw new Error(`Async run '${runId}' has a recovery descriptor for a different source run '${recoveryDescriptor.sourceRunId}'.`);
|
|
504
561
|
const state = status?.state ?? (result ? resultState(result) : undefined);
|
|
505
562
|
if (!state)
|
|
506
563
|
throw new Error(`Status file not found for async run '${runId}'.`);
|
|
@@ -519,18 +576,18 @@ export function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
|
|
|
519
576
|
throw new Error(`Async run '${runId}' has ${stepCount} children. Index ${requestedIndex} is out of range.`);
|
|
520
577
|
const selectedStep = statusSteps[requestedIndex];
|
|
521
578
|
if (selectedStep?.status === "running") {
|
|
522
|
-
const capabilityCeiling = intersectSubagentCapabilityCeilings(status?.capabilityCeiling, selectedStep.capabilityCeiling);
|
|
579
|
+
const capabilityCeiling = recoveryDescriptor ? recoveryDescriptor.capabilityCeiling : intersectSubagentCapabilityCeilings(status?.capabilityCeiling, selectedStep.capabilityCeiling);
|
|
523
580
|
return {
|
|
524
581
|
kind: "live",
|
|
525
582
|
runId,
|
|
526
583
|
asyncDir: location.asyncDir ?? undefined,
|
|
527
584
|
state,
|
|
528
585
|
...(mode ? { mode } : {}),
|
|
529
|
-
agent: selectedStep.agent,
|
|
586
|
+
agent: recoveryDescriptor?.agent ?? selectedStep.agent,
|
|
530
587
|
...(selectedStep.sessionName ?? result?.results?.[requestedIndex]?.sessionName ? { sessionName: selectedStep.sessionName ?? result?.results?.[requestedIndex]?.sessionName } : {}),
|
|
531
588
|
index: requestedIndex,
|
|
532
589
|
cwd: status?.cwd ?? result?.cwd,
|
|
533
|
-
sessionFile: selectedStep.sessionFile ?? status?.sessionFile ?? result?.sessionFile,
|
|
590
|
+
sessionFile: recoveryDescriptor ? recoveryDescriptor.sessionFile : selectedStep.sessionFile ?? status?.sessionFile ?? result?.sessionFile,
|
|
534
591
|
model: selectedStep.model,
|
|
535
592
|
thinking: selectedStep.thinking,
|
|
536
593
|
launchContractDigest: selectedStep.launchContractDigest ?? result?.results?.[requestedIndex]?.launchContractDigest ?? result?.launchContractDigest ?? recoveryDescriptor?.launchContractDigest,
|
|
@@ -554,18 +611,18 @@ export function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
|
|
|
554
611
|
if (!selected) {
|
|
555
612
|
throw new Error(`Async run '${runId}' has ${running.length} running children. Provide index to choose one.`);
|
|
556
613
|
}
|
|
557
|
-
const capabilityCeiling = intersectSubagentCapabilityCeilings(status?.capabilityCeiling, selected.step.capabilityCeiling);
|
|
614
|
+
const capabilityCeiling = recoveryDescriptor ? recoveryDescriptor.capabilityCeiling : intersectSubagentCapabilityCeilings(status?.capabilityCeiling, selected.step.capabilityCeiling);
|
|
558
615
|
return {
|
|
559
616
|
kind: "live",
|
|
560
617
|
runId,
|
|
561
618
|
asyncDir: location.asyncDir ?? undefined,
|
|
562
619
|
state,
|
|
563
620
|
...(mode ? { mode } : {}),
|
|
564
|
-
agent: selected.step.agent,
|
|
621
|
+
agent: recoveryDescriptor?.agent ?? selected.step.agent,
|
|
565
622
|
...(selected.step.sessionName ?? result?.results?.[selected.index]?.sessionName ? { sessionName: selected.step.sessionName ?? result?.results?.[selected.index]?.sessionName } : {}),
|
|
566
623
|
index: selected.index,
|
|
567
624
|
cwd: status?.cwd ?? result?.cwd,
|
|
568
|
-
sessionFile: selected.step.sessionFile ?? status?.sessionFile ?? result?.sessionFile,
|
|
625
|
+
sessionFile: recoveryDescriptor ? recoveryDescriptor.sessionFile : selected.step.sessionFile ?? status?.sessionFile ?? result?.sessionFile,
|
|
569
626
|
model: selected.step.model,
|
|
570
627
|
thinking: selected.step.thinking,
|
|
571
628
|
launchContractDigest: selected.step.launchContractDigest ?? result?.results?.[selected.index]?.launchContractDigest ?? result?.launchContractDigest ?? recoveryDescriptor?.launchContractDigest,
|
|
@@ -589,27 +646,41 @@ export function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
|
|
|
589
646
|
if (selectedStatusStep?.status === "stopped" || selectedStatusStep?.stopped === true) {
|
|
590
647
|
throw new Error(`Async run '${runId}' child ${index} was stopped and cannot be resumed. Start a new run instead.`);
|
|
591
648
|
}
|
|
592
|
-
const agent = selectedStatusStep?.agent ?? resultSteps[index]?.agent ?? result?.agent;
|
|
649
|
+
const agent = recoveryDescriptor ? recoveryDescriptor.agent : selectedStatusStep?.agent ?? resultSteps[index]?.agent ?? result?.agent;
|
|
593
650
|
if (!agent)
|
|
594
651
|
throw new Error(`Could not determine child agent for async run '${runId}'.`);
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
652
|
+
const sessionFile = recoveryDescriptor
|
|
653
|
+
? recoveryDescriptor.sessionFile
|
|
654
|
+
: statusSteps[index]?.sessionFile
|
|
655
|
+
?? resultSteps[index]?.sessionFile
|
|
656
|
+
?? (stepCount === 1 ? status?.sessionFile ?? result?.sessionFile : undefined);
|
|
600
657
|
if (!sessionFile && requireSessionFile)
|
|
601
658
|
throw new Error(`Async run '${runId}' child ${index} does not have a persisted session file to resume from.`);
|
|
602
659
|
const resolvedSessionFile = sessionFile ? validateResumeSessionFile(runId, sessionFile) : undefined;
|
|
603
|
-
const stepModel = statusSteps[index]?.launchModel ?? statusSteps[index]?.model ?? resultSteps[index]?.model ?? (stepCount === 1 ? result?.model : undefined);
|
|
604
|
-
const stepThinking = statusSteps[index]?.thinking ?? resultSteps[index]?.thinking ?? (stepCount === 1 ? result?.thinking : undefined);
|
|
605
|
-
const thinkingCeiling =
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
660
|
+
const stepModel = recoveryDescriptor ? recoveryDescriptor.model : statusSteps[index]?.launchModel ?? statusSteps[index]?.model ?? resultSteps[index]?.model ?? (stepCount === 1 ? result?.model : undefined);
|
|
661
|
+
const stepThinking = recoveryDescriptor ? recoveryDescriptor.thinking : statusSteps[index]?.thinking ?? resultSteps[index]?.thinking ?? (stepCount === 1 ? result?.thinking : undefined);
|
|
662
|
+
const thinkingCeiling = recoveryDescriptor ? recoveryDescriptor.thinkingCeiling : statusSteps[index]?.thinkingCeiling;
|
|
663
|
+
// A workflow's admission ceiling comes only from the parent-owned launch record of its run directory:
|
|
664
|
+
// a run behind a launcher can write its own status.json (including a directory nested in it) and the
|
|
665
|
+
// shared results directory. Without a record there is no ceiling, so a revive without a recovery
|
|
666
|
+
// descriptor is refused.
|
|
667
|
+
const workflowLaunch = mode === "workflow" && directRunFolder
|
|
668
|
+
? readWorkflowLaunchRecord(asyncDirRoot, runId)
|
|
669
|
+
: undefined;
|
|
670
|
+
const capabilityCeiling = recoveryDescriptor
|
|
671
|
+
? recoveryDescriptor.capabilityCeiling
|
|
672
|
+
: mode === "workflow"
|
|
673
|
+
? (workflowLaunch?.ok ? workflowLaunch.record.admissionCapabilityCeiling : undefined)
|
|
674
|
+
: intersectSubagentCapabilityCeilings(status?.capabilityCeiling, statusSteps[index]?.capabilityCeiling, result?.capabilityCeiling, resultSteps[index]?.capabilityCeiling);
|
|
675
|
+
const handoffWorktreeCwd = location.asyncDir && (!recoveryDescriptor || recoveryDescriptor.managedWorktree)
|
|
610
676
|
? resolveRetainedWorktreeCwd(parallelHandoffPath(location.asyncDir), runId, index, statusSteps[index]?.worktreePath)
|
|
611
677
|
: undefined;
|
|
612
|
-
const
|
|
678
|
+
const managedWorktreeCwd = recoveryDescriptor?.managedWorktree
|
|
679
|
+
? handoffWorktreeCwd
|
|
680
|
+
? assertLaunchedWorktreeCwd(runId, recoveryDescriptor.cwd, recoveryDescriptor.managedWorktree, handoffWorktreeCwd)
|
|
681
|
+
: launchedWorktreeCwdWithoutHandoff(runId, recoveryDescriptor.cwd, recoveryDescriptor.managedWorktree)
|
|
682
|
+
: handoffWorktreeCwd;
|
|
683
|
+
const resumeCwd = validateResumeCwd(runId, managedWorktreeCwd ?? (recoveryDescriptor ? recoveryDescriptor.cwd : status?.cwd ?? result?.cwd));
|
|
613
684
|
return {
|
|
614
685
|
kind: "revive",
|
|
615
686
|
runId,
|
|
@@ -624,9 +695,10 @@ export function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
|
|
|
624
695
|
...(resolvedSessionFile ? { sessionFile: resolvedSessionFile } : {}),
|
|
625
696
|
...(stepModel ? { model: stepModel } : {}),
|
|
626
697
|
...(stepThinking ? { thinking: stepThinking } : {}),
|
|
627
|
-
launchContractDigest: statusSteps[index]?.launchContractDigest ?? resultSteps[index]?.launchContractDigest ?? result?.launchContractDigest
|
|
628
|
-
|
|
629
|
-
...(statusSteps[index]?.
|
|
698
|
+
launchContractDigest: recoveryDescriptor ? recoveryDescriptor.launchContractDigest : statusSteps[index]?.launchContractDigest ?? resultSteps[index]?.launchContractDigest ?? result?.launchContractDigest,
|
|
699
|
+
// External runners write no recovery descriptor.
|
|
700
|
+
...(!recoveryDescriptor && statusSteps[index]?.runner ? { runner: statusSteps[index].runner } : {}),
|
|
701
|
+
...(!recoveryDescriptor && statusSteps[index]?.externalJob ? { externalJob: statusSteps[index].externalJob } : {}),
|
|
630
702
|
...(capabilityCeiling ? { capabilityCeiling } : {}),
|
|
631
703
|
...(thinkingCeiling ? { thinkingCeiling } : {}),
|
|
632
704
|
...(recoveryDescriptor ? { recoveryDescriptor } : {}),
|
|
@@ -659,8 +731,9 @@ export function applySteeringRecoveryAgentConfig(agentConfig, descriptor) {
|
|
|
659
731
|
output: descriptor.outputPath,
|
|
660
732
|
toolBudget: descriptor.initialToolBudget,
|
|
661
733
|
maxSubagentDepth: descriptor.maxSubagentDepth,
|
|
662
|
-
//
|
|
663
|
-
launcher
|
|
734
|
+
// A recorded launcher, or a recorded null (ran unwrapped), wins over the current agent file.
|
|
735
|
+
// A missing field says nothing, so the run never loses the agent file's launcher.
|
|
736
|
+
launcher: descriptor.launcher === undefined ? agentConfig.launcher : descriptor.launcher ?? undefined,
|
|
664
737
|
};
|
|
665
738
|
}
|
|
666
739
|
export function buildRevivedAsyncTask(target, message) {
|
|
@@ -3,6 +3,7 @@ export declare const ASYNC_RETENTION_DAYS = 30;
|
|
|
3
3
|
export declare const ASYNC_RETENTION_BATCH_SIZE = 100;
|
|
4
4
|
export declare const ASYNC_RETENTION_DELAY_MS = 60000;
|
|
5
5
|
export declare const ASYNC_RETENTION_TOMBSTONE_GRACE_MS: number;
|
|
6
|
+
export declare const RESUMABLE_RETENTION_DAYS = 90;
|
|
6
7
|
export interface AsyncRetentionOptions {
|
|
7
8
|
asyncDirRoot: string;
|
|
8
9
|
resultsDir: string;
|
|
@@ -11,11 +11,16 @@ import { 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";
|
|
14
|
+
import { recoveryDescriptorPath, runLaunchDir } from "../shared/run-launch-folder.js";
|
|
14
15
|
export const ASYNC_RETENTION_DAYS = 30;
|
|
15
16
|
export const ASYNC_RETENTION_BATCH_SIZE = 100;
|
|
16
17
|
export const ASYNC_RETENTION_DELAY_MS = 60_000;
|
|
17
18
|
export const ASYNC_RETENTION_TOMBSTONE_GRACE_MS = 24 * 60 * 60 * 1000;
|
|
19
|
+
// A run or result whose session file still exists can be resumed, so it is kept this long
|
|
20
|
+
// instead of ASYNC_RETENTION_DAYS. Session files outlive run dirs, so without a ceiling it is kept forever.
|
|
21
|
+
export const RESUMABLE_RETENTION_DAYS = 90;
|
|
18
22
|
const RETENTION_MS = ASYNC_RETENTION_DAYS * 24 * 60 * 60 * 1000;
|
|
23
|
+
const RESUMABLE_RETENTION_MS = RESUMABLE_RETENTION_DAYS * 24 * 60 * 60 * 1000;
|
|
19
24
|
const LOCK_NAME = ".async-retention.lock";
|
|
20
25
|
const CURSOR_NAME = ".async-retention-cursor.json";
|
|
21
26
|
const LOG_NAME = "async-retention-maintenance.jsonl";
|
|
@@ -102,7 +107,8 @@ function hasResumableContract(runDir, status) {
|
|
|
102
107
|
const statusSessionFiles = [status.sessionFile, ...(status.steps ?? []).map((step) => step.sessionFile)];
|
|
103
108
|
if (statusSessionFiles.some(existingRegularFile))
|
|
104
109
|
return true;
|
|
105
|
-
|
|
110
|
+
// runDir may be a tombstone; the launch folder is keyed by the run id.
|
|
111
|
+
const descriptorPath = recoveryDescriptorPath(path.dirname(runDir), status.runId);
|
|
106
112
|
if (!fs.existsSync(descriptorPath))
|
|
107
113
|
return false;
|
|
108
114
|
const descriptor = readJson(descriptorPath);
|
|
@@ -239,9 +245,10 @@ function runSkipReason(input) {
|
|
|
239
245
|
return "mission-reference";
|
|
240
246
|
if (hasUnresolvedRunHandoff(runDir, status))
|
|
241
247
|
return "handoff-reference";
|
|
242
|
-
if (hasResumableContract(runDir, status))
|
|
243
|
-
return "resumable";
|
|
244
248
|
const timestamp = statusTimestamp(status, runDir);
|
|
249
|
+
// Unknown ages stay protected.
|
|
250
|
+
if (hasResumableContract(runDir, status) && (timestamp === undefined || timestamp > input.resumableCutoff))
|
|
251
|
+
return "resumable";
|
|
245
252
|
if (timestamp === undefined)
|
|
246
253
|
return "unknown-age";
|
|
247
254
|
if (timestamp > input.cutoff)
|
|
@@ -464,13 +471,13 @@ function resultSkipReason(input) {
|
|
|
464
471
|
return "workflow-reference";
|
|
465
472
|
if (hasUnresolvedResultHandoff(input.data))
|
|
466
473
|
return "handoff-reference";
|
|
467
|
-
|
|
474
|
+
const timestamp = resultTimestamp(input.data, input.candidate.path);
|
|
475
|
+
if (resultHasResumableSession(input.data) && (timestamp === undefined || timestamp > input.resumableCutoff))
|
|
468
476
|
return "resumable";
|
|
469
477
|
if (input.candidate.kind === "archive" && fs.existsSync(path.join(input.resultsDir, "completion-replay", `${encodeURIComponent(runId)}.json`)))
|
|
470
478
|
return "replay-reference";
|
|
471
479
|
if (!terminalResult(input.data) && input.candidate.kind !== "replay" && input.candidate.kind !== "archive" && input.candidate.kind !== "tombstone")
|
|
472
480
|
return "non-terminal-result";
|
|
473
|
-
const timestamp = resultTimestamp(input.data, input.candidate.path);
|
|
474
481
|
if (timestamp === undefined)
|
|
475
482
|
return "unknown-age";
|
|
476
483
|
if (timestamp > input.cutoff)
|
|
@@ -690,6 +697,7 @@ export async function cleanupAsyncRetention(options) {
|
|
|
690
697
|
return finish();
|
|
691
698
|
const protectedRunIds = new Set(options.protectedRunIds ?? []);
|
|
692
699
|
const cutoff = currentTime - retentionMs;
|
|
700
|
+
const resumableCutoff = currentTime - RESUMABLE_RETENTION_MS;
|
|
693
701
|
const cursor = readCursor(maintenanceRoot);
|
|
694
702
|
const runBudget = Math.ceil(batchSize / 2);
|
|
695
703
|
const resultBudget = batchSize - runBudget;
|
|
@@ -765,7 +773,7 @@ export async function cleanupAsyncRetention(options) {
|
|
|
765
773
|
if (reconciliation.repaired)
|
|
766
774
|
result.repairedRuns += 1;
|
|
767
775
|
}
|
|
768
|
-
const initialReason = runSkipReason({ runDir, status, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, cutoff, protectedRunIds, waitRunIds: waitReferences.runIds });
|
|
776
|
+
const initialReason = runSkipReason({ runDir, status, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, cutoff, resumableCutoff, protectedRunIds, waitRunIds: waitReferences.runIds });
|
|
769
777
|
if (initialReason) {
|
|
770
778
|
increment(result.skipped, initialReason);
|
|
771
779
|
continue;
|
|
@@ -780,13 +788,14 @@ export async function cleanupAsyncRetention(options) {
|
|
|
780
788
|
continue;
|
|
781
789
|
}
|
|
782
790
|
const freshWaitReferences = parseWaitRunIds(waitSubscriptionsDir);
|
|
783
|
-
const finalReason = freshWaitReferences.safe ? runSkipReason({ runDir, status, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, cutoff, protectedRunIds, waitRunIds: freshWaitReferences.runIds }) : "wait-references-unknown";
|
|
791
|
+
const finalReason = freshWaitReferences.safe ? runSkipReason({ runDir, status, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, cutoff, resumableCutoff, protectedRunIds, waitRunIds: freshWaitReferences.runIds }) : "wait-references-unknown";
|
|
784
792
|
if (finalReason) {
|
|
785
793
|
increment(result.skipped, `recheck-${finalReason}`);
|
|
786
794
|
continue;
|
|
787
795
|
}
|
|
788
796
|
mutationStateChanged = true;
|
|
789
797
|
fs.rmSync(runDir, { recursive: true });
|
|
798
|
+
fs.rmSync(runLaunchDir(options.asyncDirRoot, status.runId), { recursive: true, force: true });
|
|
790
799
|
removeRunTombstoneMarker(maintenanceRoot, status.runId);
|
|
791
800
|
result.reapedTombstones += 1;
|
|
792
801
|
deletedIds.push(`run-tombstone:${status.runId}`);
|
|
@@ -805,7 +814,7 @@ export async function cleanupAsyncRetention(options) {
|
|
|
805
814
|
}
|
|
806
815
|
const recheckStatus = readStatus(tombstone);
|
|
807
816
|
const freshWaitReferences = parseWaitRunIds(waitSubscriptionsDir);
|
|
808
|
-
const recheckReason = freshWaitReferences.safe ? runSkipReason({ runDir: tombstone, status: recheckStatus, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, cutoff, protectedRunIds, waitRunIds: freshWaitReferences.runIds }) : "wait-references-unknown";
|
|
817
|
+
const recheckReason = freshWaitReferences.safe ? runSkipReason({ runDir: tombstone, status: recheckStatus, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, cutoff, resumableCutoff, protectedRunIds, waitRunIds: freshWaitReferences.runIds }) : "wait-references-unknown";
|
|
809
818
|
if (recheckReason) {
|
|
810
819
|
if (!fs.existsSync(runDir)) {
|
|
811
820
|
fs.renameSync(tombstone, runDir);
|
|
@@ -818,6 +827,8 @@ export async function cleanupAsyncRetention(options) {
|
|
|
818
827
|
continue;
|
|
819
828
|
}
|
|
820
829
|
fs.rmSync(tombstone, { recursive: true });
|
|
830
|
+
// Retention never deletes a workflow run, so this removes only a single run's recovery descriptor.
|
|
831
|
+
fs.rmSync(runLaunchDir(options.asyncDirRoot, status.runId), { recursive: true, force: true });
|
|
821
832
|
removeRunTombstoneMarker(maintenanceRoot, status.runId);
|
|
822
833
|
result.deletedRuns += 1;
|
|
823
834
|
deletedIds.push(`run:${status.runId}`);
|
|
@@ -842,7 +853,7 @@ export async function cleanupAsyncRetention(options) {
|
|
|
842
853
|
continue;
|
|
843
854
|
}
|
|
844
855
|
const data = readJson(candidate.path);
|
|
845
|
-
const reason = resultSkipReason({ candidate, data, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, maintenanceRoot, cutoff, protectedRunIds, waitRunIds: waitReferences.runIds });
|
|
856
|
+
const reason = resultSkipReason({ candidate, data, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, maintenanceRoot, cutoff, resumableCutoff, protectedRunIds, waitRunIds: waitReferences.runIds });
|
|
846
857
|
if (reason) {
|
|
847
858
|
increment(result.skipped, reason);
|
|
848
859
|
continue;
|
|
@@ -853,7 +864,7 @@ export async function cleanupAsyncRetention(options) {
|
|
|
853
864
|
continue;
|
|
854
865
|
}
|
|
855
866
|
const freshWaitReferences = parseWaitRunIds(waitSubscriptionsDir);
|
|
856
|
-
const finalReason = freshWaitReferences.safe ? resultSkipReason({ candidate, data, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, maintenanceRoot, cutoff, protectedRunIds, waitRunIds: freshWaitReferences.runIds }) : "wait-references-unknown";
|
|
867
|
+
const finalReason = freshWaitReferences.safe ? resultSkipReason({ candidate, data, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, maintenanceRoot, cutoff, resumableCutoff, protectedRunIds, waitRunIds: freshWaitReferences.runIds }) : "wait-references-unknown";
|
|
857
868
|
if (finalReason) {
|
|
858
869
|
increment(result.skipped, `recheck-${finalReason}`);
|
|
859
870
|
continue;
|
|
@@ -870,7 +881,7 @@ export async function cleanupAsyncRetention(options) {
|
|
|
870
881
|
const tombstoneCandidate = { ...candidate, path: tombstone, kind: "tombstone" };
|
|
871
882
|
const recheckData = readJson(tombstone);
|
|
872
883
|
const freshWaitReferences = parseWaitRunIds(waitSubscriptionsDir);
|
|
873
|
-
const recheckReason = freshWaitReferences.safe ? resultSkipReason({ candidate: tombstoneCandidate, data: recheckData, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, maintenanceRoot, cutoff, protectedRunIds, waitRunIds: freshWaitReferences.runIds }) : "wait-references-unknown";
|
|
884
|
+
const recheckReason = freshWaitReferences.safe ? resultSkipReason({ candidate: tombstoneCandidate, data: recheckData, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, maintenanceRoot, cutoff, resumableCutoff, protectedRunIds, waitRunIds: freshWaitReferences.runIds }) : "wait-references-unknown";
|
|
874
885
|
if (recheckReason) {
|
|
875
886
|
if (!fs.existsSync(candidate.path)) {
|
|
876
887
|
fs.renameSync(tombstone, candidate.path);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { listAsyncRuns } from "./async-status.js";
|
|
2
2
|
import { backgroundWorkForSession, waitForSubagents, waitRunScopes } from "./subagent-wait.js";
|
|
3
|
+
import { waitToolName } from "../../shared/wait-tool-name.js";
|
|
3
4
|
export const DEFAULT_AUTO_DRAIN_TIMEOUT_MS = 30 * 60 * 1000;
|
|
4
5
|
function resultText(value) {
|
|
5
6
|
return value.content.map((part) => part.type === "text" ? part.text : "").join(" ").trim();
|
|
@@ -55,7 +56,7 @@ export async function drainOutstandingWork(deps, observation) {
|
|
|
55
56
|
hasPendingSupervisorRequest: deps.hasPendingSupervisorRequest,
|
|
56
57
|
});
|
|
57
58
|
if (waitResult.isError) {
|
|
58
|
-
throw new Error(`Auto-drain failed for session '${sessionId}': ${resultText(waitResult) ||
|
|
59
|
+
throw new Error(`Auto-drain failed for session '${sessionId}': ${resultText(waitResult) || `${waitToolName()} returned an error without details`}.`);
|
|
59
60
|
}
|
|
60
61
|
if (waitResult.details.wait?.reason === "supervisor_request")
|
|
61
62
|
break;
|
|
@@ -4,9 +4,7 @@ import type { RecordedPid } from "./stale-run-reconciler.ts";
|
|
|
4
4
|
* different boot id cannot still be running. Undefined when the platform has none.
|
|
5
5
|
*/
|
|
6
6
|
export declare function currentBootId(): string | undefined;
|
|
7
|
-
/** This process as a recorded pid, without the fields the platform does not have. */
|
|
8
7
|
export declare function currentRecordedPid(): RecordedPid;
|
|
9
|
-
/**
|
|
8
|
+
/** Runners take Pi's value from their config. */
|
|
10
9
|
export declare function primeBootId(value: string | undefined): void;
|
|
11
|
-
/** Clears the cache so the next read calls `nextReader` (default: the OS reader). */
|
|
12
10
|
export declare function resetBootIdForTesting(nextReader?: () => string | undefined): void;
|
|
@@ -30,17 +30,15 @@ export function currentBootId() {
|
|
|
30
30
|
runtime[BOOT_ID_KEY] = { value };
|
|
31
31
|
return value;
|
|
32
32
|
}
|
|
33
|
-
/** This process as a recorded pid, without the fields the platform does not have. */
|
|
34
33
|
export function currentRecordedPid() {
|
|
35
34
|
const pidNamespaceScope = currentPidNamespaceScope();
|
|
36
35
|
const bootId = currentBootId();
|
|
37
36
|
return { pid: process.pid, ...(pidNamespaceScope ? { pidNamespaceScope } : {}), ...(bootId ? { bootId } : {}) };
|
|
38
37
|
}
|
|
39
|
-
/**
|
|
38
|
+
/** Runners take Pi's value from their config. */
|
|
40
39
|
export function primeBootId(value) {
|
|
41
40
|
runtime[BOOT_ID_KEY] = { value };
|
|
42
41
|
}
|
|
43
|
-
/** Clears the cache so the next read calls `nextReader` (default: the OS reader). */
|
|
44
42
|
export function resetBootIdForTesting(nextReader) {
|
|
45
43
|
reader = nextReader ?? readBootIdFromOs;
|
|
46
44
|
delete runtime[BOOT_ID_KEY];
|
|
@@ -36,7 +36,7 @@ export interface CompletionBatcherOptions<T> {
|
|
|
36
36
|
now?: () => number;
|
|
37
37
|
}
|
|
38
38
|
export interface CompletionBatcher<T> {
|
|
39
|
-
/**
|
|
39
|
+
/** Emits immediately when batching is disabled. */
|
|
40
40
|
push(item: T): void;
|
|
41
41
|
/** Emit any held items immediately as a single group. */
|
|
42
42
|
flush(): void;
|
|
@@ -44,8 +44,7 @@ export interface CompletionBatcher<T> {
|
|
|
44
44
|
dispose(): T[];
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* timers for reload/shutdown without emitting.
|
|
47
|
+
* The batcher is single-use per registration: it holds at most one open group.
|
|
48
|
+
* `flush` forces emission; `dispose` tears down timers for reload/shutdown without emitting.
|
|
50
49
|
*/
|
|
51
50
|
export declare function createCompletionBatcher<T>(options: CompletionBatcherOptions<T>): CompletionBatcher<T>;
|
|
@@ -50,9 +50,8 @@ function unrefHandle(handle) {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* timers for reload/shutdown without emitting.
|
|
53
|
+
* The batcher is single-use per registration: it holds at most one open group.
|
|
54
|
+
* `flush` forces emission; `dispose` tears down timers for reload/shutdown without emitting.
|
|
56
55
|
*/
|
|
57
56
|
export function createCompletionBatcher(options) {
|
|
58
57
|
const timers = options.timers ?? defaultTimers;
|
|
@@ -63,17 +63,11 @@ export interface CommandRequest {
|
|
|
63
63
|
}
|
|
64
64
|
export declare function requestAsyncCommand(dir: string, request: CommandRequest): void;
|
|
65
65
|
export declare const MAX_STEER_QUEUE_SIZE = 20;
|
|
66
|
-
/** Control inbox directory inside an async run dir. */
|
|
67
66
|
export declare function controlInboxDir(asyncDir: string): string;
|
|
68
|
-
/** Path of the portable interrupt request file. */
|
|
69
67
|
export declare function interruptRequestPath(asyncDir: string): string;
|
|
70
|
-
/** Path of the portable timeout request file. */
|
|
71
68
|
export declare function timeoutRequestPath(asyncDir: string): string;
|
|
72
|
-
/** Path of the portable manual stop request file. */
|
|
73
69
|
export declare function stopRequestPath(asyncDir: string): string;
|
|
74
|
-
/** Directory of parent-to-runner stop requests. */
|
|
75
70
|
export declare function stopRequestsDir(asyncDir: string): string;
|
|
76
|
-
/** Directory of parent-to-runner steering requests. */
|
|
77
71
|
export declare function steerRequestsDir(asyncDir: string): string;
|
|
78
72
|
export declare function steerInboxClosedPath(asyncDir: string): string;
|
|
79
73
|
export declare function stopInboxClosedPath(asyncDir: string): string;
|
|
@@ -82,27 +82,21 @@ const STOP_INBOX_CLOSED_FILE = "stop-inbox-closed.json";
|
|
|
82
82
|
const STOP_INBOX_CLOSED_MESSAGE = "Runner stop inbox is closed. Retry stop after runner shutdown is observed.";
|
|
83
83
|
const MAX_STEER_MESSAGE_BYTES = 128 * 1024;
|
|
84
84
|
const MAX_STEER_REQUEST_ID_LENGTH = 256;
|
|
85
|
-
/** Control inbox directory inside an async run dir. */
|
|
86
85
|
export function controlInboxDir(asyncDir) {
|
|
87
86
|
return path.join(asyncDir, "control");
|
|
88
87
|
}
|
|
89
|
-
/** Path of the portable interrupt request file. */
|
|
90
88
|
export function interruptRequestPath(asyncDir) {
|
|
91
89
|
return path.join(controlInboxDir(asyncDir), "interrupt.json");
|
|
92
90
|
}
|
|
93
|
-
/** Path of the portable timeout request file. */
|
|
94
91
|
export function timeoutRequestPath(asyncDir) {
|
|
95
92
|
return path.join(controlInboxDir(asyncDir), "timeout.json");
|
|
96
93
|
}
|
|
97
|
-
/** Path of the portable manual stop request file. */
|
|
98
94
|
export function stopRequestPath(asyncDir) {
|
|
99
95
|
return path.join(controlInboxDir(asyncDir), "stop.json");
|
|
100
96
|
}
|
|
101
|
-
/** Directory of parent-to-runner stop requests. */
|
|
102
97
|
export function stopRequestsDir(asyncDir) {
|
|
103
98
|
return path.join(controlInboxDir(asyncDir), STOP_REQUESTS_DIR);
|
|
104
99
|
}
|
|
105
|
-
/** Directory of parent-to-runner steering requests. */
|
|
106
100
|
export function steerRequestsDir(asyncDir) {
|
|
107
101
|
return path.join(controlInboxDir(asyncDir), STEER_REQUESTS_DIR);
|
|
108
102
|
}
|
|
@@ -9,6 +9,7 @@ import { formatNestedRunStatusLines } from "../shared/nested-render.js";
|
|
|
9
9
|
import { contextModeLabel, summarizeContextModes } from "../shared/context-mode.js";
|
|
10
10
|
import { formatAsyncRunOutputPath, formatAsyncRunProgressLabel, listAsyncRuns } from "./async-status.js";
|
|
11
11
|
import { isTrustedRecordedSessionFile } from "../../shared/session-file-trust.js";
|
|
12
|
+
import { waitToolName } from "../../shared/wait-tool-name.js";
|
|
12
13
|
const DEFAULT_TRANSCRIPT_LINES = 80;
|
|
13
14
|
const MAX_TRANSCRIPT_LINES = 500;
|
|
14
15
|
const TRANSCRIPT_TAIL_BYTES = 256 * 1024;
|
|
@@ -299,7 +300,7 @@ function formatDetachedForegroundFleetLines(runs) {
|
|
|
299
300
|
const childSummary = detachedChildren.map((child) => `${fleetChildDisplayName(child)} #${child.index}`).join(", ");
|
|
300
301
|
lines.push(`- ${run.runId} | detached | ${run.mode}${childSummary ? ` | ${childSummary}` : ""}`);
|
|
301
302
|
lines.push(` status: subagent({ action: "status", id: "${run.runId}" })`);
|
|
302
|
-
lines.push(` recovery: reply to the supervisor request first, then wait with
|
|
303
|
+
lines.push(` recovery: reply to the supervisor request first, then wait with ${waitToolName()}({ id: "${run.runId}" }); do not resume or launch a replacement while any child remains detached.`);
|
|
303
304
|
}
|
|
304
305
|
return lines;
|
|
305
306
|
}
|
|
@@ -467,8 +468,6 @@ function appendKnownArtifacts(lines, input) {
|
|
|
467
468
|
lines.push(` ${artifact}`);
|
|
468
469
|
}
|
|
469
470
|
/**
|
|
470
|
-
* Sanitizes each assembled line independently.
|
|
471
|
-
*
|
|
472
471
|
* Sanitizing the joined response would let a single binary fragment in child
|
|
473
472
|
* output collapse the whole transcript, including run state, artifact paths, and
|
|
474
473
|
* warnings, into the binary placeholder. Per-line sanitization keeps that damage
|