@vicary/pi-subagents 0.83.1 → 0.84.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/bundle/{chunk-YXFJVCOL.js → chunk-4E7BKDTX.js} +3 -3
- package/bundle/{chunk-UFL7IYCW.js → chunk-4MDR6V46.js} +8 -8
- package/bundle/{chunk-AHIFYGR3.js → chunk-67ENPDDA.js} +5 -5
- package/bundle/{chunk-ZVOAMTUQ.js → chunk-AKOIVLA5.js} +3 -3
- package/bundle/{chunk-RNIZLSEA.js → chunk-CGN2TVE7.js} +1 -0
- package/bundle/{chunk-NPIYWVOD.js → chunk-F4AMYP5N.js} +3 -3
- package/bundle/{chunk-C7JMPU5F.js → chunk-HKJLSMXV.js} +1 -1
- package/bundle/{chunk-UYK5MZWE.js → chunk-L3WFKBEI.js} +1 -1
- package/bundle/{chunk-F5DBXJ2G.js → chunk-LGLEH7B6.js} +8 -5
- package/bundle/{chunk-VLFZIN6D.js → chunk-NENDSQUY.js} +2 -2
- package/bundle/{chunk-QP5ZWNIS.js → chunk-PALJGGYC.js} +1 -1
- package/bundle/{chunk-IPGZMQXV.js → chunk-PV63UFUR.js} +5 -5
- package/bundle/{chunk-MABL3FUM.js → chunk-T44HVL5U.js} +1 -1
- package/bundle/{chunk-V6YPYWJP.js → chunk-TE4LHYHN.js} +25 -17
- package/bundle/{chunk-HCSINC66.js → chunk-X2MXCSA5.js} +24 -21
- package/bundle/index.js +1 -1
- package/bundle/preflight.js +2 -2
- package/docs/agents.md +1 -1
- package/docs/configuration.md +6 -6
- package/docs/observability.md +1 -1
- package/docs/tool-reference.md +1 -1
- package/docs/workflows.md +1 -1
- package/package.json +2 -2
- package/src/extension/schemas.js +1 -1
- package/src/runs/background/async-execution.d.ts +3 -1
- package/src/runs/background/async-execution.js +16 -2
- package/src/runs/background/async-retention.d.ts +1 -0
- package/src/runs/background/async-retention.js +16 -10
- package/src/runs/background/auto-drain.d.ts +0 -1
- package/src/runs/background/auto-drain.js +5 -5
- package/src/runs/background/run-child-session.d.ts +2 -0
- package/src/runs/background/run-child-session.js +9 -1
- package/src/runs/background/subagent-runner.js +1 -0
- package/src/runs/foreground/subagent-executor.d.ts +4 -6
- package/src/runs/foreground/subagent-executor.js +11 -18
- package/src/runs/shared/child-session.d.ts +2 -0
- package/src/runs/shared/child-session.js +1 -0
- package/src/runs/shared/model-resolution-diagnostic.d.ts +11 -0
- package/src/runs/shared/model-resolution-diagnostic.js +25 -0
- package/src/runs/shared/parallel-utils.d.ts +2 -0
- package/src/shared/types.d.ts +5 -6
- package/src/workflows/scripted-workflow.js +2 -0
- package/workflow-script-worker.cjs +449 -175
|
@@ -10,10 +10,10 @@ import {
|
|
|
10
10
|
setInlineWorkflowCoverage,
|
|
11
11
|
setMainThinkingLevelSource,
|
|
12
12
|
widgetRenderKey
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-AKOIVLA5.js";
|
|
14
14
|
import {
|
|
15
15
|
package_default
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-T44HVL5U.js";
|
|
17
17
|
import {
|
|
18
18
|
EXTERNAL_JOB_BRIDGE_REQUEST_DIR,
|
|
19
19
|
REVIVAL_ORIGIN_FILE,
|
|
@@ -61,7 +61,7 @@ import {
|
|
|
61
61
|
snapshotProviderDiagnostics,
|
|
62
62
|
workflowResumeClaimState,
|
|
63
63
|
workflowResumeRefusal
|
|
64
|
-
} from "./chunk-
|
|
64
|
+
} from "./chunk-LGLEH7B6.js";
|
|
65
65
|
import {
|
|
66
66
|
CONTACT_SUPERVISOR_TOOL_NAME,
|
|
67
67
|
NATIVE_SUPERVISOR_TOOL_NAME,
|
|
@@ -89,14 +89,14 @@ import {
|
|
|
89
89
|
resolveWaitToolConfig,
|
|
90
90
|
setDeclarationPinning,
|
|
91
91
|
topLevelSupervisorTool
|
|
92
|
-
} from "./chunk-
|
|
92
|
+
} from "./chunk-4MDR6V46.js";
|
|
93
93
|
import {
|
|
94
94
|
deliverAsyncRunStop,
|
|
95
95
|
ownerConfirmedDead,
|
|
96
96
|
readSessionMessagesTail,
|
|
97
97
|
resolveSubagentRunId,
|
|
98
98
|
restoreForegroundRunHistory
|
|
99
|
-
} from "./chunk-
|
|
99
|
+
} from "./chunk-NENDSQUY.js";
|
|
100
100
|
import {
|
|
101
101
|
ASYNC_STATUS_SNAPSHOT_KIND,
|
|
102
102
|
ASYNC_STATUS_SNAPSHOT_VERSION,
|
|
@@ -118,7 +118,7 @@ import {
|
|
|
118
118
|
resolveAsyncStatusChild,
|
|
119
119
|
stopStoppableAsyncStatusChildren,
|
|
120
120
|
withCachedUiContext
|
|
121
|
-
} from "./chunk-
|
|
121
|
+
} from "./chunk-L3WFKBEI.js";
|
|
122
122
|
import "./chunk-NF7IEKBH.js";
|
|
123
123
|
import {
|
|
124
124
|
disabledFeatureUseError,
|
|
@@ -129,7 +129,7 @@ import {
|
|
|
129
129
|
resolveDisabledFeatureSurface,
|
|
130
130
|
resolveMaxActiveAsyncRunsPerSession,
|
|
131
131
|
resolveScheduledStoreRoot
|
|
132
|
-
} from "./chunk-
|
|
132
|
+
} from "./chunk-PALJGGYC.js";
|
|
133
133
|
import {
|
|
134
134
|
ACTIVE_RUN_INDEX_DIR,
|
|
135
135
|
MissionNotFoundError,
|
|
@@ -178,7 +178,7 @@ import {
|
|
|
178
178
|
withWorkflowChildRunModel,
|
|
179
179
|
writeAsyncResultFile,
|
|
180
180
|
writeResultIndexForData
|
|
181
|
-
} from "./chunk-
|
|
181
|
+
} from "./chunk-CGN2TVE7.js";
|
|
182
182
|
import "./chunk-F4ASL6OV.js";
|
|
183
183
|
import {
|
|
184
184
|
shouldUseNativeFsWatch
|
|
@@ -1215,7 +1215,9 @@ var ASYNC_RETENTION_DAYS = 30;
|
|
|
1215
1215
|
var ASYNC_RETENTION_BATCH_SIZE = 100;
|
|
1216
1216
|
var ASYNC_RETENTION_DELAY_MS = 6e4;
|
|
1217
1217
|
var ASYNC_RETENTION_TOMBSTONE_GRACE_MS = 24 * 60 * 60 * 1e3;
|
|
1218
|
+
var RESUMABLE_RETENTION_DAYS = 90;
|
|
1218
1219
|
var RETENTION_MS = ASYNC_RETENTION_DAYS * 24 * 60 * 60 * 1e3;
|
|
1220
|
+
var RESUMABLE_RETENTION_MS = RESUMABLE_RETENTION_DAYS * 24 * 60 * 60 * 1e3;
|
|
1219
1221
|
var LOCK_NAME = ".async-retention.lock";
|
|
1220
1222
|
var CURSOR_NAME = ".async-retention-cursor.json";
|
|
1221
1223
|
var LOG_NAME = "async-retention-maintenance.jsonl";
|
|
@@ -1389,8 +1391,8 @@ function runSkipReason(input) {
|
|
|
1389
1391
|
if (hasNestedReferences(status)) return "nested-reference";
|
|
1390
1392
|
if (missionReferenceBlocksReclaim(runDir, input.resultsDir, status.runId)) return "mission-reference";
|
|
1391
1393
|
if (hasUnresolvedRunHandoff(runDir, status)) return "handoff-reference";
|
|
1392
|
-
if (hasResumableContract(runDir, status)) return "resumable";
|
|
1393
1394
|
const timestamp = statusTimestamp(status, runDir);
|
|
1395
|
+
if (hasResumableContract(runDir, status) && (timestamp === void 0 || timestamp > input.resumableCutoff)) return "resumable";
|
|
1394
1396
|
if (timestamp === void 0) return "unknown-age";
|
|
1395
1397
|
if (timestamp > input.cutoff) return "recent";
|
|
1396
1398
|
return void 0;
|
|
@@ -1558,10 +1560,10 @@ function resultSkipReason(input) {
|
|
|
1558
1560
|
if (missionObserverIndexExists(input.resultsDir, runId)) return "mission-reference";
|
|
1559
1561
|
if (input.data.mode === "workflow" || completionMode(input.data) === "workflow" || typeof input.data.parentWorkflowRunId === "string" || typeof input.data.workflowKey === "string") return "workflow-reference";
|
|
1560
1562
|
if (hasUnresolvedResultHandoff(input.data)) return "handoff-reference";
|
|
1561
|
-
|
|
1563
|
+
const timestamp = resultTimestamp(input.data, input.candidate.path);
|
|
1564
|
+
if (resultHasResumableSession(input.data) && (timestamp === void 0 || timestamp > input.resumableCutoff)) return "resumable";
|
|
1562
1565
|
if (input.candidate.kind === "archive" && fs4.existsSync(path3.join(input.resultsDir, "completion-replay", `${encodeURIComponent(runId)}.json`))) return "replay-reference";
|
|
1563
1566
|
if (!terminalResult(input.data) && input.candidate.kind !== "replay" && input.candidate.kind !== "archive" && input.candidate.kind !== "tombstone") return "non-terminal-result";
|
|
1564
|
-
const timestamp = resultTimestamp(input.data, input.candidate.path);
|
|
1565
1567
|
if (timestamp === void 0) return "unknown-age";
|
|
1566
1568
|
if (timestamp > input.cutoff) return "recent";
|
|
1567
1569
|
return void 0;
|
|
@@ -1747,6 +1749,7 @@ async function cleanupAsyncRetention(options) {
|
|
|
1747
1749
|
if (markCancelled()) return finish();
|
|
1748
1750
|
const protectedRunIds = new Set(options.protectedRunIds ?? []);
|
|
1749
1751
|
const cutoff = currentTime - retentionMs;
|
|
1752
|
+
const resumableCutoff = currentTime - RESUMABLE_RETENTION_MS;
|
|
1750
1753
|
const cursor = readCursor(maintenanceRoot);
|
|
1751
1754
|
const runBudget = Math.ceil(batchSize / 2);
|
|
1752
1755
|
const resultBudget = batchSize - runBudget;
|
|
@@ -1811,7 +1814,7 @@ async function cleanupAsyncRetention(options) {
|
|
|
1811
1814
|
status = reconciliation.status ?? void 0;
|
|
1812
1815
|
if (reconciliation.repaired) result.repairedRuns += 1;
|
|
1813
1816
|
}
|
|
1814
|
-
const initialReason = runSkipReason({ runDir, status, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, cutoff, protectedRunIds, waitRunIds: waitReferences.runIds });
|
|
1817
|
+
const initialReason = runSkipReason({ runDir, status, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, cutoff, resumableCutoff, protectedRunIds, waitRunIds: waitReferences.runIds });
|
|
1815
1818
|
if (initialReason) {
|
|
1816
1819
|
increment(result.skipped, initialReason);
|
|
1817
1820
|
continue;
|
|
@@ -1826,7 +1829,7 @@ async function cleanupAsyncRetention(options) {
|
|
|
1826
1829
|
continue;
|
|
1827
1830
|
}
|
|
1828
1831
|
const freshWaitReferences2 = parseWaitRunIds(waitSubscriptionsDir);
|
|
1829
|
-
const finalReason = freshWaitReferences2.safe ? runSkipReason({ runDir, status, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, cutoff, protectedRunIds, waitRunIds: freshWaitReferences2.runIds }) : "wait-references-unknown";
|
|
1832
|
+
const finalReason = freshWaitReferences2.safe ? runSkipReason({ runDir, status, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, cutoff, resumableCutoff, protectedRunIds, waitRunIds: freshWaitReferences2.runIds }) : "wait-references-unknown";
|
|
1830
1833
|
if (finalReason) {
|
|
1831
1834
|
increment(result.skipped, `recheck-${finalReason}`);
|
|
1832
1835
|
continue;
|
|
@@ -1850,7 +1853,7 @@ async function cleanupAsyncRetention(options) {
|
|
|
1850
1853
|
}
|
|
1851
1854
|
const recheckStatus = readStatus2(tombstone);
|
|
1852
1855
|
const freshWaitReferences = parseWaitRunIds(waitSubscriptionsDir);
|
|
1853
|
-
const recheckReason = freshWaitReferences.safe ? runSkipReason({ runDir: tombstone, status: recheckStatus, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, cutoff, protectedRunIds, waitRunIds: freshWaitReferences.runIds }) : "wait-references-unknown";
|
|
1856
|
+
const recheckReason = freshWaitReferences.safe ? runSkipReason({ runDir: tombstone, status: recheckStatus, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, cutoff, resumableCutoff, protectedRunIds, waitRunIds: freshWaitReferences.runIds }) : "wait-references-unknown";
|
|
1854
1857
|
if (recheckReason) {
|
|
1855
1858
|
if (!fs4.existsSync(runDir)) {
|
|
1856
1859
|
fs4.renameSync(tombstone, runDir);
|
|
@@ -1882,7 +1885,7 @@ async function cleanupAsyncRetention(options) {
|
|
|
1882
1885
|
continue;
|
|
1883
1886
|
}
|
|
1884
1887
|
const data = readJson(candidate.path);
|
|
1885
|
-
const reason = resultSkipReason({ candidate, data, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, maintenanceRoot, cutoff, protectedRunIds, waitRunIds: waitReferences.runIds });
|
|
1888
|
+
const reason = resultSkipReason({ candidate, data, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, maintenanceRoot, cutoff, resumableCutoff, protectedRunIds, waitRunIds: waitReferences.runIds });
|
|
1886
1889
|
if (reason) {
|
|
1887
1890
|
increment(result.skipped, reason);
|
|
1888
1891
|
continue;
|
|
@@ -1893,7 +1896,7 @@ async function cleanupAsyncRetention(options) {
|
|
|
1893
1896
|
continue;
|
|
1894
1897
|
}
|
|
1895
1898
|
const freshWaitReferences2 = parseWaitRunIds(waitSubscriptionsDir);
|
|
1896
|
-
const finalReason = freshWaitReferences2.safe ? resultSkipReason({ candidate, data, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, maintenanceRoot, cutoff, protectedRunIds, waitRunIds: freshWaitReferences2.runIds }) : "wait-references-unknown";
|
|
1899
|
+
const finalReason = freshWaitReferences2.safe ? resultSkipReason({ candidate, data, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, maintenanceRoot, cutoff, resumableCutoff, protectedRunIds, waitRunIds: freshWaitReferences2.runIds }) : "wait-references-unknown";
|
|
1897
1900
|
if (finalReason) {
|
|
1898
1901
|
increment(result.skipped, `recheck-${finalReason}`);
|
|
1899
1902
|
continue;
|
|
@@ -1910,7 +1913,7 @@ async function cleanupAsyncRetention(options) {
|
|
|
1910
1913
|
const tombstoneCandidate = { ...candidate, path: tombstone, kind: "tombstone" };
|
|
1911
1914
|
const recheckData = readJson(tombstone);
|
|
1912
1915
|
const freshWaitReferences = parseWaitRunIds(waitSubscriptionsDir);
|
|
1913
|
-
const recheckReason = freshWaitReferences.safe ? resultSkipReason({ candidate: tombstoneCandidate, data: recheckData, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, maintenanceRoot, cutoff, protectedRunIds, waitRunIds: freshWaitReferences.runIds }) : "wait-references-unknown";
|
|
1916
|
+
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";
|
|
1914
1917
|
if (recheckReason) {
|
|
1915
1918
|
if (!fs4.existsSync(candidate.path)) {
|
|
1916
1919
|
fs4.renameSync(tombstone, candidate.path);
|
|
@@ -5182,7 +5185,7 @@ function registerSlashCommands(pi, state, options = {}) {
|
|
|
5182
5185
|
}
|
|
5183
5186
|
fleetOpen = true;
|
|
5184
5187
|
try {
|
|
5185
|
-
const { openSubagentFleet } = await import("./chunk-
|
|
5188
|
+
const { openSubagentFleet } = await import("./chunk-PV63UFUR.js");
|
|
5186
5189
|
await openSubagentFleet(ctx, state, { asyncDirRoot: DIRS.async, inspectorPlugins: () => getInspectorPlugins(pi), resultsDir: DIRS.results, fleetKeybindings: options.fleetKeybindings });
|
|
5187
5190
|
} finally {
|
|
5188
5191
|
fleetOpen = false;
|
|
@@ -8571,7 +8574,7 @@ function registerSubagentExtension(pi) {
|
|
|
8571
8574
|
const ctx = withLastUiContext((current) => current);
|
|
8572
8575
|
if (!ctx) return;
|
|
8573
8576
|
try {
|
|
8574
|
-
const { openSubagentFleet } = await import("./chunk-
|
|
8577
|
+
const { openSubagentFleet } = await import("./chunk-PV63UFUR.js");
|
|
8575
8578
|
await openSubagentFleet(ctx, state, { initialKey: itemKey, asyncDirRoot: DIRS.async, resultsDir: DIRS.results, fleetKeybindings: config.fleetKeybindings, inspectorPlugins: () => getInspectorPlugins(pi) });
|
|
8576
8579
|
} catch (error) {
|
|
8577
8580
|
if (isStaleExtensionContextError(error)) {
|
|
@@ -8767,7 +8770,7 @@ function registerSubagentExtension(pi) {
|
|
|
8767
8770
|
let executor;
|
|
8768
8771
|
let executorPromise;
|
|
8769
8772
|
let executorModulePromise;
|
|
8770
|
-
const loadExecutorModule = () => executorModulePromise ??= import("./chunk-
|
|
8773
|
+
const loadExecutorModule = () => executorModulePromise ??= import("./chunk-TE4LHYHN.js");
|
|
8771
8774
|
const getExecutor = () => {
|
|
8772
8775
|
executorPromise ??= loadExecutorModule().then(({ createSubagentExecutor }) => {
|
|
8773
8776
|
executor = createSubagentExecutor(executorDeps);
|
|
@@ -8781,7 +8784,7 @@ function registerSubagentExtension(pi) {
|
|
|
8781
8784
|
modulePreloadTimer = setTimeout(() => {
|
|
8782
8785
|
loadExecutorModule().catch(() => {
|
|
8783
8786
|
});
|
|
8784
|
-
if (fleetViewEnabled) import("./chunk-
|
|
8787
|
+
if (fleetViewEnabled) import("./chunk-PV63UFUR.js").catch(() => {
|
|
8785
8788
|
});
|
|
8786
8789
|
}, MODULE_PRELOAD_DELAY_MS);
|
|
8787
8790
|
modulePreloadTimer.unref?.();
|
package/bundle/index.js
CHANGED
|
@@ -17,7 +17,7 @@ function readInstalledPackageVersion() {
|
|
|
17
17
|
var loadedPackageVersion = readInstalledPackageVersion();
|
|
18
18
|
|
|
19
19
|
// index.ts
|
|
20
|
-
var registerExtension = process.env[HERDR_PI_MODE_ENV] === "1" ? (await import("./chunk-
|
|
20
|
+
var registerExtension = process.env[HERDR_PI_MODE_ENV] === "1" ? (await import("./chunk-67ENPDDA.js")).default : process.env.PI_SUBAGENT_CHILD === "1" ? void 0 : (await import("./chunk-X2MXCSA5.js")).default;
|
|
21
21
|
function registerSubagentExtension(pi) {
|
|
22
22
|
const installedVersion = readInstalledPackageVersion();
|
|
23
23
|
if (installedVersion !== loadedPackageVersion) {
|
package/bundle/preflight.js
CHANGED
|
@@ -6,13 +6,13 @@ import {
|
|
|
6
6
|
import "./chunk-LFDBD4PW.js";
|
|
7
7
|
import {
|
|
8
8
|
loadConfig
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-PALJGGYC.js";
|
|
10
10
|
import {
|
|
11
11
|
nestedResultsPath,
|
|
12
12
|
processTerminalCandidatePath,
|
|
13
13
|
processTerminalPath,
|
|
14
14
|
resultFilePath
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-CGN2TVE7.js";
|
|
16
16
|
import {
|
|
17
17
|
applyIntercomBridgeToAgent,
|
|
18
18
|
resolveIntercomBridge,
|
package/docs/agents.md
CHANGED
|
@@ -467,7 +467,7 @@ Field notes:
|
|
|
467
467
|
| `defaultProgress` | Maintain `progress.md`. |
|
|
468
468
|
| `async` | Default a single-agent launch to background (`true`) or foreground (`false`) when the call omits `async`. Explicit call values and `forceTopLevelAsync` win. |
|
|
469
469
|
| `launcher` | Name of a [`runnerLaunchers`](configuration.md#runnerlaunchers) entry that wraps this agent's background runner, such as a sandbox command. Names only; the command itself is defined in user config. See [Sandboxing background children with a launcher](#sandboxing-background-children-with-a-launcher). |
|
|
470
|
-
| `timeoutMs` | Positive integer default runtime deadline in milliseconds for single-agent launches.
|
|
470
|
+
| `timeoutMs` | Positive integer default runtime deadline in milliseconds for single-agent launches. No runtime deadline applies when neither the call, agent, nor configuration provides one; explicit `timeoutMs`/`maxRuntimeMs` and agent defaults win. |
|
|
471
471
|
| `toolTimeoutMs` | Optional positive integer hard per-tool-call deadline in milliseconds. An explicit call value wins, then this agent default, global `toolTimeoutMs`, and `PI_SUBAGENT_TOOL_TIMEOUT_MS`. When omitted, known-fast built-in tools get a five-minute default; long-running tools get attention notices but no hard default. It does not extend the run-level deadline; `contact_supervisor`, `intercom`, and `bg_wait` are exempt. |
|
|
472
472
|
| `acceptance` | Acceptance default for single-agent launches. Use a scalar level such as `checked` or an inline/block YAML map such as `{ level: "none", reason: "lightweight lookup" }`. Explicit call values win; chain and parallel acceptance remains task/step configuration. |
|
|
473
473
|
| `acceptanceRole` | Optional `read-only` or `writer` role for automatic acceptance inference. When omitted, automatic acceptance uses lightweight attestation; task wording and agent names do not escalate it. This does not grant or revoke tools. |
|
package/docs/configuration.md
CHANGED
|
@@ -404,7 +404,7 @@ Adds a short `active_subagents` section to the parent's system prompt while this
|
|
|
404
404
|
{ "waitTool": { "enabled": true, "defaultTimeoutMs": 120000 } }
|
|
405
405
|
```
|
|
406
406
|
|
|
407
|
-
`defaultTimeoutMs` sets the blocking window used when a `bg_wait` call omits `timeoutMs`; explicit call values win, followed by this setting, then the 30-minute fallback. `bg_wait` is the only registered wait tool. When the window elapses, the tool returns a non-error `window_elapsed` result with the still-active work identities, and that work keeps running. Set `enabled` to `false` to make direct calls return immediately instead of blocking. The default is enabled. You can also set `"waitTool": false`; set `PI_SUBAGENT_WAIT_TOOL_ENABLED=false` (or `0`, `off`, `disabled`) to override config for one process. The effective enabled and default-timeout values are passed explicitly to child runtimes. Headless `agent_end` auto-drain
|
|
407
|
+
`defaultTimeoutMs` sets the blocking window used when a `bg_wait` call omits `timeoutMs`; explicit call values win, followed by this setting, then the 30-minute fallback. `bg_wait` is the only registered wait tool. When the window elapses, the tool returns a non-error `window_elapsed` result with the still-active work identities, and that work keeps running. Set `enabled` to `false` to make direct calls return immediately instead of blocking. The default is enabled. You can also set `"waitTool": false`; set `PI_SUBAGENT_WAIT_TOOL_ENABLED=false` (or `0`, `off`, `disabled`) to override config for one process. The effective enabled and default-timeout values are passed explicitly to child runtimes. Headless `agent_end` auto-drain continues across wait windows until required work completes or another stopping condition occurs. Invalid config or environment values fail instead of being coerced.
|
|
408
408
|
|
|
409
409
|
|
|
410
410
|
Blocking `bg_wait({ id: "..." })` keeps the current tool call open until that run changes. By default it returns when a run needs attention, even when the run is still working normally, for example a `bash` command open longer than `activeNoticeAfterMs`; the result then says the run is still running. Use `bg_wait({ stopOnAttention: false })` for run-to-completion flows: it waits through idle time, a tool held open, or repeated tool failures, and still ends for a supervisor/contact request, a finished run, the timeout, user input, or abort. A steer or follow-up the operator sends while a blocking wait is open also ends it, with a non-error `user_input` result listing the still-active work, so the message reaches the model without waiting out the window. In a long-lived interactive parent session, `bg_wait({ id: "...", nonBlocking: true })` instead resolves the prefix once, persists the exact run identity, returns a subscription token immediately, and wakes that session on completion, failure, attention, reconciliation failure, or timeout. Use it for provider, detached, or other background work without a native completion notification; ordinary async subagent runs notify the parent natively and do not need a wait subscription. Armed subscriptions appear in ordinary `subagent({ action: "status" })` output and are not counted as active child work. A native completion notification goes to the Pi process that launched the run while that process is running; once it has exited, the session gets the result the next time it is open in any Pi. `nonBlocking` subscriptions need a host with a UI context, such as interactive or RPC mode; plain SDK embedding without a UI context rejects them.
|
|
@@ -434,13 +434,13 @@ Forces depth-0 internal single, parallel, and chain runs into background mode an
|
|
|
434
434
|
{ "timeoutMs": 3600000 }
|
|
435
435
|
```
|
|
436
436
|
|
|
437
|
-
Global default runtime deadline, in milliseconds, for
|
|
437
|
+
Global default runtime deadline, in milliseconds, for foreground launches (single, parallel, chain, and workflow scripts) and plain single-agent async runs whenever no call-level `timeoutMs`/`maxRuntimeMs` applies. Without a configured or explicit deadline, these runs have no runtime deadline. For single-agent launches, selected agent frontmatter `timeoutMs` still wins. This only moves the *default*. Expiring this run-level deadline is terminal.
|
|
438
438
|
|
|
439
|
-
This deadline bounds the whole run. The wait for a single model response is bounded separately by Pi's `httpIdleTimeoutMs` setting (default 300000; `0` disables it), which Pi applies both as the SDK request timeout and as the undici header/body idle timeout. Detached async runners read the same setting from `~/.pi/agent/settings.json` and the project `.pi/settings.json` for their own HTTP dispatcher, so a local model that queues or prefills for longer than five minutes needs `httpIdleTimeoutMs` raised or disabled in Pi settings,
|
|
439
|
+
This deadline bounds the whole run. The wait for a single model response is bounded separately by Pi's `httpIdleTimeoutMs` setting (default 300000; `0` disables it), which Pi applies both as the SDK request timeout and as the undici header/body idle timeout. Detached async runners read the same setting from `~/.pi/agent/settings.json` and the project `.pi/settings.json` for their own HTTP dispatcher, so a local model that queues or prefills for longer than five minutes needs `httpIdleTimeoutMs` raised or disabled in Pi settings, and any configured run deadline must also allow enough time.
|
|
440
440
|
|
|
441
|
-
Use it when foreground orchestration or plain async single-agent runs need a
|
|
441
|
+
Use it when foreground orchestration or plain async single-agent runs need a default deadline. It does not set async composite top-level deadlines, and it does not replace async fan-out child deadlines.
|
|
442
442
|
|
|
443
|
-
Composite async runs (async chains, parallel tasks, and scripted workflows) stay unbounded at the top level by design. Their runner children
|
|
443
|
+
Composite async runs (async chains, parallel tasks, and scripted workflows) stay unbounded at the top level by design. Their runner children use explicit agent or runner deadlines when configured, so this value does not cap them. Must be a positive integer no greater than `2147483647` (the largest delay a Node.js timer can honor, roughly 24.8 days); invalid or out-of-range values are ignored.
|
|
444
444
|
|
|
445
445
|
## `toolTimeoutMs`
|
|
446
446
|
|
|
@@ -450,7 +450,7 @@ Composite async runs (async chains, parallel tasks, and scripted workflows) stay
|
|
|
450
450
|
|
|
451
451
|
Optional hard per-tool-call deadline in milliseconds. When configured, a child that emits `tool_execution_start` but not `tool_execution_end` is terminated with `timedOut: true` and a tool-specific error. The effective value is resolved per child: explicit `subagent` call value, then agent frontmatter, then this config value, then `PI_SUBAGENT_TOOL_TIMEOUT_MS`.
|
|
452
452
|
|
|
453
|
-
Without a configured value, Pi still applies a five-minute hard timeout to known-fast built-in tools: `read`, `grep`, `find`, `ls`, `edit`, `write`, and `structured_output`. Long-running tools such as `bash`, custom tools, and MCP tools do not get a hard default. They get the normal open-tool attention notice after `activeNoticeAfterMs` and remain bounded by
|
|
453
|
+
Without a configured value, Pi still applies a five-minute hard timeout to known-fast built-in tools: `read`, `grep`, `find`, `ls`, `edit`, `write`, and `structured_output`. Long-running tools such as `bash`, custom tools, and MCP tools do not get a hard default. They get the normal open-tool attention notice after `activeNoticeAfterMs` and remain bounded by any configured run-level deadline.
|
|
454
454
|
|
|
455
455
|
The tool timer tracks each active `toolCallId` separately and never extends the run-level deadline: when the remaining run budget is shorter, the ordinary run-level timeout wins. `contact_supervisor`, `intercom`, and `bg_wait` are exempt because their legitimate purpose can be to wait for a human, supervisor, or background run. Use hard tool timeouts only for wedge protection; an elapsed timeout is not a mutation-safe boundary. Configured values must be positive integers no greater than `2147483647`; invalid or out-of-range values are rejected with a visible error rather than silently ignored.
|
|
456
456
|
|
package/docs/observability.md
CHANGED
|
@@ -4,7 +4,7 @@ Where running subagents show up, how to inspect them, and the files and events t
|
|
|
4
4
|
|
|
5
5
|
## Foreground runs
|
|
6
6
|
|
|
7
|
-
Foreground runs stream progress in the conversation while they run. They
|
|
7
|
+
Foreground runs stream progress in the conversation while they run. They have no default wall-clock deadline unless configured; explicit `timeoutMs`/`maxRuntimeMs` and agent defaults take precedence over the global [`timeoutMs`](configuration.md#timeoutms) setting.
|
|
8
8
|
|
|
9
9
|
A foreground child is a pi session created inside the parent Pi process, not a second `pi` process. A run timeout, tool timeout, interrupt, or stop aborts the child session and disposes it. Detach keeps the session running inside the parent and publishes the same receipt and completion notification as before.
|
|
10
10
|
|
package/docs/tool-reference.md
CHANGED
|
@@ -105,7 +105,7 @@ The `subagent` tool schema lists `agent`, `task`, `workflow`, `args`, `async`, `
|
|
|
105
105
|
| `options.chatProgress` | `auto \| off \| live-card` | `auto` | Workflow chat projection. `auto` renders a live in-chat card only for watched foreground workflows in the same Git repository, including managed worktrees; it is off otherwise. Explicit `live-card` requires `async:false` and the same Git repository. Async workflows have no inline live card, so omit `chatProgress` or use `auto`/`off`; use `async:false` only when the parent must block. |
|
|
106
106
|
| `isolation` | `none \| worktree` | - | Alias kept at the top level; prefer `worktree`. Workflow child isolation. `none` runs in the shared cwd and does not need Git. `worktree` requires a managed Git worktree. Do not combine it with a contradictory `worktree` value. |
|
|
107
107
|
| `options.baseRef` | string | `HEAD` | `HEAD` or a supported named ref such as `refs/heads/release`, `refs/tags/v1`, or `origin/main`. Full 40/64-character commit IDs and revision expressions such as `HEAD~1` are unsupported. The ref must resolve to a commit at worktree allocation; omitted values default to `HEAD` resolved at that time. Source-checkout cleanliness is still checked. For a workflow script, set it on the outer request as a default or on an individual `runs.run`/`runs.all` child to override it. |
|
|
108
|
-
| `options.timeoutMs` | number | config `timeoutMs`, else
|
|
108
|
+
| `options.timeoutMs` | number | config `timeoutMs`, else none | Optional run-level max runtime in milliseconds. The top-level alias `maxRuntimeMs` is also accepted; both must agree. When omitted, the global [`timeoutMs`](configuration.md#timeoutms) config provides the default for foreground and plain single-agent async runs; otherwise no run-level deadline applies. Composite async runs (chains, parallel tasks, workflows) stay unbounded at the top level unless explicitly bounded. Expiration of a run-level deadline is terminal. |
|
|
109
109
|
| `options.toolTimeoutMs` | number | fast-tool default | Optional positive hard per-tool-call deadline in milliseconds. Precedence: call value → agent frontmatter → config → `PI_SUBAGENT_TOOL_TIMEOUT_MS`. The timer starts on `tool_execution_start`, clears on the matching `tool_execution_end`, and terminates the run with `timedOut: true` if the tool remains open. When omitted, known-fast built-in tools get a five-minute default; long-running tools get attention notices but no hard default. It never extends the run deadline; `contact_supervisor`, `intercom`, and `bg_wait` are exempt. |
|
|
110
110
|
| `options.checkpointBeforeDeadlineMs` | number | none | Async single-agent runs only. The runner requests that the child "checkpoint and stop" this many milliseconds before the run deadline (finish the current tool call, report changed files, build/test state, remaining work, commit/PR state; start no new work). This best-effort steer uses the normal steering lifecycle at the next tool boundary, so the receipt is visible in status and events; the ordinary deadline kill still applies. Precedence: call value → config `checkpointBeforeDeadlineMs`. Disarmed when the deadline leaves under one second before the checkpoint. |
|
|
111
111
|
| `options.toolBudget` | object | none | Optional child tool-call budget `{ soft?, hard, block? }`: `hard` is a positive integer and `soft`, if set, is a positive integer no greater than `hard`. At `soft` the child is nudged to finalize. After `hard`, configured tools are blocked; `block` defaults to `read`, `grep`, `find`, and `ls`, and accepts either a nonempty array of tool names or `"*"` for every tool call. Final assistant text is never blocked. |
|
package/docs/workflows.md
CHANGED
|
@@ -445,7 +445,7 @@ known, or for explicit emergency hotfix lanes.
|
|
|
445
445
|
/prompt-workflow review-release-candidate v0.51.0
|
|
446
446
|
```
|
|
447
447
|
|
|
448
|
-
For watched same-repo workflows, pass `async:false` only when the parent must block until completion. That blocking mode also shows the live in-chat workflow card. `chatProgress` can force `off` or `live-card` when the automatic policy is not what you want. Blocking workflows
|
|
448
|
+
For watched same-repo workflows, pass `async:false` only when the parent must block until completion. That blocking mode also shows the live in-chat workflow card. `chatProgress` can force `off` or `live-card` when the automatic policy is not what you want. Blocking and async workflows have no implicit runtime deadline; explicitly configured deadlines still apply. See the [tool reference](tool-reference.md) for the full parameter list.
|
|
449
449
|
|
|
450
450
|
Synchronous workflows publish trace and `emit(...)` updates through the tool update callback regardless of `chatProgress`, including RPC/headless and cross-repository runs. These updates include `details.workflow` and `details.workflowChildren`; `chatProgress: "off"` disables the live card, not transport progress. Once a child launches, its running row carries its `agent` and `runId`; for a child running in the background, that `runId` is the id of its run node in the `subagent-async` snapshot. Running foreground child rows additionally expose bounded `activity` (current tool, timing, and counters), plus resolved model/thinking when available, keyed by `childId`. Activity-only updates coalesce over 100 ms; lifecycle updates remain immediate. Activity clears when children settle, and is not persisted for async workflows. Tool names are limited to 256 UTF-8 bytes and each activity object is below 2 KiB (including JSON escaping); arguments and transcripts are not forwarded.
|
|
451
451
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@vicary/pi-subagents",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.84.0-1",
|
|
5
5
|
"description": "Pi extension for single-agent delegation and scripted multi-agent workflows",
|
|
6
6
|
"author": "Nico Bailon",
|
|
7
7
|
"license": "MIT",
|
|
@@ -135,5 +135,5 @@
|
|
|
135
135
|
"./prompts"
|
|
136
136
|
]
|
|
137
137
|
},
|
|
138
|
-
"gitHead": "
|
|
138
|
+
"gitHead": "121308bff7cb30787835d0128ec923982a199721"
|
|
139
139
|
}
|
package/src/extension/schemas.js
CHANGED
|
@@ -219,7 +219,7 @@ const SubagentParamProperties = {
|
|
|
219
219
|
description: "fresh/fork overrides every child; profile requires agent's declared defaultContext, ignoring config. Omitted: defaultSubagentContext wins over each agent defaultContext; implicit fork needs persisted parent + leaf, else fresh. forkContext may prune forks before spawn.",
|
|
220
220
|
})),
|
|
221
221
|
async: Type.Optional(Type.Boolean({ description: "Background; default asyncByDefault. false only to block parent." })),
|
|
222
|
-
timeoutMs: Type.Optional(Type.Integer({ minimum: 1, description: "Foreground and single async runs use config timeoutMs
|
|
222
|
+
timeoutMs: Type.Optional(Type.Integer({ minimum: 1, description: "Foreground and single async runs use config timeoutMs when set; otherwise no runtime deadline. Async composites have no default parent deadline. Alias maxRuntimeMs; must agree." })),
|
|
223
223
|
maxRuntimeMs: Type.Optional(Type.Integer({ minimum: 1, description: "Alias timeoutMs (same defaults)." })),
|
|
224
224
|
checkpointBeforeDeadlineMs: Type.Optional(Type.Integer({ minimum: 1, maximum: 2_147_483_647, description: "Async single-agent runs only: the runner requests that the child checkpoint and stop this many ms before the run deadline (best-effort; the deadline kill still applies)." })),
|
|
225
225
|
toolTimeoutMs: Type.Optional(Type.Integer({ minimum: 1, description: "Per-tool deadline (ms); fast builtins default 5m." })),
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Async execution logic for subagent tool
|
|
3
3
|
*/
|
|
4
4
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import type { ParentProviderRegistry } from "../shared/child-session.ts";
|
|
5
6
|
import { type AgentConfig, type UnknownAgentDiagnosticContext } from "../../agents/agents.ts";
|
|
6
7
|
import { type ClaudeCodeOverride } from "../shared/claude-code-adapter.ts";
|
|
7
8
|
import { type ChainStep } from "../../shared/settings.ts";
|
|
@@ -44,8 +45,9 @@ interface AsyncExecutionContext {
|
|
|
44
45
|
childRuntime?: ChildRuntimeConfig;
|
|
45
46
|
/** The launching session's project trust; undefined when the host has no trust concept. */
|
|
46
47
|
projectTrusted?: boolean;
|
|
48
|
+
/** The parent's model registry, read at launch to name a provider an extension registered there. */
|
|
49
|
+
parentProviderRegistry?: Pick<ParentProviderRegistry, "getRegisteredProviderIds">;
|
|
47
50
|
}
|
|
48
|
-
export declare const DEFAULT_ASYNC_TIMEOUT_MS: number;
|
|
49
51
|
interface AsyncChainParams {
|
|
50
52
|
chain: ChainStep[];
|
|
51
53
|
task?: string;
|
|
@@ -135,7 +135,17 @@ function supportsNativeRunner(nodeExecutable) {
|
|
|
135
135
|
&& nodeExecutable === process.execPath
|
|
136
136
|
&& !sourceUnderNodeModules();
|
|
137
137
|
}
|
|
138
|
-
|
|
138
|
+
/**
|
|
139
|
+
* A runner child without the ambient extensions does not load the parent extension that
|
|
140
|
+
* registered its model's provider, and still resolves the model when a built-in provider
|
|
141
|
+
* has the same id. Name that provider so a failed run can say so.
|
|
142
|
+
*/
|
|
143
|
+
function parentExtensionProviderForChild(ctx, disableAmbientExtensions, model, availableModels, preferredProvider) {
|
|
144
|
+
if (!disableAmbientExtensions || !ctx.parentProviderRegistry)
|
|
145
|
+
return undefined;
|
|
146
|
+
const provider = findModelInfo(model, availableModels, preferredProvider)?.provider;
|
|
147
|
+
return provider && ctx.parentProviderRegistry.getRegisteredProviderIds().includes(provider) ? provider : undefined;
|
|
148
|
+
}
|
|
139
149
|
export function formatAsyncStartedMessage(headline, interactive) {
|
|
140
150
|
const guidance = interactive
|
|
141
151
|
? [
|
|
@@ -997,6 +1007,7 @@ export function buildAsyncRunnerSteps(id, params) {
|
|
|
997
1007
|
runtimeSnapshotHost: ctx.pi,
|
|
998
1008
|
});
|
|
999
1009
|
const launchResolvedExtensions = externalRunner ? undefined : projectLaunchResolvedChildExtensions(toolPlan);
|
|
1010
|
+
const parentExtensionProvider = externalRunner || machine ? undefined : parentExtensionProviderForChild(ctx, toolPlan.disableAmbientExtensions, selectedModel, availableModels, a.modelProvider ?? ctx.currentModelProvider);
|
|
1000
1011
|
if (externalRunner && permissionRules) {
|
|
1001
1012
|
throw new AsyncStartValidationError(`Agent '${a.name}' uses runner.type='${externalRunnerType}', which cannot enforce native Pi child permission rules.`);
|
|
1002
1013
|
}
|
|
@@ -1026,6 +1037,7 @@ export function buildAsyncRunnerSteps(id, params) {
|
|
|
1026
1037
|
thinking: resolveEffectiveThinking(selectedModel, effectiveThinking),
|
|
1027
1038
|
...(thinkingCeiling ? { thinkingCeiling } : {}),
|
|
1028
1039
|
launchResolvedExtensions,
|
|
1040
|
+
...(parentExtensionProvider ? { parentExtensionProvider } : {}),
|
|
1029
1041
|
...(requestedModel ? { requestedModel } : {}),
|
|
1030
1042
|
...(primaryModelFromParent ? { skipPrimaryModelVerification: true } : {}),
|
|
1031
1043
|
...(availableModels && availableModels.length > 0 ? { modelVerificationRegistry: availableModels } : {}),
|
|
@@ -1051,7 +1063,7 @@ export function buildAsyncRunnerSteps(id, params) {
|
|
|
1051
1063
|
outputMode: behavior.outputMode,
|
|
1052
1064
|
sessionFile,
|
|
1053
1065
|
maxSubagentDepth: resolveChildMaxSubagentDepth(maxSubagentDepth, a.maxSubagentDepth),
|
|
1054
|
-
timeoutMs: a.defaultTimeoutMs
|
|
1066
|
+
timeoutMs: a.defaultTimeoutMs,
|
|
1055
1067
|
toolTimeoutMs: resolvedToolTimeout.toolTimeoutMs,
|
|
1056
1068
|
waitToolEnabled: params.waitToolEnabled,
|
|
1057
1069
|
waitToolDefaultTimeoutMs: params.waitToolDefaultTimeoutMs,
|
|
@@ -1811,6 +1823,7 @@ export function executeAsyncSingle(id, params) {
|
|
|
1811
1823
|
runtimeSnapshotHost: ctx.pi,
|
|
1812
1824
|
});
|
|
1813
1825
|
const launchResolvedExtensions = externalRunner ? undefined : projectLaunchResolvedChildExtensions(toolPlan);
|
|
1826
|
+
const parentExtensionProvider = externalRunner || machine ? undefined : parentExtensionProviderForChild(ctx, toolPlan.disableAmbientExtensions, selectedModel, availableModels, agentConfig.modelProvider ?? ctx.currentModelProvider);
|
|
1814
1827
|
const fast = params.fast ?? agentConfig.fast;
|
|
1815
1828
|
const launchThinking = resolveEffectiveThinking(selectedModel, effectiveThinking);
|
|
1816
1829
|
const { definitionDigest, launchContractDigest } = resolveLaunchBinding({
|
|
@@ -1933,6 +1946,7 @@ export function executeAsyncSingle(id, params) {
|
|
|
1933
1946
|
...(params.fast ?? agentConfig.fast ? { fast: params.fast ?? agentConfig.fast } : {}),
|
|
1934
1947
|
thinking: resolveEffectiveThinking(selectedModel, effectiveThinking),
|
|
1935
1948
|
...(thinkingCeiling ? { thinkingCeiling } : {}),
|
|
1949
|
+
...(parentExtensionProvider ? { parentExtensionProvider } : {}),
|
|
1936
1950
|
...(requestedModel ? { requestedModel } : {}),
|
|
1937
1951
|
...(modelOrigin === "inherited" ? { skipPrimaryModelVerification: true } : {}),
|
|
1938
1952
|
...(availableModels && availableModels.length > 0 ? { modelVerificationRegistry: availableModels } : {}),
|
|
@@ -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;
|
|
@@ -15,7 +15,11 @@ export const ASYNC_RETENTION_DAYS = 30;
|
|
|
15
15
|
export const ASYNC_RETENTION_BATCH_SIZE = 100;
|
|
16
16
|
export const ASYNC_RETENTION_DELAY_MS = 60_000;
|
|
17
17
|
export const ASYNC_RETENTION_TOMBSTONE_GRACE_MS = 24 * 60 * 60 * 1000;
|
|
18
|
+
// A run or result whose session file still exists can be resumed, so it is kept this long
|
|
19
|
+
// instead of ASYNC_RETENTION_DAYS. Session files outlive run dirs, so without a ceiling it is kept forever.
|
|
20
|
+
export const RESUMABLE_RETENTION_DAYS = 90;
|
|
18
21
|
const RETENTION_MS = ASYNC_RETENTION_DAYS * 24 * 60 * 60 * 1000;
|
|
22
|
+
const RESUMABLE_RETENTION_MS = RESUMABLE_RETENTION_DAYS * 24 * 60 * 60 * 1000;
|
|
19
23
|
const LOCK_NAME = ".async-retention.lock";
|
|
20
24
|
const CURSOR_NAME = ".async-retention-cursor.json";
|
|
21
25
|
const LOG_NAME = "async-retention-maintenance.jsonl";
|
|
@@ -239,9 +243,10 @@ function runSkipReason(input) {
|
|
|
239
243
|
return "mission-reference";
|
|
240
244
|
if (hasUnresolvedRunHandoff(runDir, status))
|
|
241
245
|
return "handoff-reference";
|
|
242
|
-
if (hasResumableContract(runDir, status))
|
|
243
|
-
return "resumable";
|
|
244
246
|
const timestamp = statusTimestamp(status, runDir);
|
|
247
|
+
// Unknown ages stay protected.
|
|
248
|
+
if (hasResumableContract(runDir, status) && (timestamp === undefined || timestamp > input.resumableCutoff))
|
|
249
|
+
return "resumable";
|
|
245
250
|
if (timestamp === undefined)
|
|
246
251
|
return "unknown-age";
|
|
247
252
|
if (timestamp > input.cutoff)
|
|
@@ -464,13 +469,13 @@ function resultSkipReason(input) {
|
|
|
464
469
|
return "workflow-reference";
|
|
465
470
|
if (hasUnresolvedResultHandoff(input.data))
|
|
466
471
|
return "handoff-reference";
|
|
467
|
-
|
|
472
|
+
const timestamp = resultTimestamp(input.data, input.candidate.path);
|
|
473
|
+
if (resultHasResumableSession(input.data) && (timestamp === undefined || timestamp > input.resumableCutoff))
|
|
468
474
|
return "resumable";
|
|
469
475
|
if (input.candidate.kind === "archive" && fs.existsSync(path.join(input.resultsDir, "completion-replay", `${encodeURIComponent(runId)}.json`)))
|
|
470
476
|
return "replay-reference";
|
|
471
477
|
if (!terminalResult(input.data) && input.candidate.kind !== "replay" && input.candidate.kind !== "archive" && input.candidate.kind !== "tombstone")
|
|
472
478
|
return "non-terminal-result";
|
|
473
|
-
const timestamp = resultTimestamp(input.data, input.candidate.path);
|
|
474
479
|
if (timestamp === undefined)
|
|
475
480
|
return "unknown-age";
|
|
476
481
|
if (timestamp > input.cutoff)
|
|
@@ -690,6 +695,7 @@ export async function cleanupAsyncRetention(options) {
|
|
|
690
695
|
return finish();
|
|
691
696
|
const protectedRunIds = new Set(options.protectedRunIds ?? []);
|
|
692
697
|
const cutoff = currentTime - retentionMs;
|
|
698
|
+
const resumableCutoff = currentTime - RESUMABLE_RETENTION_MS;
|
|
693
699
|
const cursor = readCursor(maintenanceRoot);
|
|
694
700
|
const runBudget = Math.ceil(batchSize / 2);
|
|
695
701
|
const resultBudget = batchSize - runBudget;
|
|
@@ -765,7 +771,7 @@ export async function cleanupAsyncRetention(options) {
|
|
|
765
771
|
if (reconciliation.repaired)
|
|
766
772
|
result.repairedRuns += 1;
|
|
767
773
|
}
|
|
768
|
-
const initialReason = runSkipReason({ runDir, status, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, cutoff, protectedRunIds, waitRunIds: waitReferences.runIds });
|
|
774
|
+
const initialReason = runSkipReason({ runDir, status, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, cutoff, resumableCutoff, protectedRunIds, waitRunIds: waitReferences.runIds });
|
|
769
775
|
if (initialReason) {
|
|
770
776
|
increment(result.skipped, initialReason);
|
|
771
777
|
continue;
|
|
@@ -780,7 +786,7 @@ export async function cleanupAsyncRetention(options) {
|
|
|
780
786
|
continue;
|
|
781
787
|
}
|
|
782
788
|
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";
|
|
789
|
+
const finalReason = freshWaitReferences.safe ? runSkipReason({ runDir, status, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, cutoff, resumableCutoff, protectedRunIds, waitRunIds: freshWaitReferences.runIds }) : "wait-references-unknown";
|
|
784
790
|
if (finalReason) {
|
|
785
791
|
increment(result.skipped, `recheck-${finalReason}`);
|
|
786
792
|
continue;
|
|
@@ -805,7 +811,7 @@ export async function cleanupAsyncRetention(options) {
|
|
|
805
811
|
}
|
|
806
812
|
const recheckStatus = readStatus(tombstone);
|
|
807
813
|
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";
|
|
814
|
+
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
815
|
if (recheckReason) {
|
|
810
816
|
if (!fs.existsSync(runDir)) {
|
|
811
817
|
fs.renameSync(tombstone, runDir);
|
|
@@ -842,7 +848,7 @@ export async function cleanupAsyncRetention(options) {
|
|
|
842
848
|
continue;
|
|
843
849
|
}
|
|
844
850
|
const data = readJson(candidate.path);
|
|
845
|
-
const reason = resultSkipReason({ candidate, data, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, maintenanceRoot, cutoff, protectedRunIds, waitRunIds: waitReferences.runIds });
|
|
851
|
+
const reason = resultSkipReason({ candidate, data, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, maintenanceRoot, cutoff, resumableCutoff, protectedRunIds, waitRunIds: waitReferences.runIds });
|
|
846
852
|
if (reason) {
|
|
847
853
|
increment(result.skipped, reason);
|
|
848
854
|
continue;
|
|
@@ -853,7 +859,7 @@ export async function cleanupAsyncRetention(options) {
|
|
|
853
859
|
continue;
|
|
854
860
|
}
|
|
855
861
|
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";
|
|
862
|
+
const finalReason = freshWaitReferences.safe ? resultSkipReason({ candidate, data, asyncDirRoot: options.asyncDirRoot, resultsDir: options.resultsDir, maintenanceRoot, cutoff, resumableCutoff, protectedRunIds, waitRunIds: freshWaitReferences.runIds }) : "wait-references-unknown";
|
|
857
863
|
if (finalReason) {
|
|
858
864
|
increment(result.skipped, `recheck-${finalReason}`);
|
|
859
865
|
continue;
|
|
@@ -870,7 +876,7 @@ export async function cleanupAsyncRetention(options) {
|
|
|
870
876
|
const tombstoneCandidate = { ...candidate, path: tombstone, kind: "tombstone" };
|
|
871
877
|
const recheckData = readJson(tombstone);
|
|
872
878
|
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";
|
|
879
|
+
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
880
|
if (recheckReason) {
|
|
875
881
|
if (!fs.existsSync(candidate.path)) {
|
|
876
882
|
fs.renameSync(tombstone, candidate.path);
|
|
@@ -2,7 +2,6 @@ import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
|
2
2
|
import type { Details, SubagentState } from "../../shared/types.ts";
|
|
3
3
|
import type { ReadonlyDrainObservation } from "../shared/readonly-drain-observation.ts";
|
|
4
4
|
import { type SubagentWaitDeps, type SubagentWaitParams, type WaitEventBus } from "./subagent-wait.ts";
|
|
5
|
-
export declare const DEFAULT_AUTO_DRAIN_TIMEOUT_MS: number;
|
|
6
5
|
export interface AutoDrainDeps extends Pick<SubagentWaitDeps, "asyncDirRoot" | "resultsDir" | "nestedRootRunId"> {
|
|
7
6
|
state: SubagentState;
|
|
8
7
|
events?: WaitEventBus;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { listAsyncRuns } from "./async-status.js";
|
|
2
2
|
import { backgroundWorkForSession, waitForSubagents, waitRunScopes } from "./subagent-wait.js";
|
|
3
|
-
|
|
3
|
+
const AUTO_DRAIN_WAIT_WINDOW_MS = 30 * 60 * 1000;
|
|
4
4
|
function resultText(value) {
|
|
5
5
|
return value.content.map((part) => part.type === "text" ? part.text : "").join(" ").trim();
|
|
6
6
|
}
|
|
@@ -23,10 +23,10 @@ export async function drainOutstandingWork(deps, observation) {
|
|
|
23
23
|
if (!sessionId)
|
|
24
24
|
throw new Error("Cannot auto-drain background work without an active session identity.");
|
|
25
25
|
const now = deps.now ?? Date.now;
|
|
26
|
-
const timeoutMs = deps.timeoutMs
|
|
27
|
-
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0)
|
|
26
|
+
const timeoutMs = deps.timeoutMs;
|
|
27
|
+
if (timeoutMs !== undefined && (!Number.isFinite(timeoutMs) || timeoutMs <= 0))
|
|
28
28
|
throw new Error("Auto-drain timeoutMs must be a positive finite number.");
|
|
29
|
-
const deadlineAt = now() + timeoutMs;
|
|
29
|
+
const deadlineAt = timeoutMs === undefined ? undefined : now() + timeoutMs;
|
|
30
30
|
const hasWork = deps.hasWork ?? ((id, time) => hasOutstandingWork(deps, id, time, observation));
|
|
31
31
|
const wait = deps.wait ?? waitForSubagents;
|
|
32
32
|
while (true) {
|
|
@@ -38,7 +38,7 @@ export async function drainOutstandingWork(deps, observation) {
|
|
|
38
38
|
observation?.predicate(work);
|
|
39
39
|
if (!work)
|
|
40
40
|
break;
|
|
41
|
-
const remainingMs = deadlineAt - now();
|
|
41
|
+
const remainingMs = deadlineAt === undefined ? AUTO_DRAIN_WAIT_WINDOW_MS : deadlineAt - now();
|
|
42
42
|
if (remainingMs <= 0) {
|
|
43
43
|
throw new Error(`Auto-drain timed out after ${timeoutMs}ms with background work still active in session '${sessionId}'.`);
|
|
44
44
|
}
|
|
@@ -83,6 +83,8 @@ export interface RunChildSessionInput {
|
|
|
83
83
|
}>;
|
|
84
84
|
modelResponseAliases?: Record<string, string[]>;
|
|
85
85
|
mutationTools?: readonly string[];
|
|
86
|
+
/** Provider of the launch model that a parent extension registered and this child does not load. */
|
|
87
|
+
parentExtensionProvider?: string;
|
|
86
88
|
}
|
|
87
89
|
export interface RunChildSessionResult {
|
|
88
90
|
exitCode: number;
|
|
@@ -3,7 +3,7 @@ import { qualifyModelWithProvider } from "../../shared/model-info.js";
|
|
|
3
3
|
import { acceptChildWatchdogEvent, applyChildWatchdogMessage, childWatchdogIsActive, isChildWatchdogStatusEvent, } from "../../watchdog/child-status.js";
|
|
4
4
|
import { projectChildLifecycle } from "../shared/child-lifecycle.js";
|
|
5
5
|
import { formatSubagentModelVerificationError } from "../shared/model-resolution.js";
|
|
6
|
-
import { formatChildModelResolutionDiagnostic, isChildModelResolutionFailure } from "../shared/model-resolution-diagnostic.js";
|
|
6
|
+
import { formatChildModelResolutionDiagnostic, formatMissingParentProviderDiagnostic, isChildModelResolutionFailure } from "../shared/model-resolution-diagnostic.js";
|
|
7
7
|
import { isMutatingTool, resolveCurrentPath } from "../shared/long-running-guard.js";
|
|
8
8
|
import { effectiveToolTimeoutMs, formatToolTimeoutMessage, toolTimeoutCallKey } from "../shared/tool-timeout.js";
|
|
9
9
|
import { createReportedChildSessionInput } from "../shared/child-launch.js";
|
|
@@ -520,6 +520,14 @@ export function runChildSession(input) {
|
|
|
520
520
|
&& !input.launch.session.ambientExtensions) {
|
|
521
521
|
finalError = `${promptErrorMessage}\n\n${formatChildModelResolutionDiagnostic({ agent: input.launch.config.agent, model: input.launch.session.model, host: "runner", capabilityCeiling: input.launch.toolPlan.capabilityCeiling })}`;
|
|
522
522
|
}
|
|
523
|
+
else if (input.parentExtensionProvider
|
|
524
|
+
&& session?.claimedProvider !== input.parentExtensionProvider
|
|
525
|
+
&& finalError !== undefined
|
|
526
|
+
&& (finalError === promptErrorMessage || finalError === assistantError)
|
|
527
|
+
&& toolCount === 0
|
|
528
|
+
&& messages.every((message) => message.role !== "assistant" || message.stopReason === "error")) {
|
|
529
|
+
finalError = `${finalError}\n\n${formatMissingParentProviderDiagnostic({ agent: input.launch.config.agent, model: input.launch.session.model, provider: input.parentExtensionProvider, capabilityCeiling: input.launch.toolPlan.capabilityCeiling })}`;
|
|
530
|
+
}
|
|
523
531
|
const forcedDrainAfterFinalSuccess = (forced || forcedTermination) && (cleanTerminalAssistantStopReceived || agentSettledReceived) && !finalError;
|
|
524
532
|
const forcedDrainAfterEmptyTerminal = forcedDrainAfterFinalSuccess && hasEmptyTerminalAssistantResponse(messages);
|
|
525
533
|
if (!finalError && forced && !forcedDrainAfterFinalSuccess && !interrupted && !timedOut && !stopped) {
|