Skip to content

[Bug]: Session write lock leaked after embedded run timeout during subagent announce #86816

@phoenixyy

Description

@phoenixyy

[Bug]: Session write lock leaked after embedded run timeout during subagent announce

Environment

  • OpenClaw version: 2026.5.22
  • OS: Linux 6.8.0-1047-aws (x64)
  • Provider: amazon-bedrock (Claude Sonnet 4.6, thinking=adaptive)
  • Channel: Feishu

Description

When a subagent completes and announces its result to the parent session, the announce operation acquires the parent session's write lock and triggers an embedded model call. If this embedded run hits the timeoutMs (600000ms in our case), the in-memory session write lock is not released, permanently blocking all subsequent writes to that session within the same process.

This is similar to #49157 but with a specific trigger path: subagent completion → announce → embedded run → timeout → lock leak.

Steps to Reproduce

  1. Configure agent with thinkingDefault: "adaptive" and multiple subagent spawns (PPT generation workflow with Gen + QA subagents)
  2. Have a long-running parent session with queued messages
  3. When a subagent completes, the announce operation starts an embedded run on the parent session
  4. If the parent session already has queued work or the model call is slow, the announce embedded run hits its timeout
  5. After timeout, the session write lock is never released
  6. All subsequent operations on that session fail with SessionWriteLockTimeoutError indefinitely until gateway restart

Relevant Logs

[agent/embedded] embedded run timeout: runId=announce:v1:agent:main:subagent:30205c6b-... sessionId=dec68367-... timeoutMs=600000

[diagnostic] lane task error: lane=main durationMs=630254 error="CommandLaneTaskTimeoutError: Command lane "main" task timed out after 630000ms"

[diagnostic] lane task rejected after timeout: lane=main timeoutMs=630000 error="SessionWriteLockTimeoutError: session file locked (timeout 60000ms): pid=1447975 .../dec68367-....jsonl.lock"

# From this point on, ALL operations fail:
[warn] Subagent completion direct announce failed for run ...: SessionWriteLockTimeoutError: session file locked (timeout 60000ms)
[warn] Subagent announce give up (retry-limit) ... retries=3 endedAgo=73s
Embedded agent failed before reply: session file locked (timeout 60000ms)

Key Observations

  • The .lock file itself is deleted after timeout, but the in-memory lock (process-internal HELD_LOCKS map) is never cleared
  • Because PID belongs to the live gateway process, stale-lock detection does not help
  • Only a full gateway restart resolves the deadlock
  • In our PPT workflow, this happens when multiple subagents complete near-simultaneously and their announce operations compete for the same parent session lock

Impact

  • Parent session permanently dead until restart (user messages get no response)
  • All pending subagent announces are lost (retry limit = 3, all fail)
  • No automatic recovery mechanism

Expected Behavior

When an embedded run times out, the session write lock should be released in the timeout handler (finally block / cleanup). The lock should never outlive the operation that acquired it.

Suggested Fix

Add lock release to the embedded run timeout/error path:

try {
  await embeddedRun(...)
} finally {
  releaseSessionWriteLock(sessionId)  // Must happen even on timeout/rejection
}

Workaround

Restart the gateway (systemctl --user restart openclaw-gateway-<agent>.service). No configuration change prevents this; it requires a code fix.

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.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: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.

    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