Skip to content

[Bug]: Session write-lock timeouts block subagent delivery lanes #86538

Closed

Description

@galiniliev

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

Session JSONL write-lock timeouts block main, cron-nested, and subagent lanes, then surface as delivery/lifecycle failures without enough owner diagnostics.

Steps to reproduce

  1. Run OpenClaw with main-session and subagent delivery lanes writing to session JSONL files.
  2. Contend a session write lock long enough for lane tasks and final delivery to hit the write-lock timeout.
  3. Observe lane errors and direct announce failure logs.

Expected behavior

Write-lock timeouts should preserve enough owner liveness/starttime/staleness evidence for recovery triage, and subagent final output should remain durable even when direct announce cannot acquire the lock.

Actual behavior

Gateway logs showed 161 SessionWriteLockTimeoutError lines, 41 subagent lane rejections, and repeated main-session lane errors in the 2026-05-23T14:42:08Z through 2026-05-25T14:42:08Z window.

OpenClaw version

2026.5.25 dev checkout

Operating system

Linux WSL2

Install method

pnpm dev

Model

NOT_ENOUGH_INFO

Provider / routing chain

NOT_ENOUGH_INFO

Additional provider/model setup details

NOT_ENOUGH_INFO

Logs, screenshots, and evidence

Window analyzed: 2026-05-23T14:42:08Z through 2026-05-25T14:42:08Z
Counts:
- 161 lines contained: SessionWriteLockTimeoutError
- 41 lines contained: lane task rejected after timeout
- 158 lines contained: lane task error

Redacted excerpts:
lane task rejected after timeout: lane=subagent timeoutMs=31000 error="SessionWriteLockTimeoutError: session file locked (timeout 60000ms): pid=[redacted pid] [redacted session lock path]"
lane task error: lane=cron-nested durationMs=380507 error="SessionWriteLockTimeoutError: session file locked (timeout 60000ms): pid=[redacted pid] [redacted session lock path]"
[warn] Subagent completion direct announce failed for run [redacted run id]: SessionWriteLockTimeoutError: session file locked (timeout 60000ms): pid=[redacted pid] [redacted session lock path]: code=OPENCLAW_SESSION_WRITE_LOCK_TIMEOUT

Impact and severity

Affected: main session, cron-nested, and subagent delivery lanes.
Severity: High, because completion output can fail after child work is otherwise done.
Frequency: 161 timeout lines were observed in the analyzed two-day log window.
Consequence: lifecycle delivery and direct announce can fail behind a session write lock.

Additional information

The implicated code paths were src/agents/session-write-lock.ts timeout reporting and subagent final-delivery persistence.

Activity

  1. clawsweeper commented on May 25, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 21, 2026, 8:15 AM ET / 12:15 UTC.

    Summary
    Keep open: current main and v2026.6.9 still retain the 60s session write-lock timeout class and still clear durable fallback completion text during suspended-delivery expiry; the linked closing PR remains open and unmerged, with later comments adding fresh v2026.6.8 production reports.

    Reproducibility: yes. at source level: current main still has the 60s write-lock acquire timeout and clears completion fallback during suspended-delivery expiry, and the thread includes fresh v2026.6.8 live reports. I did not run the timing-sensitive gateway race in this read-only review.

    Root-cause cluster
    Relationship: canonical
    Canonical: #86538
    Summary: This issue remains the canonical tracker for unresolved session write-lock timeout plus subagent completion delivery loss; related items either feed into it, partially overlap it, or are candidate fixes.

    Members:

    Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Next step
    A linked closing PR already owns the narrow repair, and maintainer review is needed before starting another fix lane.

    Review details

    Best possible solution:

    Review and rebase the linked repair or an equivalent narrow replacement, preserve final subagent text before suspended-delivery expiry, improve lock owner diagnostics, and explicitly track broader run-aware ownership or requester-session serialization as follow-up if out of scope.

    Do we have a high-confidence way to reproduce the issue?

    Yes, at source level: current main still has the 60s write-lock acquire timeout and clears completion fallback during suspended-delivery expiry, and the thread includes fresh v2026.6.8 live reports. I did not run the timing-sensitive gateway race in this read-only review.

    Is this the best way to solve the issue?

    Unclear as a final shape. The linked PR is a plausible narrow repair for durable fallback and diagnostics, but maintainers still need to decide whether broader run-aware lock ownership or requester-session serialization belongs in this fix cluster.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • The linked PR is a plausible narrow repair, but later comments raise broader run-aware lock ownership and requester-session serialization questions that may need separate maintainer scoping.
    • No live current-main gateway race was executed in this read-only review; confidence comes from source inspection, release inspection, and repeated live reports in the thread.
    • Several overlapping open issues track adjacent delivery, yield, and fallback ownership failures, so maintainers should keep this issue as the canonical lock/delivery tracker until a merged fix or explicit split exists.

    Codex review notes: model internal, reasoning high; reviewed against 12c34fc3a951.

    Label changes

    Label changes:

    • remove clawsweeper:fix-shape-clear: Current issue advisory state no longer selects this label.
    • remove clawsweeper:needs-maintainer-review: Current issue advisory state no longer selects this label.

    Label justifications:

    • P1: The issue affects real multi-subagent and channel delivery workflows with repeated production reports across recent releases.
    • impact:session-state: The failure is rooted in session JSONL write-lock ownership and suspended subagent completion state.
    • impact:message-loss: Subagent final output or requester-visible replies can fail, be delayed, or require manual recovery before delivery.
    Evidence reviewed

    What I checked:

    Likely related people:

    • steipete: Recent commits touched stale session locks and subagent handoff queueing around the affected lock and delivery surfaces. (role: recent area contributor and feature-history owner; confidence: high; commits: 210adf1d1189, 7ca77124fea0, f24a13879095; files: src/agents/session-write-lock.ts, src/agents/subagent-registry.ts, src/agents/subagent-registry-run-manager.ts)
    • vincentkoc: Current blame and release commits carry the central lines in this checkout, and shortlog shows repeated recent touches to these agent/session files. (role: recent current-source contributor; confidence: medium; commits: 7dd01d15c56d, c645ec4555c0; files: src/agents/session-write-lock.ts, src/agents/subagent-registry.ts, src/agents/subagent-announce-delivery.ts)
    • galiniliev: Authored the open closing PR that changes the implicated session-write-lock and suspended subagent delivery expiry paths. (role: active linked repair author; confidence: high; commits: f9c6fc7de291; files: src/agents/session-write-lock.ts, src/agents/session-write-lock.test.ts, src/agents/subagent-registry.ts)
    • sallyom: Authored a merged pending subagent completion announce fix in the adjacent delivery path, relevant to what current main does and does not solve. (role: recent adjacent fix author; confidence: medium; commits: 95c87e31e295; files: src/agents/subagent-announce-delivery.ts, src/agents/subagent-announce-delivery.test.ts)
    • openperf: Recent yielded-subagent lifecycle work touches the same registry/run-manager surfaces involved in completion delivery state. (role: recent adjacent lifecycle contributor; confidence: medium; commits: cd3eb438f07f; files: src/agents/subagent-registry.ts, src/agents/subagent-registry-run-manager.ts, src/agents/subagent-registry.test.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  2. added
    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.
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    on May 25, 2026
  3. robertdonnellyiii commented on May 29, 2026

    @robertdonnellyiii

    Me-too repro on 2026.5.28-beta.1, macOS 25.5.0, requester session = webchat dashboard, model = anthropic/claude-opus-4-7.

    User spawned 5 parallel research subagents (council pattern) on Opus 4.7 via sessions_spawn from a webchat main session. All 5 children completed cleanly, wrote their deliverables to disk, and ended with substantive (~10KB) final assistant text. openclaw tasks shows the consistent signature:

    <id>… subagent succeeded  failed   …  Required completion delivery failed before reaching the requester: SessionWrite…
    

    Gateway log shows the announce path hitting the 180s ceiling, exactly 4 retries, then giving up:

    [warn] Subagent announce completion direct announce agent call transient failure, retrying 2/4 in 5s: gateway timeout after 180000ms
    [warn] Subagent announce completion direct announce agent call transient failure, retrying 3/4 in 10s: gateway timeout after 180000ms
    

    …repeated for each of the 5 children. No completion ever delivered to the parent webchat session. From the user's perspective: parent session went silent after sessions_yield; user had to manually nudge ("did it land without an announcement again?") for the parent to discover, via subagents/openclaw tasks, that the children had in fact succeeded.

    Two extra data points worth noting:

    1. Failure-status completions DO deliver. A separate diagnostic spawn the same session crashed early with FailoverError: Unknown model: anthropic/claude-haiku-4-5 (separate model-whitelist issue). Its status: failed completion event delivered to the parent webchat without issue. So the SessionWriteLockTimeout appears to bite specifically on success-path announce-writes carrying real payload, not on failure-path short events. Useful narrowing if the linked PR doesn't already cover both lanes.

    2. 5/5 children hit the same write-lock window. Five concurrent direct-announce writes targeting the same parent webchat session JSONL appear to mutually contend for the parent's write lock. The N-concurrent-spawn case might warrant explicit serialization of announce-writes against a single requester session even after the underlying timeout fix, since 60s × 5 children > 180s ceiling on its own.

    User-side impact: durable artifact loss is small (children write deliverables to disk before final reply, so files persist), but trust impact is real — the parent agent looks like it silently abandoned the work, and discovers success only by polling openclaw tasks. Until this lands, our workaround is to instruct the parent to always openclaw tasks + read the lane files itself on the next user turn rather than trust the announce path, which defeats the point of sessions_yield.

    Happy to capture full raw gateway log slice if useful — the four [warn] lines per child are the only emitted signal at default log level.

  4. itanyplus commented on Jun 8, 2026

    @itanyplus

    Friendly ping — this is causing daily production outages

    Pinging for visibility since this is P1 and has a linked PR open.

    As of v2026.6.1 (the latest stable), this bug is still fully reproducible. The user-facing experience in Feishu/Telegram channels is:

    ⚠️ Agent failed before reply: session file locked (timeout 60000ms):
    pid=290998 alive=true ageMs=60017 sessions/*.jsonl.lock
    Please try again, or use /new to start a fresh session.
    

    This error now appears on nearly every multi-subagent workflow. The only recovery is manually deleting .lock files and restarting the gateway. Sub-agents finishing concurrently is not an edge case — it is the normal operating mode for any non-trivial task.

    Is the linked PR still on track? Is there anything blocking the merge? Happy to help test a branch if needed.

  5. itanyplus commented on Jun 9, 2026

    @itanyplus

    Just hit this again on v2026.6.5-beta.6 (Jun 9) — daily production impact, not a corner case.

    Gateway log from minutes ago:

    19:46:34 | subagent spawned via sessions_spawn
    19:49:12 | sessions_yield abort settle timed out: runId=d04b0e70 timeoutMs=2000
    19:50:12 | SessionWriteLockTimeoutError: session file locked (timeout 60000ms): pid=304241 alive=true ageMs=59987
    19:50:12 | Embedded agent failed before reply
    

    Classic pattern: subagent holds the session JSONL write lock (maxHoldMs=1020000 = 17min), next user message arrives, main session waits 60s for the lock → timeout → user sees:

    ⚠️ Agent failed before reply: session file locked (timeout 60000ms)

    This happens every single time a subagent runs longer than ~60 seconds. With complex tasks (web search + analysis + file writes), that is the norm, not the exception.

    Three stale .lock files sitting right now, all held by the gateway PID itself:

    1dc6073b...lock | pid=304241 | maxHoldMs=1020000
    7bee593d...lock | pid=304241 | maxHoldMs=1020000  
    d5c25854...lock | pid=304241 | maxHoldMs=1020000
    

    The mismatch is clear: 17-minute lock hold vs 60-second wait timeout. Any subagent doing real work will blow past 60s.

    This is P1 with a linked PR open. It has been causing daily production outages for weeks. Can we get the PR reviewed and merged? Happy to test a fix build if needed.

  6. itanyplus commented on Jun 10, 2026

    @itanyplus

    Ping — 2026.6.5 stable shipped without this fix, production impact continues

    v2026.6.5 stable just released, but PR #86540 is still unmerged. This P1 bug keeps impacting daily production.

    Latest reproduction (v2026.6.5 stable, identical to v2026.6.5-beta.6):

    Every time sessions_spawn runs parallel subagent work, the main session almost inevitably triggers a write-lock timeout. Users see:

    ⚠️ Agent failed before reply: session file locked (timeout 60000ms):
    pid=304241 alive=true ageMs=59987 sessions/*.jsonl.lock
    Please try again, or use /new to start a fresh session.
    

    Subagents finish their work, write deliverables to disk, but the delivery announce fails due to lock timeout — results are lost.

    The root contradiction remains unchanged: maxHoldMs=1020000 (17 min) vs acquireSessionWriteLock timeout=60000ms (60 s). Subagents hold the JSONL lock far longer than the acquire timeout, so any subsequent announce on the parent session is guaranteed to fail.

    PR #86540 has Azure Crabbox proof + maintainer code review (galiniliev verified at f9c6fc7d, martingarramon commented on the lock diagnostics). It has been stuck on status: 📣 needs proof for 12 days with no follow-up.

    Questions:

    This bug makes sessions_spawn + sessions_yield essentially unusable in production — subagent output is silently lost on lock contention, which defeats the entire parallel workflow pattern.

  7. itanyplus commented on Jun 11, 2026

    @itanyplus

    Still reproducing on 2026.6.6-beta.1 (commit 99648bb).

    ⚠️ session file locked (timeout 60000ms): pid=20277 alive=true ageMs=78059
      /home/itany/.openclaw/agents/main/sessions/2af7d3ff-b45c-4222-8d34-3c6f373e1da5.jsonl.lock
    
    • The lock owner PID is the gateway main process itself (MainThread / dist/index.js gateway).
    • Gateway was under normal load (active webchat session, no abnormal concurrency).
    • Same symptom as earlier reports: the process is alive, not crashed, just hitting the 60s write-lock timeout.

    Previously reproduced on 2026.6.5-beta.6, 2026.6.5, and 2026.6.1. The issue persists across all tested versions where #86540 has not landed.

  8. itanyplus commented on Jun 12, 2026

    @itanyplus

    Still reproducing on 2026.6.6-beta.1 (commit 99648bb, built from source 2026-06-10).

    New reproduction — model fallback chain triggers write-lock timeout (2026-06-12)

    A Feishu P2P user message arrived at 16:26:31 CST. The gateway started processing and the model call chain took ~3 minutes due to a primary model timeout + fallback:

    16:26:31 → lock acquired, model-snapshot: zhipuai/glm-5.1 (primary)
    16:26:31 → second Feishu message arrives, tries to acquire lock
    16:26:31..16:28:31 → second message waits 60s, times out
              → user sees: ⚠️ Agent failed before reply: session file locked (timeout 60000ms): pid=38158 alive=true ageMs=130215
    16:29:31 → model-snapshot: xiaomi-coding/mimo-v2.5-pro (fallback succeeded)
    16:29:38 → assistant reply written, lock released
    

    Lock state at time of error:

    {
      "pid": 38158,
      "createdAt": "2026-06-12T08:26:31.408Z",
      "maxHoldMs": 300000,
      "starttime": 17444257
    }

    Why this is a design issue, not a config issue:

    1. Normal LLM call chains routinely exceed 60s. Primary model timeout → fallback is a common pattern. The acquireTimeoutMs=60000 default is fundamentally too short for production use with multi-model fallback.

    2. The turn-level queue (replyRunRegistry) already serializes correctly — it waits indefinitely for the active turn to finish. But the file-level write lock operates independently and surfaces a scary error to the user instead of quietly queuing.

    3. The lock owner is the gateway itself (PID 38158 = MainThread / dist/index.js gateway). Background operations (compaction, tool-result-truncation, transcript mirroring) all try to acquire the same per-session .jsonl.lock independently of the turn admission queue, causing self-deadlock-like contention.

    Current config:

    session.writeLock.acquireTimeoutMs = 60000 (default)
    session.writeLock.maxHoldMs = 300000 (default)
    session.writeLock.staleMs = 1800000 (default)
    

    Workaround: Setting acquireTimeoutMs to match maxHoldMs (300000) prevents the error, but this just masks the issue — background writes should coordinate with the turn queue rather than independently racing for the same lock.


    Environment:

    • OpenClaw: 2026.6.6-beta.1 (commit 99648bb, source build)
    • OS: Linux 7.0.0-22-generic (x64)
    • Node: v24.16.0
    • Models in chain: zhipuai/glm-5.1 → xiaomi-coding/mimo-v2.5-pro
    • Channel: Feishu P2P
  9. aleps001 commented on Jun 13, 2026

    @aleps001

    Cross-posting detailed sessions_yield abort-settle → session-write-lock traces here, as requested when #92459 was closed as duplicate/superseded by this canonical issue. Captured on a production WhatsApp gateway (OpenClaw 2026.6.5, systemd user service, WSL2, node 22), agent topology main → workflow-lead → domain leads. Timestamps are local -03:00.

    1. sessions_yield abort settle timed out (timeoutMs=2000) — 7× in one day (2026-06-11), 3 sessions

    time (-03:00) runId sessionId
    10:43:04 0bbed05d 34cd9ea8
    17:03:13 e92c1fd4 34cd9ea8
    17:03:53 fd7fa2e8 34cd9ea8
    17:45:14 537ed53a 4987297d
    18:07:18 76f9ce51 4987297d
    19:14:31 0a90a080 9a34ce0f
    19:54:32 ea032c2e 9a34ce0f

    2. Downstream cascade — session bricked, alive=true so owner-liveness recovery never fires

    Each settle-timeout is followed by SessionWriteLockTimeoutError on that session's .jsonl.lock, with the holder pid being the gateway process itself (alive=true), so any liveness-based staleness check passes and the lock is never reclaimed:

    10:44:07 ERROR lane task error: lane=main SessionWriteLockTimeoutError: session file locked (timeout 60000ms): pid=40523 alive=true ageMs=62850  .../agents/main/sessions/34cd9ea8-….jsonl.lock
    10:44:07 ERROR Embedded agent failed before reply: session file locked (timeout 60000ms): pid=40523 alive=true ageMs=62850 …
    17:46:17 ERROR lane task error: lane=main SessionWriteLockTimeoutError: … pid=50378 alive=true ageMs=63068 .../sessions/4987297d-….jsonl.lock
    

    3. Lost subagent delivery (the data-loss mode this issue tracks)

    On session 9a34ce0f the leaked lock blocked a real subagent completion announce for ~minutes; it retried 3× against the gateway-held lock and then gave up, dropping the child's result:

    19:22:27 WARN Subagent completion direct announce failed for run 25f0793f-…: SessionWriteLockTimeoutError pid=98455 alive=true ageMs=515242 …
    19:22:32 WARN  (retry 2, same error)
    19:23:06 WARN  (retry 3, same error)
    19:23:16 WARN Subagent announce give up (retry-limit) run=25f0793f-… child=agent:personal-ai-lead:subagent:f4111087-… requester=agent:main:whatsapp:direct:+55XXXXXXXXXXX retries=3
    19:24:16 ERROR Embedded agent failed before reply: … ageMs=585355 …
    19:55:34 ERROR lane task error: lane=main … ageMs=62308 …   (session still failing >40 min after the 19:14 settle-timeout)
    

    Observed ageMs up to 585355 (~9.75 min) on a single hold; the worst real incident left the user-facing session unable to reply for ~20 min until the leaked in-flight await resolved on its own.

    4. Still reproduces on 2026.6.6 (different surface)

    After upgrading to 2026.6.6 the lock-contention class persists, now visible as an orphan → restart-sweep → cancelled chain: long effectuate subagent runs complete their work but the completion announce fails with completion agent did not produce a visible reply → Subagent announce give up (retry-limit), leaving the tracking task orphaned with no clean terminal. On the next gateway restart the sweeper settles those orphans as cancelled, and (subagent default notify=done_only) delivers a burst of Background task cancelled notices to the channel for work that had actually succeeded. (The false-notice misclassification specifically was fixed in #92448 / #92631; the underlying lock contention + lost-delivery tracked here is the part that remains.)

    Note on the fix shape

    Agreeing with the review on #92459: force-releasing the lock file or merely bumping the 2000 ms settle timeout would mask contention rather than fix it. The defect is run-aware ownership — distinguishing a legitimately long-held lock from ownership retained by an aborted/abandoned run whose holder pid is the live gateway — plus durable subagent-completion delivery, which is what #86540 is going after.

  10. 3 remaining items

  11. itanyplus commented on Jun 18, 2026

    @itanyplus

    Fresh Feishu direct-chat repro on 2026.6.8 — same gateway-owned lock, still user-visible

    Adding another live production data point on the current stable release. This is a Feishu direct-chat failure, not Slack/subagent-specific, and it still matches the core SessionWriteLockTimeoutError path tracked here while PR #86540 remains labeled status: 📣 needs proof.

    Environment

    • OpenClaw: 2026.6.8 (844f405) — npm global install
    • OS: Linux x86_64 / Ubuntu, kernel 7.0.0-22-generic
    • Node process: /usr/bin/node /usr/lib/node_modules/openclaw/dist/index.js gateway --port 18789
    • Channel: Feishu direct chat
    • Session key: agent:main:feishu:direct:ou_b21751e6f615d213220a7290f8157fce
    • Session file: /home/itany/.openclaw/agents/main/sessions/81d6a0a4-7ad3-4ad8-ac1e-74416b3ffb26.jsonl

    User-visible error

    At 2026-06-18 18:19 CST, Feishu showed:

    ⚠️ Agent failed before reply: session file locked (timeout 60000ms): pid=150880 alive=true ageMs=180210 /home/itany/.openclaw/agents/main/sessions/81d6a0a4-7ad3-4ad8-ac1e-74416b3ffb26.jsonl.lock. Please try again, or use /new to start a fresh session.
    

    The same message was seen again a few minutes later from the same Feishu direct session.

    Lock evidence captured during the incident

    {
      "pid": 150880,
      "createdAt": "2026-06-18T10:17:49.870Z",
      "maxHoldMs": 300000,
      "starttime": 70505493
    }

    Gateway process at capture time:

    PID     PPID   ELAPSED   RSS      CMD
    150880  1256   03:53:36  1612840  /usr/bin/node /usr/lib/node_modules/openclaw/dist/index.js gateway --port 18789
    

    Another session lock from the same gateway PID was also present at the same time:

    {
      "pid": 150880,
      "createdAt": "2026-06-18T10:19:38.720Z",
      "maxHoldMs": 300000,
      "starttime": 70505493
    }

    Why this is useful proof

    This reproduces the same mismatch on latest stable:

    • lock owner is the alive gateway process itself (pid=150880 alive=true)
    • lock holder advertises maxHoldMs: 300000 (5 minutes)
    • incoming Feishu message gives up after timeout 60000ms (60 seconds)
    • observed lock age was ageMs=180210 (~3 minutes), i.e. well inside the lock holder's 5-minute allowed window but already 3× longer than the requester write-lock timeout
    • result is a user-visible no reply failure in Feishu direct chat

    So this is not just stale lock cleanup. The active gateway can legally hold the session write lock long enough that normal incoming channel traffic times out before reply. This remains reproducible on 2026.6.8.

  12. itanyplus commented on Jun 21, 2026

    @itanyplus

    Still happening on 2026.6.8 — with new EmbeddedAttemptSessionTakeoverError variant

    Reporting that session file lock issues persist on 2026.6.8 (844f405, stable), with both the original lock timeout AND a new error class appearing.

    Errors observed today (2026-06-21, UTC+8)

    Error 1 — Lock timeout (the usual):

    ⚠️ Agent failed before reply: session file locked (timeout 60000ms): pid=154740 alive=true ageMs=120009 /home/itany/.openclaw/agents/main/sessions/7db64c78-7774-4d9d-91a4-9882bd6d175f.jsonl.lock
    

    Error 2 — Fence takeover (NEW since ~2026.5.x):

    session file changed while embedded prompt lock was released: /home/itany/.openclaw/agents/main/sessions/7db64c78-7774-4d9d-91a4-9882bd6d175f.jsonl
    

    This is EmbeddedAttemptSessionTakeoverError — the fence detects the session file was modified while the embedded prompt lock was released, but it cannot distinguish legitimate concurrent writes (subagent announce, auto-compaction, cron delivery) from external tampering.

    Context

    • Version: 2026.6.8 (stable, 844f405)
    • Session: Feishu DM channel, GLM-5.2 model, 67k/1.0m tokens
    • Trigger: Subagent (sessions_spawn + sessions_yield) running long-running document processing tasks
    • Behavior: The lock file is actively held by the gateway process (PID 154740, alive, running for 3 days). Deleting the .jsonl.lock file does not help — gateway immediately reacquires it because the run is still active.
    • Impact: Feishu channel becomes completely unresponsive. Every new inbound message hits the lock timeout and shows the error to the user. The session is bricked until the subagent finishes or gateway is restarted.

    Root cause analysis (from related issues)

    The fence mechanism in assertSessionFileFence (see #88703 for the most detailed analysis) has a fundamental design flaw:

    1. sessions_yield releases the write lock — when the main run yields (e.g., waiting for subagent/image generation), it releases the session file write lock and records a fence fingerprint.
    2. A second run writes to the session — subagent completion announcement, auto-compaction, or cron delivery launches a new embedded run that acquires its own write lock and writes to the same session file.
    3. Fence mismatch on reacquire — when the original run tries to reacquire the lock, assertSessionFileFence detects the fingerprint mismatch. The ownedSessionFileWrites and trustedSessionFileStates checks fail because the second run's writes used a separate lock controller instance.
    4. EmbeddedAttemptSessionTakeoverError thrown — treated as a model failure, cascading through the fallback chain (see [Bug]: Session file lock errors cascade through model fallback chain #66646 — 46% of fallback decisions in one fleet are lock-based, not model-based).

    Why this is urgent

    Suggested fix priorities

    1. Classify lock/fence errors as infrastructure errors — do NOT enter model fallback (see [Bug]: Session file lock errors cascade through model fallback chain #66646). Fail fast with "session busy" instead of wasting 60s × N models.
    2. Refresh fence after adoptCompactionTranscript — call lockGuard.refreshAfterOwnedSessionWrite() after compaction swaps the session file (see EmbeddedAttemptSessionTakeoverError: auto-compaction at reason=threshold trips fence on rewritten session jsonl #90729's suggested fix).
    3. Share owned-write tracking across lock controller instances on the same session — so the fence recognizes writes from announce runs and compaction as legitimate.
    4. Add a resume/wake mechanism for yielded runs — currently a yielded run with isStreaming()=false cannot be woken, forcing sendSubagentAnnounceDirectly to launch a new run (see session file changed while embedded prompt lock was released #88703).

    Related issues

  13. removed
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.
    on Jun 21, 2026
  14. itanyplus commented on Jun 22, 2026

    @itanyplus

    Still happening on v2026.6.9 (npm release, not dev checkout). Same session locked by the gateway process itself for 2+ minutes while the lock acquire timeout is 60s.

    Today's incident (2026-06-22, Asia/Shanghai)

    Three cascading failures on the same feishu direct session 521e74fd:

    Timestamp (UTC+8) Error Lock age
    15:32:44 SessionWriteLockTimeoutError 61s
    16:45:29 EmbeddedAttemptSessionTakeoverError (compound: lock timeout + file changed) 120s
    17:22:11 SessionWriteLockTimeoutError 116s

    All held by pid=222612 (gateway main process, alive=true), same lock file 521e74fd-634d-4680-b88b-1e01ef4359d5.jsonl.lock.

    Trigger chain

    1. Session context grew to ~252k estimated tokens (gpt-5.5, tool-heavy image editing workflow)
    2. Context overflow precheck triggered auto-compaction
    3. Compaction timed out (183s, retry also failed with "Request was aborted")
    4. Model fell back gpt-5.5 → deepseek-v4-pro (fallback chain succeeded, but lock was already stuck)
    5. Lock remained held by the compaction path; all subsequent messages hit 60s lock-acquire timeout
    warn context-overflow-precheck estimatedPromptTokens=252318 overflowTokens=3925
    warn contextEngine.compact() threw during overflow recovery: Compaction timed out
    error SessionWriteLockTimeoutError: pid=222612 alive=true ageMs=116359
    error EmbeddedAttemptSessionTakeoverError: lock timeout + file changed during prompt lock release
    

    Plus the secondary: feishu-dedup: persistent state error, falling back to memory: openKeyedStore is only available for trusted plugins

    Death spiral

    Larger session JSONL files (~10MB for this session) → slower compaction → higher lock timeout risk. The most productive sessions doing the most real work are the ones most likely to break.

    PR #86540

    ClawSweeper re-reviewed yesterday (Jun 21) and still says: blocked until real behavior proof from a real setup is added. The proof requested is "after-fix live gateway/session replay."

    This is a catch-22: we can't provide "after-fix" proof without the fix merged. The abundant before-proof (multiple production incidents across weeks, multiple OpenClaw versions) should be sufficient to demonstrate severity.

    This bug makes long-running feishu direct sessions effectively unusable after they accumulate enough context.

  15. itanyplus commented on Jun 26, 2026

    @itanyplus

    Cross-posting fresh Feishu production evidence because this thread is related. Context for this thread: Main/canonical session write-lock + subagent delivery lane issue.

    Additional production evidence from Feishu DM lane (2026-06-26)

    I'm adding fresh production evidence from a Feishu direct-message session on OpenClaw 2026.6.10.

    Environment

    • OpenClaw app: 2026.6.10
    • OS: Linux 7.0.0-22-generic x64
    • Node: 24.17.0
    • Channel: Feishu DM / p2p
    • Session model override: kuaipao-gpt/gpt-5.5
    • Workload pattern: serial sessions_spawn child runs for paper-reading tasks, with completion announcements back to the Feishu requester session
    • Session state at the time: ~540 active sessions; Feishu requester session around 70k/268k context; multiple recent spawn-child sessions

    Summary

    The Feishu lane repeatedly became unable to reliably receive normal user messages or subagent completion announcements while a long-running/compacting requester session was active. The failures were not isolated to one child run; they formed a cascade:

    1. Feishu DM dispatch enters an active/queued state.
    2. Child/subagent completion tries to announce back to the requester session.
    3. The requester session is busy or its prompt lock is released/reacquired during compaction/model work.
    4. Delivery fails via either SessionWriteLockTimeoutError, EmbeddedAttemptSessionTakeoverError, or gateway request timeout.
    5. Subagent completion retries eventually give up, so the user sees the workflow as "stalled" even though child output may already be written to disk.
    6. Feishu per-chat queue eventually hits the 300000ms cap and evicts work so later same-key messages can proceed.

    Counts from today's Feishu-related gateway logs

    From journalctl --user -u openclaw-gateway --since '2026-06-26 00:00:00', filtered for Feishu/session-lock/subagent/compaction terms:

    • SessionWriteLockTimeoutError: 12
    • Embedded agent failed before reply: 12
    • EmbeddedAttemptSessionTakeoverError: 13
    • Subagent completion direct announce failed: 38
    • Subagent announce give up: 8
    • Active requester session could not be woken: 24
    • Compaction timed out: 12
    • Full summarization failed: 9
    • per-chat task exceeded 300000ms cap: 5
    • lane wait exceeded: 45
    • long-running session: 2

    Some early entries are provider/rate-limit failures, but the afternoon cluster below is specifically session lock / takeover / completion delivery related.

    Representative timeline excerpt, redacted

    2026-06-26T13:48:30+08:00 [diagnostic] lane task error: lane=main durationMs=60167 error="SessionWriteLockTimeoutError: session file locked (timeout 60000ms): pid=<gateway-pid> alive=true ageMs=124708 <session>.jsonl.lock"
    2026-06-26T13:48:30+08:00 [diagnostic] lane task error: lane=session:agent:main:feishu:direct:<open-id> durationMs=60169 error="SessionWriteLockTimeoutError: session file locked (timeout 60000ms): pid=<gateway-pid> alive=true ageMs=124708 <session>.jsonl.lock"
    2026-06-26T13:48:30+08:00 Embedded agent failed before reply: session file locked (timeout 60000ms): pid=<gateway-pid> alive=true ageMs=124708 <session>.jsonl.lock
    2026-06-26T13:49:22+08:00 [agents/cli-compaction] CLI transcript compaction failed for kuaipao-gpt/gpt-5.5: Compaction timed out
    2026-06-26T13:51:18+08:00 [diagnostic] lane task error: lane=main durationMs=168013 error="EmbeddedAttemptSessionTakeoverError: session file changed while embedded prompt lock was released: <session>.jsonl"
    2026-06-26T13:52:04+08:00 [warn] Subagent completion direct announce failed for run <run-id>: gateway request timeout for agent
    2026-06-26T13:52:06+08:00 [warn] Subagent completion direct announce failed for run <run-id>: EmbeddedAttemptSessionTakeoverError: session file changed while embedded prompt lock was released: <session>.jsonl
    2026-06-26T13:52:08+08:00 [warn] Subagent announce give up (retry-limit) run=<run-id> child=agent:main:subagent:<child-id> requester=agent:main:feishu:direct:<open-id> retries=3 endedAgo=245s deliveryError="EmbeddedAttemptSessionTakeoverError..."
    
    2026-06-26T14:15:04+08:00 [diagnostic] lane task error: lane=main durationMs=60138 error="SessionWriteLockTimeoutError: session file locked (timeout 60000ms): pid=<gateway-pid> alive=true ageMs=86720 <session>.jsonl.lock"
    2026-06-26T14:16:19+08:00 [diagnostic] lane task error: lane=main durationMs=60139 error="SessionWriteLockTimeoutError: session file locked (timeout 60000ms): pid=<gateway-pid> alive=true ageMs=161689 <session>.jsonl.lock"
    2026-06-26T14:16:34+08:00 [agents/cli-compaction] CLI transcript compaction failed for kuaipao-gpt/gpt-5.5: Compaction timed out
    2026-06-26T14:21:02+08:00 [agents/cli-compaction] CLI transcript compaction failed for kuaipao-gpt/gpt-5.5: Compaction timed out
    
    2026-06-26T14:32:44+08:00 [diagnostic] lane task error: lane=main durationMs=60146 error="SessionWriteLockTimeoutError: session file locked (timeout 60000ms): pid=<gateway-pid> alive=true ageMs=122137 <session>.jsonl.lock"
    2026-06-26T14:33:28+08:00 [agents/cli-compaction] CLI transcript compaction failed for kuaipao-gpt/gpt-5.5: Compaction timed out
    2026-06-26T14:35:16+08:00 [diagnostic] lane task error: lane=main durationMs=127727 error="EmbeddedAttemptSessionTakeoverError: session file changed while embedded prompt lock was released: <session>.jsonl"
    2026-06-26T14:37:08+08:00 [warn] Subagent completion direct announce failed for run <run-id>: gateway request timeout for agent
    2026-06-26T14:37:12+08:00 [warn] Subagent announce give up (retry-limit) run=<run-id> child=agent:main:subagent:<child-id> requester=agent:main:feishu:direct:<open-id> retries=3 endedAgo=246s deliveryError="EmbeddedAttemptSessionTakeoverError..."
    
    2026-06-26T14:43:34+08:00 [diagnostic] lane task error: lane=main durationMs=60197 error="SessionWriteLockTimeoutError: session file locked (timeout 60000ms): pid=<gateway-pid> alive=true ageMs=125037 <session>.jsonl.lock"
    2026-06-26T14:44:26+08:00 [agents/cli-compaction] CLI transcript compaction failed for kuaipao-gpt/gpt-5.5: Compaction timed out
    2026-06-26T14:46:19+08:00 [diagnostic] lane task error: lane=main durationMs=111864 error="EmbeddedAttemptSessionTakeoverError: session file changed while embedded prompt lock was released: <session>.jsonl"
    2026-06-26T14:46:21+08:00 [warn] Active requester session could not be woken for subagent completion; falling back to requester-agent handoff: active requester session could not be woken: queue_message_failed reason=source_reply_delivery_mode_mismatch sessionId=<session-id> gatewayHealth=live
    2026-06-26T14:51:55+08:00 [diagnostic] long-running session: sessionId=<session-id> sessionKey=agent:main:feishu:direct:<open-id> state=processing age=130s queueDepth=1 reason=queued_behind_active_work classification=long_running activeWorkKind=model_call lastProgress=model_call:started lastProgressAge=67s recovery=none
    2026-06-26T14:54:43+08:00 [feishu] feishu[default]: per-chat task exceeded 300000ms cap (key=feishu:default:<chat-id>); evicting from queue so later same-key messages can proceed (#70133)
    

    Lock file state observed during the incident

    The active Feishu requester session lock was owned by the live Gateway process, not an orphaned PID:

    {
      "pid": <gateway-pid>,
      "createdAt": "2026-06-26T06:52:28.443Z",
      "maxHoldMs": 300000,
      "starttime": 131306136
    }

    The important mismatch remained: callers were failing after timeout 60000ms while the live lock could remain valid much longer (maxHoldMs: 300000 in this release; previously observed as 1020000 in older releases).

    User-visible impact

    The workflow was a serial paper-reading chain (P01..P20) where each child writes a note file and the parent should announce completion and spawn the next child. During the incident:

    • note files were written successfully through at least read_p11.md, so some child work completed;
    • the Feishu requester session still missed or delayed completion events;
    • several child completion announcements retried and gave up;
    • the human saw the workflow as stalled and had to repeatedly send manual nudges such as "child agent stopped again" / "why can't it continue automatically";
    • progress tracking lagged behind actual child output because the completion-to-parent handoff was unreliable.

    Why this seems relevant here

    This looks like the same family as the session write-lock / long-turn / subagent delivery lane issues, but today's evidence adds two details:

    1. On 2026.6.10, the lock maxHoldMs is now 300000, yet callers still fail at 60000ms, so the timeout mismatch still creates user-visible failures.
    2. Compaction timeouts and EmbeddedAttemptSessionTakeoverError appear to amplify the problem: once the requester session is busy/compacting, subagent completion delivery can fail repeatedly and eventually give up even though the child output exists.

    If useful, I can provide a fuller redacted log bundle, but I avoided pasting full paths, Feishu IDs, or local project contents here.

  16. itanyplus commented on Jun 26, 2026

    @itanyplus

    Linking #96975: metadata-only subagent completion would reduce session write-lock and delivery-lane pressure by avoiding large child payload writes into the parent/requester session.

  17. aleps001 commented on Jun 26, 2026

    @aleps001

    Cross-channel corroboration: same EmbeddedAttemptSessionTakeoverError on WhatsApp direct (2026.6.10), on the intelligence/ingest subagent chain

    Adding a fresh, log-verified repro on a different channel and workload than the Feishu evidence above — same error, so it is not isolated to Feishu or to the paper-reading pattern.

    Environment

    • OpenClaw 2026.6.10, self-hosted Linux, systemd user gateway
    • Channel: WhatsApp direct (1:1)
    • Orchestrator model gpt-5.5; chain workers gpt-5.4
    • Workload: main -> workflow-lead (an IP-ingest / IB-FM evaluation batch over 3 docs) -> intelligence-lead subagent as step_1

    What happened
    The workflow-lead run reached its first step (spawn intelligence-lead) and that embedded run failed with:

    EmbeddedAttemptSessionTakeoverError: session file changed while embedded prompt lock was released
    

    It crashed before producing any routing output (no routing-*.json), so the workflow completed with no deliverable and the user saw the workflow stall. A retry in a "clean lane" then hit the same error, and the batch's routing decisions were never produced (the 3 documents remained unevaluated).

    Refs / timing (BRT) — same error recurring across the run and the retry:

    • workflow-lead run c1d4149b..., intelligence-lead subagent 2a278381...
    • EmbeddedAttemptSessionTakeoverError at 09:16:30, 09:17:22, 09:24:03, 09:27:03

    Why this is the same family

    • Identical error string (session file changed while embedded prompt lock was released) as the Feishu evidence, on 2026.6.10.
    • The requester session (the workflow-lead/intelligence chain) is busy/large while the embedded child's prompt lock is released-and-reacquired, and the child's session file changes underneath it -> takeover error -> the step dies before output.
    • Crucially, retrying in a clean lane does not escape it — the takeover recurs, so it is the underlying concurrency/lock-release race, not a one-off. Concurrent unrelated tasks on the gateway at the same time visibly worsened it.

    This supports the #96975 direction (metadata-only completion to reduce session write-lock / delivery-lane pressure): heavy multi-agent chains where the requester session is large are exactly where the embedded prompt-lock release window gets clobbered.

    (Phone number and internal IDs redacted.)

  18. liuhaiyang14 commented on Jun 29, 2026

    @liuhaiyang14
    Contributor

    Adding one more production/root-cause data point from a macOS local gateway. This matches the canonical class here, but the useful distinction is that the observed lock was held by the live gateway process itself, not by a dead PID or an orphan .lock file.

    Environment / incident shape:

    • OpenClaw observed on 2026.6.5 during the incident; later static upgrade checks through 2026.6.10 still showed the same core risk shapes.
    • macOS LaunchAgent gateway, Node 22.22.1.
    • Live lock example: agents/research/sessions/<session>.jsonl.lock.
    • Lock payload included pid=<gateway pid>, maxHoldMs=1020000.
    • lsof showed the same gateway node process holding the lock FD, and the process was alive.
    • Active tasks existed at the time, so deleting the lock or restarting the gateway would have been unsafe.

    Observed cascade:

    sessions_yield abort settle timed out ... timeoutMs=2000
    SessionWriteLockTimeoutError: session file locked (timeout 60000ms)
    Subagent announce give up (retry-limit)
    

    The same session-write-lock timeout could block main-session replies, subagent completion announcements, and follow-up writes after sessions_yield.

    Implementation shape observed in the packaged runtime:

    • The acquire timeout default is still 60000ms.
    • The effective config path is config.session.writeLock.* or OPENCLAW_SESSION_WRITE_LOCK_*; unrelated agent-default lock settings do not change this path.
    • promptActiveSession wraps activeSession.prompt(...) inside owned transcript-write context.
    • Provider/tool/stream paths can therefore hold or re-enter the session transcript write context across long work, not only around short append/flush operations.
    • releaseEmbeddedAttemptSessionLockForAbort(...) is fire-and-forget.
    • sessions_yield abort settle defaults to 2000ms, so cleanup can time out while later transcript writes and direct announce still race the lock.
    • Completion direct announce can retry and then give up, which converts a lock-contention problem into a lost/hidden completion problem.

    Why this is not solved by only increasing timeouts:

    Raising session.writeLock.acquireTimeoutMs makes callers wait longer, but does not fix the root contradiction: long provider/tool/yield/abort work can keep the session writer unavailable while other legitimate delivery lanes need to append. It can reduce visible failures in one lane while making head-of-line blocking worse.

    Suggested fix direction:

    • Hold the session JSONL write lock only around actual append/flush/rewrite critical sections, not around long provider streams, long tools, compaction, or abort/yield settle work.
    • Make abort/yield cleanup awaitable and observable, especially when it owns or releases a session write lock.
    • Treat subagent completion announcement as durable/outbox-style delivery so a few lock-acquire failures do not permanently drop the completion surface.
    • Keep owner diagnostics in timeout errors: pid, liveness, lock age, maxHoldMs, and preferably the logical owner/action that acquired the lock.

    This is a production confirmation that the lock owner can be the live gateway itself (alive=true), so recovery logic that only handles dead owners/orphan lock files cannot resolve the failure class.

  19. itanyplus commented on Jun 29, 2026

    @itanyplus

    Additional live reproduction from a Feishu direct session on 2026-06-29.

    Environment:

    • OpenClaw app/package: 2026.6.10
    • Gateway: systemd user service, local loopback, running pid 346578
    • OS: Linux 7.0.0-22-generic x64
    • Node: 24.18.0 as reported by openclaw status
    • Channel/session surface: Feishu direct session (agent:main:feishu:direct:...)
    • The gateway was otherwise reachable when checked via openclaw status.

    Observed user-facing error at 2026-06-29 14:46 GMT+8:

    session file locked (timeout 60000ms): pid=346578 alive=true ageMs=119780 /home/itany/.openclaw/agents/main/sessions/6e8686fa-6ce1-42ef-be95-3ec6d4ab0bd4.jsonl.lock
    

    Important detail: pid=346578 is the live gateway process itself from openclaw status, not a dead PID or orphaned lock owner.

    A few minutes later the same lock path still existed. Its metadata was:

    {
      "pid": 346578,
      "createdAt": "2026-06-29T06:51:09.800Z",
      "maxHoldMs": 300000,
      "starttime": 131306136
    }

    Operational context from openclaw status around the same time:

    • Gateway service: active/running, pid 346578
    • Main Feishu direct session active about 1 minute ago
    • Main TUI session active about 1 minute ago
    • Multiple recent spawn-child/subagent sessions were also present
    • The failing path was a normal Feishu user message before reply, surfacing as a 60s session write-lock timeout.

    This looks like same-process/live-gateway session lock contention or unreleased/reentrant lock behavior rather than stale dead-PID cleanup.

    This seems to match the issue scope here: write-lock timeouts blocking channel/session delivery lanes, with the lock owner still alive and equal to the gateway process.

  20. steipete commented on Jul 11, 2026

    @steipete
    Contributor

    Write-lock timeout pileups blocking delivery lanes were reported against the file-store write path; that path is now short SQLite transactions with structured contention telemetry, changing the whole contention profile.
    Sessions and transcripts moved from JSON/JSONL files to per-agent SQLite on main (0a8e3604ba24, plus follow-up 4eef09dc3f5d), and the storage rework removed or rewrote the code paths implicated here. We're closing storage-implicated reports optimistically as part of that cleanup since we can't re-verify every historical environment. If this still reproduces on current main or the next release, please open a fresh issue with new logs and link back to this one.

  21. locked as resolved and limited conversation to collaborators on Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions