Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(agent): align subagent lifecycle with openclaw

yushen30f23459cec3
diff --git a/src/agent/subagent/registry.ts b/src/agent/subagent/registry.ts
index b2cc84462d..d6f76b9428 100644
--- a/src/agent/subagent/registry.ts
+++ b/src/agent/subagent/registry.ts
@@ -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
diff --git a/src/agent/tools/sessions-spawn.ts b/src/agent/tools/sessions-spawn.ts
index 0dfb5c8c12..9ae2cc69c2 100644
--- a/src/agent/tools/sessions-spawn.ts
+++ b/src/agent/tools/sessions-spawn.ts
@@ -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: [
{