Repository navigation
fix(mattermost): use fence-aware chunker for outbound markdown - #196331
Conversation
Switch the outbound adapter from fence-blind chunkTextForOutbound to
chunkMarkdownTextWithMode("length"), matching the matrix precedent
(e138bd4). Fenced code blocks in replies >4000 chars now close and
reopen at chunk boundaries instead of arriving broken in the channel.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR uses the existing fence-aware Markdown chunker for long outbound Mattermost messages. Example: Send a 4,587-character reply containing a Python code block with 78 indented code lines.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a current Mattermost formatting bug with a focused adapter change; no actionable defects remain, and the updated CLI proof resolves the earlier proof blocker. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherCore outbound delivery passes reply text through the Mattermost adapter's chunker before the plugin's HTTP client creates Mattermost posts. flowchart LR
A[CLI or agent reply] --> B[Core outbound delivery]
B --> C[Mattermost adapter]
C --> D[Shared Markdown chunker]
D --> E[Mattermost HTTP client]
E --> F[Mattermost posts]
Technical reviewBest possible solution: Use the existing shared Markdown chunker at Mattermost's pre-send boundary while preserving sanitization, configured limits, and cold-runtime operation. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the fence-blind pre-chunking path, and the contributor supplies a matching failing baseline CLI trace and regression-test result; no target code was executed during this review. Is this the best way to solve the issue? The patch is the smallest complete repair: replace the adapter's chunker with the existing SDK owner and extend the current delivery regression table without adding production machinery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 109ad1ca331e. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -2, Tests 0. Total -2 across 2 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed November 9, 2026, 9:10 PM ET / November 10, 2026, 02:10 UTC (Revision 2). |
|
@clawsweeper re-review. |
|
🦞👀 Re-review progress:
|
|
Real Mattermost proof for Setup: Mattermost server (mattermost-preview) and both builds in Docker on Node 24.22.1. Each reply went through Every post on this PR is within 4000 chars and has balanced fences. Main is clean against this head (no merge needed). |
|
Landed in 48beb40. Thanks @SunnyShu0925. Long Mattermost replies now keep their code blocks intact. |
…law#196331) fix(mattermost): use fence-aware chunker for outbound markdown Mattermost split long replies with chunkTextForOutbound, which ignores code fences. A reply over 4000 characters whose code block crossed the split arrived with an open fence in the first post and a stray fence in the next, so code showed as plain text and lost indentation. Mattermost now uses the fence-aware splitter the plugin SDK already exports, the same change openclaw#196167 made for Matrix. Evidence: a real Mattermost server and both builds in Docker on node:24.22.1, replies sent with openclaw message send --channel mattermost through a running Gateway and read back over the REST API. For a 4531-character reply, main posted 3996 and 526 characters with the first post ending inside an open fence and 16 code lines shown as plain text. With this change the prose and the whole Python block arrive in balanced, indented posts under 4000 characters. A short reply with code, 9000 characters without code, and Chinese text with emoji across the split are identical on both. Details: openclaw#196331 (comment). Thanks @SunnyShu0925. Co-authored-by: Ayaan Zaidi <[email protected]>
|
@obviyus Thanks a lot ! |
ClawSweeper round 3 accepted the Tlon shipped-entry trace and raised no code findings, but MS Teams and Zalouser cannot receive tenant-free shipped-entry proof: the Bot Framework serviceUrl boundary only permits Microsoft HTTPS hosts (bot-framework-service-url.ts), and Zalouser sends through the Zalo user protocol with no configurable endpoint. Follow the single-channel precedent of the merged Mattermost repair (openclaw#196331) and keep this PR to the Tlon adapter, which has recorded CLI-plus-Gateway delivery proof; Teams and Zalouser remain broken on main and are filed as a follow-up. Allocation updated to the Tlon-only net test growth (+114).
What Problem This Solves
Mattermost's outbound adapter uses the fence-blind
chunkTextForOutboundchunker. When a reply exceeds 4000 characters and contains fenced code blocks, the chunker splits mid-fence — the first chunk arrives with an unclosed code block and the second starts with a stray closing fence. The channel renders broken markdown.Why This Change Was Made
The canonical fence-aware chunker
chunkMarkdownTextWithMode(text, limit, "length")already exists insrc/auto-reply/chunk.tsand is re-exported viaopenclaw/plugin-sdk/reply-chunking. Matrix adopted it in e138bd4 (#196167), which explicitly leaves Mattermost as a follow-up. This PR applies the same one-line adapter swap: close the fence at chunk end, reopen with the original info string at chunk start.Production diff: +3/−5 (import swap + chunker lambda). Test: folded a fence row into the existing
it.eachinoutbound-delivery.test.ts, net 0 lines, no allocation.User Impact
Mattermost users receiving long replies with code blocks now see properly balanced fences in every chunk. No config change required; the existing
textChunkLimit: 4000andchunkerMode: "markdown"are unchanged.Evidence
Real behavior proof — shipped CLI, main vs this head (2026-11-10). Built the worktree twice in isolation: once with
extensions/mattermost/src/channel.tsswapped to origin/main (bd63497), once restored to this PR's head (3742be4). Sent the same 4,587-character reply through the shipped commandnode openclaw.mjs message send --channel mattermost --target channel:PROOFCHAN1 --message … --jsonagainst a local loopback Mattermost-API fixture (127.0.0.1) that records everyPOST /api/v4/posts; the config setdangerouslyAllowPrivateNetwork: trueto allow the loopback transport, and a synthetic bearer token supplied the API auth the real client path requires.origin/main build → 2 posts, fence cut mid-block, markdown broken in-channel:
post 0 ends with an open block and post 1 begins mid-code with lost indentation, then closes a fence that post 1 never opened.
This PR's head → 3 posts, every post fence-balanced, all 78 indented code lines preserved:
The block closes cleanly at post 1's end and reopens in post 2 with the original
```pythoninfo string, so each post renders as valid markdown. The request log from the same run shows the full shipped send path, not an injected sender: bearer-authenticatedGET /api/v4/users/me→GET /api/v4/users/proofbot/teams→GET /api/v4/teams/…/channels/name/PROOFCHAN1(thechannel:name target resolved through the real HTTP channel-name lookup), then 2POST /api/v4/postsfor the baseline run and 3 for the fixed run.Before / after at a glance:
result_68loses indentation at the cut)pythoninfo string, closes cleanlyRegression test, RED on origin/main (bd63497) — fence row fails, base produces broken chunks:
GREEN on this head (3742be4) — all 5 tests pass, including "sends sanitized fence through the channel handler".
Sibling regression — full mattermost lane (51 files): 464/465 pass; 1 pre-existing locale failure in
setup.test.ts(Chinese prompt strings vs English expectation, unrelated to chunking).Lane:
test/vitest/vitest.extension-database-workers.config.ts(outbound-delivery is routed there viavitest.extension-database-workers-paths.mjs). Typecheck not run locally (worktree symlink boundary); expression is byte-identical to matrix's mergedchannel.tsline.