openclaw - 💡(How to fix) Fix Stale ended subagent runs persist in childSessions, ghost agents on Floor [1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#57920Fetched 2026-04-08 01:56:06
View on GitHub
Comments
1
Participants
1
Timeline
2
Reactions
0
Participants
Timeline (top)
commented ×1cross-referenced ×1

Root Cause

resolveChildSessionKeys() (in auth-profiles-*.js, around the subagent-registry region) iterates all runs for a controller session key but never filters by endedAt. Every subagent ever spawned — even ones that completed days ago — is returned as a child session.

// Current behavior (simplified):
function resolveChildSessionKeys(controllerSessionKey, store) {
  for (const entry of listSubagentRunsForController(controllerSessionKey)) {
    childSessionKeys.add(entry.childSessionKey); // no endedAt check
  }
  // ...also checks store entries by spawnedBy/parentSessionKey
}

Fix Action

Workaround

Manually clear ended runs from runs.json:

import json
with open("~/.openclaw/subagents/runs.json") as f:
    data = json.load(f)
data["runs"] = {k: v for k, v in data["runs"].items() if not v.get("endedAt")}
with open("~/.openclaw/subagents/runs.json", "w") as f:
    json.dump(data, f, indent=2)

Code Example

// Current behavior (simplified):
function resolveChildSessionKeys(controllerSessionKey, store) {
  for (const entry of listSubagentRunsForController(controllerSessionKey)) {
    childSessionKeys.add(entry.childSessionKey); // no endedAt check
  }
  // ...also checks store entries by spawnedBy/parentSessionKey
}

---

import json
with open("~/.openclaw/subagents/runs.json") as f:
    data = json.load(f)
data["runs"] = {k: v for k, v in data["runs"].items() if not v.get("endedAt")}
with open("~/.openclaw/subagents/runs.json", "w") as f:
    json.dump(data, f, indent=2)
RAW_BUFFERClick to expand / collapse

Bug

Ended subagent runs accumulate in ~/.openclaw/subagents/runs.json indefinitely and appear as ghost child sessions on the Floor UI.

Root Cause

resolveChildSessionKeys() (in auth-profiles-*.js, around the subagent-registry region) iterates all runs for a controller session key but never filters by endedAt. Every subagent ever spawned — even ones that completed days ago — is returned as a child session.

// Current behavior (simplified):
function resolveChildSessionKeys(controllerSessionKey, store) {
  for (const entry of listSubagentRunsForController(controllerSessionKey)) {
    childSessionKeys.add(entry.childSessionKey); // no endedAt check
  }
  // ...also checks store entries by spawnedBy/parentSessionKey
}

Impact

  • Floor shows ghost agents with stale "Sending" / "now" status for agents that finished long ago
  • runs.json grows unbounded — in my case, 16 ended runs from 5 days ago still present
  • sessions_list returns stale childSessions arrays, confusing both UI and API consumers

Steps to Reproduce

  1. Spawn multiple subagents (e.g., Round Table convene)
  2. Let them all complete
  3. Wait for session resets (daily heartbeat)
  4. Check Floor — old agents still appear as children of the main session
  5. Inspect ~/.openclaw/subagents/runs.json — all ended runs still there

Expected Behavior

  1. resolveChildSessionKeys should filter out ended runs (or at least runs ended beyond a reasonable TTL, e.g. 30 minutes)
  2. runs.json should be pruned periodically — completed runs older than N hours/days should be removed
  3. Floor should only show actually active or recently-active child sessions

Workaround

Manually clear ended runs from runs.json:

import json
with open("~/.openclaw/subagents/runs.json") as f:
    data = json.load(f)
data["runs"] = {k: v for k, v in data["runs"].items() if not v.get("endedAt")}
with open("~/.openclaw/subagents/runs.json", "w") as f:
    json.dump(data, f, indent=2)

Environment

  • OpenClaw installed via Homebrew (/opt/homebrew/lib/node_modules/openclaw)
  • macOS (arm64), Node v22.22.1
  • Registry version: 2

extent analysis

Fix Plan

To resolve the issue of ghost child sessions, we need to modify the resolveChildSessionKeys function to filter out ended runs and implement a mechanism to prune old runs from runs.json.

Step 1: Modify resolveChildSessionKeys

Filter out ended runs by adding a check for endedAt:

function resolveChildSessionKeys(controllerSessionKey, store) {
  const ttl = 30 * 60 * 1000; // 30 minutes
  const now = Date.now();
  for (const entry of listSubagentRunsForController(controllerSessionKey)) {
    if (!entry.endedAt || now - entry.endedAt < ttl) {
      childSessionKeys.add(entry.childSessionKey);
    }
  }
  // ...also checks store entries by spawnedBy/parentSessionKey
}

Step 2: Prune Old Runs from runs.json

Create a function to periodically prune old runs:

function pruneOldRuns() {
  const maxAge = 24 * 60 * 60 * 1000; // 1 day
  const now = Date.now();
  const runs = JSON.parse(fs.readFileSync("~/.openclaw/subagents/runs.json"));
  runs.runs = Object.fromEntries(Object.entries(runs.runs).filter(([key, value]) => {
    return !value.endedAt || now - value.endedAt < maxAge;
  }));
  fs.writeFileSync("~/.openclaw/subagents/runs.json", JSON.stringify(runs, null, 2));
}

Schedule this function to run periodically using a scheduler like node-cron:

const cron = require("node-cron");
cron.schedule("0 0 * * *", pruneOldRuns); // run daily at midnight

Verification

After implementing these changes, verify that:

  • Ghost child sessions no longer appear on the Floor UI
  • runs.json is pruned periodically, removing old ended runs
  • The sessions_list API returns accurate childSessions arrays

Extra Tips

  • Consider adding a configuration option to adjust the TTL and max age values
  • Use a more robust storage solution, such as a database, to store subagent runs
  • Implement logging and monitoring to detect and alert on issues with ghost child sessions or pruning failures

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING