Skip to content

Bug Report: Subagent announce give-up due to EmbeddedAttemptSessionTakeoverError #91650

Description

@ksiyuna-claw

Bug Report: Subagent announce give-up due to EmbeddedAttemptSessionTakeoverError

Environment

  • OpenClaw version: 2026.5.28 (e932160)
  • OS: macOS 15.5 (Darwin 24.6, arm64)
  • Node: v26.0.0
  • Agents: 9 total (multi-agent setup with Telegram surfaces)

Summary

Subagent results are silently dropped when delivering back to parent sessions. Over 5 days, we've observed 29 give-ups (after retry exhaustion) and 106 single delivery failures, all sharing the same root cause. The subagent completes its work successfully but the result never reaches the chat window.

Root Cause

EmbeddedAttemptSessionTakeoverError:
session file changed while embedded prompt lock was released: <session.jsonl>

When a subagent finishes and the Gateway attempts to write the result back to the parent session's JSONL file, the createEmbeddedAttemptSessionLockController detects that another writer has modified the file (concurrent user message, another subagent result, etc.). It interprets this as a "session takeover" and refuses the write. After 3 retries (with endedAgo ranging 30–246s), the result is permanently lost.

Impact: 135 dropped deliveries over 5 days

Agent Give-ups Delivery failures Primary session affected
main (罗氏虾) 22 53 19dea8b0 (38 hits), 06db10e2
shanbei (扇贝) 7 18 9ae8bc57 (24 hits)
jiweixia (基围虾) 8 0
others 6 14
Total 29 106

Time Pattern

Concentrated on 2026-06-05 through 2026-06-06 (44 failures + 12 give-ups on June 6 alone). Nearly zero since June 7.

External Drive Factor

31 of the 135 errors involved sessions on /Volumes/ZHITAI/ (external SSD), suggesting I/O latency on external drives significantly increases the lock contention window.

2026-06-06 [warn] ... "text completion direct delivery failed: session file changed ...
  /Volumes/ZHITAI/.openclaw/agents/main/sessions/19dea8b0-...jsonl"

Key Observation: Long-lived persistent sessions are the primary victim

The two most-affected sessions (main and shanbei) are persistent, non-expiring sessions reused across multiple days with extensive conversation history. Each new subagent spawn + user message creates more opportunities for concurrent writes to the same JSONL file.

Proposed Mitigations / Fix Ideas

  1. Separate subagent result files — Instead of writing subagent completion directly into the parent session JSONL, write to a separate delivery queue file and then atomically merge. This avoids the lock contention entirely.

  2. Write-ahead queue with backpressure — Queue subagent completions and dequeue them sequentially with a short delay between each write, reducing concurrent write collisions.

  3. Exponential backoff on retry — Currently the retries seem to use fixed intervals. With exponential backoff (1s, 4s, 16s), many transient conflicts would likely resolve.

  4. Session file sharding for high-concurrency agents — Allow splitting a single logical session across multiple append-only shard files, reducing lock contention on a single file.

  5. Configurable retry count — Allow users to increase maxRetries beyond 3 for high-value subagent work.

Reproduction

  1. Set up a multi-agent workspace with 5+ agents
  2. Use a persistent (non-expiring) parent session that receives user messages while subagents are running
  3. Spawn multiple subagents concurrently from the same parent session
  4. Some subagent completions will be silently dropped with EmbeddedAttemptSessionTakeoverError

The issue is more frequent when the session JSONL file is large (>1MB of accumulated history) or on external storage with higher I/O latency.

Prior Art

This appears to be a known trade-off in the Gateway's session file architecture. The createEmbeddedAttemptSessionLockController is designed to prevent concurrent corruption, but the current implementation sacrifices result delivery reliability.

Log Evidence

[warn] Subagent announce give up (retry-limit) 
  run=178ffb62-... 
  child=agent:xiaohexia:subagent:07d7ddbf-... 
  requester=agent:main:telegram:direct:8560173586 
  retries=3 endedAgo=49s 
  deliveryError="text completion direct delivery failed: 
    session file changed while embedded prompt lock was released: 
    /Volumes/ZHITAI/.openclaw/agents/main/sessions/19dea8b0-...jsonl"

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions