@vicary/pi-subagents 0.84.0 → 0.86.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 +83 -0
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/{chunk-VQVVHSY6.js → chunk-2DITXA3H.js} +22 -11
- package/bundle/{chunk-V2BZYLEP.js → chunk-374MZFF4.js} +7 -2
- package/bundle/{chunk-4E7BKDTX.js → chunk-3RKFH2UZ.js} +11 -156
- package/bundle/{chunk-F4ASL6OV.js → chunk-5H4BICQZ.js} +1 -1
- package/bundle/{chunk-PALJGGYC.js → chunk-6VD7BGIC.js} +6 -3
- package/bundle/{chunk-C5P5CHYK.js → chunk-77ASNIEM.js} +1 -1
- package/bundle/{chunk-PV63UFUR.js → chunk-7QA7ZA46.js} +183 -28
- package/bundle/{chunk-NKQ6JNAS.js → chunk-7ZUFN6ME.js} +2 -1
- package/bundle/{chunk-L3WFKBEI.js → chunk-BGXEAYUM.js} +247 -153
- package/bundle/{chunk-J5YL7LYR.js → chunk-BU6PFPVX.js} +59 -27
- package/bundle/{chunk-7BWGNDNK.js → chunk-CJHFDQFJ.js} +196 -1183
- package/bundle/{chunk-DZDETGRJ.js → chunk-DD22RXYJ.js} +259 -216
- package/bundle/{chunk-CGN2TVE7.js → chunk-GJGTMLPE.js} +322 -18
- package/bundle/{chunk-XDQORLZ5.js → chunk-GLVJMI6R.js} +15 -6
- package/bundle/{chunk-D3JAFGMO.js → chunk-GRJHIXYF.js} +1 -1
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-LFDBD4PW.js → chunk-LGINOOY5.js} +2 -2
- package/bundle/{chunk-G2Z6ZH26.js → chunk-NAFLUJ26.js} +1 -1
- package/bundle/{chunk-2DHZTCOL.js → chunk-PYOAIN3V.js} +2 -2
- package/bundle/{chunk-RSLHTEQV.js → chunk-QFLPV64W.js} +324 -111
- package/bundle/{chunk-LNRJCP2Y.js → chunk-QGO6HXHG.js} +417 -242
- package/bundle/{chunk-2S4K53MV.js → chunk-S2Q75LP3.js} +1 -1
- package/bundle/{chunk-NENDSQUY.js → chunk-UR7OW5S7.js} +9 -6
- package/bundle/{chunk-RWPNQZHS.js → chunk-WHC2XHGF.js} +217 -106
- package/bundle/{chunk-AKOIVLA5.js → chunk-WN2E5XHN.js} +135 -77
- package/bundle/{chunk-4NIY3BE6.js → chunk-XOFYXQKZ.js} +2 -2
- package/bundle/{chunk-2D52JFLF.js → chunk-YK3QYNLE.js} +41 -117
- package/bundle/chunk-ZPY5QZCS.js +1067 -0
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +8 -8
- package/bundle/project-panes.js +3 -3
- package/docs/agents.md +24 -3
- package/docs/configuration.md +9 -9
- package/docs/extension-api.md +16 -1
- package/docs/observability.md +1 -1
- package/docs/tool-reference.md +3 -1
- package/docs/workflows.md +31 -3
- package/package.json +2 -2
- package/src/agents/agent-management.js +27 -11
- package/src/agents/agent-memory.d.ts +1 -4
- package/src/agents/agent-memory.js +1 -4
- package/src/agents/agents.d.ts +1 -3
- package/src/agents/agents.js +7 -6
- package/src/agents/frontmatter.js +1 -8
- package/src/agents/global-npm-root.d.ts +1 -0
- package/src/agents/global-npm-root.js +11 -3
- package/src/agents/skills.d.ts +0 -3
- package/src/agents/skills.js +0 -3
- package/src/extension/config.js +7 -1
- package/src/extension/herdr-pi-bridge.js +10 -2
- package/src/extension/index.d.ts +0 -13
- package/src/extension/index.js +43 -32
- package/src/extension/public-execution.d.ts +1 -0
- package/src/extension/public-execution.js +4 -0
- package/src/extension/reply-workflow-script.js +24 -4
- package/src/extension/schemas.d.ts +8 -3
- package/src/extension/schemas.js +6 -4
- package/src/extension/session-switch.d.ts +25 -0
- package/src/extension/session-switch.js +138 -0
- package/src/extension/subagent-guide.d.ts +1 -1
- package/src/extension/subagent-guide.js +1 -1
- package/src/extension/subagent-launch-tool.d.ts +25 -0
- package/src/extension/subagent-launch-tool.js +48 -0
- package/src/extension/tool-activation.js +35 -12
- package/src/extension/tool-description.d.ts +1 -1
- package/src/extension/tool-description.js +14 -8
- package/src/inspectors/herdr/actions.d.ts +0 -1
- package/src/inspectors/herdr/actions.js +0 -1
- package/src/inspectors/session-roots-codec.d.ts +0 -1
- package/src/inspectors/session-roots-codec.js +0 -1
- package/src/inspectors/tmux/actions.d.ts +0 -1
- package/src/inspectors/tmux/actions.js +0 -1
- package/src/integrations/herdr-status.js +3 -8
- package/src/intercom/native-supervisor-channel.js +65 -9
- package/src/runs/background/async-execution.d.ts +5 -10
- package/src/runs/background/async-execution.js +63 -29
- package/src/runs/background/async-job-tracker.js +12 -0
- package/src/runs/background/async-resume.d.ts +2 -1
- package/src/runs/background/async-resume.js +112 -39
- package/src/runs/background/async-retention.js +6 -1
- package/src/runs/background/auto-drain.d.ts +0 -1
- package/src/runs/background/auto-drain.js +7 -6
- package/src/runs/background/boot-id.d.ts +1 -3
- package/src/runs/background/boot-id.js +1 -3
- package/src/runs/background/completion-batcher.d.ts +3 -4
- package/src/runs/background/completion-batcher.js +2 -3
- package/src/runs/background/control-channel.d.ts +0 -6
- package/src/runs/background/control-channel.js +0 -6
- package/src/runs/background/fleet-view.js +2 -3
- package/src/runs/background/notify.d.ts +0 -2
- package/src/runs/background/notify.js +0 -2
- package/src/runs/background/result-watcher.d.ts +1 -0
- package/src/runs/background/result-watcher.js +59 -29
- package/src/runs/background/resume-guidance.js +4 -2
- package/src/runs/background/retained-children.js +2 -1
- package/src/runs/background/run-child-session.d.ts +0 -1
- package/src/runs/background/run-child-session.js +1 -1
- package/src/runs/background/run-status.js +9 -7
- package/src/runs/background/scheduled-runs.d.ts +3 -1
- package/src/runs/background/scheduled-runs.js +13 -16
- package/src/runs/background/subagent-runner.d.ts +2 -4
- package/src/runs/background/subagent-runner.js +15 -12
- package/src/runs/background/subagent-wait.js +12 -15
- package/src/runs/background/wait-config.d.ts +2 -0
- package/src/runs/background/wait-config.js +17 -3
- package/src/runs/background/wait-tool.js +4 -2
- package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
- package/src/runs/background/workflow-terminal-proof.js +0 -1
- package/src/runs/foreground/execution.d.ts +0 -3
- package/src/runs/foreground/execution.js +17 -9
- package/src/runs/foreground/subagent-executor.d.ts +7 -8
- package/src/runs/foreground/subagent-executor.js +113 -44
- package/src/runs/shared/acceptance.js +69 -26
- package/src/runs/shared/child-commands.js +15 -2
- package/src/runs/shared/child-hooks.d.ts +1 -7
- package/src/runs/shared/child-hooks.js +13 -5
- package/src/runs/shared/child-launch.js +6 -2
- package/src/runs/shared/child-runtime-config.d.ts +0 -1
- package/src/runs/shared/child-session.d.ts +1 -1
- package/src/runs/shared/child-session.js +21 -2
- package/src/runs/shared/child-tool-plan.d.ts +0 -1
- package/src/runs/shared/child-tool-plan.js +0 -1
- package/src/runs/shared/claude-code-adapter.js +11 -0
- package/src/runs/shared/external-cli-contract.d.ts +49 -0
- package/src/runs/shared/external-cli-contract.js +18 -13
- package/src/runs/shared/external-cli-runner.js +26 -6
- package/src/runs/shared/herdr-connection.js +2 -1
- package/src/runs/shared/herdr-pane-host.d.ts +2 -2
- package/src/runs/shared/herdr-pane-host.js +17 -1
- package/src/runs/shared/herdr-placed-run.js +48 -22
- package/src/runs/shared/lane-metadata.d.ts +0 -1
- package/src/runs/shared/lane-metadata.js +0 -1
- package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
- package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
- package/src/runs/shared/model-resolution.d.ts +2 -2
- package/src/runs/shared/model-resolution.js +7 -1
- package/src/runs/shared/model-scope.d.ts +1 -5
- package/src/runs/shared/model-scope.js +1 -5
- package/src/runs/shared/mutation-evidence.d.ts +1 -1
- package/src/runs/shared/mutation-evidence.js +52 -7
- package/src/runs/shared/nested-events.d.ts +1 -0
- package/src/runs/shared/nested-events.js +1 -1
- package/src/runs/shared/parallel-utils.d.ts +0 -1
- package/src/runs/shared/permissions.js +5 -3
- package/src/runs/shared/placement-host.d.ts +5 -1
- package/src/runs/shared/rex-pane-host.d.ts +0 -1
- package/src/runs/shared/rex-pane-host.js +0 -2
- package/src/runs/shared/run-launch-folder.d.ts +12 -0
- package/src/runs/shared/run-launch-folder.js +21 -0
- package/src/runs/shared/runner-launcher.d.ts +12 -1
- package/src/runs/shared/runner-launcher.js +16 -0
- package/src/runs/shared/single-output.d.ts +3 -3
- package/src/runs/shared/single-output.js +5 -3
- package/src/runs/shared/structured-output.d.ts +8 -0
- package/src/runs/shared/structured-output.js +40 -5
- package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
- package/src/runs/shared/subagent-prompt-runtime.js +4 -2
- package/src/runs/shared/tool-timeout.js +2 -1
- package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
- package/src/runs/shared/worktree-cleanup-plan.js +0 -1
- package/src/runs/shared/worktree.d.ts +3 -0
- package/src/runs/shared/worktree.js +20 -0
- package/src/shared/capacity-resilient-json.d.ts +1 -1
- package/src/shared/child-cache-retention.d.ts +1 -2
- package/src/shared/child-cache-retention.js +1 -2
- package/src/shared/fleet-transcript-reader.d.ts +51 -0
- package/src/shared/fleet-transcript-reader.js +333 -0
- package/src/shared/formatters.d.ts +0 -18
- package/src/shared/formatters.js +0 -18
- package/src/shared/session-succession.d.ts +16 -1
- package/src/shared/session-succession.js +41 -2
- package/src/shared/session-warnings.d.ts +7 -0
- package/src/shared/session-warnings.js +26 -0
- package/src/shared/settings.d.ts +0 -23
- package/src/shared/settings.js +3 -35
- package/src/shared/types.d.ts +90 -65
- package/src/shared/types.js +0 -12
- package/src/shared/utils.d.ts +0 -14
- package/src/shared/utils.js +0 -22
- package/src/shared/wait-tool-name.d.ts +8 -0
- package/src/shared/wait-tool-name.js +13 -0
- package/src/slash/slash-commands.js +2 -1
- package/src/slash/subagent-cost.d.ts +3 -2
- package/src/slash/subagent-cost.js +22 -3
- package/src/slash/subagents-admin.js +0 -1
- package/src/tui/fleet-status.d.ts +0 -5
- package/src/tui/fleet-status.js +4 -24
- package/src/tui/fleet-transcript.d.ts +1 -44
- package/src/tui/fleet-transcript.js +1 -327
- package/src/tui/fleet.js +6 -4
- package/src/tui/render.d.ts +0 -9
- package/src/tui/render.js +161 -66
- package/src/tui/subagent-messages.js +3 -2
- package/src/watchdog/register-child.d.ts +2 -3
- package/src/watchdog/register-child.js +2 -3
- package/src/watchdog/turn-delta.js +2 -1
- package/src/workflows/scripted-workflow.js +241 -20
- package/src/workflows/workflow-launch-record.d.ts +15 -6
- package/src/workflows/workflow-launch-record.js +30 -12
- package/src/workflows/workflow-receipt.js +36 -53
- package/src/workflows/workflow-resume-claim.js +2 -2
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +11 -8
- package/src/workflows/workflow-script-worker.d.ts +13 -0
- package/src/workflows/workflow-script-worker.js +79 -0
- package/workflow-script-process.cjs +36 -0
- package/workflow-script-worker.cjs +4 -1
|
@@ -9,6 +9,7 @@ import { ownsRun } from "../runs/shared/run-ownership.js";
|
|
|
9
9
|
import { writeAtomicJson, writePrivateAtomicJson } from "../shared/atomic-json.js";
|
|
10
10
|
import { shouldUseNativeFsWatch } from "../shared/watch-strategy.js";
|
|
11
11
|
import { MODEL_ONLY_TOOL } from "../shared/extension-context.js";
|
|
12
|
+
import { reportSessionWarning } from "../shared/session-warnings.js";
|
|
12
13
|
import { SUPERVISOR_REQUEST_MESSAGE_TYPE, SUPERVISOR_REPLY_ENTRY_TYPE, supervisorReplyHint, } from "./supervisor-ui.js";
|
|
13
14
|
const SUPERVISOR_CHANNEL_ROOT = path.join(TEMP_ROOT_DIR, "supervisor-channels");
|
|
14
15
|
const REQUESTS_DIR = "requests";
|
|
@@ -533,7 +534,22 @@ function appendSupervisorReplyEntry(pi, request, reply) {
|
|
|
533
534
|
console.error("Failed to journal native supervisor reply:", error);
|
|
534
535
|
}
|
|
535
536
|
}
|
|
536
|
-
function
|
|
537
|
+
function endedRequestText(ended, runState) {
|
|
538
|
+
const { request } = ended;
|
|
539
|
+
const iso = (time) => new Date(time).toISOString();
|
|
540
|
+
const when = ended.eventAt !== undefined ? ` at ${iso(ended.eventAt)}` : ` (noticed at ${iso(ended.endedAt)})`;
|
|
541
|
+
const subject = `Supervisor request '${request.id}' from ${request.agent} [${request.runId}#${request.childIndex}]`;
|
|
542
|
+
const runStatus = runState.asyncJobs.get(request.runId)?.status;
|
|
543
|
+
const runNow = runStatus && runStatus !== "queued" && runStatus !== "running" ? ` Run ${request.runId} is now ${runStatus}.` : "";
|
|
544
|
+
switch (ended.lifecycle) {
|
|
545
|
+
case "resolved": return `${subject} was already answered${when}.`;
|
|
546
|
+
case "expired": return `${subject} expired${when}: no reply arrived before the child's ask timeout.`;
|
|
547
|
+
case "deadline": return `${subject} ended around its ask deadline${when}: either no reply arrived before the child's ask timeout, or its run was stopped just before then.${runNow}`;
|
|
548
|
+
case "inactive": return `${subject} was closed because its child run ended${when}.${runNow}`;
|
|
549
|
+
case "missing": return `${subject} was withdrawn by the child before its ask deadline${when}. A child withdraws its request when its run is stopped, interrupted or times out, for example when a workflow aborts its other children after one fails.${runNow}`;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
function resolvePendingRequest(pending, params, ended, runState) {
|
|
537
553
|
const requests = [...pending.values()].filter((request) => request.expectsReply);
|
|
538
554
|
if (params.replyTo) {
|
|
539
555
|
const request = pending.get(params.replyTo);
|
|
@@ -541,6 +557,9 @@ function resolvePendingRequest(pending, params) {
|
|
|
541
557
|
// A child stops waiting after its ask timeout and may ask again under a new id. Its first
|
|
542
558
|
// notice can reach a busy parent after that, so name what can still be answered.
|
|
543
559
|
const current = requests.length ? `Pending now:\n${requests.map(pendingHeader).join("\n")}` : "No pending supervisor requests.";
|
|
560
|
+
const endedRequest = ended.get(params.replyTo);
|
|
561
|
+
if (endedRequest)
|
|
562
|
+
throw new Error(`${endedRequestText(endedRequest, runState(endedRequest.request))} ${current}`);
|
|
544
563
|
throw new Error(`No pending supervisor request found for replyTo '${params.replyTo}'. It was answered, expired or withdrawn. ${current}`);
|
|
545
564
|
}
|
|
546
565
|
return request;
|
|
@@ -572,7 +591,7 @@ function publicPendingRequests(pending) {
|
|
|
572
591
|
expectsReply: request.expectsReply,
|
|
573
592
|
}));
|
|
574
593
|
}
|
|
575
|
-
function buildParentSupervisorTool(pi, pending, state, onLifecycle, discover, runState) {
|
|
594
|
+
function buildParentSupervisorTool(pi, pending, state, onLifecycle, discover, runState, ended) {
|
|
576
595
|
return {
|
|
577
596
|
name: NATIVE_SUPERVISOR_TOOL_NAME,
|
|
578
597
|
...MODEL_ONLY_TOOL,
|
|
@@ -592,11 +611,11 @@ function buildParentSupervisorTool(pi, pending, state, onLifecycle, discover, ru
|
|
|
592
611
|
return { content: [{ type: "text", text: lines.length ? lines.join("\n") : "No pending supervisor requests." }], details: { pending: publicPendingRequests(pending) } };
|
|
593
612
|
}
|
|
594
613
|
if (input.action === "reply") {
|
|
595
|
-
const request = resolvePendingRequest(pending, input);
|
|
614
|
+
const request = resolvePendingRequest(pending, input, ended, runState);
|
|
596
615
|
const reply = writeReply(request, input.message ?? "");
|
|
597
616
|
appendSupervisorReplyEntry(pi, request, reply);
|
|
598
617
|
pending.delete(request.id);
|
|
599
|
-
onLifecycle(request, "resolved");
|
|
618
|
+
onLifecycle(request, "resolved", reply.createdAt);
|
|
600
619
|
clearForegroundSupervisorAttention(request, pending, state);
|
|
601
620
|
return { content: [{ type: "text", text: `Replied to supervisor request ${request.id}.` }], details: { replyTo: request.id, runId: request.runId, agent: request.agent } };
|
|
602
621
|
}
|
|
@@ -654,12 +673,37 @@ export function createNativeSupervisorChannel(pi, state, deps = {}) {
|
|
|
654
673
|
requestCorrelations.set(key, { request, state: "resolved", updatedAt: Date.now() });
|
|
655
674
|
pruneRequestCorrelations();
|
|
656
675
|
};
|
|
657
|
-
|
|
676
|
+
// How each request ended, so a late reply can say why it is gone instead of a generic miss.
|
|
677
|
+
const endedRequests = new Map();
|
|
678
|
+
const rememberEndedRequest = (request, lifecycle, eventAt) => {
|
|
679
|
+
if (!request.expectsReply)
|
|
680
|
+
return;
|
|
681
|
+
const now = Date.now();
|
|
682
|
+
endedRequests.delete(request.id);
|
|
683
|
+
endedRequests.set(request.id, { request, lifecycle, endedAt: now, ...(eventAt !== undefined ? { eventAt } : {}) });
|
|
684
|
+
for (const [id, ended] of endedRequests) {
|
|
685
|
+
if (now - ended.endedAt <= SUPERVISOR_REQUEST_CORRELATION_RETENTION_MS && endedRequests.size <= MAX_SUPERVISOR_REQUEST_CORRELATIONS)
|
|
686
|
+
break;
|
|
687
|
+
endedRequests.delete(id);
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
const observeRequestLifecycle = (request, lifecycle, eventAt) => {
|
|
658
691
|
settleNotices.delete(request.id);
|
|
659
692
|
if (queuedNotices.delete(request.id))
|
|
660
693
|
updateDeliverySubscription();
|
|
661
694
|
if (lifecycle !== "wrong-session")
|
|
662
695
|
rememberResolvedRequest(request);
|
|
696
|
+
// A child that hits its ask deadline deletes its own request file, so a missing file past the deadline can be
|
|
697
|
+
// that timeout or a stop just before it. The parent extends a queued ask's expiresAt in memory too, so a live
|
|
698
|
+
// ask never reads as past it.
|
|
699
|
+
if (lifecycle !== "wrong-session" && lifecycle !== "pending") {
|
|
700
|
+
const now = Date.now();
|
|
701
|
+
const expiresAt = requestExpiresAt(request, now);
|
|
702
|
+
if (lifecycle === "missing" && now > expiresAt)
|
|
703
|
+
rememberEndedRequest(request, "deadline", expiresAt);
|
|
704
|
+
else
|
|
705
|
+
rememberEndedRequest(request, lifecycle, lifecycle === "expired" ? expiresAt : eventAt);
|
|
706
|
+
}
|
|
663
707
|
updateSettleSubscription();
|
|
664
708
|
};
|
|
665
709
|
const getSupervisorRequestState = (event) => {
|
|
@@ -716,7 +760,7 @@ export function createNativeSupervisorChannel(pi, state, deps = {}) {
|
|
|
716
760
|
};
|
|
717
761
|
const registerParentTools = () => {
|
|
718
762
|
if (!hasTool(pi, NATIVE_SUPERVISOR_TOOL_NAME))
|
|
719
|
-
pi.registerTool(buildParentSupervisorTool(pi, pending, state, observeRequestLifecycle, () =>
|
|
763
|
+
pi.registerTool(buildParentSupervisorTool(pi, pending, state, observeRequestLifecycle, () => pollOnce(), runState, endedRequests));
|
|
720
764
|
};
|
|
721
765
|
// A session that never delegated through `subagent` does not declare the reply tool (scheduled runs, runs
|
|
722
766
|
// adopted after a resume), so declare it before the model is asked to use it.
|
|
@@ -742,7 +786,7 @@ export function createNativeSupervisorChannel(pi, state, deps = {}) {
|
|
|
742
786
|
// Supervisor delivery must not fail because best-effort temp cleanup failed.
|
|
743
787
|
}
|
|
744
788
|
};
|
|
745
|
-
const
|
|
789
|
+
const pollOnce = () => {
|
|
746
790
|
cleanupStaleChannelsIfDue();
|
|
747
791
|
// Only display notifications require a live UI context, not request registration.
|
|
748
792
|
refreshPendingRequests(pending, state, observeRequestLifecycle, runState);
|
|
@@ -777,7 +821,7 @@ export function createNativeSupervisorChannel(pi, state, deps = {}) {
|
|
|
777
821
|
continue;
|
|
778
822
|
}
|
|
779
823
|
seenFiles.add(file);
|
|
780
|
-
observeRequestLifecycle(request, "resolved");
|
|
824
|
+
observeRequestLifecycle(request, "resolved", now);
|
|
781
825
|
cleanupRequestLifecycle(request, "resolved");
|
|
782
826
|
continue;
|
|
783
827
|
}
|
|
@@ -835,6 +879,17 @@ export function createNativeSupervisorChannel(pi, state, deps = {}) {
|
|
|
835
879
|
channels?.retire?.();
|
|
836
880
|
updateSettleSubscription();
|
|
837
881
|
};
|
|
882
|
+
// Never throws: this runs from timers, watchers, setImmediate and event handlers, and Pi exits the process on an
|
|
883
|
+
// uncaught exception, so one unreadable temp directory must not end the session. Callers whose answer a model or a
|
|
884
|
+
// drain decision reads use pollOnce, so a failed scan is not mistaken for "no pending requests".
|
|
885
|
+
const poll = () => {
|
|
886
|
+
try {
|
|
887
|
+
pollOnce();
|
|
888
|
+
}
|
|
889
|
+
catch (error) {
|
|
890
|
+
reportSessionWarning(state, `Supervisor channel poll failed: ${error instanceof Error ? error.message : String(error)}`, "supervisor-channel-poll");
|
|
891
|
+
}
|
|
892
|
+
};
|
|
838
893
|
const handleBeforeSettle = (event) => {
|
|
839
894
|
if (!started || event.outcome !== "completed")
|
|
840
895
|
return;
|
|
@@ -1048,7 +1103,7 @@ export function createNativeSupervisorChannel(pi, state, deps = {}) {
|
|
|
1048
1103
|
hasPendingRequests: () => {
|
|
1049
1104
|
if (!started)
|
|
1050
1105
|
return false;
|
|
1051
|
-
|
|
1106
|
+
pollOnce();
|
|
1052
1107
|
return pending.size > 0;
|
|
1053
1108
|
},
|
|
1054
1109
|
start: () => {
|
|
@@ -1111,6 +1166,7 @@ export function createNativeSupervisorChannel(pi, state, deps = {}) {
|
|
|
1111
1166
|
pending.clear();
|
|
1112
1167
|
settleNotices.clear();
|
|
1113
1168
|
requestCorrelations.clear();
|
|
1169
|
+
endedRequests.clear();
|
|
1114
1170
|
seenFiles.clear();
|
|
1115
1171
|
},
|
|
1116
1172
|
pending,
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Async execution logic for subagent tool
|
|
3
|
-
*/
|
|
4
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
5
2
|
import type { ParentProviderRegistry } from "../shared/child-session.ts";
|
|
6
3
|
import { type AgentConfig, type UnknownAgentDiagnosticContext } from "../../agents/agents.ts";
|
|
@@ -17,6 +14,7 @@ import { type ChildRuntimeConfig } from "../shared/child-runtime-config.ts";
|
|
|
17
14
|
import type { ImportedAsyncRoot } from "./chain-root-attachment.ts";
|
|
18
15
|
import type { SessionLeaseRequest } from "../shared/session-lease.ts";
|
|
19
16
|
import type { ActiveAsyncCapacityHandle } from "./active-async-capacity.ts";
|
|
17
|
+
import { type RequiredRunnerLauncher } from "../../shared/types.ts";
|
|
20
18
|
import { type ResolvedSubagentCapabilityCeiling } from "../shared/capability-ceiling.ts";
|
|
21
19
|
import { type PermissionConfig } from "../shared/permissions.ts";
|
|
22
20
|
import { type ExtensionBindings } from "../shared/extension-bindings.ts";
|
|
@@ -48,7 +46,6 @@ interface AsyncExecutionContext {
|
|
|
48
46
|
/** The parent's model registry, read at launch to name a provider an extension registered there. */
|
|
49
47
|
parentProviderRegistry?: Pick<ParentProviderRegistry, "getRegisteredProviderIds">;
|
|
50
48
|
}
|
|
51
|
-
export declare const DEFAULT_ASYNC_TIMEOUT_MS: number;
|
|
52
49
|
interface AsyncChainParams {
|
|
53
50
|
chain: ChainStep[];
|
|
54
51
|
task?: string;
|
|
@@ -134,6 +131,10 @@ interface AsyncSingleParams {
|
|
|
134
131
|
machine?: string;
|
|
135
132
|
/** Launch cwd as typed when a machine is set: a path on that machine, never resolved locally. */
|
|
136
133
|
machineCwd?: string;
|
|
134
|
+
/** The launcher and agent definition digest the call requires; checked here, on what this launch spawns. */
|
|
135
|
+
requireLauncher?: RequiredRunnerLauncher;
|
|
136
|
+
/** A revived run's inherited requirement: recorded for its own resumes, not checked here (resume already checked it). */
|
|
137
|
+
carriedRequiredLauncher?: RequiredRunnerLauncher;
|
|
137
138
|
maxOutput?: MaxOutputConfig;
|
|
138
139
|
artifactsDir?: string;
|
|
139
140
|
artifactConfig: ArtifactConfig;
|
|
@@ -288,13 +289,7 @@ export declare function resolveClaudeCodeThinking(source: string | false | undef
|
|
|
288
289
|
* owns the remote model registry, so the combination fails instead of losing both flags. */
|
|
289
290
|
export declare function assertClaudeCodeOverrideIsLocal(agent: string, machine: string | undefined, override: ClaudeCodeOverride | undefined): void;
|
|
290
291
|
export declare function buildAsyncRunnerSteps(id: string, params: AsyncRunnerStepBuildParams): AsyncRunnerStepBuildResult;
|
|
291
|
-
/**
|
|
292
|
-
* Execute a chain asynchronously
|
|
293
|
-
*/
|
|
294
292
|
export declare function executeAsyncChain(id: string, params: AsyncChainParams): AsyncExecutionResult | Promise<AsyncExecutionResult>;
|
|
295
|
-
/**
|
|
296
|
-
* Execute a single agent asynchronously
|
|
297
|
-
*/
|
|
298
293
|
export declare function workflowAwaitedAsyncResultPath(asyncDir: string): string;
|
|
299
294
|
export declare function executeAsyncSingle(id: string, params: AsyncSingleParams): AsyncExecutionResult | Promise<AsyncExecutionResult>;
|
|
300
295
|
export {};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Async execution logic for subagent tool
|
|
3
|
-
*/
|
|
4
|
-
import { spawn } from "node:child_process";
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
5
2
|
import { randomUUID } from "node:crypto";
|
|
6
3
|
import * as fs from "node:fs";
|
|
7
4
|
import * as path from "node:path";
|
|
@@ -33,7 +30,7 @@ import { resolveToolTimeoutMs, toolTimeoutFromEnv } from "../shared/tool-timeout
|
|
|
33
30
|
import { resolveModelScopesForAgent } from "../shared/model-scope.js";
|
|
34
31
|
import { findModelInfo, resolveEffectiveThinking } from "../../shared/model-info.js";
|
|
35
32
|
import { assertThinkingWithinCeiling, intersectThinkingCeilings } from "../../shared/thinking-ceiling.js";
|
|
36
|
-
import { resolveExpectedWorktreeAgentCwd, resolveWorktreeProvider, shouldDeferWorktreeCwd, WORKTREE_AGENT_CWD_PLACEHOLDER } from "../shared/worktree.js";
|
|
33
|
+
import { buildWorktreeNaming, resolveExpectedWorktreeAgentCwd, resolveWorktreeProvider, shouldDeferWorktreeCwd, WORKTREE_AGENT_CWD_PLACEHOLDER } from "../shared/worktree.js";
|
|
37
34
|
import { buildWorkflowGraphSnapshot } from "../shared/workflow-graph.js";
|
|
38
35
|
import { ChainOutputValidationError, validateChainOutputBindings } from "../shared/chain-outputs.js";
|
|
39
36
|
import { createStructuredOutputRuntime } from "../shared/structured-output.js";
|
|
@@ -54,7 +51,7 @@ import { statusStepDescription } from "./chain-append.js";
|
|
|
54
51
|
import { currentBootId, currentRecordedPid } from "./boot-id.js";
|
|
55
52
|
import { currentPidNamespaceScope } from "./pid-namespace.js";
|
|
56
53
|
import { checkRecordedPidLiveness } from "./stale-run-reconciler.js";
|
|
57
|
-
import { lookupRunnerLauncher, resolveAgentRunnerLauncher, runnerLauncherPlacementError } from "../shared/runner-launcher.js";
|
|
54
|
+
import { checkRequiredRunnerLauncher, lookupRunnerLauncher, resolveAgentRunnerLauncher, runnerLauncherPlacementError } from "../shared/runner-launcher.js";
|
|
58
55
|
import { SUBAGENT_PROCESS_TERMINAL_EVENT } from "../../shared/types.js";
|
|
59
56
|
import { assertAgentAllowedByCapabilityCeiling, intersectSubagentCapabilityCeilings, resolveCurrentSubagentCapabilityCeiling } from "../shared/capability-ceiling.js";
|
|
60
57
|
import { resolveLaunchBinding } from "../../shared/launch-contract.js";
|
|
@@ -62,7 +59,9 @@ import { resolvePermissionRules } from "../shared/permissions.js";
|
|
|
62
59
|
import { normalizeExtensionBindings, omitExtensionBindingsEnv } from "../shared/extension-bindings.js";
|
|
63
60
|
import { omitGitRoutingEnv } from "../shared/git-environment.js";
|
|
64
61
|
import { assertWorkflowLaneKey, normalizeWorkflowLaneMetadata } from "../shared/lane-metadata.js";
|
|
62
|
+
import { recoveryDescriptorPath } from "../shared/run-launch-folder.js";
|
|
65
63
|
import { assertRequiredChildExtensionsAdmitted, resolveRequiredChildExtensions, writeRetainedRequiredChildExtensions } from "../../shared/required-child-extensions.js";
|
|
64
|
+
import { DEFAULT_WAIT_TOOL_NAME, waitToolName } from "../../shared/wait-tool-name.js";
|
|
66
65
|
const require = nodeModule.createRequire(import.meta.url);
|
|
67
66
|
// Cache failures as well as roots: management must remain loadable, and launches must not retry another SDK.
|
|
68
67
|
const piPackageSelection = (() => {
|
|
@@ -146,15 +145,14 @@ function parentExtensionProviderForChild(ctx, disableAmbientExtensions, model, a
|
|
|
146
145
|
const provider = findModelInfo(model, availableModels, preferredProvider)?.provider;
|
|
147
146
|
return provider && ctx.parentProviderRegistry.getRegisteredProviderIds().includes(provider) ? provider : undefined;
|
|
148
147
|
}
|
|
149
|
-
export const DEFAULT_ASYNC_TIMEOUT_MS = 30 * 60 * 1000;
|
|
150
148
|
export function formatAsyncStartedMessage(headline, interactive) {
|
|
151
149
|
const guidance = interactive
|
|
152
150
|
? [
|
|
153
|
-
|
|
151
|
+
`Detached. Return control now: native completion wakes you, so do not sleep, poll, or call ${waitToolName()} for it.`,
|
|
154
152
|
"One-shot check: subagent({ action: \"status\", id: \"...\" }).",
|
|
155
153
|
]
|
|
156
154
|
: [
|
|
157
|
-
|
|
155
|
+
`Detached non-interactive run: Pi auto-drains current-session subagent work at agent_end. Do not run sleep timers or polling loops. Use ${waitToolName()} only for results this turn needs from work without native notification, and subagent({ action: \"status\", id: \"...\" }) for a one-shot check.`,
|
|
158
156
|
];
|
|
159
157
|
return [headline, "", ...guidance].join("\n");
|
|
160
158
|
}
|
|
@@ -183,9 +181,6 @@ function closeFd(fd) {
|
|
|
183
181
|
// Best-effort cleanup; child process already owns its duplicated stdio fd.
|
|
184
182
|
}
|
|
185
183
|
}
|
|
186
|
-
/**
|
|
187
|
-
* Spawn the async runner process
|
|
188
|
-
*/
|
|
189
184
|
const RUNNER_STARTUP_TIMEOUT_MS = 10_000;
|
|
190
185
|
function waitForStartupInterval(delayMs = 20) {
|
|
191
186
|
return new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
@@ -287,6 +282,33 @@ function terminateRunnerBeforeProceed(pid) {
|
|
|
287
282
|
}
|
|
288
283
|
return !runnerIsAlive(pid);
|
|
289
284
|
}
|
|
285
|
+
function parentPid(pid) {
|
|
286
|
+
let ppid;
|
|
287
|
+
if (process.platform === "linux") {
|
|
288
|
+
try {
|
|
289
|
+
const stat = fs.readFileSync(`/proc/${pid}/stat`, "utf-8");
|
|
290
|
+
ppid = Number(stat.slice(stat.lastIndexOf(")") + 1).trim().split(/\s+/)[1]);
|
|
291
|
+
}
|
|
292
|
+
catch {
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
const result = spawnSync("ps", ["-o", "ppid=", "-p", String(pid)], { encoding: "utf-8" });
|
|
298
|
+
if (result.error || result.status !== 0)
|
|
299
|
+
return undefined;
|
|
300
|
+
ppid = Number(result.stdout.trim());
|
|
301
|
+
}
|
|
302
|
+
return Number.isSafeInteger(ppid) && ppid > 0 ? ppid : undefined;
|
|
303
|
+
}
|
|
304
|
+
/** The runner reports its own pid, so behind a launcher only a pid inside the spawned launcher's tree may be signalled. */
|
|
305
|
+
function isInProcessTree(pid, rootPid) {
|
|
306
|
+
for (let current = pid; current !== undefined && current > 1; current = parentPid(current)) {
|
|
307
|
+
if (current === rootPid)
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
290
312
|
async function terminateRunnerBeforeProceedAsyncDefault(proc, processClosed) {
|
|
291
313
|
for (const signal of ["SIGTERM", "SIGKILL"]) {
|
|
292
314
|
if (proc.pid === undefined || !runnerIsAlive(proc.pid))
|
|
@@ -449,7 +471,7 @@ function spawnRunner(cfg, suffix, cwd, initialStatus, initialStatusPath, launchP
|
|
|
449
471
|
// its own identity before it is allowed to proceed.
|
|
450
472
|
const launcher = cfg.launcher;
|
|
451
473
|
const bootId = launcher ? undefined : currentBootId();
|
|
452
|
-
const launchConfig = { ...cfg, runnerProcessInstanceId, ...(launchBarrierToken ? { launchBarrierToken } : {}), ...(bootId ? { bootId } : {}) };
|
|
474
|
+
const launchConfig = { ...cfg, runnerProcessInstanceId, ...(launchBarrierToken ? { launchBarrierToken } : {}), ...(bootId ? { bootId } : {}), ...(waitToolName() !== DEFAULT_WAIT_TOOL_NAME ? { waitToolName: waitToolName() } : {}) };
|
|
453
475
|
writePrivateAtomicJson(cfgPath, launchConfig);
|
|
454
476
|
const command = binaryHost ?? nodeExecutable;
|
|
455
477
|
const launchForStartup = launchConfig;
|
|
@@ -477,10 +499,12 @@ function spawnRunner(cfg, suffix, cwd, initialStatus, initialStatusPath, launchP
|
|
|
477
499
|
if (identityPath)
|
|
478
500
|
fs.rmSync(identityPath, { force: true });
|
|
479
501
|
let runnerIdentity;
|
|
480
|
-
// Wrapper exit is not runner exit, so only a reported runner in this namespace may be signalled
|
|
502
|
+
// Wrapper exit is not runner exit, so only a reported runner in this namespace may be signalled, and only
|
|
503
|
+
// inside the spawned launcher's process tree. Otherwise the runner exits when proceed never arrives.
|
|
481
504
|
const terminateBeforeProceed = (pid) => !launcher
|
|
482
505
|
? terminateRunnerBeforeProceed(pid)
|
|
483
|
-
: runnerIdentity !== undefined && runnerIdentity.pidNamespaceScope === currentPidNamespaceScope()
|
|
506
|
+
: runnerIdentity !== undefined && runnerIdentity.pidNamespaceScope === currentPidNamespaceScope()
|
|
507
|
+
&& isInProcessTree(runnerIdentity.pid, pid) && terminateRunnerBeforeProceed(runnerIdentity.pid);
|
|
484
508
|
const adoptRunnerIdentity = (pid, pidNamespaceScope) => {
|
|
485
509
|
if (typeof pid !== "number" || !Number.isSafeInteger(pid) || pid < 1)
|
|
486
510
|
return `Async runner reported an invalid process identity in '${launchAsyncDir}'.`;
|
|
@@ -928,7 +952,7 @@ export function buildAsyncRunnerSteps(id, params) {
|
|
|
928
952
|
taskTemplate = taskTemplate.replace(/\{chain_dir\}/g, behaviorCwd ?? runnerCwd);
|
|
929
953
|
const taskText = `${readInstructions.prefix}${taskTemplate}${progressInstructions.suffix}`;
|
|
930
954
|
// A namespaced parallel output path is added to each child's task by the runner.
|
|
931
|
-
const task = namespaceOutputPath ? taskText : injectSingleOutputInstruction(taskText, outputPath, a);
|
|
955
|
+
const task = namespaceOutputPath ? taskText : injectSingleOutputInstruction(taskText, outputPath, a, machine);
|
|
932
956
|
const modelScopes = resolveModelScopesForAgent(ctx.modelScope, a.name, ctx.currentModel, ctx.scopedModelIds);
|
|
933
957
|
const modelOrigin = resolveModelOrigin({ explicitModel: s.model, agentModel: a.model, parentModel: ctx.currentModel });
|
|
934
958
|
const primaryModelFromParent = modelOrigin === "inherited";
|
|
@@ -987,7 +1011,8 @@ export function buildAsyncRunnerSteps(id, params) {
|
|
|
987
1011
|
if (launchRuleError)
|
|
988
1012
|
throw new AsyncStartValidationError(launchRuleError);
|
|
989
1013
|
const fast = s.fast ?? params.fast ?? a.fast;
|
|
990
|
-
|
|
1014
|
+
// Admission already refused mandatory entries for a placed child, which skips the rest.
|
|
1015
|
+
const requiredExtensions = externalRunner || machine ? [] : params.requiredExtensions ?? ctx.childRuntime?.requiredExtensions ?? registeredExtensions;
|
|
991
1016
|
const toolPlan = resolvePiLaunchToolPlan({
|
|
992
1017
|
tools: a.tools,
|
|
993
1018
|
excludeTools: a.excludeTools,
|
|
@@ -1064,7 +1089,7 @@ export function buildAsyncRunnerSteps(id, params) {
|
|
|
1064
1089
|
outputMode: behavior.outputMode,
|
|
1065
1090
|
sessionFile,
|
|
1066
1091
|
maxSubagentDepth: resolveChildMaxSubagentDepth(maxSubagentDepth, a.maxSubagentDepth),
|
|
1067
|
-
timeoutMs: a.defaultTimeoutMs
|
|
1092
|
+
timeoutMs: a.defaultTimeoutMs,
|
|
1068
1093
|
toolTimeoutMs: resolvedToolTimeout.toolTimeoutMs,
|
|
1069
1094
|
waitToolEnabled: params.waitToolEnabled,
|
|
1070
1095
|
waitToolDefaultTimeoutMs: params.waitToolDefaultTimeoutMs,
|
|
@@ -1230,9 +1255,6 @@ export function buildAsyncRunnerSteps(id, params) {
|
|
|
1230
1255
|
throw error;
|
|
1231
1256
|
}
|
|
1232
1257
|
}
|
|
1233
|
-
/**
|
|
1234
|
-
* Execute a chain asynchronously
|
|
1235
|
-
*/
|
|
1236
1258
|
export function executeAsyncChain(id, params) {
|
|
1237
1259
|
const { chain, agents, ctx, cwd, maxOutput, artifactsDir, artifactConfig, shareEnabled, sessionRoot, sessionFilesByFlatIndex, thinkingOverridesByFlatIndex, maxSubagentDepth, worktreeSetupHook, worktreeSetupHookTimeoutMs, worktreeBaseDir, baseRef, worktreeProvider, worktreeBranchPrefix, controlConfig, controlIntercomTarget, childIntercomTarget, nestedRoute, } = params;
|
|
1238
1260
|
const resultMode = params.resultMode ?? "chain";
|
|
@@ -1555,14 +1577,12 @@ export function executeAsyncChain(id, params) {
|
|
|
1555
1577
|
};
|
|
1556
1578
|
return spawnResultOrPromise instanceof Promise ? spawnResultOrPromise.then(finishSpawnResult) : finishSpawnResult(spawnResultOrPromise);
|
|
1557
1579
|
}
|
|
1558
|
-
/**
|
|
1559
|
-
* Execute a single agent asynchronously
|
|
1560
|
-
*/
|
|
1561
1580
|
export function workflowAwaitedAsyncResultPath(asyncDir) {
|
|
1562
1581
|
return path.join(asyncDir, "workflow-result.json");
|
|
1563
1582
|
}
|
|
1564
1583
|
export function executeAsyncSingle(id, params) {
|
|
1565
|
-
const { agent,
|
|
1584
|
+
const { agent, ctx, cwd, maxOutput, artifactsDir, artifactConfig, shareEnabled, sessionRoot, sessionFile, maxSubagentDepth, worktreeSetupHook, worktreeSetupHookTimeoutMs, worktreeBaseDir, baseRef, worktreeProvider, worktreeBranchPrefix, controlConfig, controlIntercomTarget, childIntercomTarget, nestedRoute, } = params;
|
|
1585
|
+
let agentConfig = params.agentConfig;
|
|
1566
1586
|
let lane;
|
|
1567
1587
|
try {
|
|
1568
1588
|
lane = normalizeWorkflowLaneMetadata(params.lane, "lane");
|
|
@@ -1632,6 +1652,13 @@ export function executeAsyncSingle(id, params) {
|
|
|
1632
1652
|
if (resolvedLauncher.error)
|
|
1633
1653
|
return formatAsyncStartError("single", resolvedLauncher.error);
|
|
1634
1654
|
const launcher = resolvedLauncher.launcher;
|
|
1655
|
+
if (params.requireLauncher) {
|
|
1656
|
+
const required = checkRequiredRunnerLauncher(agentConfig, launcher?.name, params.requireLauncher);
|
|
1657
|
+
if (required.error !== undefined)
|
|
1658
|
+
return formatAsyncStartError("single", required.error);
|
|
1659
|
+
// The launch records the digest it checked, not a second hash of an agent file that may have changed since.
|
|
1660
|
+
agentConfig = { ...agentConfig, definitionDigest: required.definitionDigest };
|
|
1661
|
+
}
|
|
1635
1662
|
const registeredExtensions = resolveRequiredChildExtensions(ctx.parentSessionId ?? ctx.currentSessionId ?? undefined);
|
|
1636
1663
|
try {
|
|
1637
1664
|
assertRequiredChildExtensionsAdmitted([params.requiredExtensions, ctx.childRuntime?.requiredExtensions, registeredExtensions], { agent: agentConfig.name, runnerType: agentConfig.runner?.type, machine: requestedMachine });
|
|
@@ -1698,7 +1725,7 @@ export function executeAsyncSingle(id, params) {
|
|
|
1698
1725
|
const validationError = validateFileOnlyOutputMode(outputMode, outputPath, `Async single run (${agent})`);
|
|
1699
1726
|
if (validationError)
|
|
1700
1727
|
return formatAsyncStartError("single", validationError);
|
|
1701
|
-
const taskWithOutputInstruction = injectSingleOutputInstruction(task, outputPath, agentConfig);
|
|
1728
|
+
const taskWithOutputInstruction = injectSingleOutputInstruction(task, outputPath, agentConfig, machine);
|
|
1702
1729
|
// Reads: caller override > agent defaultReads > none. `~`/`~/` expand to home;
|
|
1703
1730
|
// absolute paths pass through; relative paths resolve against the child cwd.
|
|
1704
1731
|
const reads = params.reads !== undefined ? params.reads : agentConfig.defaultReads ?? false;
|
|
@@ -1803,7 +1830,8 @@ export function executeAsyncSingle(id, params) {
|
|
|
1803
1830
|
return formatAsyncStartError("single", error instanceof Error ? error.message : String(error));
|
|
1804
1831
|
}
|
|
1805
1832
|
}
|
|
1806
|
-
|
|
1833
|
+
// Admission already refused mandatory entries for a placed child, which skips the rest.
|
|
1834
|
+
const requiredExtensions = externalRunner || machine ? [] : params.requiredExtensions ?? ctx.childRuntime?.requiredExtensions ?? registeredExtensions;
|
|
1807
1835
|
const toolPlan = resolvePiLaunchToolPlan({
|
|
1808
1836
|
tools: agentConfig.tools,
|
|
1809
1837
|
excludeTools: agentConfig.excludeTools,
|
|
@@ -1851,6 +1879,7 @@ export function executeAsyncSingle(id, params) {
|
|
|
1851
1879
|
agentContract: params.agentContract,
|
|
1852
1880
|
});
|
|
1853
1881
|
const recoveryAgentConfig = params.recoveryAgentConfig ?? agentConfig;
|
|
1882
|
+
const requiredLauncher = params.requireLauncher ?? params.carriedRequiredLauncher;
|
|
1854
1883
|
const recoveryDescriptor = {
|
|
1855
1884
|
...(ctx.modelResponseAliases ? { modelResponseAliases: ctx.modelResponseAliases } : {}),
|
|
1856
1885
|
version: 1,
|
|
@@ -1860,6 +1889,10 @@ export function executeAsyncSingle(id, params) {
|
|
|
1860
1889
|
...(requiredExtensions.length > 0 ? { requiredExtensions } : {}),
|
|
1861
1890
|
runFanoutBudget,
|
|
1862
1891
|
sourceRunId: id,
|
|
1892
|
+
...(ctx.currentSessionId ? { sessionId: ctx.currentSessionId } : {}),
|
|
1893
|
+
// The worktree the runner will create, fixed here from launch inputs (the runner's own naming call).
|
|
1894
|
+
...(managedWorktreeProvider === "native" ? { managedWorktree: { provider: "native", cwd: instructionCwd } } : {}),
|
|
1895
|
+
...(managedWorktreeProvider === "worktrunk" ? { managedWorktree: { provider: "worktrunk", branch: buildWorktreeNaming({ runId: `${id}-s0`, index: 0, agent, label: lane?.key ?? params.workflowKey, task: taskText, branchPrefix: worktreeBranchPrefix }).requestedBranch } } : {}),
|
|
1863
1896
|
...(params.agentContract ? { agentContract: params.agentContract } : {}),
|
|
1864
1897
|
agent,
|
|
1865
1898
|
launchResolvedExtensions,
|
|
@@ -1897,7 +1930,8 @@ export function executeAsyncSingle(id, params) {
|
|
|
1897
1930
|
...(params.context ? { context: params.context } : {}),
|
|
1898
1931
|
...(params.intercomBridge !== undefined ? { intercomBridge: params.intercomBridge } : {}),
|
|
1899
1932
|
...(params.baseRef !== undefined ? { baseRef: params.baseRef } : {}),
|
|
1900
|
-
|
|
1933
|
+
launcher: launcher ? launcher.name : null,
|
|
1934
|
+
...(requiredLauncher ? { requiredLauncher } : {}),
|
|
1901
1935
|
...(deadlineAt !== undefined ? { absoluteDeadlineAt: deadlineAt } : {}),
|
|
1902
1936
|
...(resolvedToolBudget.budget ? { initialToolBudget: resolvedToolBudget.budget } : {}),
|
|
1903
1937
|
maxSubagentDepth: resolveChildMaxSubagentDepth(maxSubagentDepth, recoveryAgentConfig.maxSubagentDepth),
|
|
@@ -1910,7 +1944,7 @@ export function executeAsyncSingle(id, params) {
|
|
|
1910
1944
|
};
|
|
1911
1945
|
if (!externalRunner) {
|
|
1912
1946
|
try {
|
|
1913
|
-
writePrivateAtomicJson(path.
|
|
1947
|
+
writePrivateAtomicJson(recoveryDescriptorPath(path.dirname(asyncDir), id), recoveryDescriptor);
|
|
1914
1948
|
}
|
|
1915
1949
|
catch (error) {
|
|
1916
1950
|
return formatAsyncStartError("single", `Failed to persist async recovery descriptor for '${id}': ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -16,6 +16,7 @@ import { validHostStepNodes } from "../shared/host-step-status.js";
|
|
|
16
16
|
import { readProcessTerminal } from "./process-terminal.js";
|
|
17
17
|
import { withCachedUiContext } from "../../shared/extension-context.js";
|
|
18
18
|
import { OWNING_SESSION_COMPLETION_OWNER } from "../../shared/completion-owner.js";
|
|
19
|
+
import { ownerSessionIds } from "../shared/run-ownership.js";
|
|
19
20
|
const CONTROL_EVENT_READ_CHUNK_BYTES = 64 * 1024;
|
|
20
21
|
const MAX_CONTROL_EVENT_LINE_BYTES = 1024 * 1024;
|
|
21
22
|
const CONTROL_EVENT_SCAN_WINDOW_BYTES = 2 * 1024 * 1024;
|
|
@@ -746,7 +747,18 @@ export function createAsyncJobTracker(pi, state, asyncDirRoot, options = {}) {
|
|
|
746
747
|
if (now >= nextLivenessAt) {
|
|
747
748
|
nextLivenessAt = now + livenessIntervalMs;
|
|
748
749
|
let widgetChanged = false;
|
|
750
|
+
// A session reopened in this process takes its runs back from the session that replaced it.
|
|
751
|
+
const owners = state.currentSessionId ? ownerSessionIds(state.currentSessionId) : undefined;
|
|
749
752
|
for (const job of state.asyncJobs.values()) {
|
|
753
|
+
if (owners && job.sessionId !== undefined && !owners.has(job.sessionId)) {
|
|
754
|
+
cancelCleanup(job.asyncId);
|
|
755
|
+
closeJobWatcher(job.asyncId);
|
|
756
|
+
state.asyncJobs.delete(job.asyncId);
|
|
757
|
+
state.fleetJobs?.delete(job.asyncId);
|
|
758
|
+
options.onJobCleanup?.(job.asyncId);
|
|
759
|
+
widgetChanged = true;
|
|
760
|
+
continue;
|
|
761
|
+
}
|
|
750
762
|
watchJob(job);
|
|
751
763
|
if (refreshJob(job))
|
|
752
764
|
widgetChanged = true;
|
|
@@ -51,8 +51,9 @@ export declare function findAsyncRunPrefixMatches(prefix: string, asyncDirRoot:
|
|
|
51
51
|
location: AsyncRunLocation;
|
|
52
52
|
}>;
|
|
53
53
|
export declare function resolveAsyncRunLocation(params: AsyncResumeParams, asyncDirRoot: string, resultsDir: string): AsyncRunLocation;
|
|
54
|
+
/** A workflow-mode target has a ceiling only when its parent-owned launch record exists (resolveAsyncResumeTarget). */
|
|
54
55
|
export declare function asyncReviveRequiresRecoveryDescriptor(target: Pick<AsyncResumeTarget, "recoveryDescriptor" | "mode" | "sessionFile" | "capabilityCeiling">): boolean;
|
|
55
|
-
export declare function readAsyncRecoveryDescriptor(
|
|
56
|
+
export declare function readAsyncRecoveryDescriptor(runsRoot: string, runId: string): SteeringRecoveryDescriptor | undefined;
|
|
56
57
|
export declare function resolveAsyncResumeTarget(params: AsyncResumeParams, deps?: AsyncResumeDeps, options?: AsyncResumeOptions): AsyncResumeTarget;
|
|
57
58
|
export declare function applySteeringRecoveryAgentConfig(agentConfig: AgentConfig, descriptor: SteeringRecoveryDescriptor): AgentConfig;
|
|
58
59
|
export declare function buildRevivedAsyncTask(target: AsyncResumeTarget, message: string): string;
|