Skip to content

fix(discord): send fresh final messages after previews - #99711

Merged
steipete merged 4 commits into
openclaw:mainfrom
davelutztx:fix-discord-final-new-message
Jul 6, 2026
Merged

steipete merged 4 commits into
openclaw:mainfrom
davelutztx:fix-discord-final-new-message

Conversation

@davelutztx

@davelutztx davelutztx commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Discord partial streaming finalized an answer by editing the existing preview message. If the user left the channel during a long turn, that MESSAGE_UPDATE did not reliably advance Discord's unread/channel highlight, so a completed answer could arrive unnoticed.

Fixes #99662.

Why This Change Was Made

The durable final now uses the normal send path, producing a fresh message after preview cleanup. This matches Discord's separate Create Message and Gateway message event contracts and removes the second in-place finalization path.

Fresh bot messages normally parse broadcast mentions, unlike the old edit path. The maintained version therefore carries an explicit allowed_mentions policy through text, media, chunked, and forum delivery: targeted user and role pings remain enabled, while @everyone and @here cannot escalate.

User Impact

  • Completed streamed Discord answers arrive as a new message and can restore the normal unread/channel cue.
  • The preview is cleared only after the fresh final succeeds; a failed send retains the visible preview.
  • Targeted user/role mentions continue to work without enabling broadcast pings.
  • Media, TTS, error, chunking, reply, forum, and progress-summary routes keep their existing delivery behavior.

Evidence

  • Exact prepared head: 0041b7ffa47e128242fc2f3bc2a55b4eb30985b1.
  • Hosted exact-head CI: run 28811114011, including production/test typechecks, lint, build, guards, QA smoke, and relevant compact shards.
  • Blacksmith Testbox tbx_01kww6wp8mafqazb1d425qyf36: 183 focused Discord tests passed; pnpm check:changed passed extension production/test typechecks, full extension lint, and repository guards.
  • Sanitized AWS Crabbox run_ade515667559: the exact pushed fork head passed the same 183 focused tests with public networking, no Tailscale, no instance role, and no hydrated credentials.
  • Live Discord sandbox on the exact pushed head: preview and final had distinct increasing message IDs; both messages were readable; literal @everyone produced mention_everyone=false; both test messages deleted successfully with HTTP 204.
  • Fresh autoreview after the runtime-enum repair: no accepted/actionable findings, confidence 0.96.

Implementation Notes

  • Declares Discord in-place finalEdit support disabled while retaining normal fallback and preview cleanup.
  • Deletes the duplicate final-edit/chunking branches and delegates lifecycle ordering to the shared finalizable-preview helper.
  • Adds focused regression coverage for fresh finals, mention safety, TTS/media/error fallback, and failed-send preview retention.

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 3, 2026
@clawsweeper

clawsweeper Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 3, 2026, 8:03 PM ET / 00:03 UTC.

Summary
The branch disables Discord live-preview final edits so partial-stream finals fall back to fresh final delivery, with Discord adapter and handler tests updated for that behavior.

PR surface: Source -72, Tests -7. Total -79 across 4 files.

Reproducibility: yes. for a source-level reproduction: current main can finalize ordinary Discord partial-preview finals by editing the preview message, and the linked issue supplies observed Discord created/edited timestamps for the missed highlight path. I did not run a live Discord client reproduction in this read-only review.

Review metrics: 1 noteworthy metric.

  • Broadcast finalization controls: 2 expectations changed from edit-path controls to fresh-send expectations. The PR changes the @everyone and targeted-plus-@everyone cases that previously protected Discord broadcast mention behavior.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #99662
Summary: This PR is the candidate fix for the linked Discord unread/highlight issue; related Discord finalization and notification reports overlap but do not replace the open bug.

Members:

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

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🧂 unranked krab
Result: blocked until real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Preserve fresh final delivery for ordinary partial-stream finals while keeping @everyone/@here suppressed or on the safe edit path.
  • [P1] Add focused tests that prove broadcast and mixed targeted-plus-broadcast finals cannot create an unsuppressed broadcast ping.
  • [P1] Add redacted real Discord proof that the source channel becomes unread/highlighted after switching away during a long partial-stream turn.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body lists tests only; it needs redacted Discord screenshots, recording, terminal/live output, or logs showing the after-fix unread/highlight behavior before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Mantis proof suggestion
A real Discord UI proof would materially show whether a fresh final message restores the unread/channel highlight behavior after the user switches away. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis visual task: verify in Discord that a long partial-streamed turn sends a fresh final message and the source channel becomes unread/highlighted after switching away.

Risk before merge

  • [P1] Broadcast-containing partial-stream finals can change from safe preview edits into fresh Discord sends without the explicit allowed_mentions suppression used by preview messages.
  • [P1] The PR body lists test commands only, so it still does not prove in a real Discord client that the source channel becomes unread/highlighted after a long partial-stream turn finishes.

Maintainer options:

  1. Preserve broadcast safety before merge (recommended)
    Change the fallback decision so @everyone/@here finals either stay on the edit path or are fresh-sent with explicit allowed_mentions suppression while ordinary finals still create a completion message.
  2. Accept broadcast create behavior
    Maintainers can intentionally accept fresh sends for broadcast-containing finals, but that should be an explicit Discord-channel policy decision before merge.
  3. Pause for live Discord proof
    Hold the PR until a redacted Discord run shows the unread/highlight fix and the broadcast safety behavior in a real guild channel.

Next step before merge

  • [P1] Needs contributor or maintainer action: the code must restore broadcast mention safety and the external PR still needs real Discord proof, so this is not a safe automated repair lane.

Security
Needs attention: The diff removes the current broadcast mention safety guard, so model-generated @everyone/@here text can be routed through a fresh Discord send without explicit mention suppression.

Review findings

  • [P1] Preserve broadcast mention suppression for fresh finals — extensions/discord/src/monitor/message-handler.process.ts:891-892
Review details

Best possible solution:

Repair the PR so ordinary partial-stream finals are fresh messages, @everyone/@here remains suppressed or stays on the safe edit path, and the author adds redacted real Discord proof before merge.

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

Yes for a source-level reproduction: current main can finalize ordinary Discord partial-preview finals by editing the preview message, and the linked issue supplies observed Discord created/edited timestamps for the missed highlight path. I did not run a live Discord client reproduction in this read-only review.

Is this the best way to solve the issue?

No. Fresh final delivery is a plausible fix for the unread/highlight bug, but this implementation is too broad because it removes the existing @everyone/@here safety distinction without adding explicit mention suppression.

Full review comments:

  • [P1] Preserve broadcast mention suppression for fresh finals — extensions/discord/src/monitor/message-handler.process.ts:891-892
    Returning undefined here sends every partial-stream final through normal fresh delivery, including text with @everyone or @here. The preview path explicitly suppresses mentions, while the normal Discord message request has no allowed_mentions override, so this can turn a completion update into a broadcast ping; keep those finals on the safe path or add explicit suppression before fresh-send fallback.
    Confidence: 0.93

Overall correctness: patch is incorrect
Overall confidence: 0.93

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 8fe917b4f778.

Label changes

Label justifications:

  • P2: This is a Discord channel bug-fix PR with limited blast radius, but it has a blocking delivery-safety defect before merge.
  • merge-risk: 🚨 message-delivery: The diff can turn broadcast-containing partial finals into fresh Discord messages, changing who receives completion notifications.
  • merge-risk: 🚨 security-boundary: The patch removes an existing guard that prevented model-generated @everyone/@here text from taking the normal fresh-send path without explicit mention suppression.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body lists tests only; it needs redacted Discord screenshots, recording, terminal/live output, or logs showing the after-fix unread/highlight behavior before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source -72, Tests -7. Total -79 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 5 77 -72
Tests 2 46 53 -7
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 51 130 -79

Security concerns:

  • [high] Fresh finals can parse broadcast mentions — extensions/discord/src/monitor/message-handler.process.ts:891
    The patched buildFinalEdit always falls back to normal delivery, while the normal fresh Discord request path has no allowed_mentions override; broadcast-containing final text can therefore take a path the existing preview safety guard avoided.
    Confidence: 0.9

What I checked:

Likely related people:

  • openperf: Authored the merged Discord live-preview mention fallback in fix(discord): ping mention-bearing final replies under live preview (#88360) #88527, including the broadcast and mixed-mention safety boundary this PR changes. (role: introduced behavior; confidence: high; commits: fb246b35887d, a5d8f09fd496; files: extensions/discord/src/monitor/message-handler.process.ts, extensions/discord/src/mentions.ts, extensions/discord/src/monitor/message-handler.process.test.ts)
  • steipete: Provided pre-merge proof and review context for the prior Discord mention finalization PR and appears in recent Discord channel history. (role: reviewer and recent area contributor; confidence: medium; commits: 23716de4468b, 304e2c83c01f, 1507a9701b83; files: extensions/discord/src/channel.ts, extensions/discord/src/monitor/message-handler.process.ts, src/channels/message/live.ts)
  • Peetiegonzalez: Recent merged Discord progress and reasoning work in fix(anthropic): surface reasoning and pre-tool commentary on Discord #96106 touched the same process handler and adjacent tests. (role: recent progress-streaming contributor; confidence: medium; commits: 905fab902c24, 1641d64fb004, 9b8fe8e54d9e; files: extensions/discord/src/monitor/message-handler.process.ts, extensions/discord/src/monitor/message-handler.process.test.ts, extensions/discord/src/monitor/message-handler.draft-preview.ts)
  • compoodment: Authored the merged Discord progress-mode final-delivery fix in [codex] Fix Discord progress mode dropping final replies #83443, touching the same handler and test surface. (role: adjacent final-delivery contributor; confidence: medium; commits: 8aa3322c749d, a9407d2f65ce; files: extensions/discord/src/monitor/message-handler.process.ts, extensions/discord/src/monitor/message-handler.process.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

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.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jul 3, 2026
@steipete steipete self-assigned this Jul 6, 2026
@steipete
steipete force-pushed the fix-discord-final-new-message branch from 9efa67a to 0041b7f Compare July 6, 2026 17:38
@openclaw-barnacle openclaw-barnacle Bot added size: M and removed size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 6, 2026
@steipete
steipete force-pushed the fix-discord-final-new-message branch from 0041b7f to 695b8fc Compare July 6, 2026 18:01
@steipete

steipete commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Land-ready proof for exact head 695b8fcf19316d229d7bdda394e551511941c1b9:

  • Refactored Discord streaming finalization so a partial preview is discarded and the durable final is sent as a fresh message. Shared preview lifecycle now owns discard/fallback; duplicate edit/chunk policy was removed.
  • Threaded one dependency-typed allowed_mentions policy through text, media, chunks, and forum sends. User/role mentions remain usable while @everyone and @here stay suppressed.
  • Added deterministic regression coverage for preview/final ordering and mention policy. Focused Blacksmith Testbox: 183/183 passed (tbx_01kww6wp8mafqazb1d425qyf36). Broad pnpm check:changed passed twice.
  • Sanitized public-network AWS Crabbox run on the equivalent pre-rebase code tree: 183/183 passed (run_ade515667559), with no instance role, Tailscale, hydrated credentials, or ambient preload.
  • Live Discord sandbox proof on the equivalent pre-rebase code tree: distinct preview/final message IDs, preview created first, final created second, both observed, broadcast mention suppressed, both test messages deleted (cleanup: [204, 204]). Browser screenshot proof was unavailable because the approved Chrome extension was not connected; API/live transport proof completed.
  • Hosted exact-head CI is green: https://github.com/openclaw/openclaw/actions/runs/28812483733
  • Real behavior proof is green: https://github.com/openclaw/openclaw/actions/runs/28812481628
  • Fresh autoreview: no actionable findings, confidence 0.96.

Thanks @davelutztx for the original report and implementation direction.

@steipete
steipete merged commit 8aaf9fc into openclaw:main Jul 6, 2026
91 checks passed
@steipete

steipete commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

@davelutztx

Copy link
Copy Markdown
Contributor Author

Nice that this landed for the missed-highlight issue. One follow-up concern from the review: fresh final sends should explicitly suppress @everyone / @here via allowed_mentions, or keep broadcast-containing finals on the safe edit path.

I do not use broadcast pings myself, so this is not likely to affect my workflow directly, but it seems worth hardening so model-generated final text cannot accidentally notify a whole server.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 7, 2026
* fix(discord): send fresh final messages after previews

* fix(discord): suppress broadcast mentions on fresh finals

* docs(changelog): note Discord streamed final fix

* fix(discord): stabilize targeted mention policy

---------

Co-authored-by: Dave Lutz <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Discord channel not highlighted when partial-streamed turn finishes via edited message

3 participants