fix(agent): align subagent lifecycle with openclaw

This commit is contained in:
yushen 2026-02-03 17:22:41 +08:00
parent 1cd778b845
commit 30f23459ce
2 changed files with 11 additions and 7 deletions

View file

@ -47,10 +47,9 @@ export function initSubagentRegistry(): void {
resumedRuns.add(runId);
handleRunCompletion(record);
}
}
// If not ended, the child agent session is lost on restart —
// mark as ended with unknown outcome
else if (!record.startedAt) {
} else {
// If not ended, the child agent session is lost on restart —
// mark as ended with unknown outcome
record.endedAt = Date.now();
record.outcome = { status: "unknown" };
persist();
@ -246,6 +245,10 @@ function handleRunCompletion(record: SubagentRunRecord): void {
if (!announced) {
console.warn(`[SubagentRegistry] Announce flow failed for run ${record.runId}`);
// Allow retry on next restart if announce failed.
record.cleanupHandled = false;
persist();
return;
}
// Handle session cleanup

View file

@ -100,6 +100,10 @@ export function createSessionsSpawnTool(
model,
});
// Write the task to the child (non-blocking) before registering,
// so waitForIdle() observes the queued work.
childAgent.write(task);
// Register the run for lifecycle tracking
registerSubagentRun({
runId,
@ -111,9 +115,6 @@ export function createSessionsSpawnTool(
timeoutSeconds,
});
// Write the task to the child (non-blocking)
childAgent.write(task);
return {
content: [
{