Skip to content

fix(discord): subagent results posted into a Discord thread requester are marked failed - #163756

Merged
obviyus merged 1 commit into
openclaw:mainfrom
MertBasar0:fix/163724-discord-thread-settle-credit
Oct 3, 2026
Merged

obviyus merged 1 commit into
openclaw:mainfrom
MertBasar0:fix/163724-discord-thread-settle-credit

Conversation

@MertBasar0

@MertBasar0 MertBasar0 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Closes #163724

What Problem This Solves

Fixes: a requester session that lives in a Discord thread posts its result with the message tool and ends with NO_REPLY, the post shows up in the thread, and every child completion is still marked deliveryStatus=failed.

User Impact

User impact: subagent results posted into the requester's own Discord thread are now counted as delivered, instead of showing as failed tasks with a misleading "recovered requester" error.

Why This Change Was Made

Discord addresses a thread by its own channel id. The settle turn's requester route is {to: channel:T, threadId: T}, but the message-tool send was recorded as plain channel:T with no thread evidence, so sourceDeliveryTargetsMatch rejected it. Other threaded channels (Slack, Telegram, Matrix, MSTeams, Mattermost) supply that evidence through threading.resolveAutoThreadId. Discord didn't implement it.

Discord now implements resolveAutoThreadId. It returns the current thread only when the send's target normalizes to that thread's own channel (channel:<currentThreadTs>). The shared matcher is unchanged.

  • A send to the parent channel or a sibling channel gets no thread evidence, so it can't be credited against a thread delivery.
  • The physical target is unchanged: Discord's outbound already resolves {to: channel:T, threadId: T} to channel:T, and the outbound session route is keyed on the same peer id. One routing difference: when T has a webhook thread binding, the message-tool send now uses the same binding path as the session's normal threaded replies.
  • buildToolContext is intentionally left alone. Passing inbound MessageThreadId through there would change source-reply mirror placement for inbound thread turns, and the settle turn already gets currentThreadTs and currentChannelId from its run context (threadId/to from the announce dispatch).

Out of scope: the issue's secondary wording point ("recovered requester…" text for runs with no restart).

Evidence

Real behavior proof: isolated mock-Gateway channel boundary (Crabline)

There's no live Discord here, so this is an isolated mock-Gateway channel boundary proof. A real QA Gateway runs the real bundled Discord plugin against a Crabline local Discord REST + Gateway WS server. mock-openai scripts the reported requester flow:

  1. A message arrives inside a Discord thread (type-11 channel with parent_id).
  2. The requester calls sessions_spawn (run mode), then sessions_yield.
  3. In the settle wake it calls message(action="send", target="channel:<thread>") and replies NO_REPLY.

Config: messages.groupChat.visibleReplies: message_tool, the setup where group replies go through the message tool. The proof-only harness (mock planner, scenario, Windows-host staging workarounds) isn't part of this PR.

Both runs use the same harness. RED reverts only extensions/discord/src/channel.ts to base 87af5763bb; GREEN is this PR's head 96806b7. In both, the real Discord plugin records requesterOrigin = {to: "channel:159028662354834067", threadId: "159028662354834067"}, the shape from the issue.

Thread posts (Crabline POST /api/v10/channels/<thread>/messages) Requester model calls after the settle send Persisted child run delivery
RED (resolver reverted) yield notice + settle post (QA-163724-THREAD-SETTLE-OK …) 4 (NO_REPLY continuation, 2 settled-turn finalization passes, heartbeat) failed / intentional_non_delivery / message_tool_only
GREEN (this PR) yield notice + settle post (same, exactly once) 0. The turn ends at the message tool delivered, 4.3 s after the settle post
RED / GREEN suite output
RED   [qa-suite] fail step="thread requester spawns, yields, and settles through the message tool"
      details=child delivery was failed: {"status":"failed","disposition":"intentional_non_delivery","lastError":"message_tool_only",
      "payload":{"requesterOrigin":{"channel":"discord","to":"channel:159028662354834067","accountId":"default","threadId":"159028662354834067"},
      "label":"qa-163724-worker","outcome":{"status":"ok"},"terminalReply":{"disposition":"visible","text":"QA-163724-CHILD-RESULT"}}}
GREEN [qa-suite] pass step="thread requester spawns, yields, and settles through the message tool"
      persisted delivery: {"status":"delivered","disposition":"delivered","deliveredAt":"2026-10-02T21:58:31.564Z"}
      settle post:        2026-10-02T21:58:27.280Z POST /api/v10/channels/159028662354834067/messages "QA-163724-THREAD-SETTLE-OK QA-163724-CHILD-RESULT"

RED's error text is message_tool_only rather than the issue's "recovered requester completed without durable final delivery evidence". That's a different classifier branch on current main, with the same outcome: the child is marked failed even though the thread post landed.

Webhook-bound thread branch

Crabline has no Discord webhook endpoints, so this branch is proven one layer down, still over real HTTP. The pieces are:

  • the real Discord resolver feeding core resolveAndApplyOutboundThreadId, which message-action-send.ts runs before it passes threadId to the send;
  • the real Discord outbound.sendText;
  • a real thread-binding manager holding a webhook binding for T;
  • the real Discord REST client, sending to a local recording server via DISCORD_API_URL.

The same send is then passed to the settle credit check.

  • GREEN: resolvedThreadId: T. One POST /api/v10/webhooks/<id>/<token>?wait=true&thread_id=T and no bot send. The extracted send is {to: channel:T, threadId: T, threadImplicit: true}, and the credit check returns true.
  • RED: resolvedThreadId: null. The send goes out as a bot POST /api/v10/channels/T/messages, the extracted send is {to: channel:T}, and the credit check returns false.

So in a webhook-bound thread, the settle send now takes the binding's webhook/persona path, the same one the session's normal threaded replies use. It lands in the same channel and is credited.

Tests in this PR

  • src/agents/subagents/announce/subagent-announce-delivery.discord-thread.test.ts: composed regression with the real Discord plugin. RED without the fix, GREEN with it (2 tests).
    • pnpm test <file> --maxWorkers=1 wall time is about 26–31 s, almost all vitest transform; the tests take under 40 ms.
  • extensions/discord/src/channel.test.ts: resolver cases for the same thread (channel:T and bare T), a sibling channel, a user target, and no current thread. 40/40.
  • Acceptance suites plus neighbors, all green locally: source-delivery-plan, source-reply-mirror, subagent-announce-direct-delivery, subagent-announce-delivery.yielded-settle, embedded-agent-subscribe.tools.extract, message-action-threading, extensions/discord/src/outbound-adapter (183 tests). threading.registry-backed-shard-a..h are green as well.
  • oxlint, oxfmt --check and git diff --check are clean. CI is green on 96806b7.
  • History check: across all 188 commits touching extensions/discord/src/channel.ts since 2026-01-18, Discord never had resolveAutoThreadId. This adds a missing hook; it doesn't bring back a removed one.

Observed, out of scope: with the default visibleReplies: automatic, this flow doesn't end failed on either head. After NO_REPLY, the existing settled-turn finalization re-prompts; if the model stays silent, it posts "The tool run finished, but no final summary was produced…", and that visible reply is credited. This PR doesn't change that path.

Independent verification (2026-10-03)

Verified unchanged head 96806b7fe59343784ba4f0c68efe9ff50987cff3 in secretless Node 24 Docker isolation. No additional source changes were needed. Thanks @MertBasar0 for the fix and @stuart-minion-ai for the report.

  • Built the Gateway and ran the real Discord plugin against the local Crabline REST/WebSocket server. The baseline reverted only extensions/discord/src/channel.ts to PR parent 87af5763bbc0bd1febc08d78eedc7fafd9eb5225, then rebuilt/finalized the plugin runtime. This is a discriminating revert baseline, not a whole-current-main execution.
  • With visibleReplies: message_tool, both versions posted the settle result exactly once to the same POST /api/v10/channels/T/messages. Baseline persisted child delivery as failed / intentional_non_delivery; candidate persisted delivered / delivered. Baseline consumed the scripted NO_REPLY and finalization continuations; candidate completed at the successful message-tool send.
  • Parent and sibling targets were not credited: the existing completion-source guard rejected cross-conversation sends and the child delivery failed. These are rejection controls, not successful cross-channel sends.
  • A normal threaded final reply delivered on both versions. The automatic-reply-mode control also delivered on both, preserving its existing finalization behavior.
  • Real HTTP webhook-binding check: baseline used the bot channel-message endpoint; candidate used the binding webhook with thread_id=T and the bound persona. Destination stayed T, matching normal bound-thread reply routing.
  • The composed regression failed on baseline because the extracted thread ID was missing and passed on candidate. Candidate: 2 settlement tests plus 40 Discord channel tests passed (38.15 s combined wrapper wall time); baseline regression: 1 failed / 1 passed (19.29 s).
  • Live smoke on the exact candidate: one passive-proxied gpt-5-mini request through the built Gateway returned P163724-LIVE-OK; utility jobs were disabled. This was a provider smoke, not live Discord proof. The credential file and live container were removed.
  • No overlap with Pash/Sarah changes in the touched files.

CI run 37058065890 succeeded on this exact head; no jobs were rerun. The exact-head ClawSweeper review remains ready for maintainer review.

…n thread

A requester living in a Discord thread posts its verified result with the
message tool and ends with NO_REPLY. Discord addresses a thread by its own
channel id, so the send was recorded as channel:<T> with no thread evidence
and never matched the requester route {to: channel:<T>, threadId: <T>}; every
child completion was marked failed.

Discord now implements threading.resolveAutoThreadId, returning the current
thread only when the send targets that thread's own channel. Parent and
sibling channels gain no thread evidence, and the send target is unchanged.

Related to openclaw#163724
@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord agents Agent runtime and tooling size: S labels Oct 2, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 2, 2026
@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 2, 2026, 6:29 PM ET / 22:29 UTC (Revision 2).

ClawSweeper review

What this changes

Discord now identifies message-tool sends to the requester’s own thread so successfully posted subagent results count as delivered, with resolver and settlement regression coverage.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused fix absent from current main and the latest release. The new Gateway and HTTP traces satisfy the earlier proof request, and no blocking patch defect was found.

Priority: P1
Reviewed head: 96806b7fe59343784ba4f0c68efe9ff50987cff3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A narrow repair with meaningful regression coverage and adequate production-boundary red/green evidence.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (logs): The captured red/green Gateway trace exercises Discord’s resolver through requester settlement and shows a real HTTP thread post followed by persisted delivered status. Additional real-client HTTP evidence covers the existing webhook-binding path. This satisfies the prior proof request under the accepted isolated channel-boundary policy; it is not a live Discord service run. No stored-data contract changes require migration proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The captured red/green Gateway trace exercises Discord’s resolver through requester settlement and shows a real HTTP thread post followed by persisted delivered status. Additional real-client HTTP evidence covers the existing webhook-binding path. This satisfies the prior proof request under the accepted isolated channel-boundary policy; it is not a live Discord service run. No stored-data contract changes require migration proof.
Evidence reviewed 10 items Pinned introduced change: The merge-base-to-head patch adds the existing optional threading resolver and focused tests. The verified test-merge comparison retains precisely these changes against its main parent.
Existing contract and narrow repair: The optional resolver already exists in ChannelThreadingAdapter. Discord returns the current thread only when the normalized destination equals that thread’s channel; parent, sibling, and user destinations do not inherit it. This implements an existing plugin contract without expanding the SDK.
Delivery accounting mechanism: Message-tool extraction invokes the registered threading resolver with the current thread. The shared source matcher rejects missing thread evidence; the new composed regression verifies credit for the requester thread and rejection for its parent.
Findings None None.
Security None None.

How this fits together

Discord’s channel plugin supplies conversation identity to OpenClaw’s shared message tool. Subagent completion accounting uses that identity to determine whether the requester actually delivered its result.

flowchart TD
  A[Child task finishes] --> B[Requester resumes in Discord thread]
  B --> C[Message tool sends result]
  C --> D[Discord resolves thread identity]
  D --> E[Discord transport posts message]
  E --> F[Completion checks delivery evidence]
  F --> G[Child delivery recorded]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +10, Tests +97. Total +107 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 10 0 +10
Tests 2 97 0 +97
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 107 0 +107

Review metrics

Metric Value Why it matters
Production versus regression coverage production +10, tests +97 Production growth implements one missing existing adapter hook; tests cover destination inference and composed settlement credit.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #163724
Summary: This PR targets the canonical requester-thread delivery defect; the other open PR repairs complementary receipt evidence.

Members:

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

Technical review

Best possible solution:

Keep thread identity in Discord’s existing adapter so settlement recognizes successful same-thread delivery without weakening shared destination checks.

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

Yes: current source explains the missing thread evidence, and the supplied red/green Gateway trace exercises the reported spawn, yield, message-tool send, and silent settlement flow. This reviewer did not execute a current-main reproduction.

Is this the best way to solve the issue?

Yes: implementing Discord’s existing thread resolver repairs the producer of delivery identity while preserving the shared matcher, destination, and unrelated inbound context behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1b986492be2c.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured red/green Gateway trace exercises Discord’s resolver through requester settlement and shows a real HTTP thread post followed by persisted delivered status. Additional real-client HTTP evidence covers the existing webhook-binding path. This satisfies the prior proof request under the accepted isolated channel-boundary policy; it is not a live Discord service run. No stored-data contract changes require migration proof.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The captured red/green Gateway trace exercises Discord’s resolver through requester settlement and shows a real HTTP thread post followed by persisted delivered status. Additional real-client HTTP evidence covers the existing webhook-binding path. This satisfies the prior proof request under the accepted isolated channel-boundary policy; it is not a live Discord service run. No stored-data contract changes require migration proof.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: An established Discord subagent workflow marks successfully delivered results as failed on current releases.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The captured red/green Gateway trace exercises Discord’s resolver through requester settlement and shows a real HTTP thread post followed by persisted delivered status. Additional real-client HTTP evidence covers the existing webhook-binding path. This satisfies the prior proof request under the accepted isolated channel-boundary policy; it is not a live Discord service run. No stored-data contract changes require migration proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured red/green Gateway trace exercises Discord’s resolver through requester settlement and shows a real HTTP thread post followed by persisted delivered status. Additional real-client HTTP evidence covers the existing webhook-binding path. This satisfies the prior proof request under the accepted isolated channel-boundary policy; it is not a live Discord service run. No stored-data contract changes require migration proof.

Evidence

What I checked:

  • Pinned introduced change: The merge-base-to-head patch adds the existing optional threading resolver and focused tests. The verified test-merge comparison retains precisely these changes against its main parent. (extensions/discord/src/channel.ts:672, 96806b7fe593)
  • Existing contract and narrow repair: The optional resolver already exists in ChannelThreadingAdapter. Discord returns the current thread only when the normalized destination equals that thread’s channel; parent, sibling, and user destinations do not inherit it. This implements an existing plugin contract without expanding the SDK. (src/channels/plugins/types.core.ts:409, 96806b7fe593)
  • Delivery accounting mechanism: Message-tool extraction invokes the registered threading resolver with the current thread. The shared source matcher rejects missing thread evidence; the new composed regression verifies credit for the requester thread and rejection for its parent. (src/agents/subagents/announce/subagent-announce-delivery.discord-thread.test.ts:63, 96806b7fe593)
  • Current-main and release necessity: Fetched main still lacks Discord’s resolveAutoThreadId implementation. Inspection of v2026.9.7 likewise finds the threading adapter without this hook, so neither establishes an already-landed replacement. (extensions/discord/src/channel.ts:668, 1b986492be2c)
  • Latest-release source check: The supplied latest release is v2026.9.7; its Discord channel descriptor has no resolveAutoThreadId hook. (extensions/discord/src/channel.ts:668, c074824a27c9)
  • After-fix production-boundary proof: The captured PR body, sourceRevision 1cc1e2cf43941224b48adfbe09ce449c720a4fd5701f4d29a772d63e47aa9444, describes a real QA Gateway loading the bundled Discord plugin against local REST and Gateway WS endpoints. The requester spawns, yields, sends into its thread, and ends silently. Reverting only the resolver records failed delivery; the reviewed head records exactly one settle post and persisted delivered status at 2026-10-02T21:58:31.564Z. This supplies the prior review’s requested settlement evidence under the repository’s accepted isolated channel-boundary proof policy. (96806b7fe593)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-02T20:08:38.170Z sha 96806b7 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 2, 2026
@obviyus
obviyus merged commit 782abf3 into openclaw:main Oct 3, 2026
146 of 148 checks passed
@obviyus

obviyus commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

Landed as 782abf3. Thanks @MertBasar0!

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 3, 2026
… are marked failed (openclaw#163756)

Fixes openclaw#163724.

A requester session in a Discord thread that posts a subagent result with the message tool and then replies `NO_REPLY` had the child completion marked as failed, even though the post appeared in the thread. Discord now implements `threading.resolveAutoThreadId`. It returns the current thread only when the send targets that thread's own channel, so the delivery matcher credits the post. Sends to parent or sibling channels get no thread evidence and are not credited.

Proof: a built Gateway ran the real Discord plugin against a local Discord stand-in (Crabline) with `visibleReplies=message_tool`. Base reported failed/intentional_non_delivery, and this change reports delivered. Both posted once to `channel:T`. Parent and sibling sends were not credited. Normal threaded finals and automatic mode delivered on both. When the thread has a webhook binding, the message-tool send now uses that webhook with `thread_id=T`, which matches the session's normal threaded replies; the destination is unchanged. The regression test fails on base and passes here. A live gpt-5-mini call passed.

Co-authored-by: Ayaan Zaidi <[email protected]>
yozakura-ava pushed a commit to yozakura-ava/openclaw that referenced this pull request Oct 4, 2026
… are marked failed (openclaw#163756)

Fixes openclaw#163724.

A requester session in a Discord thread that posts a subagent result with the message tool and then replies `NO_REPLY` had the child completion marked as failed, even though the post appeared in the thread. Discord now implements `threading.resolveAutoThreadId`. It returns the current thread only when the send targets that thread's own channel, so the delivery matcher credits the post. Sends to parent or sibling channels get no thread evidence and are not credited.

Proof: a built Gateway ran the real Discord plugin against a local Discord stand-in (Crabline) with `visibleReplies=message_tool`. Base reported failed/intentional_non_delivery, and this change reports delivered. Both posted once to `channel:T`. Parent and sibling sends were not credited. Normal threaded finals and automatic mode delivered on both. When the thread has a webhook binding, the message-tool send now uses that webhook with `thread_id=T`, which matches the session's normal threaded replies; the destination is unchanged. The regression test fails on base and passes here. A live gpt-5-mini call passed.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 782abf3)
Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: discord Channel integration: discord P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

2 participants