Summary
Embedded-run subagents spawned with the parameter may leave zombie state in the session store after the parent agent terminates, causing subsequent runs to encounter stale execution contexts.
Bug type
Behavior bug (incorrect output/state without crash)
Steps to Reproduce
- Start an OpenClaw agent with embedded-run capability
- Spawn a subagent with
- Terminate the parent agent (Ctrl+C or timeout)
- Start a new agent session
- Observe stale session data or zombie subagent state in or debug logs
Expected Behavior
When a parent agent terminates, all embedded-run subagents should be cleanly terminated and their session state should be removed from the session store.
Actual Behavior
Embedded-run subagent state persists in the session store, causing:
- Stale entries in
- Potential memory leaks from zombie agent processes
- Confusion in subsequent runs that attempt to reuse the session lane
Root Cause Analysis
The issue appears to be in the session compaction logic. When the parent agent's lane is cleared, embedded-run subagents spawned on that lane are not properly cleaned up because:
- Race condition: The lane cleanup () happens before subagent termination completes
- Missing cleanup callback: Embedded-run agents register handlers but these may not fire if the parent terminates abruptly
- State persistence: Session metadata is written to disk () before subagent cleanup completes
Code Location
- File: or similar
- Function: or
- Problem: No synchronous cleanup of child subagents before lane state is cleared
Proposed Solution
Add a synchronous cleanup phase before lane compaction:
Alternatively, add a flag to embedded-run config that ensures subagents register proper exit handlers.
Environment
- OpenClaw: 2026.3.13
- OS: Linux/macOS
- Node: 22.x
Labels
- bug
- component:agents
- component:session
Summary
Embedded-run subagents spawned with the parameter may leave zombie state in the session store after the parent agent terminates, causing subsequent runs to encounter stale execution contexts.
Bug type
Behavior bug (incorrect output/state without crash)
Steps to Reproduce
Expected Behavior
When a parent agent terminates, all embedded-run subagents should be cleanly terminated and their session state should be removed from the session store.
Actual Behavior
Embedded-run subagent state persists in the session store, causing:
Root Cause Analysis
The issue appears to be in the session compaction logic. When the parent agent's lane is cleared, embedded-run subagents spawned on that lane are not properly cleaned up because:
Code Location
Proposed Solution
Add a synchronous cleanup phase before lane compaction:
Alternatively, add a flag to embedded-run config that ensures subagents register proper exit handlers.
Environment
Labels