Skip to content

EmbeddedPromptLockFileChangedError causes subagent announce to retry after message already delivered, resulting in duplicate messages #89995

Description

@Nelsoncongbao

Summary

When a subagent completes and triggers an announce back to the requester session, if the main session file is concurrently being written (e.g., main agent is sending a Feishu message at the same moment), the announce throws EmbeddedPromptLockFileChangedError and retries — even though the message was already successfully delivered. This causes duplicate messages in the channel.

Steps to Reproduce

  1. Spawn a subagent via sessions_spawn
  2. Subagent completes and triggers announce to main session
  3. At the same moment, main agent is writing to the session file (e.g., delivering a reply to the user)
  4. Announce throws session file changed while embedded prompt lock was released
  5. Announce retries 3 times (5s / 10s / 20s intervals)
  6. Each retry successfully sends the message → user receives 3 identical duplicate messages

Log Evidence

feishu: sendText target=user:ou_xxx, textLength=25          ← message sent successfully
[warn] Subagent completion direct announce failed: text completion direct delivery failed: session file changed while embedded prompt lock was released: /path/to/session.jsonl
feishu: sendText target=user:ou_xxx, textLength=25          ← retry #1, duplicate sent
[warn] Subagent completion direct announce failed: ... session file changed ...
feishu: sendText target=user:ou_xxx, textLength=25          ← retry #2, duplicate sent
[warn] Subagent announce give up (retry-limit) run=xxx

Root Cause

In subagent-announce-delivery.js, the error session file changed while embedded prompt lock was released (thrown as EmbeddedPromptLockFileChangedError) is not classified in either:

  • TRANSIENT_ANNOUNCE_DELIVERY_ERROR_PATTERNS
  • PERMANENT_ANNOUNCE_DELIVERY_ERROR_PATTERNS

Despite this, the announce still retries. Critically, no idempotency check is performed before retrying — the code does not verify whether the message was already delivered before attempting to send again.

Suggested Fix

Either:

  1. Add /session file changed while embedded prompt lock was released/i to PERMANENT_ANNOUNCE_DELIVERY_ERROR_PATTERNS to prevent retry after this error
  2. Record a delivery idempotency token when sendText succeeds, and check it before each retry to avoid duplicate delivery

Environment

  • OpenClaw version: 2026.6.1-beta.3 (3b53e2c)
  • Channel: Feishu (via @larksuite/openclaw-lark plugin v2026.5.20)
  • OS: Darwin 25.3.0 (arm64)
  • Node: v24.14.1
  • Reproducible: consistently, every subagent announce when main session has concurrent write activity

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions