openclaw - 💡(How to fix) Fix [Bug]: Session compaction deadlock blocks child subagent SessionManager.open() [1 comments, 2 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#74181Fetched 2026-04-30 06:27:44
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Timeline (top)
closed ×1commented ×1cross-referenced ×1

Error Message

Subagent spawn should succeed even when parent session is compacting, OR subagent spawn should be rejected immediately with a clear error rather than silently timing out. 2. Medium-term: Reject subagent spawn with clear error if parent is compacting, instead of blocking

Root Cause

When a session reaches the compaction threshold (~200k tokens), the parent agent's compaction process acquires a WRITE lock on the session file. If a child subagent spawn is attempted simultaneously, SessionManager.open() tries to acquire a READ lock on the same file. The child blocks indefinitely because the parent's WRITE lock is held for the duration of the compaction/summarization process.

Fix Action

Workaround

Use lightContext: true when spawning subagents to avoid triggering compaction during the spawn.

RAW_BUFFERClick to expand / collapse

Bug Description

When a session reaches the compaction threshold (~200k tokens), the parent agent's compaction process acquires a WRITE lock on the session file. If a child subagent spawn is attempted simultaneously, SessionManager.open() tries to acquire a READ lock on the same file. The child blocks indefinitely because the parent's WRITE lock is held for the duration of the compaction/summarization process.

This creates a structural deadlock where:

  1. Parent session is in compaction (WRITE lock held)
  2. Child subagent spawn requests READ lock → blocks
  3. Subagent times out with zero output (0 tokens, empty result)
  4. Parent session logs "stuck session" warning after 120s

Repro Steps

  1. Use a model with small context window or heavy tool usage to reach compaction threshold
  2. While session is near compaction, spawn a subagent via sessions_spawn with default context
  3. Observe subagent times out with no output
  4. Check logs for stuck session and InteractionEventListener slow-listener warnings

Expected Behavior

Subagent spawn should succeed even when parent session is compacting, OR subagent spawn should be rejected immediately with a clear error rather than silently timing out.

Actual Behavior

Subagent spawn blocks indefinitely until timeout. The subagent receives no tokens and produces no output. The parent session appears "stuck" in processing state for 120s+.

Environment

  • OpenClaw: 2026.4.23
  • Runtime: ollama/deepseek-v4-pro:cloud
  • Context: ~200k tokens at deadlock
  • Config: agents.defaults.subagents.runTimeoutSeconds: 900

Workaround

Use lightContext: true when spawning subagents to avoid triggering compaction during the spawn.

Related Issues

  • #9855 — Session lock deadlock on timeout during compaction (related but focuses on timeout cleanup)
  • #7688 — Auto-compaction blocks other sessions
  • #7630 — Session lane deadlock after LLM timeout

Severity

High — breaks all subagent delegation when session approaches compaction threshold. Affects any workload using sessions_spawn with normal context.

Suggested Fix

  1. Short-term: Allow READ lock acquisition during compaction (upgradeable locks, or use a separate compaction lock)
  2. Medium-term: Reject subagent spawn with clear error if parent is compacting, instead of blocking
  3. Long-term: Move compaction to a background process that doesn't hold the session lock

extent analysis

TL;DR

Implementing upgradeable locks or using a separate compaction lock can resolve the session lock deadlock issue during compaction.

Guidance

  • Verify the deadlock scenario by reproducing the issue with the provided repro steps and checking for "stuck session" warnings in the logs.
  • Apply the suggested short-term fix by allowing READ lock acquisition during compaction, which can be achieved by implementing upgradeable locks.
  • Consider the medium-term fix, which involves rejecting subagent spawn with a clear error if the parent is compacting, to prevent indefinite blocking.
  • As a temporary workaround, use lightContext: true when spawning subagents to avoid triggering compaction during the spawn.

Example

No code snippet is provided as the issue does not contain specific code references.

Notes

The suggested fixes have different implementation complexities and may require significant changes to the session management and locking mechanisms.

Recommendation

Apply the workaround by using lightContext: true when spawning subagents, as it provides a temporary solution to avoid the deadlock issue.

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 [Bug]: Session compaction deadlock blocks child subagent SessionManager.open() [1 comments, 2 participants]