@xzzpig/pi-subagents 0.14.0 → 0.15.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 +239 -0
- package/README.md +7 -6
- package/agents/evidence-auditor.md +34 -0
- package/agents/researcher.md +23 -13
- package/agents/reviewer.md +3 -2
- package/docs/agents.md +55 -136
- package/docs/configuration.md +92 -14
- package/docs/extension-api.md +132 -74
- package/docs/fork-extensions.md +184 -0
- package/docs/missions.md +10 -2
- package/docs/models.md +11 -22
- package/docs/observability.md +63 -11
- package/docs/standalone-background.md +59 -0
- package/docs/tool-reference.md +42 -23
- package/docs/watchdog.md +39 -10
- package/docs/workflows.md +58 -19
- package/index.ts +5 -2
- package/inspector-runner.mjs +2 -2
- package/node_modules/@xzzpig/pi-components/dist/src/transcript.d.ts +13 -3
- package/node_modules/@xzzpig/pi-components/dist/src/transcript.js +18 -6
- package/node_modules/@xzzpig/pi-components/src/transcript.ts +26 -6
- package/package.json +9 -4
- package/prompts/parallel-review.md +1 -1
- package/runner-peer-loader.mjs +24 -0
- package/runner-peer-preload.mjs +36 -0
- package/skills/pi-subagents/SKILL.md +34 -22
- package/skills/pi-subagents/references/constraints-and-recipes.md +3 -2
- package/skills/pi-subagents/references/execution-controls.md +27 -8
- package/skills/pi-subagents/references/management-authoring-rpc.md +2 -2
- package/skills/pi-subagents/references/multi-lane-orchestration.md +3 -1
- package/skills/pi-subagents/references/prompting-and-roles.md +17 -13
- package/skills/pi-subagents/references/review-and-validation.md +3 -3
- package/src/agents/advertised-agent-prompt.ts +94 -0
- package/src/agents/agent-eject.ts +339 -0
- package/src/agents/agent-management.ts +79 -387
- package/src/agents/agent-serializer.ts +6 -3
- package/src/agents/agents.ts +198 -72
- package/src/agents/builtin-names.ts +1 -0
- package/src/agents/chain-serializer.ts +5 -0
- package/src/agents/runtime-agent-registry.ts +7 -6
- package/src/api/agent-management.ts +2 -2
- package/src/api/delegation.ts +4 -0
- package/src/api/preflight.ts +131 -86
- package/src/api/required-child-extensions.ts +6 -0
- package/src/api/shared-types.ts +3 -1
- package/src/api/workflow-resources.ts +6 -0
- package/src/extension/config.ts +14 -37
- package/src/extension/fanout-child.ts +68 -5
- package/src/extension/herdr-pi-bridge.ts +164 -0
- package/src/extension/index.ts +141 -51
- package/src/extension/public-execution.ts +7 -6
- package/src/extension/rpc.ts +8 -21
- package/src/extension/schemas.ts +86 -84
- package/src/extension/tool-description.ts +32 -79
- package/src/inspectors/actions.ts +148 -0
- package/src/inspectors/ghostty/actions.ts +74 -0
- package/src/inspectors/ghostty/plugin.ts +17 -0
- package/src/inspectors/herdr/actions.ts +99 -179
- package/src/inspectors/herdr/plugin.ts +20 -0
- package/src/inspectors/herdr/project-panes.ts +4 -1
- package/src/inspectors/{herdr/inspector-runner.ts → inspector-runner.ts} +12 -12
- package/src/inspectors/plugins.ts +8 -0
- package/src/inspectors/{herdr/session-roots-codec.ts → session-roots-codec.ts} +3 -14
- package/src/inspectors/types.ts +51 -0
- package/src/integrations/pi-web-session-liveness.ts +73 -0
- package/src/intercom/intercom-bridge.ts +50 -8
- package/src/intercom/native-supervisor-channel.ts +142 -115
- package/src/intercom/supervisor-ui.ts +3 -2
- package/src/missions/workflow-state.ts +37 -16
- package/src/policy/authority.ts +4 -0
- package/src/profiles/profiles.ts +12 -6
- package/src/runs/background/active-async-capacity.ts +22 -18
- package/src/runs/background/active-run-index.ts +17 -1
- package/src/runs/background/async-execution.ts +359 -176
- package/src/runs/background/async-job-tracker.ts +41 -7
- package/src/runs/background/async-resume.ts +19 -12
- package/src/runs/background/async-retention.ts +20 -0
- package/src/runs/background/async-status-snapshot.ts +10 -12
- package/src/runs/background/async-status.ts +38 -35
- package/src/runs/background/auto-drain.ts +59 -35
- package/src/runs/background/binary-bootstrap.ts +38 -0
- package/src/runs/background/chain-append.ts +1 -1
- package/src/runs/background/chain-root-attachment.ts +22 -33
- package/src/runs/background/control-channel.ts +78 -44
- package/src/runs/background/fleet-view.ts +30 -2
- package/src/runs/background/notify.ts +193 -19
- package/src/runs/background/owned-process-tree.ts +35 -8
- package/src/runs/background/process-terminal.ts +23 -23
- package/src/runs/background/result-files.ts +8 -4
- package/src/runs/background/result-watcher.ts +19 -2
- package/src/runs/background/retained-nested-route-tracker.ts +96 -0
- package/src/runs/background/run-child-session.ts +118 -41
- package/src/runs/background/run-status.ts +78 -5
- package/src/runs/background/runner-aliases.ts +22 -5
- package/src/runs/background/runner-child-launch.ts +93 -0
- package/src/runs/background/runner-child-sessions.ts +5 -4
- package/src/runs/background/runner-http-dispatcher.ts +119 -0
- package/src/runs/background/scheduled-runs.ts +51 -18
- package/src/runs/background/stale-run-reconciler.ts +38 -12
- package/src/runs/background/steering.ts +20 -2
- package/src/runs/background/subagent-runner.ts +770 -444
- package/src/runs/background/subagent-wait.ts +179 -28
- package/src/runs/background/wait-completions.ts +79 -27
- package/src/runs/background/wait-subscriptions.ts +9 -3
- package/src/runs/background/wait-tool.ts +5 -3
- package/src/runs/foreground/async-steering-action.ts +37 -7
- package/src/runs/foreground/async-stop-action.ts +93 -3
- package/src/runs/foreground/execution.ts +174 -194
- package/src/runs/foreground/foreground-history.ts +5 -2
- package/src/runs/foreground/prompt-audit.ts +12 -6
- package/src/runs/foreground/subagent-executor.ts +915 -411
- package/src/runs/foreground/workflow-detach-reconcile.ts +10 -5
- package/src/runs/foreground/workflow-foreground-steering.ts +57 -2
- package/src/runs/shared/acceptance.ts +54 -14
- package/src/runs/shared/agent-contract.ts +1 -1
- package/src/runs/shared/async-status-projection.ts +172 -78
- package/src/runs/shared/capability-ceiling.ts +2 -0
- package/src/runs/shared/child-hooks.ts +167 -3
- package/src/runs/shared/child-launch-plan.ts +15 -3
- package/src/runs/shared/child-launch.ts +49 -85
- package/src/runs/shared/child-lifecycle.ts +6 -3
- package/src/runs/shared/child-runtime-config.ts +8 -1
- package/src/runs/shared/child-session.ts +130 -24
- package/src/runs/shared/child-tool-plan.ts +149 -112
- package/src/runs/shared/completion-evidence.ts +2 -2
- package/src/runs/shared/completion-guard.ts +6 -3
- package/src/runs/shared/dynamic-fanout.ts +2 -2
- package/src/runs/shared/effective-system-prompt.ts +33 -0
- package/src/runs/shared/external-cli-contract.ts +11 -1
- package/src/runs/shared/external-cli-preflight.ts +6 -2
- package/src/runs/shared/external-cli-runner.ts +9 -7
- package/src/runs/shared/herdr-connection.ts +134 -0
- package/src/runs/shared/herdr-external-adapters.ts +169 -0
- package/src/runs/shared/herdr-machine.ts +279 -0
- package/src/runs/shared/herdr-pi-protocol.ts +59 -0
- package/src/runs/shared/herdr-placed-run.ts +263 -0
- package/src/runs/shared/host-step-status.ts +11 -11
- package/src/runs/shared/llm-intent-arbiter.ts +40 -21
- package/src/runs/shared/model-resolution-diagnostic.ts +76 -0
- package/src/runs/shared/{model-fallback.ts → model-resolution.ts} +34 -218
- package/src/runs/shared/model-scope.ts +1 -1
- package/src/runs/shared/nested-events.ts +27 -34
- package/src/runs/shared/orca-progress-tabs.ts +7 -1
- package/src/runs/shared/parallel-handoff.ts +57 -12
- package/src/runs/shared/parallel-utils.ts +10 -4
- package/src/runs/shared/pi-spawn.ts +10 -0
- package/src/runs/shared/profile-extensions.ts +134 -0
- package/src/runs/shared/profile-launch-env.ts +113 -0
- package/src/runs/shared/readonly-drain-observation.ts +42 -0
- package/src/runs/shared/run-fanout-budget.ts +8 -8
- package/src/runs/shared/runtime-acknowledged-extensions.ts +3 -3
- package/src/runs/shared/sandbox-profile-guard.ts +34 -0
- package/src/runs/shared/subagent-prompt-runtime.ts +23 -5
- package/src/runs/shared/task-intent.ts +46 -13
- package/src/runs/shared/workflow-async-child-guidance.ts +18 -0
- package/src/runs/shared/worktree-cleanup-plan.ts +6 -3
- package/src/runs/shared/worktree-setup-command.ts +213 -0
- package/src/runs/shared/worktree.ts +437 -214
- package/src/shared/child-cache-retention.ts +43 -0
- package/src/shared/fork-context.ts +15 -72
- package/src/shared/launch-contract.ts +70 -8
- package/src/shared/model-response-aliases.ts +13 -0
- package/src/shared/opencode-session-headers.ts +30 -0
- package/src/shared/permission-profile.ts +14 -0
- package/src/shared/pruned-fork.ts +1 -1
- package/src/shared/required-child-extensions.ts +81 -0
- package/src/shared/sandbox-profile.ts +14 -0
- package/src/shared/settings.ts +5 -2
- package/src/shared/shortcuts.ts +0 -4
- package/src/shared/types.ts +163 -90
- package/src/shared/utils.ts +10 -2
- package/src/shared/watch-strategy.ts +2 -0
- package/src/shared/workflow-child-permit.ts +18 -13
- package/src/slash/delegation-adapters.ts +3 -1
- package/src/slash/delegation-request.ts +14 -0
- package/src/slash/slash-commands.ts +2 -7
- package/src/slash/subagents-admin.ts +31 -14
- package/src/tui/fleet-status.ts +165 -20
- package/src/tui/fleet.ts +30 -19
- package/src/tui/render.ts +210 -50
- package/src/watchdog/child-status.ts +28 -28
- package/src/watchdog/lsp-diagnostics.ts +1 -1
- package/src/watchdog/model-selection.ts +21 -1
- package/src/watchdog/permission-arbiter.ts +5 -2
- package/src/watchdog/register-child.ts +10 -2
- package/src/watchdog/register-main.ts +39 -35
- package/src/watchdog/render.ts +1 -1
- package/src/watchdog/review.ts +122 -74
- package/src/watchdog/rules.ts +1 -1
- package/src/watchdog/runtime.ts +100 -27
- package/src/watchdog/scope.ts +1 -1
- package/src/watchdog/settings.ts +3 -0
- package/src/watchdog/tool-actions.ts +13 -12
- package/src/watchdog/turn-delta.ts +23 -0
- package/src/watchdog/types.ts +5 -3
- package/src/watchdog/warning-format.ts +1 -1
- package/src/workflows/chat-progress.ts +3 -3
- package/src/workflows/scripted-workflow.ts +349 -26
- package/src/workflows/workflow-checklist.ts +17 -20
- package/src/workflows/workflow-child-summary.ts +57 -8
- package/src/workflows/workflow-preflight.ts +19 -19
- package/src/workflows/workflow-receipt.ts +24 -6
- package/src/workflows/workflow-resources.ts +108 -22
- package/src/workflows/workflow-settlement.ts +3 -0
- package/src/runs/shared/model-exclusions.ts +0 -373
- /package/src/inspectors/{herdr/shell-command.ts → shell-command.ts} +0 -0
package/src/profiles/profiles.ts
CHANGED
|
@@ -20,7 +20,7 @@ export type RecommendedRoleTier = "cheap" | "medium" | "strong";
|
|
|
20
20
|
interface ProfileAgentOverride {
|
|
21
21
|
model?: string;
|
|
22
22
|
thinking?: string | false;
|
|
23
|
-
|
|
23
|
+
machine?: string;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export interface SubagentProfileFile {
|
|
@@ -144,10 +144,7 @@ function validateSubagentProfile(filePath: string, parsed: Record<string, unknow
|
|
|
144
144
|
if (thinking !== undefined && thinking !== false && typeof thinking !== "string") {
|
|
145
145
|
throw new Error(`Profile '${filePath}' has invalid thinking for '${name}'; expected a string or false.`);
|
|
146
146
|
}
|
|
147
|
-
|
|
148
|
-
if (fallbackModels !== undefined && fallbackModels !== false && (!Array.isArray(fallbackModels) || fallbackModels.some((item) => typeof item !== "string"))) {
|
|
149
|
-
throw new Error(`Profile '${filePath}' has invalid fallbackModels for '${name}'; expected an array of strings or false.`);
|
|
150
|
-
}
|
|
147
|
+
if ((override as Record<string, unknown>).fallbackModels !== undefined) throw new Error(`Profile '${filePath}' uses removed field fallbackModels for '${name}'; configure one model instead.`);
|
|
151
148
|
}
|
|
152
149
|
const disableBuiltins = (subagents as Record<string, unknown>).disableBuiltins;
|
|
153
150
|
if (disableBuiltins !== undefined && typeof disableBuiltins !== "boolean") {
|
|
@@ -489,10 +486,19 @@ export function applySubagentProfile(name: string): { filePath: string; settings
|
|
|
489
486
|
: {};
|
|
490
487
|
// A profile owns the complete agent mapping, but unrelated subagent settings
|
|
491
488
|
// (notably disableBuiltins, modelScope, watchdog, etc.) survive profile switches.
|
|
489
|
+
// Machine placement is not a model choice, so an existing pin survives a profile switch too.
|
|
490
|
+
const agentOverrides: Record<string, ProfileAgentOverride> = { ...profile.subagents.agentOverrides };
|
|
491
|
+
const existingOverrides = existing.agentOverrides && typeof existing.agentOverrides === "object" && !Array.isArray(existing.agentOverrides)
|
|
492
|
+
? existing.agentOverrides as Record<string, unknown>
|
|
493
|
+
: {};
|
|
494
|
+
for (const [name, value] of Object.entries(existingOverrides)) {
|
|
495
|
+
const machine = value && typeof value === "object" && !Array.isArray(value) ? (value as Record<string, unknown>).machine : undefined;
|
|
496
|
+
if (typeof machine === "string" && agentOverrides[name]?.machine === undefined) agentOverrides[name] = { ...agentOverrides[name], machine };
|
|
497
|
+
}
|
|
492
498
|
settings.subagents = {
|
|
493
499
|
...existing,
|
|
494
500
|
...profile.subagents,
|
|
495
|
-
agentOverrides
|
|
501
|
+
agentOverrides,
|
|
496
502
|
};
|
|
497
503
|
writeJsonFile(settingsPath, settings);
|
|
498
504
|
return { filePath, settingsPath };
|
|
@@ -12,7 +12,7 @@ export const DEFAULT_ABANDONED_SLOT_RELEASE_AFTER_MS = 20 * 60 * 1000;
|
|
|
12
12
|
export const MIN_ABANDONED_SLOT_RELEASE_AFTER_MS = 5 * 60 * 1000;
|
|
13
13
|
export const MAX_ABANDONED_SLOT_RELEASE_AFTER_MS = 24 * 60 * 60 * 1000;
|
|
14
14
|
|
|
15
|
-
export interface
|
|
15
|
+
export interface ActiveAsyncCapacityOwner {
|
|
16
16
|
version: 1;
|
|
17
17
|
reservationToken: string;
|
|
18
18
|
ownerSessionId: string;
|
|
@@ -29,7 +29,7 @@ export interface ActiveAsyncCapacityOwnerV1 {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export interface ActiveAsyncCapacityHandle {
|
|
32
|
-
readonly owner:
|
|
32
|
+
readonly owner: ActiveAsyncCapacityOwner;
|
|
33
33
|
markStarted(runnerProcessInstanceId: string): void;
|
|
34
34
|
markWorkflowStarted(): void;
|
|
35
35
|
rollback(): boolean;
|
|
@@ -44,7 +44,7 @@ interface CapacityOptions {
|
|
|
44
44
|
abandonedSlotReleaseAfterMs?: number | false;
|
|
45
45
|
pidLiveness?: (pid: number) => PidLiveness;
|
|
46
46
|
afterSlotRename?: (releasedDir: string) => void;
|
|
47
|
-
writeOwner?: (filePath: string, owner:
|
|
47
|
+
writeOwner?: (filePath: string, owner: ActiveAsyncCapacityOwner) => void;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export interface ActiveAsyncCapacityReleaseEvidence {
|
|
@@ -61,7 +61,7 @@ export type ActiveAsyncCapacityReleaseVerdict =
|
|
|
61
61
|
| { state: "not-owned"; reason: string };
|
|
62
62
|
|
|
63
63
|
export interface ActiveAsyncCapacityInspection {
|
|
64
|
-
owner?:
|
|
64
|
+
owner?: ActiveAsyncCapacityOwner;
|
|
65
65
|
relation: "current" | "source" | "none";
|
|
66
66
|
slotDir?: string;
|
|
67
67
|
release: ActiveAsyncCapacityReleaseVerdict;
|
|
@@ -100,9 +100,9 @@ function slotDir(poolDir: string, slot: number): string {
|
|
|
100
100
|
return path.join(poolDir, `slot-${slot}`);
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
function parseOwner(value: unknown):
|
|
103
|
+
function parseOwner(value: unknown): ActiveAsyncCapacityOwner | undefined {
|
|
104
104
|
if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
|
|
105
|
-
const owner = value as Partial<
|
|
105
|
+
const owner = value as Partial<ActiveAsyncCapacityOwner>;
|
|
106
106
|
if (owner.version !== 1
|
|
107
107
|
|| typeof owner.reservationToken !== "string" || !owner.reservationToken
|
|
108
108
|
|| typeof owner.ownerSessionId !== "string" || !owner.ownerSessionId
|
|
@@ -116,10 +116,10 @@ function parseOwner(value: unknown): ActiveAsyncCapacityOwnerV1 | undefined {
|
|
|
116
116
|
if (owner.sourceRunId !== undefined && typeof owner.sourceRunId !== "string") return undefined;
|
|
117
117
|
if (owner.runnerProcessInstanceId !== undefined && (typeof owner.runnerProcessInstanceId !== "string" || !owner.runnerProcessInstanceId)) return undefined;
|
|
118
118
|
if (owner.runnerStartedAt !== undefined && (typeof owner.runnerStartedAt !== "number" || !Number.isFinite(owner.runnerStartedAt))) return undefined;
|
|
119
|
-
return owner as
|
|
119
|
+
return owner as ActiveAsyncCapacityOwner;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
function readOwner(dir: string):
|
|
122
|
+
function readOwner(dir: string): ActiveAsyncCapacityOwner | undefined {
|
|
123
123
|
try {
|
|
124
124
|
return parseOwner(JSON.parse(fs.readFileSync(path.join(dir, "owner.json"), "utf-8")));
|
|
125
125
|
} catch {
|
|
@@ -142,7 +142,7 @@ function snapshotFor(sessionId: string, limit: number | undefined, rootDir: stri
|
|
|
142
142
|
return { used: occupiedSlots(sessionDir(sessionId, rootDir)).length, limit: limit ?? 0 };
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
function matchingOwner(dir: string, expected:
|
|
145
|
+
function matchingOwner(dir: string, expected: ActiveAsyncCapacityOwner): ActiveAsyncCapacityOwner | undefined {
|
|
146
146
|
const owner = readOwner(dir);
|
|
147
147
|
return owner?.reservationToken === expected.reservationToken
|
|
148
148
|
&& owner.runId === expected.runId
|
|
@@ -176,7 +176,7 @@ function withSlotClaim<T>(dir: string, operation: () => T): { acquired: true; va
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
function removeOwnedSlot(dir: string, expected:
|
|
179
|
+
function removeOwnedSlot(dir: string, expected: ActiveAsyncCapacityOwner, options: CapacityOptions, requireUnstarted = false, release?: ActiveAsyncCapacityReleaseVerdict): boolean {
|
|
180
180
|
if (requireUnstarted && (expected.runnerProcessInstanceId || expected.runnerStartedAt)) return false;
|
|
181
181
|
const claimed = withSlotClaim(dir, () => {
|
|
182
182
|
const current = matchingOwner(dir, expected);
|
|
@@ -193,7 +193,7 @@ function removeOwnedSlot(dir: string, expected: ActiveAsyncCapacityOwnerV1, opti
|
|
|
193
193
|
return claimed.acquired && claimed.value;
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
function appendAbandonedReleaseEvent(asyncDir: string, owner:
|
|
196
|
+
function appendAbandonedReleaseEvent(asyncDir: string, owner: ActiveAsyncCapacityOwner, evidence: ActiveAsyncCapacityReleaseEvidence, now: number): void {
|
|
197
197
|
try {
|
|
198
198
|
const eventsPath = path.join(asyncDir, "events.jsonl");
|
|
199
199
|
fs.mkdirSync(path.dirname(eventsPath), { recursive: true });
|
|
@@ -213,7 +213,7 @@ function terminalState(state: AsyncStatus["state"]): boolean {
|
|
|
213
213
|
return state !== "queued" && state !== "running" && state !== "paused";
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
function runnerReleaseVerdict(owner:
|
|
216
|
+
function runnerReleaseVerdict(owner: ActiveAsyncCapacityOwner, status: AsyncStatus | null, options: CapacityOptions): ActiveAsyncCapacityReleaseVerdict {
|
|
217
217
|
if (!status) return { state: "retained", reason: "status file is missing or unreadable" };
|
|
218
218
|
if (!owner.runnerProcessInstanceId) return { state: "retained", reason: "runner process identity has not been recorded" };
|
|
219
219
|
if (status.sessionId !== owner.ownerSessionId) return { state: "retained", reason: `status session ${status.sessionId ?? "unknown"} does not match owner session ${owner.ownerSessionId}` };
|
|
@@ -262,7 +262,7 @@ function abandonedRunnerReleaseVerdict(status: AsyncStatus, proofState: string,
|
|
|
262
262
|
};
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
function workflowReleaseVerdict(owner:
|
|
265
|
+
function workflowReleaseVerdict(owner: ActiveAsyncCapacityOwner, status: AsyncStatus | null, liveWorkflowRunIds: ReadonlySet<string>): ActiveAsyncCapacityReleaseVerdict {
|
|
266
266
|
if (!status) return { state: "retained", reason: "status file is missing or unreadable" };
|
|
267
267
|
if (status.sessionId !== owner.ownerSessionId) return { state: "retained", reason: `status session ${status.sessionId ?? "unknown"} does not match owner session ${owner.ownerSessionId}` };
|
|
268
268
|
if (status.runId !== owner.runId) return { state: "retained", reason: `status run ${status.runId} does not match owner run ${owner.runId}` };
|
|
@@ -280,6 +280,10 @@ function workflowReleaseVerdict(owner: ActiveAsyncCapacityOwnerV1, status: Async
|
|
|
280
280
|
if (!childStatus) return { state: "retained", reason: `async workflow child ${label} status is missing or unreadable` };
|
|
281
281
|
if (!terminalState(childStatus.state)) return { state: "retained", reason: `async workflow child ${label} is still ${childStatus.state}` };
|
|
282
282
|
if (!childStatus.processTerminal?.runnerProcessInstanceId) return { state: "retained", reason: `async workflow child ${label} has no runner process identity` };
|
|
283
|
+
if (childStatus.processTerminal.state === "not-started"
|
|
284
|
+
&& childStatus.processTerminal.runId === step.runId
|
|
285
|
+
&& typeof childStatus.error === "string"
|
|
286
|
+
&& childStatus.error) continue;
|
|
283
287
|
const proof = readProcessTerminal(childDir, {
|
|
284
288
|
runId: step.runId,
|
|
285
289
|
runnerProcessInstanceId: childStatus.processTerminal.runnerProcessInstanceId,
|
|
@@ -289,7 +293,7 @@ function workflowReleaseVerdict(owner: ActiveAsyncCapacityOwnerV1, status: Async
|
|
|
289
293
|
return { state: "releasable", reason: "workflow is terminal, controller is gone, and async children have observed proof" };
|
|
290
294
|
}
|
|
291
295
|
|
|
292
|
-
function ownerReleaseVerdict(owner:
|
|
296
|
+
function ownerReleaseVerdict(owner: ActiveAsyncCapacityOwner, liveWorkflowRunIds: ReadonlySet<string>, options: CapacityOptions): ActiveAsyncCapacityReleaseVerdict {
|
|
293
297
|
const status = readStatus(owner.asyncDir);
|
|
294
298
|
return owner.kind === "runner"
|
|
295
299
|
? runnerReleaseVerdict(owner, status, options)
|
|
@@ -364,7 +368,7 @@ export function getActiveAsyncCapacitySnapshot(
|
|
|
364
368
|
return reconcileActiveAsyncCapacity(sessionId, limit, options);
|
|
365
369
|
}
|
|
366
370
|
|
|
367
|
-
function createSlot(poolDir: string, owner:
|
|
371
|
+
function createSlot(poolDir: string, owner: ActiveAsyncCapacityOwner): boolean {
|
|
368
372
|
const destination = slotDir(poolDir, owner.slot);
|
|
369
373
|
fs.mkdirSync(poolDir, { recursive: true, mode: 0o700 });
|
|
370
374
|
try {
|
|
@@ -379,7 +383,7 @@ function createSlot(poolDir: string, owner: ActiveAsyncCapacityOwnerV1): boolean
|
|
|
379
383
|
return true;
|
|
380
384
|
}
|
|
381
385
|
|
|
382
|
-
function handleFor(owner:
|
|
386
|
+
function handleFor(owner: ActiveAsyncCapacityOwner, limit: number, options: CapacityOptions, rollbackOwner?: ActiveAsyncCapacityOwner): ActiveAsyncCapacityHandle {
|
|
383
387
|
const rootDir = options.rootDir ?? ACTIVE_ASYNC_CAPACITY_DIR;
|
|
384
388
|
const writeOwner = options.writeOwner ?? writePrivateAtomicJson;
|
|
385
389
|
const dir = slotDir(sessionDir(owner.ownerSessionId, rootDir), owner.slot);
|
|
@@ -462,7 +466,7 @@ export function acquireActiveAsyncCapacity(
|
|
|
462
466
|
const poolDir = sessionDir(input.sessionId, rootDir);
|
|
463
467
|
const token = options.token?.() ?? randomUUID();
|
|
464
468
|
for (let slot = 0; slot < input.limit; slot++) {
|
|
465
|
-
const owner:
|
|
469
|
+
const owner: ActiveAsyncCapacityOwner = {
|
|
466
470
|
version: 1,
|
|
467
471
|
reservationToken: token,
|
|
468
472
|
ownerSessionId: input.sessionId,
|
|
@@ -495,7 +499,7 @@ export function transferActiveAsyncCapacity(
|
|
|
495
499
|
if (!current || !status || status.runId !== input.sourceRunId || status.state === "queued" || status.state === "running") {
|
|
496
500
|
throw new Error(`Active async capacity source '${input.sourceRunId}' is not transferable.`);
|
|
497
501
|
}
|
|
498
|
-
const next:
|
|
502
|
+
const next: ActiveAsyncCapacityOwner = {
|
|
499
503
|
...current,
|
|
500
504
|
runId: input.runId,
|
|
501
505
|
sourceRunId: input.sourceRunId,
|
|
@@ -76,7 +76,7 @@ export function releaseActiveRunIndex(asyncDir: string): void {
|
|
|
76
76
|
releaseToolCallAliases(asyncDir);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
export function updateActiveRunIndex(asyncDir: string, state: AsyncStatus["state"], toolCallId?: string, options: { retryCapacityErrors?: boolean } = {}): void {
|
|
79
|
+
export function updateActiveRunIndex(asyncDir: string, state: AsyncStatus["state"], toolCallId?: string, options: { retryCapacityErrors?: boolean; terminalIndexBeforeRelease?: boolean } = {}): void {
|
|
80
80
|
const marker = markerPath(asyncDir);
|
|
81
81
|
if (isActiveAsyncState(state)) {
|
|
82
82
|
fs.mkdirSync(path.dirname(marker), { recursive: true });
|
|
@@ -94,6 +94,22 @@ export function updateActiveRunIndex(asyncDir: string, state: AsyncStatus["state
|
|
|
94
94
|
}
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
|
+
if (options.terminalIndexBeforeRelease) {
|
|
98
|
+
fs.mkdirSync(path.dirname(marker), { recursive: true });
|
|
99
|
+
fs.writeFileSync(marker, "", { flag: "a" });
|
|
100
|
+
const status = readStatus(asyncDir);
|
|
101
|
+
if (status?.state === state) {
|
|
102
|
+
try {
|
|
103
|
+
updateTerminalRunIndex(asyncDir, status);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (options.retryCapacityErrors) throw error;
|
|
106
|
+
console.error(`Failed to write async terminal-run index for '${asyncDir}':`, error);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
releaseActiveRunIndex(asyncDir);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
97
113
|
releaseActiveRunIndex(asyncDir);
|
|
98
114
|
const status = readStatus(asyncDir);
|
|
99
115
|
if (status && status.state === state) {
|