Skip to content

improve(matrix): avoid duplicate outbound body projection - #128392

Merged
steipete merged 1 commit into
mainfrom
codex/perf-matrix-prepared-body-current
Aug 23, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-matrix-prepared-body-current

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users sending an ordinary single-event Matrix message would pay for the same Markdown-to-Matrix body projection twice before provider delivery. Rich Markdown made this duplicate CPU work measurable on the outbound hot path.

Why This Change Was Made

Matrix text preparation now carries its already-rendered body to formatting when the exact converted text is sent as one event. Multichunk messages retain the existing per-chunk projection path, and provider payload, routing, retry, storage, and public contracts are unchanged.

User Impact

Single-event Matrix text, captions, voice followups, single-message sends, and edits avoid one redundant body render. A controlled rich-Markdown benchmark measured a 33.2% reduction in preparation time for the affected path.

Evidence

  • Exact pre-fix regression: focused test failed because one outbound event projected the body twice; candidate passes with one projection.
  • Focused Matrix owner/sibling set: 9 files, 212 tests passed.
  • Full Matrix extension: 32 files, 537 tests passed across 4 shards.
  • Provider-boundary semantic differential: 9 representative cases / 13 SDK events byte-identical after normalizing only sentAt.
  • node scripts/check-changed.mjs --timed -- ...: passed (extensions, extensionTests), including production/test typechecks, formatting, type-aware Oxlint (0 findings), dead-code, boundary, guard, and cycle checks.
  • git diff --check: passed.
  • Structured autoreview: TruffleHog clean; Codex gpt-5.6-sol / high clean, patch correct at 0.99 confidence.

@clawsweeper

clawsweeper Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added channel: matrix Channel integration: matrix size: S labels Aug 23, 2026
@steipete
steipete marked this pull request as ready for review August 23, 2026 22:19
@openclaw-barnacle openclaw-barnacle Bot added the maintainer Maintainer-authored PR label Aug 23, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 23, 2026
@clawsweeper

clawsweeper Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 23, 2026, 6:26 PM ET / 22:26 UTC.

ClawSweeper review

What this changes

The PR carries the Matrix plain-text body rendered during preparation into single-event formatting so it is not projected twice before delivery.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

No blocking correctness or security findings. Current main still performs the duplicate body projection, while this maintainer-labeled PR removes it without changing the HTML, mention, routing, or multi-chunk paths; wait for exact-head CI before merge handling.

Priority: P3
Reviewed head: 4e36fe8c9c23dcbeb04a7da7bfc3f5f937b2defa

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-boundary optimization with a credible regression guard and no identified behavior regression.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository state identifies the author as a MEMBER, so the external-contributor real-behavior-proof gate does not apply; the PR body also records focused Matrix and payload-differential evidence.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository state identifies the author as a MEMBER, so the external-contributor real-behavior-proof gate does not apply; the PR body also records focused Matrix and payload-differential evidence.
Evidence reviewed 6 items Current main still duplicates the projection: Preparation renders the converted text to measure event size, then formatting renders the same markdown again for the outbound body; the normal send path connects those stages.
Patch retains the multi-event boundary: The branch reuses the rendered body only when the text fits one event and the outgoing markdown exactly equals the converted text; chunked events continue through the existing formatter path.
Formatting semantics remain owned by the formatter: Only the plain body accepts an optional prepared value; the existing HTML and mention-resolution calls still receive the original markdown and client.
Findings None None.
Security None None.

Live Verification

Command: pnpm openclaw -- --help

Result: FAIL (partial) — step 2 expect_output Usage:: expected terminal output was not visible within 30 seconds: "Usage:"

pnpm openclaw -- --help
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128392-wynxJF/target$ pnpm openclaw -- --help
$ node scripts/run-node.mjs -- --help
pnpm openclaw -- --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 105.51 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.7s
node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

[tsdown-build] invocation 2/2 finished in 14.6s
[plugin-control-plane-loads] verified 35 built modules with native require and checked doctor closures
runtime-postbuild: 11 phases completed in 4262ms (slowest: built plugin control-plane loads 3537ms)
 •●●:.        .:●●•
:●●●●:        :●●●●:
.●●●●:.:•●●•:.:●●●●.
 .●●●: •●●●●• :●●●.    █▀▀▀█ █▀▀▀█ █▀▀▀▀ █▄  █ █▀▀▀▀ █     █▀▀▀█ █   █
 ..:••●●●●●●●●••:..    █   █ █▀▀▀▀ █▀▀▀  █ ▀▄█ █     █     █▀▀▀█ █▄▀▄█
.::••••●●●●●●••••::.   ▀▀▀▀▀ ▀     ▀▀▀▀▀ ▀   ▀ ▀▀▀▀▀ ▀▀▀▀▀ ▀   ▀ ▀   ▀
 . .:  •●●●●•  :. .
    .  :●●●●:  .
      .●●●●●●.
       :••••:

┌  Hi — I'm OpenClaw. I keep this system running. Let's get you set up.
│
◇  Setup choices ───────────────────────────────────────────
… output truncated …

Assertions:

  • FAIL expect_output: Usage:

How this fits together

Matrix outbound delivery turns agent text into one or more Matrix events, formats each event’s plain and HTML bodies, then sends it through the Matrix client. The change reuses a preparation result only when the exact prepared text becomes one event.

flowchart LR
  A[Outgoing text] --> B[Matrix text preparation]
  B --> C{Single event?}
  C -->|Yes| D[Reuse prepared plain body]
  C -->|No| E[Render each chunk]
  D --> F[Format HTML and mentions]
  E --> F
  F --> G[Matrix client delivery]
Loading

Before merge

  • Resolve merge risk (P1) - Exact-head CI is not complete: the provided check state still has an extension-boundary job in progress, so merge handling should wait for its result.
Agent review details

Security

None.

PR surface

Source +11, Tests +62. Total +73 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 18 7 +11
Tests 1 62 0 +62
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 80 7 +73

Review metrics

Metric Value Why it matters
Production vs test LOC production +18/-7 (net +11), tests +62/-0 The small production increase carries an already-computed body through existing formatting call sites; the added focused test protects the performance invariant.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the prepared plain body as a preparation-owned fact, reuse it only for the exact single-event text, and merge after exact-head CI completes.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the prepared plain body as a preparation-owned fact, reuse it only for the exact single-event text, and merge after exact-head CI completes.

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

Yes—source inspection shows the single-event body is rendered once for size calculation and again during formatting on current main; execution was not performed in this read-only review.

Is this the best way to solve the issue?

Yes—the preparation owner already computes the required body for its size invariant, and the strict single-event equality guard preserves the existing per-chunk formatter behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 6669872a95f8.

Labels

Label changes:

  • add P3: This is a narrow Matrix outbound performance improvement with no reported delivery or compatibility regression.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository state identifies the author as a MEMBER, so the external-contributor real-behavior-proof gate does not apply; the PR body also records focused Matrix and payload-differential evidence.

Label justifications:

  • P3: This is a narrow Matrix outbound performance improvement with no reported delivery or compatibility regression.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository state identifies the author as a MEMBER, so the external-contributor real-behavior-proof gate does not apply; the PR body also records focused Matrix and payload-differential evidence.

Evidence

What I checked:

Likely related people:

  • steipete: Current preparation, formatting, and send-path lines blame to the recent outbound-preparation commit, and feature history shows sustained work on the Matrix send surface. (role: recent Matrix outbound-path contributor; confidence: high; commits: 000aea1d7a3c, 21103ff8e91c, 25149801189f; files: extensions/matrix/src/matrix/send.ts, extensions/matrix/src/matrix/send/chunking.ts, extensions/matrix/src/matrix/send/formatting.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.

Copy link
Copy Markdown
Contributor Author

Land-ready disposition for reviewed head 4e36fe8c9c23dcbeb04a7da7bfc3f5f937b2defa:

  • ClawSweeper reported no correctness or security finding and judged the preparation-owned fact reuse the best solution. No rank-up moves were listed.
  • The sole Before merge item is resolved: exact-head CI run 32670237382 completed green, and native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 128392 passed using the hosted exact-head gates.
  • ClawSweeper's generic pnpm openclaw -- --help live smoke did not reach Usage: within 30 seconds because the clean checkout first built the repository and then entered onboarding. That partial result has no Matrix touched-file overlap and is not treated as changed-surface proof. The explicit remaining proof gap is no authenticated Matrix provider mutation; this behavior-neutral CPU optimization instead has byte-identical SDK payload captures and full Matrix coverage.
  • Production LOC is +18/-7 (net +11); tests are +62/-0. The positive production delta is the smallest private fact-carrying change across the existing preparation/formatting boundary. It adds no cache, public/config/protocol/security/storage surface, compatibility path, or alternate projection owner.
  • Exact pre-fix regression: one SDK-bound event projected its plain body twice; candidate focused regression passes with one projection. Focused owner/sibling proof passed 9 files / 212 tests; full Matrix passed 32 files / 537 tests across four shards.
  • node scripts/check-changed.mjs --timed -- ... passed the extensions, extensionTests lanes, including production/test typechecks, formatting, type-aware Oxlint (0 findings), dead-code, boundaries, guards, and import cycles. TruffleHog plus Codex gpt-5.6-sol/high autoreview was clean (patch is correct, 0.99).
  • Current-main drift through 6669872a95f has no touched-file overlap. Codex hard-gate sources were inspected directly at app-server-protocol/src/protocol/v2/turn.rs:71-158, core/src/session/turn.rs:153-238, and core/src/codex_thread.rs:190-205; they do not alter this Matrix-owned contract.

Recommendation remains READY FOR /prepare-pr with no unresolved before-merge item.

@steipete
steipete merged commit ca0af9c into main Aug 23, 2026
185 checks passed
@steipete
steipete deleted the codex/perf-matrix-prepared-body-current branch August 23, 2026 22:41

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: matrix Channel integration: matrix maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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