fix(subagent): wait for completion before announce
The previous immediate probe (timeoutMs: 0) only caught already-completed runs. Cross-process spawns need to actually wait via agent.wait RPC for the gateway to signal completion, then trigger the announce flow. - Rename probeImmediateCompletion to waitForSubagentCompletion - Use 10 minute wait timeout for agent.wait RPC - Remove leftover debug console.log statements
This commit is contained in:
@@ -68,7 +68,9 @@ function ensureListener() {
|
|||||||
onAgentEvent((evt) => {
|
onAgentEvent((evt) => {
|
||||||
if (!evt || evt.stream !== "lifecycle") return;
|
if (!evt || evt.stream !== "lifecycle") return;
|
||||||
const entry = subagentRuns.get(evt.runId);
|
const entry = subagentRuns.get(evt.runId);
|
||||||
if (!entry) return;
|
if (!entry) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const phase = evt.data?.phase;
|
const phase = evt.data?.phase;
|
||||||
if (phase === "start") {
|
if (phase === "start") {
|
||||||
const startedAt =
|
const startedAt =
|
||||||
@@ -148,18 +150,23 @@ export function registerSubagentRun(params: {
|
|||||||
});
|
});
|
||||||
ensureListener();
|
ensureListener();
|
||||||
if (archiveAfterMs) startSweeper();
|
if (archiveAfterMs) startSweeper();
|
||||||
void probeImmediateCompletion(params.runId);
|
// Wait for subagent completion via gateway RPC (cross-process).
|
||||||
|
// The in-process lifecycle listener is a fallback for embedded runs.
|
||||||
|
void waitForSubagentCompletion(params.runId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function probeImmediateCompletion(runId: string) {
|
// Default wait timeout: 10 minutes. This covers most subagent runs.
|
||||||
|
const DEFAULT_SUBAGENT_WAIT_TIMEOUT_MS = 10 * 60 * 1000;
|
||||||
|
|
||||||
|
async function waitForSubagentCompletion(runId: string) {
|
||||||
try {
|
try {
|
||||||
const wait = (await callGateway({
|
const wait = (await callGateway({
|
||||||
method: "agent.wait",
|
method: "agent.wait",
|
||||||
params: {
|
params: {
|
||||||
runId,
|
runId,
|
||||||
timeoutMs: 0,
|
timeoutMs: DEFAULT_SUBAGENT_WAIT_TIMEOUT_MS,
|
||||||
},
|
},
|
||||||
timeoutMs: 2000,
|
timeoutMs: DEFAULT_SUBAGENT_WAIT_TIMEOUT_MS + 10_000,
|
||||||
})) as { status?: string; startedAt?: number; endedAt?: number };
|
})) as { status?: string; startedAt?: number; endedAt?: number };
|
||||||
if (wait?.status !== "ok" && wait?.status !== "error") return;
|
if (wait?.status !== "ok" && wait?.status !== "error") return;
|
||||||
const entry = subagentRuns.get(runId);
|
const entry = subagentRuns.get(runId);
|
||||||
|
|||||||
Reference in New Issue
Block a user