@xzzpig/pi-subagents 0.2.0 → 0.4.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 +96 -0
- package/README.md +2 -0
- package/agents/oracle.md +7 -5
- package/agents/researcher.md +1 -1
- package/agents/reviewer.md +2 -2
- package/agents/scout.md +1 -1
- package/agents/worker.md +1 -1
- package/docs/agents.md +3 -0
- package/docs/configuration.md +121 -10
- package/docs/extension-api.md +36 -0
- package/docs/missions.md +5 -3
- package/docs/observability.md +43 -3
- package/docs/tool-reference.md +20 -3
- package/docs/workflows.md +2 -2
- package/package.json +4 -4
- package/skills/pi-subagents/references/constraints-and-recipes.md +3 -2
- package/skills/pi-subagents/references/execution-controls.md +5 -4
- package/skills/pi-subagents/references/management-authoring-rpc.md +2 -2
- package/skills/pi-subagents/references/prompting-and-roles.md +31 -15
- package/src/agents/agent-serializer.ts +2 -0
- package/src/agents/agents.ts +46 -15
- package/src/api/external-runs.ts +174 -84
- package/src/api/preflight.ts +13 -7
- package/src/extension/config.ts +59 -0
- package/src/extension/doctor.ts +40 -0
- package/src/extension/index.ts +83 -9
- package/src/extension/public-execution.ts +37 -4
- package/src/extension/rpc.ts +8 -10
- package/src/extension/schemas.ts +12 -10
- package/src/extension/tool-description.ts +13 -9
- package/src/inspectors/herdr/actions.ts +13 -8
- package/src/inspectors/herdr/inspector-runner.ts +16 -3
- package/src/inspectors/herdr/project-panes.ts +2 -6
- package/src/inspectors/herdr/shell-command.ts +16 -0
- package/src/intercom/intercom-bridge.ts +9 -5
- package/src/intercom/native-supervisor-channel.ts +19 -42
- package/src/missions/goal-driver.ts +3 -1
- package/src/missions/lifecycle.ts +4 -7
- package/src/missions/store.ts +12 -7
- package/src/missions/workflow-state.ts +6 -2
- package/src/runs/background/active-async-capacity.ts +431 -0
- package/src/runs/background/active-run-index.ts +77 -3
- package/src/runs/background/async-execution.ts +190 -72
- package/src/runs/background/async-job-tracker.ts +5 -0
- package/src/runs/background/async-resume.ts +21 -7
- package/src/runs/background/async-status-snapshot.ts +277 -0
- package/src/runs/background/async-status.ts +17 -6
- package/src/runs/background/chain-append.ts +33 -15
- package/src/runs/background/chain-root-attachment.ts +2 -2
- package/src/runs/background/completion-replay.ts +11 -1
- package/src/runs/background/fleet-view.ts +21 -6
- package/src/runs/background/owned-process-tree.ts +104 -0
- package/src/runs/background/process-terminal.ts +17 -3
- package/src/runs/background/result-files.ts +437 -0
- package/src/runs/background/result-watcher.ts +188 -41
- package/src/runs/background/resume-guidance.ts +27 -7
- package/src/runs/background/retained-children.ts +75 -18
- package/src/runs/background/run-id-resolver.ts +30 -24
- package/src/runs/background/run-status.ts +106 -5
- package/src/runs/background/scheduled-runs.ts +54 -28
- package/src/runs/background/stale-run-reconciler.ts +30 -16
- package/src/runs/background/subagent-runner.ts +352 -62
- package/src/runs/background/subagent-wait.ts +2 -0
- package/src/runs/background/wait-completions.ts +5 -2
- package/src/runs/foreground/async-dismiss-action.ts +2 -1
- package/src/runs/foreground/chain-execution.ts +53 -2
- package/src/runs/foreground/execution.ts +309 -34
- package/src/runs/foreground/foreground-control.ts +12 -0
- package/src/runs/foreground/prompt-audit.ts +172 -0
- package/src/runs/foreground/subagent-executor.ts +936 -224
- package/src/runs/shared/acceptance.ts +13 -4
- package/src/runs/shared/completion-guard.ts +107 -1
- package/src/runs/shared/external-cli-runner.ts +4 -0
- package/src/runs/shared/llm-intent-arbiter.ts +302 -0
- package/src/runs/shared/model-fallback.ts +16 -2
- package/src/runs/shared/nested-events.ts +66 -62
- package/src/runs/shared/orca-progress-tabs.ts +375 -0
- package/src/runs/shared/parallel-utils.ts +4 -0
- package/src/runs/shared/pi-args.ts +44 -1
- package/src/runs/shared/run-fanout-budget.ts +280 -0
- package/src/runs/shared/single-output.ts +4 -2
- package/src/runs/shared/subagent-control.ts +15 -0
- package/src/runs/shared/subagent-prompt-runtime.ts +1 -9
- package/src/runs/shared/subagent-startup-retry.ts +12 -0
- package/src/runs/shared/task-intent.ts +19 -3
- package/src/runs/shared/tool-timeout.ts +93 -0
- package/src/runs/shared/worktree.ts +17 -5
- package/src/shared/agent-stream-options.ts +5 -0
- package/src/shared/artifacts.ts +2 -6
- package/src/shared/display-text.ts +50 -0
- package/src/shared/node-executable.ts +21 -0
- package/src/shared/types.ts +143 -5
- package/src/shared/utils.ts +3 -1
- package/src/slash/slash-commands.ts +34 -25
- package/src/slash/slash-live-state.ts +3 -0
- package/src/tui/fleet-status.ts +164 -47
- package/src/tui/fleet-transcript.ts +1 -48
- package/src/tui/fleet.ts +352 -27
- package/src/tui/render.ts +122 -44
- package/src/watchdog/permission-arbiter.ts +2 -1
- package/src/watchdog/review.ts +4 -3
- package/src/workflows/chat-progress.ts +10 -2
- package/src/workflows/scripted-workflow.ts +292 -79
|
@@ -19,10 +19,12 @@ import { buildChainInstructions, isCheckpointStep, isDynamicParallelStep, isPara
|
|
|
19
19
|
import type { RunnerStep } from "../shared/parallel-utils.ts";
|
|
20
20
|
import type { ContextMode } from "../shared/context-mode.ts";
|
|
21
21
|
import { resolvePiPackageRoot } from "../shared/pi-spawn.ts";
|
|
22
|
+
import { resolveNodeExecutable } from "../../shared/node-executable.ts";
|
|
22
23
|
import { buildSkillInjection, normalizeSkillInput, resolveSkillsWithFallback } from "../../agents/skills.ts";
|
|
23
24
|
import { buildAgentMemoryInjection } from "../../agents/agent-memory.ts";
|
|
24
|
-
import { PI_CODING_AGENT_PACKAGE_ROOT_ENV, resolveChildCwd } from "../../shared/utils.ts";
|
|
25
|
+
import { PI_CODING_AGENT_PACKAGE_ROOT_ENV, PROMPT_REDACTED, resolveChildCwd } from "../../shared/utils.ts";
|
|
25
26
|
import { buildModelCandidates, resolveEffectiveSubagentModel, resolveModelCandidate, resolveSubagentModelOverride, type AvailableModelInfo, type ParentModel } from "../shared/model-fallback.ts";
|
|
27
|
+
import { resolveToolTimeoutMs, toolTimeoutFromEnv } from "../shared/tool-timeout.ts";
|
|
26
28
|
import type { ModelScopeConfig } from "../shared/model-scope.ts";
|
|
27
29
|
import { resolveEffectiveThinking } from "../../shared/model-info.ts";
|
|
28
30
|
import { resolveExpectedWorktreeAgentCwd } from "../shared/worktree.ts";
|
|
@@ -30,17 +32,21 @@ import { buildWorkflowGraphSnapshot } from "../shared/workflow-graph.ts";
|
|
|
30
32
|
import { ChainOutputValidationError, validateChainOutputBindings } from "../shared/chain-outputs.ts";
|
|
31
33
|
import { createStructuredOutputRuntime } from "../shared/structured-output.ts";
|
|
32
34
|
import { resolveEffectiveAcceptance, validateAcceptanceInput, validateExecutionAcceptance } from "../shared/acceptance.ts";
|
|
35
|
+
import { createRunFanoutBudget, writeRunFanoutBudgetDescriptor } from "../shared/run-fanout-budget.ts";
|
|
33
36
|
import {
|
|
34
37
|
type AcceptanceInput,
|
|
35
38
|
type AgentContract,
|
|
39
|
+
type AsyncStatus,
|
|
36
40
|
type ArtifactConfig,
|
|
37
41
|
type Details,
|
|
42
|
+
type IntercomBridgeConfig,
|
|
38
43
|
type JsonSchemaObject,
|
|
39
44
|
type MaxOutputConfig,
|
|
40
45
|
type NestedRouteInfo,
|
|
41
46
|
type ResolvedControlConfig,
|
|
42
47
|
type ResolvedTurnBudget,
|
|
43
48
|
type ResolvedToolBudget,
|
|
49
|
+
type RunFanoutBudgetDescriptor,
|
|
44
50
|
type ToolBudgetConfig,
|
|
45
51
|
type SubagentRunMode,
|
|
46
52
|
type SteeringRecoveryDescriptor,
|
|
@@ -53,12 +59,14 @@ import {
|
|
|
53
59
|
resolveChildMaxSubagentDepth,
|
|
54
60
|
} from "../../shared/types.ts";
|
|
55
61
|
import { nestedResultsPath, nestedSummaryFromAsyncStatus, resolveInheritedNestedRouteFromEnv, resolveNestedParentAddressFromEnv, writeNestedEvent } from "../shared/nested-events.ts";
|
|
62
|
+
import { resultFilePath } from "./result-files.ts";
|
|
56
63
|
import { appendTurnBudgetSystemPrompt, initialTurnBudgetState } from "../shared/turn-budget.ts";
|
|
57
64
|
import { validateToolBudgetConfig } from "../shared/tool-budget.ts";
|
|
58
65
|
import { usageBudgetState } from "../shared/usage-budget.ts";
|
|
59
66
|
import type { ImportedAsyncRoot } from "./chain-root-attachment.ts";
|
|
60
67
|
import type { SessionLeaseRequest } from "../shared/session-lease.ts";
|
|
61
68
|
import { finalizeProcessTerminal, readProcessTerminal } from "./process-terminal.ts";
|
|
69
|
+
import type { ActiveAsyncCapacityHandle } from "./active-async-capacity.ts";
|
|
62
70
|
import { SUBAGENT_PROCESS_TERMINAL_EVENT } from "../../shared/types.ts";
|
|
63
71
|
import { assertAgentAllowedByCapabilityCeiling, decodeSubagentCapabilityCeiling, intersectSubagentCapabilityCeilings, resolveCurrentSubagentCapabilityCeiling, SUBAGENT_CAPABILITY_CEILING_ENV, type ResolvedSubagentCapabilityCeiling } from "../shared/capability-ceiling.ts";
|
|
64
72
|
import { agentDefinitionDigest, launchBindingDigest } from "../../shared/launch-contract.ts";
|
|
@@ -168,11 +176,19 @@ interface AsyncChainParams {
|
|
|
168
176
|
toolBudget?: ResolvedToolBudget;
|
|
169
177
|
usageBudget?: UsageBudgetConfig;
|
|
170
178
|
configToolBudget?: ResolvedToolBudget;
|
|
179
|
+
/** Optional per-call hard toolTimeoutMs override (highest precedence). */
|
|
180
|
+
callToolTimeoutMs?: number;
|
|
181
|
+
/** Global config.toolTimeoutMs (third precedence, after agent frontmatter). */
|
|
182
|
+
configToolTimeoutMs?: number;
|
|
183
|
+
/** PI_SUBAGENT_TOOL_TIMEOUT_MS override (lowest precedence). */
|
|
184
|
+
toolTimeoutMsEnv?: string | undefined;
|
|
171
185
|
/** Global cap on simultaneously-running subagent tasks within the async run. */
|
|
172
186
|
globalConcurrencyLimit?: number;
|
|
173
187
|
capabilityCeiling?: ResolvedSubagentCapabilityCeiling;
|
|
188
|
+
runFanoutBudget?: RunFanoutBudgetDescriptor;
|
|
174
189
|
parentWorkflowRunId?: string;
|
|
175
190
|
workflowKey?: string;
|
|
191
|
+
activeAsyncCapacity?: ActiveAsyncCapacityHandle;
|
|
176
192
|
}
|
|
177
193
|
|
|
178
194
|
interface AsyncSingleParams {
|
|
@@ -181,6 +197,8 @@ interface AsyncSingleParams {
|
|
|
181
197
|
/** Raw caller-facing goal used only by the started event. */
|
|
182
198
|
goal?: string;
|
|
183
199
|
agentConfig: AgentConfig;
|
|
200
|
+
/** Agent contract before per-run bridge injection, used only for recovery persistence. */
|
|
201
|
+
recoveryAgentConfig?: AgentConfig;
|
|
184
202
|
ctx: AsyncExecutionContext;
|
|
185
203
|
cwd?: string;
|
|
186
204
|
maxOutput?: MaxOutputConfig;
|
|
@@ -208,20 +226,29 @@ interface AsyncSingleParams {
|
|
|
208
226
|
worktreeSetupHookTimeoutMs?: number;
|
|
209
227
|
worktreeBaseDir?: string;
|
|
210
228
|
controlConfig?: ResolvedControlConfig;
|
|
229
|
+
intercomBridge?: IntercomBridgeConfig;
|
|
211
230
|
controlIntercomTarget?: string;
|
|
212
231
|
childIntercomTarget?: (agent: string, index: number) => string | undefined;
|
|
213
232
|
nestedRoute?: NestedRouteInfo;
|
|
214
233
|
acceptance?: AcceptanceInput;
|
|
215
234
|
timeoutMs?: number;
|
|
216
235
|
absoluteDeadlineAt?: number;
|
|
236
|
+
/** Optional per-call hard toolTimeoutMs override (highest precedence). */
|
|
237
|
+
toolTimeoutMs?: number;
|
|
217
238
|
turnBudget?: { maxTurns: number; graceTurns?: number };
|
|
218
239
|
toolBudget?: ResolvedToolBudget | ToolBudgetConfig;
|
|
219
240
|
usageBudget?: UsageBudgetConfig;
|
|
220
241
|
configToolBudget?: ResolvedToolBudget;
|
|
242
|
+
/** Global config.toolTimeoutMs (third precedence, after agent frontmatter). */
|
|
243
|
+
configToolTimeoutMs?: number;
|
|
244
|
+
/** PI_SUBAGENT_TOOL_TIMEOUT_MS override (lowest precedence). */
|
|
245
|
+
toolTimeoutMsEnv?: string | undefined;
|
|
221
246
|
allowZeroToolBudget?: boolean;
|
|
222
247
|
capabilityCeiling?: ResolvedSubagentCapabilityCeiling;
|
|
248
|
+
runFanoutBudget?: RunFanoutBudgetDescriptor;
|
|
223
249
|
parentWorkflowRunId?: string;
|
|
224
250
|
workflowKey?: string;
|
|
251
|
+
activeAsyncCapacity?: ActiveAsyncCapacityHandle;
|
|
225
252
|
}
|
|
226
253
|
|
|
227
254
|
interface AsyncExecutionResult {
|
|
@@ -254,6 +281,12 @@ export interface AsyncRunnerStepBuildParams {
|
|
|
254
281
|
validateOutputBindings?: boolean;
|
|
255
282
|
toolBudget?: ResolvedToolBudget;
|
|
256
283
|
configToolBudget?: ResolvedToolBudget;
|
|
284
|
+
/** Optional per-call hard toolTimeoutMs override from the subagent invocation. */
|
|
285
|
+
callToolTimeoutMs?: number;
|
|
286
|
+
/** Global config.toolTimeoutMs (third precedence, after agent frontmatter). */
|
|
287
|
+
configToolTimeoutMs?: number;
|
|
288
|
+
/** PI_SUBAGENT_TOOL_TIMEOUT_MS override (lowest precedence). */
|
|
289
|
+
toolTimeoutMsEnv?: string | undefined;
|
|
257
290
|
capabilityCeiling?: ResolvedSubagentCapabilityCeiling;
|
|
258
291
|
}
|
|
259
292
|
|
|
@@ -291,27 +324,6 @@ export function isAsyncAvailable(): boolean {
|
|
|
291
324
|
return jitiCliPath !== undefined;
|
|
292
325
|
}
|
|
293
326
|
|
|
294
|
-
function isNodeExecutableName(execPath: string): boolean {
|
|
295
|
-
const basename = path.basename(execPath).toLowerCase();
|
|
296
|
-
return basename === "node" || basename === "node.exe" || basename === "nodejs" || basename === "nodejs.exe";
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
function canUseCurrentNodeExecutable(execPath: string): boolean {
|
|
300
|
-
try {
|
|
301
|
-
fs.accessSync(execPath, process.platform === "win32" ? fs.constants.F_OK : fs.constants.X_OK);
|
|
302
|
-
return true;
|
|
303
|
-
} catch {
|
|
304
|
-
return false;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
function resolveAsyncRunnerNodeCommand(): string {
|
|
309
|
-
if (isNodeExecutableName(process.execPath) && canUseCurrentNodeExecutable(process.execPath)) {
|
|
310
|
-
return process.execPath;
|
|
311
|
-
}
|
|
312
|
-
return process.platform === "win32" ? "node.exe" : "node";
|
|
313
|
-
}
|
|
314
|
-
|
|
315
327
|
export function resolveAsyncRunnerLogPaths(cfg: object): { stdoutPath: string; stderrPath: string } | undefined {
|
|
316
328
|
const asyncDir = typeof (cfg as { asyncDir?: unknown }).asyncDir === "string"
|
|
317
329
|
? (cfg as { asyncDir: string }).asyncDir
|
|
@@ -343,7 +355,7 @@ type RunnerStartupState = "ready" | "acknowledged";
|
|
|
343
355
|
|
|
344
356
|
type RunnerStartupWaitResult =
|
|
345
357
|
| { ok: true; token: string }
|
|
346
|
-
| { ok: false; error: string };
|
|
358
|
+
| { ok: false; error: string; startupDidNotProceed?: boolean };
|
|
347
359
|
|
|
348
360
|
function waitForStartupInterval(delayMs = 20): void {
|
|
349
361
|
if (RUNNER_STARTUP_WAIT_VIEW) {
|
|
@@ -360,14 +372,14 @@ function readRunnerStartup(startupPath: string, expectedState: RunnerStartupStat
|
|
|
360
372
|
if (!fs.existsSync(startupPath)) return undefined;
|
|
361
373
|
try {
|
|
362
374
|
const payload = JSON.parse(fs.readFileSync(startupPath, "utf-8")) as { state?: unknown; token?: unknown; error?: unknown };
|
|
363
|
-
if (payload.state === "error" && typeof payload.error === "string") return { ok: false, error: payload.error };
|
|
375
|
+
if (payload.state === "error" && typeof payload.error === "string") return { ok: false, error: payload.error, startupDidNotProceed: true };
|
|
364
376
|
if (payload.state !== expectedState) return undefined;
|
|
365
377
|
if (typeof payload.token !== "string" || (expectedToken !== undefined && payload.token !== expectedToken)) {
|
|
366
|
-
return { ok: false, error: `Async runner wrote an invalid ${expectedState} startup handshake: ${startupPath}
|
|
378
|
+
return { ok: false, error: `Async runner wrote an invalid ${expectedState} startup handshake: ${startupPath}`, startupDidNotProceed: true };
|
|
367
379
|
}
|
|
368
380
|
return { ok: true, token: payload.token };
|
|
369
381
|
} catch (error) {
|
|
370
|
-
return { ok: false, error: `Failed to read async runner startup handshake '${startupPath}': ${error instanceof Error ? error.message : String(error)}
|
|
382
|
+
return { ok: false, error: `Failed to read async runner startup handshake '${startupPath}': ${error instanceof Error ? error.message : String(error)}`, startupDidNotProceed: true };
|
|
371
383
|
}
|
|
372
384
|
}
|
|
373
385
|
|
|
@@ -381,7 +393,7 @@ function waitForRunnerStartup(startupPath: string, expectedState: RunnerStartupS
|
|
|
381
393
|
}
|
|
382
394
|
const finalResult = readRunnerStartup(startupPath, expectedState, expectedToken);
|
|
383
395
|
if (finalResult) return finalResult;
|
|
384
|
-
return { ok: false, error: `Timed out after ${timeoutMs}ms waiting for the async runner startup state '${expectedState}'
|
|
396
|
+
return { ok: false, error: `Timed out after ${timeoutMs}ms waiting for the async runner startup state '${expectedState}'.`, startupDidNotProceed: true };
|
|
385
397
|
}
|
|
386
398
|
|
|
387
399
|
function writeRunnerStartupControl(filePath: string, payload: { action: "ack" | "proceed"; token: string }): void {
|
|
@@ -402,20 +414,63 @@ function runnerIsAlive(pid: number): boolean {
|
|
|
402
414
|
}
|
|
403
415
|
}
|
|
404
416
|
|
|
405
|
-
function terminateRunnerBeforeProceed(pid: number):
|
|
417
|
+
function terminateRunnerBeforeProceed(pid: number): boolean {
|
|
406
418
|
for (const signal of ["SIGTERM", "SIGKILL"] as const) {
|
|
407
|
-
if (!runnerIsAlive(pid)) return;
|
|
419
|
+
if (!runnerIsAlive(pid)) return true;
|
|
408
420
|
try {
|
|
409
421
|
process.kill(pid, signal);
|
|
410
422
|
} catch {
|
|
411
|
-
if (!runnerIsAlive(pid)) return;
|
|
423
|
+
if (!runnerIsAlive(pid)) return true;
|
|
412
424
|
}
|
|
413
425
|
const deadline = Date.now() + 1000;
|
|
414
426
|
while (runnerIsAlive(pid) && Date.now() < deadline) waitForStartupInterval();
|
|
415
427
|
}
|
|
428
|
+
return !runnerIsAlive(pid);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function persistPreProceedStartupFailure(asyncDir: string, runId: string, runnerProcessInstanceId: string, sessionId: string | undefined, message: string): void {
|
|
432
|
+
const now = Date.now();
|
|
433
|
+
try {
|
|
434
|
+
const statusPath = path.join(asyncDir, "status.json");
|
|
435
|
+
let status: Partial<AsyncStatus> = {};
|
|
436
|
+
try {
|
|
437
|
+
status = JSON.parse(fs.readFileSync(statusPath, "utf-8")) as Partial<AsyncStatus>;
|
|
438
|
+
} catch {}
|
|
439
|
+
writePrivateAtomicJson(statusPath, {
|
|
440
|
+
...status,
|
|
441
|
+
runId,
|
|
442
|
+
...(sessionId ? { sessionId } : {}),
|
|
443
|
+
state: "failed",
|
|
444
|
+
lastUpdate: now,
|
|
445
|
+
error: message,
|
|
446
|
+
processTerminal: {
|
|
447
|
+
version: 1,
|
|
448
|
+
state: "not-started",
|
|
449
|
+
runId,
|
|
450
|
+
runnerProcessInstanceId,
|
|
451
|
+
},
|
|
452
|
+
});
|
|
453
|
+
writePrivateAtomicJson(path.join(asyncDir, "process-terminal-candidate.json"), {
|
|
454
|
+
version: 1,
|
|
455
|
+
runId,
|
|
456
|
+
runnerProcessInstanceId,
|
|
457
|
+
writers: {},
|
|
458
|
+
expectedWriters: { 0: 0 },
|
|
459
|
+
});
|
|
460
|
+
} catch {
|
|
461
|
+
// Startup failures must still return the original launch error.
|
|
462
|
+
}
|
|
416
463
|
}
|
|
417
464
|
|
|
418
|
-
|
|
465
|
+
interface SpawnRunnerResult {
|
|
466
|
+
pid?: number;
|
|
467
|
+
runnerProcessInstanceId?: string;
|
|
468
|
+
error?: string;
|
|
469
|
+
terminationObserved?: boolean;
|
|
470
|
+
startupDidNotProceed?: boolean;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function spawnRunner(cfg: object, suffix: string, cwd: string, onProcessTerminal?: (proof: unknown) => void): SpawnRunnerResult {
|
|
419
474
|
if (!jitiCliPath) {
|
|
420
475
|
return { error: "upstream jiti for TypeScript execution could not be found; ensure package dependencies are installed" };
|
|
421
476
|
}
|
|
@@ -435,9 +490,11 @@ function spawnRunner(cfg: object, suffix: string, cwd: string, onProcessTerminal
|
|
|
435
490
|
const launchConfig = { ...cfg, runnerProcessInstanceId };
|
|
436
491
|
fs.writeFileSync(cfgPath, JSON.stringify(launchConfig));
|
|
437
492
|
const runner = path.join(path.dirname(fileURLToPath(import.meta.url)), "subagent-runner.ts");
|
|
438
|
-
const nodeCommand =
|
|
439
|
-
const launchForStartup = launchConfig as typeof launchConfig & { asyncDir?: unknown; revivalLease?: unknown };
|
|
493
|
+
const nodeCommand = resolveNodeExecutable();
|
|
494
|
+
const launchForStartup = launchConfig as typeof launchConfig & { asyncDir?: unknown; id?: unknown; sessionId?: unknown; revivalLease?: unknown };
|
|
440
495
|
const launchAsyncDir = typeof launchForStartup.asyncDir === "string" ? launchForStartup.asyncDir : undefined;
|
|
496
|
+
const launchRunId = typeof launchForStartup.id === "string" ? launchForStartup.id : suffix;
|
|
497
|
+
const launchSessionId = typeof launchForStartup.sessionId === "string" ? launchForStartup.sessionId : undefined;
|
|
441
498
|
const startupPath = typeof launchForStartup.revivalLease === "object" && launchAsyncDir
|
|
442
499
|
? path.join(launchAsyncDir, "runner-startup.json")
|
|
443
500
|
: undefined;
|
|
@@ -526,27 +583,36 @@ function spawnRunner(cfg: object, suffix: string, cwd: string, onProcessTerminal
|
|
|
526
583
|
}
|
|
527
584
|
proc.unref();
|
|
528
585
|
if (startupPath && startupAckPath && startupProceedPath) {
|
|
586
|
+
const persistStartupFailure = (message: string) => {
|
|
587
|
+
if (launchAsyncDir) persistPreProceedStartupFailure(launchAsyncDir, launchRunId, runnerProcessInstanceId, launchSessionId, message);
|
|
588
|
+
};
|
|
529
589
|
const ready = waitForRunnerStartup(startupPath, "ready", RUNNER_STARTUP_TIMEOUT_MS);
|
|
530
590
|
if (ready.ok === false) {
|
|
531
|
-
|
|
532
|
-
|
|
591
|
+
persistStartupFailure(ready.error);
|
|
592
|
+
const terminationObserved = terminateRunnerBeforeProceed(proc.pid);
|
|
593
|
+
return { pid: proc.pid, runnerProcessInstanceId, error: ready.error, terminationObserved, startupDidNotProceed: ready.startupDidNotProceed };
|
|
533
594
|
}
|
|
534
595
|
try {
|
|
535
596
|
writeRunnerStartupControl(startupAckPath, { action: "ack", token: ready.token });
|
|
536
597
|
} catch (error) {
|
|
537
|
-
|
|
538
|
-
|
|
598
|
+
const message = `Failed to acknowledge async runner startup: ${error instanceof Error ? error.message : String(error)}`;
|
|
599
|
+
persistStartupFailure(message);
|
|
600
|
+
const terminationObserved = terminateRunnerBeforeProceed(proc.pid);
|
|
601
|
+
return { pid: proc.pid, runnerProcessInstanceId, error: message, terminationObserved, startupDidNotProceed: true };
|
|
539
602
|
}
|
|
540
603
|
const acknowledged = waitForRunnerStartup(startupPath, "acknowledged", RUNNER_STARTUP_TIMEOUT_MS, ready.token);
|
|
541
604
|
if (acknowledged.ok === false) {
|
|
542
|
-
|
|
543
|
-
|
|
605
|
+
persistStartupFailure(acknowledged.error);
|
|
606
|
+
const terminationObserved = terminateRunnerBeforeProceed(proc.pid);
|
|
607
|
+
return { pid: proc.pid, runnerProcessInstanceId, error: acknowledged.error, terminationObserved, startupDidNotProceed: acknowledged.startupDidNotProceed };
|
|
544
608
|
}
|
|
545
609
|
try {
|
|
546
610
|
writeRunnerStartupControl(startupProceedPath, { action: "proceed", token: ready.token });
|
|
547
611
|
} catch (error) {
|
|
548
|
-
|
|
549
|
-
|
|
612
|
+
const message = `Failed to authorize async runner startup: ${error instanceof Error ? error.message : String(error)}`;
|
|
613
|
+
persistStartupFailure(message);
|
|
614
|
+
const terminationObserved = terminateRunnerBeforeProceed(proc.pid);
|
|
615
|
+
return { pid: proc.pid, runnerProcessInstanceId, error: message, terminationObserved, startupDidNotProceed: true };
|
|
550
616
|
}
|
|
551
617
|
try {
|
|
552
618
|
fs.rmSync(startupPath, { force: true });
|
|
@@ -554,7 +620,7 @@ function spawnRunner(cfg: object, suffix: string, cwd: string, onProcessTerminal
|
|
|
554
620
|
// Proceed is the commit point; handshake cleanup cannot turn a running revival into a start error.
|
|
555
621
|
}
|
|
556
622
|
}
|
|
557
|
-
return { pid: proc.pid };
|
|
623
|
+
return { pid: proc.pid, runnerProcessInstanceId };
|
|
558
624
|
} catch (error) {
|
|
559
625
|
closeFd(stdoutFd);
|
|
560
626
|
closeFd(stderrFd);
|
|
@@ -648,7 +714,7 @@ export function buildAsyncRunnerSteps(id: string, params: AsyncRunnerStepBuildPa
|
|
|
648
714
|
...(s.model !== undefined ? { model: s.model } : {}),
|
|
649
715
|
};
|
|
650
716
|
};
|
|
651
|
-
const buildSeqStep = (s: SequentialStep, sessionFile?: string, behaviorCwd?: string, progressPrecreated = false, resolvedBehavior?: ResolvedStepBehavior, flatIndex?: number, parallelOutputNamespace?: { stepIndex: number; taskIndex?: number }) => {
|
|
717
|
+
const buildSeqStep = (s: SequentialStep, sessionFile?: string, behaviorCwd?: string, progressPrecreated = false, resolvedBehavior?: ResolvedStepBehavior, flatIndex?: number, parallelOutputNamespace?: { stepIndex: number; taskIndex?: number }, runFanoutPath?: string) => {
|
|
652
718
|
const a = agents.find((x) => x.name === s.agent)!;
|
|
653
719
|
const externalRunner = a.runner?.type === "external-cli";
|
|
654
720
|
if (externalRunner) {
|
|
@@ -668,6 +734,13 @@ export function buildAsyncRunnerSteps(id: string, params: AsyncRunnerStepBuildPa
|
|
|
668
734
|
const toolBudgetInput = s.toolBudget ?? params.toolBudget ?? a.toolBudget ?? params.configToolBudget;
|
|
669
735
|
const resolvedToolBudget = validateToolBudgetConfig(toolBudgetInput, s.toolBudget ? "toolBudget" : a.toolBudget ? "agent.toolBudget" : "config.toolBudget");
|
|
670
736
|
if (resolvedToolBudget.error) throw new AsyncStartValidationError(resolvedToolBudget.error);
|
|
737
|
+
const resolvedToolTimeout = resolveToolTimeoutMs({
|
|
738
|
+
callValue: params.callToolTimeoutMs,
|
|
739
|
+
agentValue: a.defaultToolTimeoutMs,
|
|
740
|
+
configValue: params.configToolTimeoutMs,
|
|
741
|
+
envValue: params.toolTimeoutMsEnv ?? toolTimeoutFromEnv(),
|
|
742
|
+
});
|
|
743
|
+
if (resolvedToolTimeout.error) throw new AsyncStartValidationError(resolvedToolTimeout.error);
|
|
671
744
|
const stepCwd = resolveChildCwd(runnerCwd, s.cwd);
|
|
672
745
|
const instructionCwd = behaviorCwd ?? stepCwd;
|
|
673
746
|
const readExistenceCwd = behaviorCwd ? stepCwd : instructionCwd;
|
|
@@ -748,6 +821,7 @@ export function buildAsyncRunnerSteps(id: string, params: AsyncRunnerStepBuildPa
|
|
|
748
821
|
parentSessionId: ctx.parentSessionId ?? ctx.currentSessionId,
|
|
749
822
|
permissionRules,
|
|
750
823
|
...(params.capabilityCeiling ? { capabilityCeiling: params.capabilityCeiling } : {}),
|
|
824
|
+
...(runFanoutPath ? { runFanoutPath } : {}),
|
|
751
825
|
agent: s.agent,
|
|
752
826
|
task,
|
|
753
827
|
...(a.runner ? { runner: a.runner } : {}),
|
|
@@ -780,6 +854,7 @@ export function buildAsyncRunnerSteps(id: string, params: AsyncRunnerStepBuildPa
|
|
|
780
854
|
sessionFile,
|
|
781
855
|
maxSubagentDepth: resolveChildMaxSubagentDepth(maxSubagentDepth, a.maxSubagentDepth),
|
|
782
856
|
timeoutMs: a.defaultTimeoutMs ?? DEFAULT_ASYNC_TIMEOUT_MS,
|
|
857
|
+
toolTimeoutMs: resolvedToolTimeout.toolTimeoutMs,
|
|
783
858
|
waitToolEnabled: params.waitToolEnabled,
|
|
784
859
|
effectiveAcceptance: resolveEffectiveAcceptance({
|
|
785
860
|
explicit: s.acceptance,
|
|
@@ -839,7 +914,7 @@ export function buildAsyncRunnerSteps(id: string, params: AsyncRunnerStepBuildPa
|
|
|
839
914
|
}
|
|
840
915
|
}
|
|
841
916
|
const staticStep = nextFlatStep();
|
|
842
|
-
return buildSeqStep({ ...t, agentContract: t.agentContract ?? s.agentContract, gateOn: t.gateOn ?? s.gateOn }, staticStep.sessionFile, behaviorCwd, progressPrecreated, parallelBehaviors[taskIndex], staticStep.index, { stepIndex, taskIndex });
|
|
917
|
+
return buildSeqStep({ ...t, agentContract: t.agentContract ?? s.agentContract, gateOn: t.gateOn ?? s.gateOn }, staticStep.sessionFile, behaviorCwd, progressPrecreated, parallelBehaviors[taskIndex], staticStep.index, { stepIndex, taskIndex }, resultMode === "parallel" ? `tasks[${taskIndex}]` : `chain[${stepIndex}].parallel[${taskIndex}]`);
|
|
843
918
|
}),
|
|
844
919
|
concurrency: s.concurrency,
|
|
845
920
|
failFast: s.failFast,
|
|
@@ -884,7 +959,7 @@ export function buildAsyncRunnerSteps(id: string, params: AsyncRunnerStepBuildPa
|
|
|
884
959
|
};
|
|
885
960
|
}
|
|
886
961
|
const staticStep = nextFlatStep();
|
|
887
|
-
return buildSeqStep(s as SequentialStep, staticStep.sessionFile, undefined, false, undefined, staticStep.index);
|
|
962
|
+
return buildSeqStep(s as SequentialStep, staticStep.sessionFile, undefined, false, undefined, staticStep.index, undefined, `chain[${stepIndex}]`);
|
|
888
963
|
});
|
|
889
964
|
const steps = params.attachRoot
|
|
890
965
|
? [{
|
|
@@ -966,8 +1041,11 @@ export function executeAsyncChain(
|
|
|
966
1041
|
const asyncDir = inheritedNestedRoute
|
|
967
1042
|
? path.join(TEMP_ROOT_DIR, "nested-subagent-runs", inheritedNestedRoute.rootRunId, id)
|
|
968
1043
|
: path.join(DIRS.async, id);
|
|
1044
|
+
let runFanoutBudget: RunFanoutBudgetDescriptor;
|
|
969
1045
|
try {
|
|
1046
|
+
runFanoutBudget = params.runFanoutBudget ?? createRunFanoutBudget(id, 64);
|
|
970
1047
|
fs.mkdirSync(asyncDir, { recursive: true });
|
|
1048
|
+
writeRunFanoutBudgetDescriptor(asyncDir, runFanoutBudget);
|
|
971
1049
|
} catch (error) {
|
|
972
1050
|
const message = error instanceof Error ? error.message : String(error);
|
|
973
1051
|
return {
|
|
@@ -1000,6 +1078,9 @@ export function executeAsyncChain(
|
|
|
1000
1078
|
asyncDir,
|
|
1001
1079
|
toolBudget: params.toolBudget,
|
|
1002
1080
|
configToolBudget: params.configToolBudget,
|
|
1081
|
+
callToolTimeoutMs: params.callToolTimeoutMs,
|
|
1082
|
+
configToolTimeoutMs: params.configToolTimeoutMs,
|
|
1083
|
+
toolTimeoutMsEnv: params.toolTimeoutMsEnv ?? toolTimeoutFromEnv(),
|
|
1003
1084
|
capabilityCeiling,
|
|
1004
1085
|
});
|
|
1005
1086
|
if ("error" in built) {
|
|
@@ -1030,13 +1111,13 @@ export function executeAsyncChain(
|
|
|
1030
1111
|
return "agent" in step ? [childIntercomTarget(step.agent, childTargetIndex++)] : [undefined];
|
|
1031
1112
|
}) : undefined;
|
|
1032
1113
|
|
|
1033
|
-
let spawnResult:
|
|
1114
|
+
let spawnResult: SpawnRunnerResult = {};
|
|
1034
1115
|
try {
|
|
1035
1116
|
spawnResult = spawnRunner(
|
|
1036
1117
|
{
|
|
1037
1118
|
id,
|
|
1038
1119
|
steps,
|
|
1039
|
-
resultPath: inheritedNestedRoute ? nestedResultsPath(inheritedNestedRoute.rootRunId, id) :
|
|
1120
|
+
resultPath: inheritedNestedRoute ? nestedResultsPath(inheritedNestedRoute.rootRunId, id) : resultFilePath(DIRS.results, id),
|
|
1040
1121
|
cwd: runnerCwd,
|
|
1041
1122
|
placeholder: "{previous}",
|
|
1042
1123
|
maxOutput,
|
|
@@ -1063,6 +1144,7 @@ export function executeAsyncChain(
|
|
|
1063
1144
|
timeoutMs: params.timeoutMs,
|
|
1064
1145
|
deadlineAt,
|
|
1065
1146
|
globalConcurrencyLimit: params.globalConcurrencyLimit,
|
|
1147
|
+
runFanoutBudget,
|
|
1066
1148
|
workflowGraph,
|
|
1067
1149
|
...(params.parentWorkflowRunId ? { parentWorkflowRunId: params.parentWorkflowRunId } : {}),
|
|
1068
1150
|
...(params.workflowKey ? { workflowKey: params.workflowKey } : {}),
|
|
@@ -1079,13 +1161,21 @@ export function executeAsyncChain(
|
|
|
1079
1161
|
(proof) => ctx.pi.events.emit(SUBAGENT_PROCESS_TERMINAL_EVENT, proof),
|
|
1080
1162
|
);
|
|
1081
1163
|
} catch (error) {
|
|
1164
|
+
params.activeAsyncCapacity?.rollback();
|
|
1082
1165
|
const message = error instanceof Error ? error.message : String(error);
|
|
1083
1166
|
return formatAsyncStartError(resultMode, `Failed to start async ${resultMode} '${id}': ${message}`);
|
|
1084
1167
|
}
|
|
1085
1168
|
|
|
1086
1169
|
if (spawnResult.error) {
|
|
1170
|
+
if (!spawnResult.pid || !spawnResult.runnerProcessInstanceId || (spawnResult.startupDidNotProceed && spawnResult.terminationObserved)) params.activeAsyncCapacity?.rollback();
|
|
1171
|
+
else params.activeAsyncCapacity?.markStarted(spawnResult.runnerProcessInstanceId);
|
|
1087
1172
|
return formatAsyncStartError(resultMode, `Failed to start async ${resultMode} '${id}': ${spawnResult.error}`);
|
|
1088
1173
|
}
|
|
1174
|
+
if (!spawnResult.pid || !spawnResult.runnerProcessInstanceId) {
|
|
1175
|
+
params.activeAsyncCapacity?.rollback();
|
|
1176
|
+
return formatAsyncStartError(resultMode, `Failed to start async ${resultMode} '${id}': runner identity unavailable`);
|
|
1177
|
+
}
|
|
1178
|
+
params.activeAsyncCapacity?.markStarted(spawnResult.runnerProcessInstanceId);
|
|
1089
1179
|
|
|
1090
1180
|
if (spawnResult.pid) {
|
|
1091
1181
|
const eventFirstStep = eventChain[0];
|
|
@@ -1166,8 +1256,8 @@ export function executeAsyncChain(
|
|
|
1166
1256
|
mode: resultMode,
|
|
1167
1257
|
agent: firstAgents[0],
|
|
1168
1258
|
agents: flatAgents,
|
|
1169
|
-
task: firstTask?.
|
|
1170
|
-
goal: workflowGoal?.
|
|
1259
|
+
task: firstTask?.trim() ? PROMPT_REDACTED : undefined,
|
|
1260
|
+
goal: workflowGoal?.trim() ? PROMPT_REDACTED : undefined,
|
|
1171
1261
|
chain: eventChain.map((s) =>
|
|
1172
1262
|
isParallelStep(s) ? `[${s.parallel.map((t) => t.agent).join("+")}]` : isDynamicParallelStep(s) ? `expand:${s.parallel.agent}` : (s as SequentialStep).agent,
|
|
1173
1263
|
),
|
|
@@ -1176,6 +1266,7 @@ export function executeAsyncChain(
|
|
|
1176
1266
|
workflowGraph,
|
|
1177
1267
|
cwd: runnerCwd,
|
|
1178
1268
|
asyncDir,
|
|
1269
|
+
...(sessionRoot ? { sessionRoot } : {}),
|
|
1179
1270
|
...(params.timeoutMs !== undefined ? { timeoutMs: params.timeoutMs, deadlineAt } : {}),
|
|
1180
1271
|
...(initialTurnBudget ? { turnBudget: initialTurnBudget } : {}),
|
|
1181
1272
|
...(initialUsageBudget ? { usageBudget: initialUsageBudget } : {}),
|
|
@@ -1279,8 +1370,11 @@ export function executeAsyncSingle(
|
|
|
1279
1370
|
const asyncDir = inheritedNestedRoute
|
|
1280
1371
|
? path.join(TEMP_ROOT_DIR, "nested-subagent-runs", inheritedNestedRoute.rootRunId, id)
|
|
1281
1372
|
: path.join(DIRS.async, id);
|
|
1373
|
+
let runFanoutBudget: RunFanoutBudgetDescriptor;
|
|
1282
1374
|
try {
|
|
1375
|
+
runFanoutBudget = params.runFanoutBudget ?? createRunFanoutBudget(id, 64);
|
|
1283
1376
|
fs.mkdirSync(asyncDir, { recursive: true });
|
|
1377
|
+
writeRunFanoutBudgetDescriptor(asyncDir, runFanoutBudget);
|
|
1284
1378
|
} catch (error) {
|
|
1285
1379
|
const message = error instanceof Error ? error.message : String(error);
|
|
1286
1380
|
return {
|
|
@@ -1321,17 +1415,27 @@ export function executeAsyncSingle(
|
|
|
1321
1415
|
? deadlineAt - Date.now()
|
|
1322
1416
|
: params.timeoutMs;
|
|
1323
1417
|
if (timeoutMs !== undefined && timeoutMs <= 0) return formatAsyncStartError("single", "The source run's absolute deadline expired before recovery could launch.");
|
|
1418
|
+
const resolvedToolTimeout = resolveToolTimeoutMs({
|
|
1419
|
+
callValue: params.toolTimeoutMs,
|
|
1420
|
+
agentValue: agentConfig.defaultToolTimeoutMs,
|
|
1421
|
+
configValue: params.configToolTimeoutMs,
|
|
1422
|
+
envValue: params.toolTimeoutMsEnv ?? toolTimeoutFromEnv(),
|
|
1423
|
+
});
|
|
1424
|
+
if (resolvedToolTimeout.error) return formatAsyncStartError("single", resolvedToolTimeout.error);
|
|
1425
|
+
const toolTimeoutMs = resolvedToolTimeout.toolTimeoutMs;
|
|
1324
1426
|
const initialTurnBudget = params.turnBudget ? initialTurnBudgetState(params.turnBudget) : undefined;
|
|
1325
1427
|
const initialUsageBudget = usageBudgetState(params.usageBudget, undefined);
|
|
1326
1428
|
const resolvedSessionDir = params.sessionDir ?? (sessionRoot ? path.join(sessionRoot, `async-${id}`) : undefined);
|
|
1327
1429
|
const structuredOutput = params.structuredOutputSchema
|
|
1328
1430
|
? createStructuredOutputRuntime(params.structuredOutputSchema, path.join(asyncDir, "structured-output"))
|
|
1329
1431
|
: undefined;
|
|
1330
|
-
const modelCandidates =
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1432
|
+
const modelCandidates = externalRunner
|
|
1433
|
+
? []
|
|
1434
|
+
: buildModelCandidates(primaryModel, agentConfig.fallbackModels, availableModels, ctx.currentModelProvider, { scope: ctx.modelScope })
|
|
1435
|
+
.flatMap((candidate) => {
|
|
1436
|
+
const resolved = applyThinkingSuffix(candidate, effectiveThinking, params.thinkingOverride !== undefined);
|
|
1437
|
+
return resolved ? [resolved] : [];
|
|
1438
|
+
});
|
|
1335
1439
|
const effectiveSystemPrompt = appendTurnBudgetSystemPrompt(systemPrompt, params.turnBudget);
|
|
1336
1440
|
const toolPlan = resolvePiLaunchToolPlan({
|
|
1337
1441
|
tools: agentConfig.tools,
|
|
@@ -1373,9 +1477,11 @@ export function executeAsyncSingle(
|
|
|
1373
1477
|
async: true,
|
|
1374
1478
|
agentContract: params.agentContract,
|
|
1375
1479
|
});
|
|
1480
|
+
const recoveryAgentConfig = params.recoveryAgentConfig ?? agentConfig;
|
|
1376
1481
|
const recoveryDescriptor: SteeringRecoveryDescriptor = {
|
|
1377
1482
|
version: 1,
|
|
1378
1483
|
launchContractDigest,
|
|
1484
|
+
runFanoutBudget,
|
|
1379
1485
|
sourceRunId: id,
|
|
1380
1486
|
...(params.agentContract ? { agentContract: params.agentContract } : {}),
|
|
1381
1487
|
agent,
|
|
@@ -1383,30 +1489,31 @@ export function executeAsyncSingle(
|
|
|
1383
1489
|
...(sessionFile ? { sessionFile } : {}),
|
|
1384
1490
|
cwd: runnerCwd,
|
|
1385
1491
|
...(model ? { model } : {}),
|
|
1386
|
-
...(
|
|
1492
|
+
...(recoveryAgentConfig.fallbackModels ? { fallbackModels: [...recoveryAgentConfig.fallbackModels] } : {}),
|
|
1387
1493
|
...(effectiveThinking ? { thinking: resolveEffectiveThinking(model, effectiveThinking) } : {}),
|
|
1388
|
-
...(
|
|
1389
|
-
...(
|
|
1390
|
-
...(
|
|
1391
|
-
...(
|
|
1392
|
-
...(
|
|
1393
|
-
systemPromptMode:
|
|
1394
|
-
inheritProjectContext:
|
|
1395
|
-
inheritSkills:
|
|
1494
|
+
...(recoveryAgentConfig.tools ? { tools: [...recoveryAgentConfig.tools] } : {}),
|
|
1495
|
+
...(recoveryAgentConfig.extensions ? { extensions: [...recoveryAgentConfig.extensions] } : {}),
|
|
1496
|
+
...(recoveryAgentConfig.subagentOnlyExtensions ? { subagentOnlyExtensions: [...recoveryAgentConfig.subagentOnlyExtensions] } : {}),
|
|
1497
|
+
...(recoveryAgentConfig.mcpDirectTools ? { mcpDirectTools: [...recoveryAgentConfig.mcpDirectTools] } : {}),
|
|
1498
|
+
...(recoveryAgentConfig.systemPrompt ? { systemPrompt: recoveryAgentConfig.systemPrompt } : {}),
|
|
1499
|
+
systemPromptMode: recoveryAgentConfig.systemPromptMode,
|
|
1500
|
+
inheritProjectContext: recoveryAgentConfig.inheritProjectContext,
|
|
1501
|
+
inheritSkills: recoveryAgentConfig.inheritSkills,
|
|
1396
1502
|
...(resolvedSkills.length ? { skills: resolvedSkills.map((skill) => skill.name) } : {}),
|
|
1397
|
-
...(
|
|
1398
|
-
...(
|
|
1399
|
-
...(
|
|
1400
|
-
...(
|
|
1503
|
+
...(recoveryAgentConfig.skillPath ? { skillPath: [...recoveryAgentConfig.skillPath] } : {}),
|
|
1504
|
+
...(recoveryAgentConfig.filePath ? { agentFilePath: recoveryAgentConfig.filePath } : {}),
|
|
1505
|
+
...(recoveryAgentConfig.completionGuard !== undefined ? { completionGuard: recoveryAgentConfig.completionGuard } : {}),
|
|
1506
|
+
...(recoveryAgentConfig.memory ? { memory: { ...recoveryAgentConfig.memory } } : {}),
|
|
1401
1507
|
...(outputPath ? { outputPath } : {}),
|
|
1402
1508
|
outputMode,
|
|
1403
1509
|
...(params.structuredOutputSchema ? { structuredOutputSchema: params.structuredOutputSchema } : {}),
|
|
1404
1510
|
...(params.acceptance !== undefined ? { acceptance: params.acceptance } : {}),
|
|
1405
1511
|
...(controlConfig ? { controlConfig } : {}),
|
|
1512
|
+
...(params.intercomBridge !== undefined ? { intercomBridge: params.intercomBridge } : {}),
|
|
1406
1513
|
...(deadlineAt !== undefined ? { absoluteDeadlineAt: deadlineAt } : {}),
|
|
1407
1514
|
...(initialTurnBudget ? { initialTurnBudget: { maxTurns: initialTurnBudget.maxTurns, graceTurns: initialTurnBudget.graceTurns } } : {}),
|
|
1408
1515
|
...(resolvedToolBudget.budget ? { initialToolBudget: resolvedToolBudget.budget } : {}),
|
|
1409
|
-
maxSubagentDepth: resolveChildMaxSubagentDepth(maxSubagentDepth,
|
|
1516
|
+
maxSubagentDepth: resolveChildMaxSubagentDepth(maxSubagentDepth, recoveryAgentConfig.maxSubagentDepth),
|
|
1410
1517
|
...(maxOutput ? { maxOutput } : {}),
|
|
1411
1518
|
share: shareEnabled,
|
|
1412
1519
|
...(resolvedSessionDir ? { sessionDir: resolvedSessionDir } : {}),
|
|
@@ -1421,7 +1528,7 @@ export function executeAsyncSingle(
|
|
|
1421
1528
|
return formatAsyncStartError("single", `Failed to persist async recovery descriptor for '${id}': ${error instanceof Error ? error.message : String(error)}`);
|
|
1422
1529
|
}
|
|
1423
1530
|
}
|
|
1424
|
-
let spawnResult:
|
|
1531
|
+
let spawnResult: SpawnRunnerResult = {};
|
|
1425
1532
|
try {
|
|
1426
1533
|
spawnResult = spawnRunner(
|
|
1427
1534
|
{
|
|
@@ -1467,7 +1574,7 @@ export function executeAsyncSingle(
|
|
|
1467
1574
|
],
|
|
1468
1575
|
resultPath: params.parentWorkflowRunId !== undefined && params.revivalLease !== undefined
|
|
1469
1576
|
? workflowAwaitedAsyncResultPath(asyncDir)
|
|
1470
|
-
: inheritedNestedRoute ? nestedResultsPath(inheritedNestedRoute.rootRunId, id) :
|
|
1577
|
+
: inheritedNestedRoute ? nestedResultsPath(inheritedNestedRoute.rootRunId, id) : resultFilePath(DIRS.results, id),
|
|
1471
1578
|
cwd: runnerCwd,
|
|
1472
1579
|
placeholder: "{previous}",
|
|
1473
1580
|
maxOutput,
|
|
@@ -1486,6 +1593,7 @@ export function executeAsyncSingle(
|
|
|
1486
1593
|
controlConfig,
|
|
1487
1594
|
timeoutMs,
|
|
1488
1595
|
deadlineAt,
|
|
1596
|
+
toolTimeoutMs,
|
|
1489
1597
|
turnBudget: params.turnBudget,
|
|
1490
1598
|
toolBudget: params.toolBudget,
|
|
1491
1599
|
usageBudget: params.usageBudget,
|
|
@@ -1494,6 +1602,7 @@ export function executeAsyncSingle(
|
|
|
1494
1602
|
resultMode: "single",
|
|
1495
1603
|
launchContractDigest,
|
|
1496
1604
|
launchResolvedExtensions,
|
|
1605
|
+
runFanoutBudget,
|
|
1497
1606
|
...(params.parentWorkflowRunId ? { parentWorkflowRunId: params.parentWorkflowRunId } : {}),
|
|
1498
1607
|
...(params.workflowKey ? { workflowKey: params.workflowKey } : {}),
|
|
1499
1608
|
...(params.revivalLease ? { revivalLease: params.revivalLease } : {}),
|
|
@@ -1510,13 +1619,21 @@ export function executeAsyncSingle(
|
|
|
1510
1619
|
(proof) => ctx.pi.events.emit(SUBAGENT_PROCESS_TERMINAL_EVENT, proof),
|
|
1511
1620
|
);
|
|
1512
1621
|
} catch (error) {
|
|
1622
|
+
params.activeAsyncCapacity?.rollback();
|
|
1513
1623
|
const message = error instanceof Error ? error.message : String(error);
|
|
1514
1624
|
return formatAsyncStartError("single", `Failed to start async run '${id}': ${message}`);
|
|
1515
1625
|
}
|
|
1516
1626
|
|
|
1517
1627
|
if (spawnResult.error) {
|
|
1628
|
+
if (!spawnResult.pid || !spawnResult.runnerProcessInstanceId || (spawnResult.startupDidNotProceed && spawnResult.terminationObserved)) params.activeAsyncCapacity?.rollback();
|
|
1629
|
+
else params.activeAsyncCapacity?.markStarted(spawnResult.runnerProcessInstanceId);
|
|
1518
1630
|
return formatAsyncStartError("single", `Failed to start async run '${id}': ${spawnResult.error}`);
|
|
1519
1631
|
}
|
|
1632
|
+
if (!spawnResult.pid || !spawnResult.runnerProcessInstanceId) {
|
|
1633
|
+
params.activeAsyncCapacity?.rollback();
|
|
1634
|
+
return formatAsyncStartError("single", `Failed to start async run '${id}': runner identity unavailable`);
|
|
1635
|
+
}
|
|
1636
|
+
params.activeAsyncCapacity?.markStarted(spawnResult.runnerProcessInstanceId);
|
|
1520
1637
|
|
|
1521
1638
|
if (spawnResult.pid) {
|
|
1522
1639
|
if (inheritedNestedRoute && nestedAddress) {
|
|
@@ -1562,10 +1679,11 @@ export function executeAsyncSingle(
|
|
|
1562
1679
|
sessionId: ctx.currentSessionId,
|
|
1563
1680
|
mode: "single",
|
|
1564
1681
|
agent,
|
|
1565
|
-
task: task?.
|
|
1566
|
-
goal: (params.goal ?? task).
|
|
1682
|
+
task: task?.trim() ? PROMPT_REDACTED : undefined,
|
|
1683
|
+
goal: (params.goal ?? task).trim() ? PROMPT_REDACTED : undefined,
|
|
1567
1684
|
cwd: runnerCwd,
|
|
1568
1685
|
asyncDir,
|
|
1686
|
+
...(sessionRoot ? { sessionRoot } : {}),
|
|
1569
1687
|
launchContractDigest,
|
|
1570
1688
|
launchResolvedExtensions,
|
|
1571
1689
|
...(params.parentWorkflowRunId ? { parentWorkflowRunId: params.parentWorkflowRunId } : {}),
|
|
@@ -125,6 +125,7 @@ export function createAsyncJobTracker(pi: Pick<ExtensionAPI, "events">, state: S
|
|
|
125
125
|
return {
|
|
126
126
|
asyncId: run.id,
|
|
127
127
|
asyncDir: run.asyncDir,
|
|
128
|
+
toolCallId: run.toolCallId,
|
|
128
129
|
status: run.state,
|
|
129
130
|
sessionId: run.sessionId,
|
|
130
131
|
activityState: run.activityState,
|
|
@@ -557,10 +558,13 @@ export function createAsyncJobTracker(pi: Pick<ExtensionAPI, "events">, state: S
|
|
|
557
558
|
const agents = firstGroupCount && firstGroupCount > 0
|
|
558
559
|
? rawAgents?.slice(0, firstGroupCount)
|
|
559
560
|
: rawAgents;
|
|
561
|
+
const sessionRoot = state.liveAsyncSessionRoots?.get(info.id);
|
|
562
|
+
state.liveAsyncSessionRoots?.delete(info.id);
|
|
560
563
|
state.asyncJobs.set(info.id, {
|
|
561
564
|
asyncId: info.id,
|
|
562
565
|
asyncDir,
|
|
563
566
|
...(typeof info.cwd === "string" ? { cwd: path.resolve(info.cwd) } : {}),
|
|
567
|
+
...(sessionRoot ? { sessionRoot } : {}),
|
|
564
568
|
status: "queued",
|
|
565
569
|
pid: typeof info.pid === "number" ? info.pid : undefined,
|
|
566
570
|
...(typeof info.sessionId === "string" ? { sessionId: info.sessionId } : {}),
|
|
@@ -637,6 +641,7 @@ export function createAsyncJobTracker(pi: Pick<ExtensionAPI, "events">, state: S
|
|
|
637
641
|
state.asyncJobs.clear();
|
|
638
642
|
state.fleetJobs?.clear();
|
|
639
643
|
state.foregroundControls?.clear();
|
|
644
|
+
state.liveAsyncSessionRoots?.clear();
|
|
640
645
|
state.lastForegroundControlId = null;
|
|
641
646
|
state.resultFileCoalescer.clear();
|
|
642
647
|
if (ctx?.hasUI) {
|