openclaw - 💡(How to fix) Fix subagent sessions never auto-cleaned — sessionRetention only applies to cron, 507 subagent sessions accumulated in 8 days causing Gateway eventLoop stall

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…

Subagent sessions created via sessions_spawn are never automatically cleaned up by Gateway's session pruning/maintenance cycle. This causes unbounded session accumulation, particularly for heavy subagent users (e.g. agent-architect performing batch agent audits).

Root Cause

  1. eventLoop utilization = 1 — Gateway's diagnostic liveness check shows eventLoopUtilization=1 because maintaining 520 sessions in memory blocks the event loop
  2. Stalled sessions — architect's sessions flagged as "stalled: active_work_without_progress" repeatedly (age 370-471 seconds)
  3. Gateway RSS growth — memory pressure warnings even after raising thresholds to 8GB
  4. session-locks accumulation — 36,000ms of cumulative lock time observed

Fix Action

Workaround

Currently manually cleaning subagent sessions. Suggest either:

  1. Add sessionRetention support for subagent sessions
  2. Add a cleanup option to sessions_spawn
  3. Add an auto-cleanup sweep for completed subagent sessions
RAW_BUFFERClick to expand / collapse

Summary

Subagent sessions created via sessions_spawn are never automatically cleaned up by Gateway's session pruning/maintenance cycle. This causes unbounded session accumulation, particularly for heavy subagent users (e.g. agent-architect performing batch agent audits).

Evidence

  • Agent: agent-architect
  • Total sessions: 520
  • Subagent sessions: 507 (97.5%)
  • Session dates: 2026-05-18 through 2026-05-26, accumulating daily
  • Never compacted: 481 out of 507
  • Total session file size: 68 MB

Direct Impact

  1. eventLoop utilization = 1 — Gateway's diagnostic liveness check shows eventLoopUtilization=1 because maintaining 520 sessions in memory blocks the event loop
  2. Stalled sessions — architect's sessions flagged as "stalled: active_work_without_progress" repeatedly (age 370-471 seconds)
  3. Gateway RSS growth — memory pressure warnings even after raising thresholds to 8GB
  4. session-locks accumulation — 36,000ms of cumulative lock time observed

Related Issues

  • #51767 — sessionRetention does not apply to subagent sessions — only cron-run sessions are swept
  • #47975 — Subagent sessions persist after completion, main session becomes unresponsive
  • #43193 — Session leak: Cron jobs and subagents create sessions that never get cleaned up
  • #49000 — Sub-agent session store entries persist after archiveAfterMinutes sweep
  • #58429 — Feature request: auto-cleanup completed subagent sessions

Expected Behavior

Subagent sessions should be subject to the same session retention/pruning policies as cron sessions. After a subagent run completes (success/failure/timeout), its session should be eligible for cleanup after a configurable TTL.

Environment

  • OpenClaw version: 2026.5.24-beta.2
  • Node.js: v22.22.0
  • Agent count: 83
  • OS: Linux (WSL2), 31GB RAM
  • NODE_OPTIONS=--max-old-space-size=8192 already configured

Workaround

Currently manually cleaning subagent sessions. Suggest either:

  1. Add sessionRetention support for subagent sessions
  2. Add a cleanup option to sessions_spawn
  3. Add an auto-cleanup sweep for completed subagent sessions

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 never auto-cleaned — sessionRetention only applies to cron, 507 subagent sessions accumulated in 8 days causing Gateway eventLoop stall