Repository navigation
fix(cli): recognize markdown fences only on matching lines - #13331
Conversation
Verification verdict: ✅ merge-ready — 805/805 scripted assertions passedVerified head: 中文摘要(点击展开)结论:可以合并(merge-ready),805/805 条脚本断言全部通过,未发现阻塞性问题。
Central claim and A/B proofClaim: the streaming Markdown splitter (used by The change replaces A/B cells (oracle = exact strings / info objects, both arms on the built
|
| Scenario | base eb0b79c |
head fd96930 |
Verdict |
|---|---|---|---|
Issue #13309: Use `~~~` as the fence marker. split before More |
{lang:"\"}` + synthetic fences inserted into prose |
null; chunks are exactly the original substrings |
flipped: broken → fixed |
Inline ``` / ~~~ unwrapped mid-line (2 siblings) |
false fence, synthetic close/reopen | prose, exact substring split | flipped |
The `cat```dog` ran. (code span mid-line) |
false fence with lang:"dog\"` |
prose | flipped |
~~~ ~~~x / ~~~ ~~~~~x (same-char marker in info string) |
block falsely closed by the info string | {lang:"~~~x"} / {lang:"~~~~~x"} |
flipped (opposite direction) |
```tsinvalid /~~~tsinvalid (backtick in info string) |
accepted as fence | rejected as fence (CommonMark) | flipped |
| Genuine controls: backtick, tilde, 4-run, cross-type nesting, 2-space indent, CRLF, unclosed-at-EOF, empty info, language-less reopen, boundary splits | — | byte-identical to base on all 40 cells | preserved |
findLastSafeSplitPoint semantics (double-newline preference, cap fallbacks, 1000-block doc, oversized leading block) |
— | identical outputs on all cells | preserved |
Evidence: 01-ab-issue-repro.png (the headline flip), 02-adjudication-matrix.png (113 assertions).
Differential fuzz (second oracle)
400 seeded documents (inline markers, both fence chars, run lengths 3–6, indents 0–4 spaces, hostile info strings incl. backticks/tildes, CRLF variants, CJK prose) × ~10 split points each = 4091 comparisons: base dist vs head dist vs an independently written line-scanner oracle implementing the renderer contract.
unexpectedDivergences: 0— on documents containing only line-initial valid fences, base and head never disagree.oracleDisagreements: 0— head matches the independent oracle at every one of the 4091 points.invFailures: 0— every head split is either an exact substring split (no fence) or has byte-exact synthetic close/reopen structure (round-trips to the original).expectedDivergences: 2217— all inside documents carrying a mid-line marker or info-string hazard, i.e. exactly the bug class being fixed.
Evidence: 03-fuzz-differential.png. Harness: fuzz.mjs (seed 13331, reproducible).
Focused suites and vacuity
- Head, 4 suites touching the changed surface: 569/569 passed (markdown-utilities 53, MarkdownDisplay 190, use-llm-stream 289, pending-rendered-height 37) — matches the PR's own cloud count. Evidence:
04-vitest-head-suites.png.
- Vacuity / load-bearing proof of the new tests: the head test file was copied onto the base source (only the import path rewritten to the old filename). Result: exactly the 11 new assertions failed, all 42 pre-existing assertions stayed green — the 11 being the two inline-marker tests, two same-char-info tests, two backtick-info rejections, two indented-fence recognitions (poisoned on base by the inline marker in their fixture's intro line), and the three scan-count spy bounds (base's
indexOfmechanism never touches the regex). No unrelated failure, so the suite pins both the fix and the preservation. Evidence:05-vacuity-head-tests-on-base.png.
- Level-confound control: base probed at source level AND at built-dist level: 66/66 scenario cells identical, so the source-level base cells used early in the round equal the shipped artifact.
Performance
Hostile line ``` + N spaces + trailing backtick (the shape that is quadratic for the renderer regex), splitter with cap 16384, min of 3 runs:
| N | head splitter | base splitter | raw CODE_FENCE_RE exec |
|---|---|---|---|
| 2,000 | 0.001 ms | 0.001 ms | 5.4 ms |
| 5,000 | 0.001 ms | 0.001 ms | 33.6 ms |
| 20,000 | 0.044 ms | 0.005 ms | 533.8 ms |
| 40,000 | 0.044 ms | 0.008 ms | 2,134.9 ms |
1000 closed fenced blocks with the cap past the end: head 4.1 ms vs base 324.6 ms, outputs identical. The PR's absolute numbers differ from mine (arm64 Node 24 vs this x86_64 Catalina Node 22 host) but the superlinear regex curve and the prefix filter's avoidance are reproduced — corroborated, with the regex cost measured directly on this host.
Evidence: 06-perf-ladder.png.
Reviewer Test Plan walk-through
Every step of the PR's own plan was executed: split before More on the issue example (head: null + exact substrings ✓), genuine backtick/tilde blocks (close/reopen with original language and continuation line ✓ — start-line=2 after line1), indented and longer fences (✓), info strings containing backticks (rejected ✓). No step was found structurally unreachable.
Findings
No blocking findings. Informational observations (not merge conditions):
- A split inside an indented fence re-opens the tail fence without the original indentation (
```tsreopens as```ts). This is unchanged from base (both arms byte-identical) and pinned by the PR's own new test — cosmetic, pre-existing. - The
if (!match) continuefallback after the backtick pre-filter infindNextFenceappears unreachable: no line was found that passes the pre-filter yet failsCODE_FENCE_RE. Harmless redundant defense; also serves as the guard if the pre-filter and regex ever drift. - The splitter now follows the renderer's
^ *(unlimited leading spaces), wider than CommonMark's 0–3 spaces — a deliberate alignment with the renderer's pre-existing contract (the regex is untouched by this PR), so the splitter and the display can no longer disagree, which was the issue's root complaint.
Not covered
- Live interactive streaming TUI with a real model backend (the author also scoped this out; the streaming caller is covered by the
use-llm-streamsuite and the rendering of split output by theMarkdownDisplaysuite). - Full repository unit-test suite — only the 4 suites on the changed surface were run. The rename is fully accounted for: zero remaining
markdownUtilitiesreferences at head. - Repo-wide
typecheck/lintas separate gates — both arms' fullnpm run build(which compiles every workspace package incl. cli's tsc) exited 0. - Windows runtime (this host is macOS 10.15.7 x86_64).
- GitHub Actions CI state (the PR's
action_requiredlanes) was not evaluated; this report is local behavioral evidence only.
Methodology
Local maintainer round on macOS 10.15.7 x86_64, Node v22.23.3, pnpm 11.24.0. Two git worktrees at the exact OIDs above; dependencies installed once at head (corepack pnpm install --frozen-lockfile) and APFS-cloned into base (PR touches no manifest/lockfile); internal @qwen-code/* symlinks realpath-verified to resolve inside each own tree, so neither arm can load the other's code. Both trees built clean (npm run build, exit 0). Harnesses (probe.mjs, adjudicate.mjs, fuzz.mjs, demo-ab.mjs) are mock-free, drive the compiled dist/ output under plain node, and live in the artifact dir alongside raw probe JSON. Vitest 3.2.7 ran via an esbuild-wasm dispatcher (ESBUILD_BINARY_PATH) because this host predates esbuild's macOS 12 binary floor; the installed esbuild is 0.25.12 and the wasm route matched it. Artifact dir: tmp/pr13331-verify-20261007-001302/.
Merge QwenLM/qwen-code main at ac497ae so the existing Markdown fence fix is checked under the current lint gate. Preserve the original PR changes and the upstream empty-file-list guards.
qwen-code-review-bot
left a comment
There was a problem hiding this comment.
Reviewed — no blockers. Suggestions are inline.
中文说明
已审查——无阻断问题。 建议见行内评论。
— qwen3.8-max via Qwen Code /review (v0.25.0)
| while (lineStart < content.length) { | ||
| const newlineIndex = content.indexOf('\n', lineStart); | ||
| const lineEnd = newlineIndex === -1 ? content.length : newlineIndex; | ||
| // This pre-filter must remain a superset of CODE_FENCE_RE. |
There was a problem hiding this comment.
[Suggestion] R1-1: findNextFence now decides "is this a fence line?" twice — once with the hand-rolled pre-filter under this comment (skip space-only indentation, require three or more backticks or tildes, advance the whole run, reject a backtick after it), and once with the shared CODE_FENCE_RE it delegates to. The invariant that the pre-filter stays a superset of that regex is carried by this comment alone: nothing in the suite compares the two recognizers' verdicts. markdown-utilities.test.ts:8 does import CODE_FENCE_RE, but its only three uses are vi.spyOn(CODE_FENCE_RE, 'exec') at :105/:120/:135, which count calls rather than compare decisions; the rejects an opening fence with a backtick in its info string case asserts .toBeNull(), which the pre-filter satisfies whatever the regex says; and pending-rendered-height.test.ts has no fence-marker cases at all.
So if the regex is ever widened at pending-rendered-height.ts:40 for a renderer or height reason — the indent class becoming tab-tolerant so tab-indented fences render as code, or a tilde fence's info string being allowed to contain a backtick as CommonMark permits — then MarkdownDisplay.tsx:468 and fitPendingSlice start recognizing a fence this pre-filter still rejects, and no test fails. getEnclosingFenceInfo returns null for an index the renderer draws inside a code block, use-llm-stream.ts:2026-2028 keeps that block pending, and when a capped hard split does land inside it splitFencedMarkdown takes its plain-substring early return: the committed head renders as an unterminated fence and the tail as unhighlighted prose with no gutter. That is the bug class this PR fixes, arriving silently from the other direction.
To be explicit about the size of the risk, this is latent rather than live. Parity is exact today — a shaped corpus of 54 cases (27 lines across LF and CRLF, tab / > / - indents, a backtick in the info string for both fence characters, trailing spaces, a mid-line marker) and a random sweep of 2102 documents over 3324 probe indices both came back with 0 divergences. The verification note already on this PR also observed that the equivalence is comment-enforced rather than backed by a shared matcher; what is new here is the measurement that no test detects the drift, plus the corrected fix witness at the end.
Witness:
mutant MA — CODE_FENCE_RE widened to accept a tab-indented fence,
applied at vitest transform time (worktree files never edited)
markdown-utilities + pending-rendered-height + MarkdownDisplay
Test Files 3 passed (3)
Tests 280 passed (280) <- nothing goes red
same tree, proposed parity test injected (expectation derived from the
imported CODE_FENCE_RE binding, not from a copy of the pattern):
intact : Tests 54 passed (54)
MA : Tests 1 failed | 53 passed
+ [ "\"\t```ts\" splitter=false regex=true" ]
A table-driven parity case in the new fence recognition block of packages/cli/src/ui/utils/markdown-utilities.test.ts would close this with no production change: for a corpus of fence-shaped lines — a tab-indented fence, a blockquote-prefixed one, delimiter runs of 3/4/6, a backtick in the info string for both fence characters, a mid-line marker, trailing spaces, and a CRLF variant — assert that getEnclosingFenceInfo(line + '\nx\n', idxOf('x')) !== null iff CODE_FENCE_RE.test(line).
The corpus has to be judged against the binding already imported at markdown-utilities.test.ts:8, not against a literal copy of the pattern (export const CODE_FENCE_RE = /^ *(`{3,}|~{3,}) *([^`]*)$/;, packages/cli/src/ui/utils/pending-rendered-height.ts:40): a copied pattern just restates the pre-filter and can then never disagree with the renderer, which is exactly the drift this test exists to catch. The same object is read by fitPendingSlice (pending-rendered-height.ts:172) and twice by the renderer (MarkdownDisplay.tsx:77 and :181).
The new case should go red when CODE_FENCE_RE is widened to accept a tab-indented fence while the pre-filter still skips only spaces — please apply that mutation and confirm the tab row fails. Note that the check is one-sided rather than two-sided: deleting the backtick guard at :69-72 leaves the parity case green, because that guard is exactly redundant with today's regex (its info-string group cannot contain a backtick, so no line exists that the guard rejects and the regex accepts), and that mutation is already pinned as a perf assertion by the three skips the fence regex for a backtick after the full %s delimiter exec-count tests, which go from ~1 ms to 142-146 ms each without it.
中文说明
findNextFence 现在会两次判断"这一行是不是围栏行"——一次是这条注释下方的手写前置过滤(跳过纯空格缩进、要求三个以上反引号或波浪号、走完整个分隔符串、拒绝串后出现反引号),另一次是它委托的共享 CODE_FENCE_RE。"前置过滤必须保持为该正则的超集"这一不变量只由这条注释承担:测试套件中没有任何用例比较两个识别器的判定结果。markdown-utilities.test.ts:8 确实导入了 CODE_FENCE_RE,但它唯一的三处使用是 :105/:120/:135 的 vi.spyOn(CODE_FENCE_RE, 'exec'),统计的是调用次数而非判定结果;rejects an opening fence with a backtick in its info string 用例断言 .toBeNull(),而无论正则如何规定,前置过滤都能满足它;pending-rendered-height.test.ts 则完全没有围栏标记相关用例。
因此,如果将来出于渲染或行高计算的需要放宽 pending-rendered-height.ts:40 处的正则——例如缩进字符类改为兼容制表符,使制表符缩进的围栏被渲染为代码块;或按 CommonMark 允许波浪号围栏的信息串包含反引号——那么 MarkdownDisplay.tsx:468 与 fitPendingSlice 就会开始识别一个此前置过滤仍然拒绝的围栏,而没有任何测试失败。此时 getEnclosingFenceInfo 会对渲染器画在代码块内部的索引返回 null,use-llm-stream.ts:2026-2028 让该块持续挂起,而一旦带长度上限的硬切分落在块内,splitFencedMarkdown 就会走它的纯子串提前返回:已提交的前半段渲染成未闭合的围栏,后半段渲染成没有高亮、没有行号的普通正文。这正是本 PR 要修的那类缺陷,只是从相反方向悄悄回来。
需要明确风险量级:这是潜在问题而非现存问题。目前两者完全一致——54 个构造用例(27 行文本分别覆盖 LF 与 CRLF、制表符 / > / - 缩进、两种围栏字符的信息串中带反引号、行尾空格、行中标记)以及 2102 篇文档、3324 个探测下标的随机扫描,都得到 0 处分歧。本 PR 已有的验证说明也指出这种等价性只靠注释维持、没有共享匹配器支撑;此处新增的是"没有测试能发现该漂移"这一实测结论,以及文末修正过的修复验收条件。
证据(witness)为上方代码块中的程序输出,两种语言下完全相同,不再重复。
在 packages/cli/src/ui/utils/markdown-utilities.test.ts 新增的 fence recognition 分组里加一个表驱动的一致性用例即可闭环,且无需改动生产代码:对一组围栏形状的行——制表符缩进的围栏、带引用前缀的围栏、3/4/6 长度的分隔符串、两种围栏字符的信息串中带反引号、行中标记、行尾空格,以及一个 CRLF 变体——断言 getEnclosingFenceInfo(line + '\nx\n', idxOf('x')) !== null 当且仅当 CODE_FENCE_RE.test(line)。
该用例必须以 markdown-utilities.test.ts:8 已导入的绑定为判定依据,而不是照抄一份正则字面量(export const CODE_FENCE_RE = /^ *(`{3,}|~{3,}) *([^`]*)$/;,见 packages/cli/src/ui/utils/pending-rendered-height.ts:40):照抄的写法只是把前置过滤重述一遍,永远不可能与渲染器产生分歧,而那恰恰是这个测试要防的漂移。同一个对象还被 fitPendingSlice(pending-rendered-height.ts:172)以及渲染器的两处(MarkdownDisplay.tsx:77、:181)读取。
新用例应当在"放宽 CODE_FENCE_RE 使其接受制表符缩进的围栏、而前置过滤仍只跳过空格"时变红——请实际施加该变异并确认制表符那一行失败。注意这个检查是单向而非双向的:删除 :69-72 的反引号保护后,一致性用例仍然是绿的,因为该保护与当前正则完全冗余(正则的信息串分组不可能包含反引号,所以不存在"保护拒绝但正则接受"的行),而且该变异已被三个 skips the fence regex for a backtick after the full %s delimiter 调用次数用例以性能断言的形式钉住——去掉保护后它们各自从约 1 ms 变为 142-146 ms。
— qwen3.8-max via Qwen Code /review (v0.25.0)
|
@qwen-code /triage |
|
Sandboxed verification: ✅ passed — merge-ready (agent verdict) - workflow run Ran the PR in an isolated, token-free container: A/B against the base build, mock-free harness assertions, targeted gates. Advisory evidence for human reviewers — not a review, an approval, or a CI check. Scripted assertions: 3262 passed · 0 failed · 3262 total Flakiness gate: ✅ 3 changed test file(s) x 5 identical rounds, no divergence 中文 — 判定:✅ 通过 · 可合入(agent 判定)沙箱验证在隔离、无凭证的容器中执行了该 PR 的代码(与 base 构建 A/B 对照、无 mock harness 断言、定向门禁)。仅作为评审证据,不构成评审、批准或 CI 检查。 脚本断言:3262 通过 · 0 失败 · 3262 总计 抖动门:✅ 3 changed test file(s) x 5 identical rounds, no divergence Verification reportPR #13331 — deep verificationVerdict: 中文摘要结论: A/B 结论:以「渲染器自身规则」为裁判(从
详见下方 Central claim + A/B 与 Perf A/B 两表;证据截图为 变异与空测试检查:9 个单点变异全部被击杀,0 存活;同文件内的正向对照 M8 使 6 条测试变红并报出期望值差异。把核心修复整体回退(M1)会让 Findings(均非阻塞):① 同一提交路径上 未覆盖范围:4 个提交在本 depth-2 检出下只有 head 可达( Central claim + A/BCentral claim. The streaming Markdown splitter ( Secondary claims. (S1) The perf half — one fence scan plus a monotone Oracle. Control cleanliness. The PR touches no manifest and no lockfile (
Cells 1–8 are witnessed by Cell 9 is the user-visible symptom, not a string comparison. The harness replicates What base injected into a document that contains no code block: and the ordinary prose after line 392 rendered as a numbered code block. Head renders it as prose and the chunks concatenate back to the source byte-for-byte. Sibling sweep. The reported input is one door into a room with several, so 24 adjacent shapes were each driven through the fixed build at every character index (cell 1; all Boundary probing. Every index of every fixture was probed, not just the reported split point, so the Perf A/B (secondary claim S1)
Growth over Corrections to the PR descriptionLabelled as corrections to the description, not requests to change code.
Everything else I could check reproduced: 569/569 across the four suites, 53/53 in the helper suite, and the stated Before value Vacuity check and mutation matrix
M1 is the vacuity check on the PR's central new test group and it is not vacuous: the kill is behavioural, quoting expected-versus-actual values, not a broken import or fixture. M8 is the required positive control and it is landed in the mutated file, and the chosen command ( M5 and M6 fail identically (7 tests, same first assertion) — layered guards hiding each other. That is expected here: M9 is adjudicated by running its build, not by reading it: classified redundant defence by design (behaviour-identical over 1.2 M probes), not a coverage gap and not dead code in the pejorative sense — it exists so the splitter follows the renderer's single source of truth if FindingsAll non-blocking. None is a defect in this PR's code. 1. The same quadratic regex is still unguarded on the same streaming commit path (pre-existing, partially disclosed) — Suggestion
Growth ×3.93 for N ×2.00 — exactly quadratic. The PR's pre-filter makes the splitter immune (×1.04, flat, ≈50,000× faster at N=40k). That part is a genuine win and it is proven. The residual: Bounded honestly. Not introduced by this PR — the regex and both consumers predate it, and the PR reduces total exposure. Provenance: the splitter's only inputs are Reproduce: node tmp/pr13331-verify-20261008-075026/regex-exposure.mjsFollow-up, not a condition of this PR: hoist the pre-filter this PR already wrote into a shared 2. The "must remain a superset" invariant is enforced only by a comment — Suggestion// This pre-filter must remain a superset of CODE_FENCE_RE.The census shows the two accept-sets are equal over 488,280 exhaustively enumerated lines, and M9 shows deleting the regex changes nothing behaviourally. So the invariant is the only thing coupling the splitter to the renderer, and no test pins its direction. A future relaxation of Cheap fix, in the spirit of the existing spy tests: it('the pre-filter admits everything CODE_FENCE_RE admits', () => {
const ALPHABET = [' ', '\t', '`', '~', 'a'];
const walk = (line: string) => {
if (line.length > 0 && CODE_FENCE_RE.test(line)) {
expect(getEnclosingFenceInfo(`${line}\nX`, line.length + 1)).not.toBeNull();
}
if (line.length < 6) for (const c of ALPHABET) walk(line + c);
};
walk('');
});That is the census harness reduced to a fixture; it runs in well under a second at length ≤ 6 and would go red on any relaxation of the shared regex. Reproduce the full census: 3. The termination guard's only CI protection is an out-of-memory crash — Suggestion
Mutant M2 does not fail an assertion. It kills the vitest worker: ~49 s and ~4 GB before the crash, surfacing as Reproduce: 4. Two CommonMark deviations inherited from the renderer, neither named in the accepted-tradeoff list — NoteThe Risk & Scope section discloses the tradeoff correctly ("streaming split boundaries now follow the existing renderer's fence pattern"). Enumerating the unnamed siblings of that mechanism, both measured in
Splitter and renderer agree in both rows, which is the right call for this PR and keeps rendered output self-consistent. Both deviations are pre-existing in 5. Rename is complete — verified, no actionSecondary claim S2 holds. Zero references to Not covered
MethodologyCI Five harnesses drove the code, all mock-free with respect to the unit under test:
Injection check. PR title, body (English and Chinese) and all four commit messages were treated as untrusted input. No instruction attempting to steer this verification was found — no request to skip the A/B, pre-declare a verdict, or treat a suite as known-flaky. The body's self-reported numbers were treated as hypotheses and each one I could reach was independently re-measured; two are refined in Corrections and the rest reproduced. Flakiness gate logEvidence imagesHarness scripts and raw logs are in the workflow run artifacts (7-day retention). — Qwen Code · sandboxed verification |
|
Thanks for the PR — and for filing the issue first with a runnable reproduction. That made this stage quick. Template ✓ — every required heading is present, including the Chinese mirror. Problem: observed, not theoretical. #13309 reports against a real build (0.21.5, macOS arm64) and ships a copy-pasteable source-level repro. I traced the old code by hand to confirm the "before" claim rather than take it on faith: Direction: clearly aligned. This is output fidelity in the streaming renderer — the splitter and the renderer disagreed about what a code fence is, and the disagreement corrupted ordinary prose. No auth, sandbox, model-selection, telemetry, release, or public-contract surface, and no API or config change. Nothing to escalate. Size: no core paths — everything is Approach: the shape is right, and I want to call out one thing it got correct that's easy to miss — it imports the renderer's existing
Risk: no elevated signals — none of the changed files match the revert-correlated path list. Moving on to code review. 🔍 中文说明感谢贡献!也感谢先开 issue 并附上可直接运行的复现,这让准入判断很快。 模板 ✓ —— 所有必需标题齐全,包含中文对照部分。 问题: 是已观测到的 bug,不是理论性加固。#13309 基于真实版本(0.21.5,macOS arm64)报告,并给出了可复制粘贴的源码级复现。我没有直接采信"修复前"的描述,而是手工推演了旧代码: 方向: 明确对齐。这是流式渲染的输出正确性问题 —— 切分器与渲染器对"什么是代码围栏"的判断不一致,而这个不一致会破坏普通正文。不涉及鉴权、沙箱、模型选择、遥测、发布或公开契约面,也没有 API 或配置变更。无需上报。 规模: 未触及核心路径 —— 全部位于 方案: 整体思路正确,其中有一点值得特别指出、也很容易被忽略 —— 它引入了渲染器已有的
风险: 无升级信号 —— 变更文件均未命中与回滚相关的路径清单。 进入代码审查 🔍 — Qwen Code · qwen3.8-max-2026-09-02 Reviewed at |
Code reviewI read the head version of The pre-filter really is a superset of Renderer parity holds on the shapes that could diverge. Tab-indented and blockquote-prefixed fences are rejected by both sides. CRLF is the subtle one: The closed-block cursor reproduces the old predicate exactly. Old I also hand-traced the No collateral damage. Two non-blocking notes. The superset invariant is enforced by a comment, not by a test — the prior Three of the new tests assert on Test evidenceWhat this comment carries: the PR's own CI results, read from the API — no PR code was built or executed here. This is an unattended run, so per the review rules the evidence is GitHub's, not mine. Both PR CI workflows have settled at the reviewed head: Nothing is red and nothing is in flight, so there is no failing-job log to quote. I fetched once and did not poll.
Behavioural A/B. A maintainer-run verification on this PR already did the load-bearing work: an A/B against the issue's reproduction commit, 40 genuine-fence control cells byte-identical between arms, a 4091-cell differential fuzz, and a non-vacuity check showing exactly 11 new assertions fail when the head tests are run against base sources. That was measured at Not verified: the live interactive streaming TUI. Nobody has driven a real streaming session end-to-end — the PR body names this as out of scope, the A/B was run against built output rather than a live terminal, and Sandboxed verification would settle it: 中文说明代码审查 我完整读了 head 版本的 前置过滤确实是 在可能产生分歧的形状上,与渲染器保持一致。 制表符缩进和带引用前缀的围栏两边都拒绝。CRLF 是微妙的一处: 闭合块游标与旧判定完全等价。 旧的 我还手工推演了 没有附带损伤。 两点非阻断说明。 超集这一不变量由注释维持,而非测试 —— 上一轮 三个新测试断言了 测试证据 本条评论携带的证据:通过 API 读取的 PR 自身 CI 结果 —— 这里没有构建或执行任何 PR 代码。 这是无人值守运行,按审查规则证据来自 GitHub 而非我本地。 两个 PR CI 工作流在被审查的 head 上均已结束: 没有红色项,也没有仍在运行的项,因此没有失败作业日志可引用。我只取了一次结果、未做轮询。 行为 A/B。 本 PR 上已有一次由维护者执行的验证完成了关键工作:针对 issue 复现提交的 A/B、40 个真围栏对照格在两臂逐字节一致、4091 格差分模糊测试,以及非 vacuous 检查(把 head 测试放到 base 源码上恰好 11 个新断言失败)。该验证是在 未验证:live 交互式流式 TUI。 没有人真正端到端跑过一次流式会话 —— PR 正文将其列为范围外,A/B 是针对构建产物而非 live 终端做的,而 沙箱验证可以补上这一点: — Qwen Code · qwen3.8-max-2026-09-02 Reviewed at |
|
Confidence: 4/5 — the fix is correct and I could verify that from the code rather than from anyone's word; the two reservations are a comment-enforced invariant and a live-TUI gap nobody has closed. Going into this I expected to push back on scope, and I ended up not being able to. My own instinct for this bug was the same shape the author chose: stop scanning for fence delimiters anywhere in the string and instead ask the renderer what it considers a fence, then use that answer rather than a second opinion. The PR does exactly that, importing What I did push on was the The boundary semantics are the part most likely to hide a regression, so I checked them against the predicate they replace rather than against intuition: What keeps this at 4 rather than 5: The superset invariant between the pre-filter and And nobody has driven a real streaming session. The unit and renderer coverage is strong, the A/B was run against built output, and I don't suspect anything is hiding there — but I'd rather name the gap than paper over it. Six months from now this reads as a clear win: the two recognizers now share one definition, the accidental quadratic is gone, the naming convention debt is paid down, and the tests explain themselves. Nothing here made me curse the author. Verdict: approve. Both PR CI workflows are completed and green on the reviewed head, so there's nothing left to wait for. Approving pinned to 中文说明置信度:4/5 —— 修复是正确的,而且这一点是我从代码本身验证出来的,不是采信任何人的说法;两点保留意见分别是一个由注释维持的不变量,以及一个尚无人闭合的 live TUI 缺口。 开始前我原以为要在范围上提出反对,结果没能找到。我对这个 bug 的直觉方案与作者选择的形状一致:不再在整串文本中任意位置搜索围栏分隔符,而是去问渲染器"什么才算围栏",然后使用那个答案,而不是再给出第二份判断。这个 PR 正是这么做的 —— 引入 我确实质疑过的是 边界语义是最可能藏回退的地方,所以我是拿它与被替代的判定对照检查的,而不是凭直觉: 让它停在 4 分而不是 5 分的原因: 前置过滤与 以及没有人真正跑过一次流式会话。单元与渲染器覆盖很强,A/B 是针对构建产物做的,我不怀疑那里藏着什么 —— 但我宁愿点名这个缺口,也不愿掩盖它。 六个月后再看,这是一次明确的收益:两个识别器现在共享同一定义,意外的平方复杂度消失了,命名约定的欠账还上了,测试也能自我说明。这里没有任何东西会让我在维护时埋怨作者。 结论:批准。 两个 PR CI 工作流在被审查的 head 上均已完成且为绿色,已无需等待。批准通过 reviews API 锁定在 — Qwen Code · qwen3.8-max-2026-09-02 Reviewed at |
qwen-code-review-bot
left a comment
There was a problem hiding this comment.
LGTM, looks ready to ship. ✅
|
Released in v0.25.2. |











What this PR does
The streaming Markdown splitter now recognizes code fences with the renderer's line-matching rules. Inline backtick or tilde markers remain ordinary prose; genuine fenced blocks retain their close/reopen behavior and line numbering. Regression coverage includes inline markers, invalid info strings, indented fences, and longer delimiters. Internal helper naming and imports follow the repository's conventions.
Why it's needed
An inline fence mention such as
Use `~~~` as the fence marker.previously opened a false code block during splitting and inserted synthetic fences into ordinary prose.Reviewer Test Plan
How to verify
Split the issue example before
More ordinary prose follows.: both resulting strings should match the original substrings and the enclosing-fence result should be null. Repeat inside genuine backtick and tilde fenced blocks: the first chunk should close the block and the second should reopen it with the original language and the correct continuation line. Also verify indented and longer fences and info strings containing backticks.Validation at
fd0e42e: 41 Markdown utility tests and 289 streaming tests passed. Six parent/fixed reproduction scenarios passed, including controls for genuine backtick and tilde fences.Evidence (Before & After)
For
Use `~~~` as the fence marker.\nMore ordinary prose follows., split beforeMore:eb0b79c): the enclosing-fence result was{ lang: "`", startLine: 1 }; the first chunk gained a closing~~~and the second gained a reopening fence with an incorrect info string.fd0e42e): the enclosing-fence result isnull; the chunks are exactlyUse `~~~` as the fence marker.\nandMore ordinary prose follows..qwen-code:start-line=2on both revisions.Tested on
Environment (optional)
macOS arm64, Node.js v24.13.0, npm 11.6.2. Existing local dependencies and built workspace prerequisites were reused. Verification used source-level scripts and focused unit tests.
Risk & Scope
Linked Issues
Fixes #13309
中文说明
这个 PR 做了什么
Markdown 流式切分现在按渲染器的逐行规则识别代码围栏。正文中内联出现的反引号或波浪号保留为普通正文,真正的代码块仍能在切分时闭合、重开并延续行号。回归用例覆盖内联标记、无效信息字符串、缩进围栏和较长的分隔符;内部辅助模块的命名与引用也按仓库约定更新。
为什么需要
此前,正文中类似
Use `~~~` as the fence marker.的内联围栏说明会在切分时被误判为代码块起点,导致普通正文被插入多余围栏。评审者验证计划
如何验证
在 Issue 示例的
More ordinary prose follows.前切分:两段结果应分别等于原文的对应子串,所处代码围栏的判断结果应为 null。再在真正的反引号和波浪号代码块内切分:前段应闭合代码块,后段应按原语言重开,并延续正确的行号。同时检查带缩进、较长的围栏,以及包含反引号的信息字符串。fd0e42e的验证结果:41 项 Markdown 工具测试与 289 项流式处理测试通过;修复前后共 6 个脚本复现场景通过,其中包含真正的反引号与波浪号围栏对照。证据(修复前后)
对
Use `~~~` as the fence marker.\nMore ordinary prose follows.,在More前切分:eb0b79c):所处围栏的判断结果为{ lang: "`", startLine: 1 };前段多出闭合~~~,后段多出信息字符串错误的重开围栏。fd0e42e):判断结果为null;两段准确保留为Use `~~~` as the fence marker.\n与More ordinary prose follows.。qwen-code:start-line=2。测试平台
运行环境(可选)
macOS arm64、Node.js v24.13.0、npm 11.6.2。复用了现有本地依赖和已构建的工作区前置包,使用源码脚本与定向单元测试验证。
风险与范围
关联 Issue
Fixes #13309
Cloud verification (
fd96930)The latest review suggestions are addressed in
fd96930. Fence state is scanned once, and a bounded line check avoids the shared regex when an info string contains a backtick after the entire delimiter run. Valid fence lines still use the original shared regex, including both captures, exact run lengths, language, and continuation line numbering. The prefix filter is documented as a superset of that regex. Regression tests pin the closed-block cursor reset, same-character tilde info strings, positive scan-count lower bounds, and rejected long-space fence lines.process.exitCodeerror does not reproduce on the unmodified reviewed head or the fix with their own pinned frozen installs; both full repository typechecks pass. Its local Node types 22.20.1 allownull, while the previously borrowed root types 20.19.1 do not. No Mem0 source or dependency manifest was changed.action_required; this update makes no GitHub CI-success claim. No live model API or interactive TUI verification was performed, and math-block precedence remains outside scope.云端后续验证说明
五条新建议已处理:保留共享正则与第二 capture,只在线内完整分隔符之后存在反引号时跳过必定失败的匹配;补充 cursor reset、同字符 tilde-info、spy 正下界与长空格拒绝行回归。两份独立冻结安装的未修改基线和修复版本均构建与全仓类型检查通过;修复版本另通过 bundle、CLI 类型检查、格式、lint 和 569 项定向测试。四组变异只令各自对应的新断言失败,独立审阅及 Unicode/边界检查通过。
更正先前的 Mem0 类型检查失败说明:正确局部依赖中的 Node types 22.20.1 允许 null,借用的根依赖 20.19.1 不允许;未修改基线与修复版本的全仓检查现在均通过,Mem0 源码和依赖声明未改。既有 renderer 回溯成本、live TUI 与全仓单元测试未由此次验证覆盖。机器人 4/4 与本地检查均不代表 GitHub 主 CI/tui-parity 通过。
Upstream integration verification (5a4e3a1)
Normally merged upstream main
ac497aeed956981e817b4301837866730359a65finto this branch to address the approved CI lane's lint gate freshness failure before dependency installation. The merge contains the upstream gate change6b878e1a04ec70a35f8d14125fb3aafea4fb8973, preserves the original seven-file PR diff, and does not weaken the gate or change the shared fence regex/captures.On Linux with Node 22.23.3 / pnpm 11.24.0 and the merged tree's frozen dependencies:
fd96930and none on the actual new merge commit: 25/25 assertions. This is an ancestry-based local verification, not a live GitHub CI pass.The fork ref and PR metadata both read back the full head
5a4e3a1a4ac2ff5e0301cc203c6f6da3dc84b7e7. Its new Qwen Code CI run 37508564532 and tui-parity run 37508564531 are completed / action_required, awaiting maintainer approval. No CI success is claimed and no further review request was sent.中文
已正常合并当前 upstream main
ac497aeed,新 head 为5a4e3a1a4ac2ff5e0301cc203c6f6da3dc84b7e7。包含导致原 CI freshness 失败的上游门禁提交,保留原 PR 七文件差异及共享 regex/captures;没有 force push 或弱化门禁。冻结依赖下 build、bundle、全仓及 integration typecheck、零 warning ESLint、实际 Prettier 检查均通过,四组回归重新通过 569/569,lint helper 16/16、freshness 原生测试 9/9、实际新提交 ancestry 验证 25/25。完整 merge 的原生 hook 虽返回 0,但应用阶段对 main 已有的被忽略目录内 E2E 文件报错,不能称完整 hook 通过;提交树与 hook 前索引完全一致,PR 七文件的实际 lint-staged 配置另行通过。新 head 两个 CI run 仍为 action_required,需要维护者批准,未宣称 CI 通过或追加 review 请求。