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
-
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.
-
Write-ahead queue with backpressure — Queue subagent completions and dequeue them sequentially with a short delay between each write, reducing concurrent write collisions.
-
Exponential backoff on retry — Currently the retries seem to use fixed intervals. With exponential backoff (1s, 4s, 16s), many transient conflicts would likely resolve.
-
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.
-
Configurable retry count — Allow users to increase maxRetries beyond 3 for high-value subagent work.
Reproduction
- Set up a multi-agent workspace with 5+ agents
- Use a persistent (non-expiring) parent session that receives user messages while subagents are running
- Spawn multiple subagents concurrently from the same parent session
- 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"
Bug Report: Subagent announce give-up due to EmbeddedAttemptSessionTakeoverError
Environment
2026.5.28 (e932160)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
When a subagent finishes and the Gateway attempts to write the result back to the parent session's JSONL file, the
createEmbeddedAttemptSessionLockControllerdetects 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 (withendedAgoranging 30–246s), the result is permanently lost.Impact: 135 dropped deliveries over 5 days
19dea8b0(38 hits),06db10e29ae8bc57(24 hits)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.Key Observation: Long-lived persistent sessions are the primary victim
The two most-affected sessions (
mainandshanbei) 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
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.
Write-ahead queue with backpressure — Queue subagent completions and dequeue them sequentially with a short delay between each write, reducing concurrent write collisions.
Exponential backoff on retry — Currently the retries seem to use fixed intervals. With exponential backoff (1s, 4s, 16s), many transient conflicts would likely resolve.
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.
Configurable retry count — Allow users to increase
maxRetriesbeyond 3 for high-value subagent work.Reproduction
EmbeddedAttemptSessionTakeoverErrorThe 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
createEmbeddedAttemptSessionLockControlleris designed to prevent concurrent corruption, but the current implementation sacrifices result delivery reliability.Log Evidence