openclaw - 💡(How to fix) Fix Subagent sessions not cleaned up after archiveAfterMinutes (orphaned sessions accumulate) [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#71716Fetched 2026-04-26 05:09:26
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
closed ×1

Root Cause

Bug #49000 — Silent RPC failure (root cause for April 17 sessions) sessions.delete is wrapped in try/catch with no retry. If the gateway is unavailable during the sweep window (restart, timeout), the sessions.json entry persists forever with no reconciliation. Archival begins (runs.json deleted) but sessions.json RPC silently fails → sessions survive but are never moved to archive.

Fix Action

Fix / Workaround

Bug #58429 — Config workaround is blunt session.maintenance.pruneAfter: "7d" exists as a workaround but has no granularity and is not documented as a mitigation for this specific issue.

Workarounds (documented)

  • #49000 (root cause: silent RPC swallow)
  • #52327 (3 structural gaps, production incident)
  • #9634 (failed sessions not cleaned)
  • #58429 (pruneAfter workaround)

Code Example

"subagents": {
  "archiveAfterMinutes": 60,
  "maxChildrenPerAgent": 10,
  "maxSpawnDepth": 2,
  "maxConcurrent": 8
}
RAW_BUFFERClick to expand / collapse

Bug Report: Subagent sessions not cleaned up after archiveAfterMinutes

Issue Summary

Subagent sessions are not being cleaned up after archiveAfterMinutes: 60 (1 hour) as configured. Sessions persist for days, accumulating in agents/*/sessions/ directories. The sessions-archived/ folder remains empty, indicating archival never completed successfully.

Config:

"subagents": {
  "archiveAfterMinutes": 60,
  "maxChildrenPerAgent": 10,
  "maxSpawnDepth": 2,
  "maxConcurrent": 8
}

Reproduction Data

  • Environment: Self-hosted OpenClaw on Linux
  • First observed: Sessions from 2026-04-17 still present on 2026-04-25 (10+ days old)
  • Current session count: 47 .jsonl files in agents/main/sessions/
  • Archive folder: sessions-archived/ is empty
  • Child session refs: Parent agent shows 15 child session references despite maxChildrenPerAgent: 10

How archiveAfterMinutes Is Supposed to Work

Timer-based sweep in subagent-registry.ts via sweepSubagentRuns(). Deletes from runs.json, calls sessions.delete RPC on sessions.json. .jsonl files are separate.

Confirmed Bug Breakdown

Bug #49000 — Silent RPC failure (root cause for April 17 sessions) sessions.delete is wrapped in try/catch with no retry. If the gateway is unavailable during the sweep window (restart, timeout), the sessions.json entry persists forever with no reconciliation. Archival begins (runs.json deleted) but sessions.json RPC silently fails → sessions survive but are never moved to archive.

Bug #52327 — Three structural gaps

  1. In-memory timers lost on gateway restart — if a restart occurs within the 60-min window, those sessions are permanently orphaned
  2. mode: "session" thread-bound sessions are entirely excluded from archival — they never receive an archive timestamp
  3. No restart-safe catch-up mechanism (unlike cron.sessionRetention which runs on startup)

Bug #9634 — Failed sessions not cleaned Even with cleanup: "delete", failed subagent sessions are not removed from sessions.json.

Bug #58429 — Config workaround is blunt session.maintenance.pruneAfter: "7d" exists as a workaround but has no granularity and is not documented as a mitigation for this specific issue.

Workarounds (documented)

  1. Direct sessions.json editing — backup first, then remove orphaned entries
  2. Add session.maintenance.pruneAfter: "7d" to config — blunt instrument per #58429
  3. Gateway restart — resets in-memory timers but does not fix existing orphans

Expected Behavior

Sessions should be archived (moved to sessions-archived/) after archiveAfterMinutes of inactivity, and orphaned entries in sessions.json should not persist indefinitely.

References

  • #49000 (root cause: silent RPC swallow)
  • #52327 (3 structural gaps, production incident)
  • #9634 (failed sessions not cleaned)
  • #58429 (pruneAfter workaround)

Reported via OpenClaw agent with session archival research. Full research notes available on request.

extent analysis

TL;DR

Implement a workaround by adding session.maintenance.pruneAfter: "7d" to the config to mitigate the issue of subagent sessions not being cleaned up after archiveAfterMinutes.

Guidance

  • Review the subagents config to ensure archiveAfterMinutes is correctly set to 60 minutes.
  • Consider adding session.maintenance.pruneAfter: "7d" to the config as a temporary workaround to prune sessions after 7 days.
  • Be aware that this workaround has no granularity and may not be suitable for all use cases.
  • Directly editing sessions.json to remove orphaned entries is also an option, but be sure to backup the file first.

Notes

The provided config and issue description suggest that the archiveAfterMinutes setting is not being respected due to underlying bugs (#49000, #52327, #9634, #58429). The suggested workaround may help mitigate the issue, but a more permanent fix may require addressing the root causes of these bugs.

Recommendation

Apply the workaround by adding session.maintenance.pruneAfter: "7d" to the config, as it provides a temporary solution to prune sessions and prevent them from accumulating indefinitely.

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

openclaw - 💡(How to fix) Fix Subagent sessions not cleaned up after archiveAfterMinutes (orphaned sessions accumulate) [1 participants]