Skip to content

[Bug]: Embedded-run session state leak - zombie agents persist after parent agent termination #48573

@ai-nurmamat

Description

@ai-nurmamat

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

  1. Start an OpenClaw agent with embedded-run capability
  2. Spawn a subagent with
  3. Terminate the parent agent (Ctrl+C or timeout)
  4. Start a new agent session
  5. 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:

  1. Race condition: The lane cleanup () happens before subagent termination completes
  2. Missing cleanup callback: Embedded-run agents register handlers but these may not fire if the parent terminates abruptly
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions