You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sub-agent session store entries persist after archiveAfterMinutes sweep (sessions.delete failure silently swallowed) #49000
When agents.defaults.subagents.archiveAfterMinutes triggers a sweep, the subagent run record is deleted from runs.json but the corresponding session store entry in sessions.json persists indefinitely if the sessions.delete gateway RPC fails.
Root Cause
In subagent-registry.ts, sweepSubagentRuns():
The run record is deleted from the in-memory map and persisted to disk
sessions.delete is called via callGateway()
The call is wrapped in try/catch {} that silently swallows all errors
If the gateway is temporarily unavailable (restart, timeout, connection issue), the session store entry is never cleaned up, and there's no retry or reconciliation mechanism.
Expected Behavior
Session store entries should be reliably cleaned up when a subagent run is swept.
Actual Behavior
Session store entries accumulate indefinitely. On a system with archiveAfterMinutes: 720, we observed 5 orphaned session store entries aged 3-40 hours with no corresponding runs.json record.
Suggested Fix
Either move subagentRuns.delete() to after successful sessions.delete, or implement retry
Add reverse orphan reconciliation in reconcileOrphanedRestoredRuns() — scan sessions.json for subagent-keyed entries that have no matching runs.json record, and clean them up on startup
Environment
OpenClaw 2026.3.13
macOS arm64
archiveAfterMinutes: 720
Reproduction
Set agents.defaults.subagents.archiveAfterMinutes to a small value (e.g., 5)
Spawn several subagents (mode: "run")
Wait for sweep interval (60s)
Restart gateway while sweep is in progress, OR trigger gateway restart via config change during sweep window
Observe: runs.json entries cleaned up, but sessions.json entries persist
This is closely related to #29795 (sub-agents persist after reboot) — both stem from the same root problem: runs.json and sessions.json are two independent sources of truth with no atomic operation or reconciliation between them.
The ordering fix (delete sessions first, then runs) is necessary but not sufficient — a crash between the two operations still leaves orphans. The reconciliation approach is the real fix.
One practical addition to the suggested reconciliation in reconcileOrphanedRestoredRuns(): add a grace period (e.g. 5 min) before deleting orphaned session entries on startup, to avoid a race where a subagent session was just created but the runs.json write hasn't flushed yet. This edge case is especially relevant on systems with slow disk I/O or during high subagent spawn rates.
For anyone hitting this now: you can manually clean up orphaned entries by stopping the gateway, diffing the session keys in sessions.json against runs.json, removing entries that exist only in sessions, and restarting.
Current main already keeps archived sub-agent runs when sessions.delete fails, retries cleanup on later sweeps, and has regression coverage for the reported failure mode. The changelog records this as shipped in v2026.4.10.
What I checked:
Sweep now retries instead of dropping run record first:sweepSubagentRuns() calls sessions.delete, logs and continues on failure, and only deletes the in-memory run after the gateway delete succeeds. (src/agents/subagent-registry.ts:606)
Regression test covers failed delete then later successful retry: Test keeps archived delete-mode runs for retry when sessions.delete fails asserts the run is still present after the first delete failure and is removed only after the second sweep succeeds. Adjacent test also verifies overlapping sweeps do not duplicate in-flight cleanup. (src/agents/subagent-registry.archive.e2e.test.ts:124)
Release notes say this shipped: The 2026.4.10 changelog section includes: Agents/subagents: preserve archived delete-mode runs until sessions.delete succeeds and prevent overlapping archive sweeps from duplicating in-flight cleanup attempts. (#61801). (CHANGELOG.md:863)
So I’m closing this as already implemented rather than keeping a duplicate issue open.
Activity
Ryce commentedon Mar 17, 2026
Hollychou924 commentedon Mar 17, 2026
astroclaw commentedon Mar 17, 2026
This is closely related to #29795 (sub-agents persist after reboot) — both stem from the same root problem:
runs.jsonandsessions.jsonare two independent sources of truth with no atomic operation or reconciliation between them.The ordering fix (delete sessions first, then runs) is necessary but not sufficient — a crash between the two operations still leaves orphans. The reconciliation approach is the real fix.
One practical addition to the suggested reconciliation in
reconcileOrphanedRestoredRuns(): add a grace period (e.g. 5 min) before deleting orphaned session entries on startup, to avoid a race where a subagent session was just created but the runs.json write hasn't flushed yet. This edge case is especially relevant on systems with slow disk I/O or during high subagent spawn rates.For anyone hitting this now: you can manually clean up orphaned entries by stopping the gateway, diffing the session keys in
sessions.jsonagainstruns.json, removing entries that exist only in sessions, and restarting.steipete commentedon Apr 25, 2026
Closing this as implemented after Codex review.
Current
mainalready keeps archived sub-agent runs whensessions.deletefails, retries cleanup on later sweeps, and has regression coverage for the reported failure mode. The changelog records this as shipped inv2026.4.10.What I checked:
sweepSubagentRuns()callssessions.delete, logs andcontinues on failure, and only deletes the in-memory run after the gateway delete succeeds. (src/agents/subagent-registry.ts:606)keeps archived delete-mode runs for retry when sessions.delete failsasserts the run is still present after the first delete failure and is removed only after the second sweep succeeds. Adjacent test also verifies overlapping sweeps do not duplicate in-flight cleanup. (src/agents/subagent-registry.archive.e2e.test.ts:124)2026.4.10changelog section includes:Agents/subagents: preserve archived delete-mode runs until sessions.delete succeeds and prevent overlapping archive sweeps from duplicating in-flight cleanup attempts. (#61801). (CHANGELOG.md:863)So I’m closing this as already implemented rather than keeping a duplicate issue open.
Review notes: reviewed against 01bc49c88c0c; fix evidence: release v2026.4.10.