Skip to content

[Bug] ACP thread-bound session: Claude Code replies not delivered to Discord thread #96665

Closed as not planned

Description

@chouzz

Bug: ACP thread-bound session replies generated but not delivered to Discord thread

Environment

  • OpenClaw version: 2026.6.10 (git sha: 97aaf2a)
  • Node.js: v24.14.1
  • OS: Linux 6.8.0-106-generic (x64)
  • Channel: Discord
  • ACP backend: acpx (Claude Agent SDK)
  • Claude model: claude-opus-4-8

Summary

When spawning a Claude Code ACP session with sessions_spawn(runtime="acp", thread=true, mode="session"), the ACP session internally processes user messages and generates correct replies, but the replies are never delivered back to the Discord thread. The user sees no response in the thread despite Claude Code having responded successfully.

Reproduction Steps

  1. Configure Discord channel with threadBindings.enabled: true and threadBindings.spawnSessions: true
  2. In Discord, trigger a Claude Code ACP thread spawn (e.g. ask the main agent to start a coding task with Claude Code)
  3. The thread is created and the initial ACP response may or may not appear
  4. Send a follow-up message in the thread (e.g. "你是什么模型?")
  5. Expected: Claude Code's reply appears in the thread
  6. Actual: No reply appears in the thread

Evidence from session data

1. ACP session transcript confirms replies were generated

Session file: ~/.openclaw/agents/claude/sessions/<session-id>.jsonl

[1782312859974] user: 你是什么模型呢?
[1782312859977] assistant: 我是 Claude Opus 4.8(模型 ID: claude-opus-4-8)...

[1782312881932] user: 你用的是什么模型?
[1782312881937] assistant: 我当前使用的是 Opus 4.8 模型...

[1782313113861] user: 你可以做什么呢?
[1782313113865] assistant: 作为 AI 助手,我可以帮你处理各种软件工程任务...

All user messages received replies. The ACP session internally works correctly.

2. Session metadata shows correct delivery context

From sessions.json:

{
  "sessionKey": "agent:claude:acp:ee6778d0-...",
  "status": "running",
  "route": {
    "channel": "discord",
    "accountId": "default",
    "thread": { "id": "1519354938080235580" }
  },
  "deliveryContext": {
    "channel": "discord",
    "to": "channel:1519354938080235580",
    "accountId": "default",
    "threadId": "1519354938080235580"
  },
  "originatingThreadId": "1519354938080235580"
}

The delivery context is correctly populated with the Discord thread ID.

3. Bot CAN send messages to the thread

When the parent agent uses the message tool directly to send a test message to the thread, it succeeds. The bot has proper permissions.

4. ACP sessionKey lacks :thread: suffix

The ACP session key is agent:claude:acp:ee6778d0-... — it does not contain a :thread: suffix. This is notable because resolveRoutedDeliveryThreadId falls back to parseSessionThreadInfoFast(sessionKey), which extracts thread IDs from the session key's :thread: suffix.

Code path analysis

The delivery goes through:

  1. dispatch-acp module → createAcpDispatchDeliveryCoordinator()
  2. deliver(kind, payload) function
  3. When shouldRouteToOriginating is true → calls routeReply()
  4. threadId is resolved via:
    • params.originatingThreadId (from session metadata)
    • OR resolveRoutedDeliveryThreadId() which tries:
      • sessionCtx.MessageThreadId (from inbound message transport)
      • sessionCtx.TransportThreadId (from transport layer)
      • parseSessionThreadInfoFast(sessionKey) (parses :thread: suffix)

The delivery failure appears to happen inside routeReply(), but the error is only logged via logVerbose() which outputs to gateway stdout. Since the gateway's stdout is piped to a socket, these logs are not easily accessible for debugging.

Relevant code in dispatch-acp-CFUMtx6P.js:572:

if (!result.ok) {
    logVerbose(`dispatch-acp: route-reply (acp/${kind}) failed: ${result.error ?? "unknown error"}`);
    return false;
}

Observations

  • Initial task completion (mode="run" style) may deliver the first reply, but follow-up messages in the thread never get replies delivered
  • lastInteractionAt is not updated when follow-up messages arrive (stays at spawn time), even though updatedAt is
  • The issue affects accountId: "default" sessions; accountId: "coder" sessions need further verification
  • Two currently running ACP sessions (a0cbaf86, 6eb2eda6) exhibit the same behavior

Debugging suggestions

  1. Expose logVerbose output for dispatch-acp: route-reply failures — pipe to a log file or make it accessible via the API
  2. Add a metric/counter for ACP delivery failures so they're visible in /status
  3. Check if shouldRouteToOriginating is correctly set to true for follow-up ACP runs
  4. Verify originatingThreadId propagation from session metadata to the delivery coordinator for follow-up runs (not just the initial spawn)

Related issues

Activity

  1. clawsweeper commented on Jun 25, 2026

    @clawsweeper
    Contributor

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

    Summary
    Keep open: current main still lacks the stored ACP delivery-context thread fallback needed for this Discord thread-delivery report, and the related focused fix PR is open but not merged and has its own review blockers.

    Reproducibility: no. live reproduction was run, but the issue is source-reproducible: current main cannot recover deliveryContext.threadId for ACP session keys that lack a :thread: suffix on the visible ACP dispatch path.

    Root-cause cluster
    Relationship: canonical
    Canonical: #96665
    Summary: This issue is the canonical concrete Discord/ACP delivery report; the related open PR is a candidate fix but is not merged or sufficient yet.

    Members:

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

    Ways to help us reproduce this

    • Add a screenshot or short recording showing the behavior.
    • Add expected vs actual behavior.

    Next step
    No new repair job should be queued while the issue is already paired with the open focused candidate PR.

    Review details

    Best possible solution:

    Keep this issue as the canonical user report until a PR wires a trusted ACP stored thread id into visible ACP dispatch, preserves the stale-route guard, adds focused regression coverage, and provides redacted Discord/ACP proof.

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

    No live reproduction was run, but the issue is source-reproducible: current main cannot recover deliveryContext.threadId for ACP session keys that lack a :thread: suffix on the visible ACP dispatch path.

    Is this the best way to solve the issue?

    Yes for the direction, not for closing yet: the narrow maintainable fix is to pass a trusted ACP stored thread id into pre-dispatch ACP delivery while preserving the stale-route guard, then prove it with regression and live Discord/ACP evidence.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • No live Discord/Claude ACP reproduction was run in this read-only review; the current confidence is based on reporter artifacts plus source-path inspection.
    • The open candidate PR still has review blockers, so maintainers should not treat this issue as solved until a corrected PR merges and proves the Discord/ACP thread behavior.

    Codex review notes: model internal, reasoning high; reviewed against 6de357ad4772.

    Label changes

    Label changes:

    • add maturity:stable: Discord is scored M4 Stable, and the affected taxonomy feature includes Discord thread-bound session routing and ACP agent routing.

    Label justifications:

    • P2: This is a bounded but user-visible ACP Discord delivery bug rather than a core-wide outage.
    • impact:message-loss: The reported failure is generated ACP replies not appearing in the bound Discord thread.
    • impact:session-state: The bug depends on ACP thread-bound session routing metadata and stored delivery context.
    • maturity:stable: Discord is scored M4 Stable, and the affected taxonomy feature includes Discord thread-bound session routing and ACP agent routing.
    Evidence reviewed

    What I checked:

    • documented expected behavior: ACP interactive sessions bound with --thread should route follow-up messages directly to the ACP session and deliver ACP output back to the same channel/thread/topic. Public docs: docs/tools/acp-agents.md. (docs/tools/acp-agents.md:621, 6de357ad4772)
    • current helper lacks stored deliveryContext fallback: Current main's resolveRoutedDeliveryThreadId only checks inbound MessageThreadId, inbound TransportThreadId, and the session-key thread suffix; ACP keys like agent:<id>:acp:<uuid> do not carry that suffix. (src/auto-reply/reply/routed-delivery-thread.ts:5, 6de357ad4772)
    • pre-dispatch route excludes normalized stored thread ids: The ACP pre-dispatch path intentionally avoids reading normalized store thread ids to prevent stale-route resurrection, so the issue needs a trusted ACP-specific stored-thread source rather than a broad fallback. (src/auto-reply/reply/dispatch-from-config.ts:1301, 6de357ad4772)
    • visible ACP dispatch receives the earlier route thread id: reply_dispatch passes originatingThreadId: routeReplyThreadId into the ACP hook, so visible ACP delivery can be controlled before the later normal reply-run path executes. (src/auto-reply/reply/dispatch-from-config.ts:2636, 6de357ad4772)
    • ACP delivery still cannot recover session entry context: If originatingThreadId is absent, ACP delivery calls resolveRoutedDeliveryThreadId with only ctx and sessionKey, not the stored session entry that contains deliveryContext.threadId. (src/auto-reply/reply/dispatch-acp-delivery.ts:429, 6de357ad4772)
    • stored delivery context is seeded at spawn: The gateway agent path normalizes request channel/to/account/threadId into a delivery hint and merges it into session delivery fields, matching the reporter's stored deliveryContext.threadId observation. (src/gateway/server-methods/agent.ts:1910, 6de357ad4772)

    Likely related people:

    • sandieman2: Authored recent queued follow-up and routed-thread reply delivery work that touched dispatch-from-config, dispatch-acp-delivery, and get-reply-run. (role: recent area contributor; confidence: medium; commits: c67dc59b02b0; files: src/auto-reply/reply/dispatch-from-config.ts, src/auto-reply/reply/dispatch-acp-delivery.ts, src/auto-reply/reply/get-reply-run.ts)
    • MonkeyLeeT: Authored the sessions_send external route preservation work near the same effective-route and ACP delivery boundary. (role: route inheritance contributor; confidence: medium; commits: 6cb06f5fbcf5; files: src/auto-reply/reply/dispatch-acp-delivery.ts, src/auto-reply/reply/dispatch-from-config.ts, src/auto-reply/reply/effective-reply-route.ts)
    • mariosousa-finn: Authored gateway subagent thread-announcement work that seeded deliveryContext from request channel/to/threadId, which is the stored source needed here. (role: delivery-context seeding contributor; confidence: medium; commits: ac13b09b742d; files: src/gateway/server-methods/agent.ts, src/gateway/server.agent.subagent-delivery-context.test.ts)
    • moeedahmed: Recently changed ACP manual-spawn tracking in the gateway agent path adjacent to delivery-context seeding. (role: recent adjacent ACP spawn contributor; confidence: medium; commits: a9eb0d7e9cae; files: src/gateway/server-methods/agent.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
    P2Normal backlog priority with limited blast radius.
    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.
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    maturity:stableBroken existing behavior primarily owned by an M4/M5 scorecard surface.
    on Jun 25, 2026
  3. openclaw-barnacle commented on Jul 14, 2026

    @openclaw-barnacle

    This issue has been automatically marked as stale due to inactivity.
    Please add updates or it will be closed.

  4. openclaw-barnacle commented on Jul 21, 2026

    @openclaw-barnacle

    Closing due to inactivity.
    If this is still an issue, please retry on the latest OpenClaw release and share updated details.
    If you are absolutely sure it still happens on the latest release, open a new issue with fresh steps to reproduce.

  5. locked as resolved and limited conversation to collaborators on Sep 16, 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

    P2Normal backlog priority with limited blast radius.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm 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.maturity:stableBroken existing behavior primarily owned by an M4/M5 scorecard surface.staleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions