Skip to content

fix(discord): preserve authored block order in presentation components - #119506

Merged
vincentkoc merged 1 commit into
openclaw:mainfrom
wanyongstar:fix/discord-presentation-block-order
Aug 5, 2026
Merged

vincentkoc merged 1 commit into
openclaw:mainfrom
wanyongstar:fix/discord-presentation-block-order

Conversation

@wanyongstar

@wanyongstar wanyongstar commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

fix(discord): preserve authored block order in presentation components instead of sinking buttons below all text

What Problem This Solves

buildDiscordPresentationComponents (extensions/discord/src/shared-interactive.ts) turns an agent's authored MessagePresentation — an ordered list of text, context, divider, button, and select blocks — into Discord Components V2 layout. The Discord V2 protocol allows text, separators, and action rows to interleave arbitrarily, so the authored order is the message layout.

The builder however runs two passes: it first collects every text/context/divider block (in order), then appends every buttons/select block. A presentation authored as [text "构建结果", buttons […], text "3 个测试被跳过"] renders as [text 构建结果, text 3 个测试被跳过, actions] — the trailing note jumps above the buttons and the buttons sink below all text. Selects written before buttons get moved after them too. Users see a scrambled message whose controls no longer sit where the author placed them.

代码证据: in extensions/discord/src/shared-interactive.ts (main), buildDiscordPresentationComponents (:207-241) iterates presentation.blocks twice — the first for loop (:217) emits only text/context/divider, the second (:235) appends buttons/select — so output order can never interleave. Meanwhile the @deprecated sibling buildDiscordInteractiveComponents (:183-205) renders the same block kinds in a single order-preserving pass, and its test preserves authored shared text blocks around controls (shared-interactive.test.ts:57) pins interleaving as the intended contract. The outbound path (outbound-components.ts:135) sends the spec verbatim as a V2 layout, so the reordering is user-visible.

Root Cause

  • Bug introduced by commit fd0970c077377a30847efb3d118bac7dd093891b on 2026-04-21, which introduced the order-breaking split between prose and controls. Commit b78c2ee8c850 only made the second pass explicit while carrying the existing ordering bug forward.
  • Violated invariant: "presentation block order is the message layout." The two-pass implementation silently reinterprets the block list as "all prose first, all controls last" — an ordering rule that exists nowhere in the Discord V2 protocol or in the deprecated renderer it replaced.
  • Trigger condition: any presentation that places a text/context/divider block after a buttons or select block — e.g. a result summary followed by action buttons followed by a footnote.

Why This Change Was Made

  • Option A (chosen): merge the two passes into one order-preserving loop (title still pinned first) — restores the invariant at the single place it is violated, matches the deprecated renderer's proven semantics, and changes nothing for presentations that are already prose-then-controls.
  • Option B: document the reordering as intended — rejected: it contradicts the V2 layout model and the deprecated function's pinned contract, and gives authors no way to place controls mid-message.
  • Option C: annotate blocks with explicit positions — rejected: inventing a new ordering mechanism to work around a broken default, instead of fixing the default.

User Impact

  • Affected scenario: Discord messages built from presentations that interleave text and controls (result cards with footnotes, multi-section approval prompts, select-then-button forms).
  • Before: controls always render below all prose regardless of authored order; trailing notes and dividers float above them.
  • After: blocks render in authored order, identical to the deprecated renderer's behavior.
  • Behavior change: only presentations with text/context/divider blocks positioned after buttons/select change (they now render as authored); prose-then-controls presentations produce byte-identical output.

Evidence

Setup: the real buildDiscordPresentationComponents executed via node --import tsx with an authored [text, buttons, text] presentation; the produced layout is printed and checked against the authored order. No mocks anywhere.

Before (on main)

$ node --import tsx proof-discord-order.mjs   # main version
[proof] authored order: [text(Build finished), actions, text(3 tests were skipped)]
[proof] produced layout: ["text(\"Build finished\")","text(\"3 tests were skipped\")","actions"]
[proof] RESULT: FAIL - authored order broken: buttons moved to the end, trailing note jumped above them (actions at index 2)
exit=1

After (with fix)

$ node --import tsx proof-discord-order.mjs   # with fix
[proof] authored order: [text(Build finished), actions, text(3 tests were skipped)]
[proof] produced layout: ["text(\"Build finished\")","actions","text(\"3 tests were skipped\")"]
[proof] RESULT: PASS - authored order preserved; trailing note stays after the buttons
exit=0

Tests and Validation

  • node node_modules/vitest/vitest.mjs run extensions/discord/src/shared-interactive.test.ts — 21 passed (20 existing + 1 new: preserves authored block order around controls for the presentation builder)
  • Red-green check: with the source change stashed, the new test fails; with the fix, the full file passes.
  • Manual verification is the proof above (same script on main vs fixed code).

Punchcard-Session: clear-orchard-lantern-bc

buildDiscordPresentationComponents rendered presentations in two
passes - all text/context/divider blocks first, then every
buttons/select block - so any block authored after a control was moved
above it and controls always sank below all prose. Discord Components
V2 layouts interleave freely and the deprecated single-pass renderer
pins interleaving as the contract, so merge the passes into one
order-preserving loop (title still pinned first).
@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 5, 2026
@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. P2 Normal backlog priority with limited blast radius. labels Aug 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 5, 2026, 2:04 AM ET / 06:04 UTC.

ClawSweeper review

What this changes

The PR merges Discord’s two presentation-rendering passes so text, context, dividers, buttons, and selects are emitted in their authored order.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: this is a narrow, correct Discord renderer repair. Current main still separates prose blocks from controls, while the PR restores the portable presentation contract’s authored order without changing action encoding or limits.

Priority: P2
Reviewed head: 0cf9335e84b5d143f02ee8d7abbe49a5574a1cca

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-backed repair with direct regression coverage and credible real-function before/after proof.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR body includes a before/after terminal transcript from the actual presentation builder, and its reported output matches the inspected current-main and PR-head logic.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body includes a before/after terminal transcript from the actual presentation builder, and its reported output matches the inspected current-main and PR-head logic.
Evidence reviewed 4 items Current-main defect: Current main still renders prose/context/divider blocks in one loop and buttons/selects in a second loop, so an authored text-control-text sequence cannot remain ordered.
Portable contract and delivery path: MessagePresentation defines blocks as ordered, and Discord’s outbound adapter passes the generated specification to the component builder, which appends blocks to its container in sequence.
Exact-head regression coverage: The PR adds a focused presentation-builder assertion for text, buttons, then text, matching the reported user-visible ordering failure.
Findings None None.
Security None None.

How this fits together

OpenClaw passes ordered portable presentation blocks to the Discord plugin, which converts them into Components V2 blocks for outbound delivery. The generated specification is then serialized into Discord’s ordered container layout.

flowchart LR
  A[Portable presentation blocks] --> B[Discord presentation renderer]
  B --> C[Ordered component specification]
  C --> D[Discord V2 container]
  D --> E[Outbound Discord message]
Loading

Before merge

  • Resolve merge risk (P1) - The branch is behind current main, so required checks should cover the final merge candidate before landing.
  • Complete next step (P2) - No repair lane is needed because the submitted patch already fixes the confirmed owner-boundary defect; normal exact-head merge gates remain.
Agent review details

Security

None.

PR surface

Source -2, Tests +24. Total +22 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 0 2 -2
Tests 1 24 0 +24
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 24 2 +22

Review metrics

Metric Value Why it matters
Production versus regression coverage production -2, tests +24 The patch removes the duplicate traversal and adds one direct regression assertion for the restored ordering contract.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the one-pass renderer after the final merge candidate has current exact-head CI coverage.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the one-pass renderer after the final merge candidate has current exact-head CI coverage.

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

Yes. Current main’s two loops deterministically reorder an authored text-control-text presentation, and the PR’s focused regression case exercises that path.

Is this the best way to solve the issue?

Yes. Repairing the Discord presentation renderer is the narrow owner-boundary fix; changing producers or introducing explicit position metadata would contradict the existing ordered-block contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 20bd49db8950.

Labels

Label changes:

  • add P2: This is a confirmed Discord layout regression with a bounded channel-specific user impact.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes a before/after terminal transcript from the actual presentation builder, and its reported output matches the inspected current-main and PR-head logic.
  • 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 (terminal): The PR body includes a before/after terminal transcript from the actual presentation builder, and its reported output matches the inspected current-main and PR-head logic.

Label justifications:

  • P2: This is a confirmed Discord layout regression with a bounded channel-specific user impact.
  • 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 (terminal): The PR body includes a before/after terminal transcript from the actual presentation builder, and its reported output matches the inspected current-main and PR-head logic.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes a before/after terminal transcript from the actual presentation builder, and its reported output matches the inspected current-main and PR-head logic.

Evidence

What I checked:

Likely related people:

  • steipete: Peter Steinberger authored the recent Discord interactive-response consolidation and the earlier presentation-rendering commit identified by local history. (role: recent area contributor; confidence: high; commits: 9214e6381d49, b78c2ee8c850; files: extensions/discord/src/shared-interactive.ts, extensions/discord/src/outbound-components.ts)

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.

@vincentkoc vincentkoc self-assigned this Aug 5, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(discord): preserve authored block order in presentation components This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@vincentkoc
vincentkoc merged commit 57a237a into openclaw:main Aug 5, 2026
132 of 143 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 5, 2026
Punchcard-Session: frost-brook-timber-mx

* origin/main:
  fix: cap local tsgo CPU usage (#119517)
  fix(tool-search): normalize dotted call arguments (#119418) (#119464)
  fix(qa): retain child output on CLI timeouts (#119524)
  fix(discord): preserve authored block order in presentation components (#119506)
  fix: make plugin verification restart guidance install-neutral (#119508)
  fix(qa): preserve profile execution contracts (#119519)
  test(qa): cover managed OTEL runtime paths (#118965)

Punchcard-Session: frost-brook-timber-mx
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 6, 2026
openclaw#119506)

buildDiscordPresentationComponents rendered presentations in two
passes - all text/context/divider blocks first, then every
buttons/select block - so any block authored after a control was moved
above it and controls always sank below all prose. Discord Components
V2 layouts interleave freely and the deprecated single-pass renderer
pins interleaving as the contract, so merge the passes into one
order-preserving loop (title still pinned first).
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 6, 2026
Punchcard-Session: frost-brook-timber-mx

* origin/main:
  fix: cap local tsgo CPU usage (openclaw#119517)
  fix(tool-search): normalize dotted call arguments (openclaw#119418) (openclaw#119464)
  fix(qa): retain child output on CLI timeouts (openclaw#119524)
  fix(discord): preserve authored block order in presentation components (openclaw#119506)
  fix: make plugin verification restart guidance install-neutral (openclaw#119508)
  fix(qa): preserve profile execution contracts (openclaw#119519)
  test(qa): cover managed OTEL runtime paths (openclaw#118965)

Punchcard-Session: frost-brook-timber-mx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants