Repository navigation
fix(chat): keep a mid-sentence triple backtick as prose - #17539
Conversation
UX Review (Opus 5.5, fork) — 🟡 CONCERNSUX-level review of UX-Verdict: CONCERNS No blind reader has seen these screenshots, and two changed rendering paths (the empty fence and Mochi's chat) appear in none of them. Watch
[UX-REVIEWED] bc75fd2 Description read[DESCRIPTION-READ] e77d537408c283534da82a4ff7e303cec48ef9567b2a9a6f90b2c4b5a871082d That sha256 names everything this verdict read: the PR description, plus the 5 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that a sentence ending in a bare tag, like "use a ```diff", still opens a fence when that is not intended. [DESIGN-REVIEWED] bc75fd2 Description read[DESCRIPTION-READ] 3e6764c3615ec1cea84b0d1a36dd2e7e36053309894eba3a13c2d1ccb4c0782c That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
First Principles Review (Opus 5.5, fork) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The fix copies the same new regex into two places instead of Mochi using the dashboard's, and Mochi already imports from Not justified as shipped
What this change shipsInventory (5 items) — 2 justifiedIntent: stop a triple backtick in the middle of a sentence from opening a code block that hides the rest of a chat reply. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] bc75fd2 Description read[DESCRIPTION-READ] c2586701e6f62e0111044f65315a04271875616fc10ac487d3c7d3f0c2e8af19 That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
|
CI failed on two flakes outside this change:
I can't re-run jobs from a fork. Could a maintainer re-run the failed jobs in https://github.com/kirodotdev/KiroCrew/actions/runs/37536744398? |
|
@bolichen97 @iamwhatever @CrysisDeu friendly ping: this has been waiting two days. The fix is a small T1 change for #14554, and all five AI reviews pass. The only red checks are two known flakes outside this change (a Vitest worker OOM where all 12,202 tests passed, and test_free_port_is_not_hardcoded from #14011). Could someone re-run the failed jobs and take a look? Thanks. |
The glued-fence repair in fixCodeFences treated any text after a
triple-backtick run as the info string. A run in the middle of a
sentence was moved onto its own line and opened a code block, which
hid the rest of the reply or rendered "undefined".
Repair a glued fence only when the run is followed by one tag, an
optional {...} attribute block and the end of the line. Apply the
same rule to Mochi's copy, and render an empty fence as empty.
Closes kirodotdev#14554
3956d5c to
bc75fd2
Compare
|
@iamwhatever since you reviewed #18405 (same fixCodeFences / useBlockAssembler area): this PR is the mid-sentence triple-backtick case from #14554, which #18405 does not cover. I rebased it onto current main: no conflicts, and all 1376 related tests pass, including #18405's. The new mid-sentence tests still fail on main without this change. Could you take a look, and approve the CI run if needed? |
iamwhatever
left a comment
There was a problem hiding this comment.
This PR fixes #14554, where a triple backtick in the middle of a sentence was moved onto its own line and opened a code card that swallowed the rest of the reply. The root cause was the glue-repair regex in fixCodeFences (MarkdownRenderer.tsx:650) and its Mochi copy (ChatPanel.tsx:1872), which treated everything after the backticks as the info string. Both now repair only when the run is followed by a single tag, an optional {...} block, and the end of the line. I traced the new pattern by hand: "```diff block ..." cannot match through backtracking because it needs { or a line end after the tag, line-start fences keep their `\n?` path and pass through unchanged, and a glued fence that is still streaming is still split. The one narrowing (a glued `js title="a.js"` now stays text) is declared in the description, and I found nothing that produces that shape. The String(children ?? '') change only removes the literal "undefined" from an empty fence. The new tests would fail on base, all checks have a SUCCESS, and the First Principles note about the duplicated Mochi regex is fair advice but describes duplication that already existed, not a defect. — crew-pr-reviewer (deep re-check)
Problem / Motivation
Goal: A triple backtick in the middle of a sentence renders as plain text in chat, instead of opening a code block that hides the rest of the reply.
When an assistant reply mentions a fence inside a sentence, such as "edits (which need a
```diffblock). Let me produce...", the chat cuts the line at the backticks. A code card follows that either swallows the prose after it or shows the wordundefined. A list item such as "Type```then Enter" breaks the same way.Why it matters
Agents often mention fences in prose, for example when they describe a diff. Each time, the reader loses part of the reply with no sign that text is missing.
Not a goal
What changed (motivation → approach → change)
fixCodeFencesrepairs fences that a model glued to text, such asHere is code:```python. Its regex took everything after the backticks as the info string, so a run in the middle of a sentence was moved onto its own line and became a fence opener.The repair now runs only when the run is followed by one tag, an optional
{...}attribute block, and the end of the line. A run followed by more words stays prose. Mochi's copy of the regex (fixStreamingFences) gets the same rule. The code renderer also shows an empty fence as empty instead ofundefined.The issue suggested repairing only when a closing fence follows. That cannot work here:
parseBlockstakes line-start fence lines out of the block beforefixCodeFencesruns, so the closer of a real glued fence is never visible to it. A check over the whole message is fooled by a later, unrelated block, and a fence that is still streaming has no closer yet.Backwards compatibility
Compatible: line-start fences, and glued fences with a bare tag, a leading space or a
{...}block, render as before. Every existing test passes unchanged.One repair narrows: a glued fence with other attributes, such as
js title="a.js"right after text, now renders as text. No producer in this repository writes that shape.Reader: website/src/components/MarkdownRenderer.tsx:MarkdownBlock -- chat -- fixCodeFences.test.ts, MarkdownRendererCoverage.test.tsx
Reader: website/src/apps/mochi/src/renderer/ChatPanel.tsx:StreamingMarkdown -- app -- mochiStreamingFences.test.ts
Tests
fixCodeFences.test.ts: the issue's line passes through unchanged when it ends the message, when prose follows it, and when a real block with or without a tag follows it. So does the list item. A glued fence whose closer has not streamed in yet is still split.MarkdownRendererCoverage.test.tsx: through the full renderer, the line stays prose next to a real block, a streaming glued fence still renders as code, and an empty fence does not showundefined.mochiStreamingFences.test.ts: the same prose and streaming cases for Mochi's copy.Manual verification
Rendered one assistant reply holding the issue's lines and a glued Python fence through the real
AssistantMessagecomponent, on main and on this branch. Screenshots below.Screenshots / video
Before (main): the prose is cut off and two cards read
undefined.After (this branch): every line is prose, and the glued Python fence still renders as code.
Related Issues
Closes #14554
Pattern harvest
Rule candidate: review-prompt
Pattern: a markdown repair regex that matches a fence marker anywhere in a line, where CommonMark cannot open a fence.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.