Repository navigation
fix(discord): keep code fences intact when rebalancing reasoning italics - #103166
Conversation
|
@clawsweeper review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Codex review: needs maintainer review before merge. Reviewed July 18, 2026, 11:57 PM ET / July 19, 2026, 03:57 UTC. Summary PR surface: Source +89, Tests +98. Total +187 across 2 files. Reproducibility: unclear. for an independently repeated current-main live Discord run; the source-level production helper path and reported base-versus-head regression test provide a concrete, medium-confidence reproduction boundary. Review metrics: none identified. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Merge the bounded fix after a maintainer confirms the final merge result preserves the exact code-leading continuation fixtures and ordinary non-code italic continuation behavior. Do we have a high-confidence way to reproduce the issue? Unclear for an independently repeated current-main live Discord run; the source-level production helper path and reported base-versus-head regression test provide a concrete, medium-confidence reproduction boundary. Is this the best way to solve the issue? Yes, provisionally: reusing the chunker fence grammar and inserting any italic reopen after a leading code span is narrower and more maintainable than special-casing individual delimiter forms. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against cc57514e680d. Label changesLabel justifications:
Evidence reviewedPR surface: Source +89, Tests +98. Total +187 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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
Review history (6 earlier review cycles)
|
|
Addressed ClawSweeper P2 on incomplete balancing:
Head: @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
Re-review request (current head)Head: Previous ClawSweeper P2 is addressed:
Local gates: focused vitest PASS, @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Re-review: full fence grammar alignmentHead: Addressed ClawSweeper P2 (Reuse the chunker’s full fence grammar):
Local: 24/24 vitest, @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
1d5120c to
15baa02
Compare
|
@clawsweeper re-review Refreshed this branch onto current main via merge (non-force push) after all conflicts were resolved.
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review Refreshed exact-head proof for Also fixed Discord package typecheck / knip CI on this surface: restored |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Co-authored-by: wuqingxuan <[email protected]>
529b4bc to
5b0cfcb
Compare
|
Merged via squash.
|
…etwork-none * origin/main: (74 commits) fix(ui): make Control UI ownership and permissions reliable (#115364) feat(system-agent): host memory import in Ask OpenClaw (#115376) fix(chat): preserve literal Markdown image examples (#113904) refactor(chat): keep web and terminal sessions synchronized (#115377) fix(ui): order model picker by provider strength (#115380) feat(ui): make Memory settings a destination page with live overview and dreams (#115383) docs(security): fix warning line wrap (#115388) fix(memory-core): avoid cubic MMR similarity rescans (#113359) fix(discord): preserve code-leading reasoning chunks (#103166) fix(slack): protect outbound hooks from previews fix(ui): keep explicit navigation ahead of chat canonicalization (#115366) fix(exec): safely cancel pending node approvals (#115373) fix: make Code Mode reliable across gateway and provider lifecycles (#115379) perf(ui): debounce event-driven session list refreshes and right-size child paging (#115374) feat(talk): support GPT-Live realtime voice over ChatGPT OAuth (#115226) feat(system-agent): guide gateway configuration in Ask OpenClaw (#115363) fix(agents): make overflow recovery append-only via branch-and-reappend (#115271) (#115310) fix(macos): bound websocket ping so a dropped pong cannot orphan its continuation (#115362) fix(codex): isolate native hook relay startup (#115078) fix(ci): stop reviving superseded pull request workflows (#115378) ... # Conflicts: # CHANGELOG.md
Co-authored-by: Peter Steinberger <[email protected]>
Closes #102911
What Problem This Solves
Fixes an issue where Discord reasoning messages that wrap content in
_…_would corrupt markdown code fences and inline code when the message was split across chunks. After a chunk boundary that started with a code delimiter, the italics rebalancer could prepend_(breaking_```python/_~~~/_code``) or leave unmatched trailing_on continuation chunks.Why This Change Was Made
rebalanceReasoningItalicsstill closes/reopens reasoning italics so each Discord message stays independently balanced. When the next chunk starts with a code delimiter:_onto the code opener._on pure-code continuations._when the chunk actually opened reasoning italics.The leading code-span scanner reuses the chunker’s fence grammar (
FENCE_RE/parseFenceLine):```/~~~)Also restores main’s strict-index guards (
expectDefined,charAt) so the Discord package typecheck and knip production export scan stay green after the main refresh, and keepschunkDiscordTextunexported (tests usechunkDiscordTextWithMode).Regression tests assert exact second-chunk output and even
_counts for backtick, tilde, indented, longer-close, inline, and pure-code cases.User Impact
Discord reasoning/thinking replies that contain code blocks or inline code no longer break markdown fences at chunk boundaries, including tilde and indented fences, and each chunk keeps balanced reasoning italics when text continues after code.
Evidence
Focused tests (exact head
529b4bc3006)Production-path harness at exact head
529b4bc3006API:
chunkDiscordTextWithMode({ chunkMode: "length" })→rebalanceReasoningItalicsOpts:
{ maxLines: 10, maxChars: 2000 }Exact second chunks:
All cases: 2 chunks; every chunk has an even
_count; no second chunk starts with_``` /_~~~ / _``.CI surface fixes on this head
noUncheckedIndexedAccess:window.charAt(i),expectDefinedfor segment/chunk indexes (aligned with main)chunkDiscordText(production callers already usechunkDiscordTextWithMode)Real behavior proof
_balance.chunkDiscordTextWithMode→ internal length chunker →rebalanceReasoningItalics. Verification host: local macOS.529b4bc3006f4d22f4dd76589f45933ac0768d0fnode --import tsxharness for tilde, indented, longer-close, pure fence, inline, and normal-text fixturesnode scripts/run-vitest.mjs extensions/discord/src/chunk.test.ts(24/24)529b4bc3006; all even_parity._on non-code continuations ("_10. line\n11. line\n12. line_").AI disclosure
This fix was authored with AI assistance (Grok). Implementation, tests, and proof were verified against ClawSweeper review findings on #103166 (exact-head runtime proof; typecheck/knip CI on the Discord chunk surface).