Skip to content

fix(prepare-pr): strip tilde and indented fences in --check-body - #22848

Closed
buluoray wants to merge 2 commits into
mainfrom
fix/check-body-fences-22112
Closed

buluoray wants to merge 2 commits into
mainfrom
fix/check-body-fences-22112

Conversation

@buluoray

@buluoray buluoray commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: diff_signals.py --check-body skips every CommonMark code fence in ## What changed, not only a backtick fence at column 0.

The fence regex in _what_changed_unfenced was ^```.*?^```[ \t]*$. A ~~~ block, a backtick block indented one to three spaces, or a four-backtick block stayed in the text. Its words counted toward WORD_LIMIT, and since #22089 its table rows counted toward the eight-row limit, so a code example holding nine table rows gave a false exit 21.

Why it matters

An author who writes a valid tilde-fenced or indented example in a PR body gets a "too long" or "too many rows" refusal for code the reader never scans as prose. The failure is loud and easy to clear by switching to a column-0 backtick fence, so the cost is friction, not a silent pass.

Not a goal

  • Changing where the ## What changed section ends. It is still cut at the first ## line before fences are stripped, so a ## line inside a fence ends the section; a test pins today's answer.
  • Changing WORD_LIMIT, TABLE_ROW_LIMIT or any other check.

What changed (motivation → approach → change)

Symptom: tilde and indented fences counted as prose and table rows. Cause: a regex that only knew one fence form. Change: diff_signals.py gets a small line-based _strip_fences, which follows the CommonMark rule. A fence opens with three or more backticks or tildes, indented up to three spaces; a backtick opener's info string holds no backtick. It closes on a line of the same character, at least as long, with only blanks after it. A fence behind list markers (- ~~~, 1. ```py) closes at its item's content indent and ends with its item, so one item's indented closer cannot open a block that hides the prose up to the next item. When unsure, the scanner counts a block as prose, since stripping rendered prose would let an over-limit body pass. A fence that never meets its closer is counted, opener included. A non-blank line left of the opener's fence column ends the block unclosed, so text after a list item is never hidden by a fence on the item's continuation line. No fence opens inside an HTML block (a line starting with <, after any list markers, up to the next blank line or a raw block's end marker such as </pre>). Indent is measured with tabs expanded to four-column stops. One valid form is now overcounted: a fence indented one to three spaces whose content starts at column 0 (CommonMark renders it as code; here it counts). The list-prefix quantifiers in _FENCE_OPEN are possessive, so a long - - - line is rejected in linear time. A fence inside a blockquote (> ~~~) is still counted, as before.

fence form before after
~~~ / longer tilde 🟥 counted 🟩 skipped
backtick, 1-3 space indent, content at the fence column 🟥 counted 🟩 skipped
backtick, 1-3 space indent, content at column 0 🟥 counted 🟥 counted
closed fence pair inside an HTML block 🟥 skipped 🟩 counted
four or more backticks 🟥 counted 🟩 skipped
unclosed fence 🟩 counted 🟩 counted
fence in a list item 🟥 counted 🟩 skipped

Backwards compatibility

Compatible: no flag, exit code or message changes. A body counts more than today only where main hid text GitHub renders outside a fence: a column-0 block closed by an indented or longer closer, or a backtick opener with a backtick in its info string.

Removes nothing: the change narrows what is counted inside one section; no key, flag, exit code or function is removed or renamed.

Tests

In test/test_prepare_pr_diff_signals.py:

  • test_fence_forms_skip_both_word_and_row_counts: tilde, longer tilde, indented backtick, indented with info string, four backticks. Each block holds 20 table rows and 4 words, indented to the fence column; rows must be 0 and only the outside prose counts.
  • test_a_closed_fence_pair_inside_html_is_counted (<div>, - <div>, <pre> past a blank line) and test_a_fence_after_an_html_block_ends_still_strips.
  • test_a_tab_indented_line_stays_inside_its_list_fence.
  • test_a_line_left_of_the_fence_ends_it_and_is_counted: a fence on a list item's continuation line, then 50 words after the item.
  • test_an_indented_fence_with_column_zero_content_is_counted: pins the one overcounted form.
  • test_a_non_closing_line_stays_inside_the_fence: the other character, a shorter run, and a closer with an info string do not close.
  • test_four_space_indent_is_not_a_fence_and_an_unclosed_fence_is_counted.
  • test_an_unclosed_fence_counts_as_prose_so_a_long_body_fails (<details>, <div>, - ````, 1. ~~~): 50 words after an opener that never closes; --check-body` exits 21.
  • test_a_backtick_in_the_info_string_is_not_an_opener: ```a`b stays prose, so a later fence line cannot hide the rows between.
  • test_a_deep_list_closer_must_reach_the_item_content_indent: a four-wide item closes at four to seven spaces; at three the item ends unclosed and its rows count.
  • test_a_long_list_marker_line_is_scanned_in_linear_time: conftest.assert_rejected_without_backtracking ramps a - pump; before the fix 16 units (65 characters) took 10.7 s.
  • test_a_list_item_fence_closes_at_its_own_indent_and_keeps_the_prose_between (tilde and backtick): two list-item examples with 30 words between; all 30 count.
  • test_list_fences_nest_and_end_with_their_item: ordered and nested items, and an unclosed item fence that ends with its item and stays counted.
  • test_a_blockquote_fence_is_still_counted: pins today's answer for > ~~~.
  • test_a_heading_inside_a_fence_still_ends_the_section: pins the residual named under Not a goal.

Revert check, one mutation at a time, each restored after:

mutation fails
block ends at item width, not fence column 2 tests
no tab expansion tab test
no HTML blocks 3 HTML cases
HTML start without list prefix list-div
<pre> ends at blank line pre-past-blank
unclosed fence stripped 4 tests
no info-string lookahead info-string test
closer ignores item indent 2 tests
old backtracking regex linear-time guard

With the fix the whole file passes (67 passed, three runs).

Manual verification

N/A — the function is pure text processing and the unit tests drive it directly through what_changed_table_rows and what_changed_prose, the two callers --check-body uses.

Related Issues

Closes #22112
Related: #22089, #11006

Pattern harvest

Not generalizable: the repo has other backtick-only fence regexes (for example preview_text.py, card_lifecycle.py), but they parse model or chat output; this one gates a human-written PR body, where every CommonMark fence form is valid input, and claim_preflight.py and docs_lint.py already accept tilde fences. pr_status.py has its own _fence_opening / _is_closing_fence; they do not know list items, so reusing them would bring back the list case.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license.

Decision for the owner

The decision is whether --check-body should count every fence it is unsure of as prose, at the cost of overcounting a fence indented one to three spaces whose content starts at column 0. This PR does, because overcounting only makes the length gate stricter, while stripping rendered prose lets a long body pass.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision db00cdc39d10c597c615671f4aa44f057180d436 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of db00cdc39d10c597c615671f4aa44f057180d436 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

No design-level concerns: the change only affects one PR-body length gate, and whenever the scanner is unsure it counts the text, so the gate never gets looser.

Notes

  • The scanner rebuilds a lot of CommonMark (list indents, HTML blocks, tab stops) to fix friction the description itself calls "easy to clear". If a later edge case needs one more rule, cap the scope there rather than keep extending it.

[DESIGN-REVIEWED] db00cdc

Description read

[DESCRIPTION-READ] 215024ca93cad60c3e0aa7692a8446481feb4c0992733a6ff87220e44e59d61f

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of db00cdc39d10c597c615671f4aa44f057180d436 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Linked issue #22112, aimed at the cause (a regex that knew one fence form); the riders only push toward counting more.

Notes

  • Item 4 — oversized: _HTML_RAW_ENDS carries five raw-block kinds (script|style|textarea, <?, CDATA, <!X) for a PR body, but the tests only exercise <pre>, <div> and <details>. Subtraction: shrink _HTML_RAW_ENDS to the pre and !-- rows.
  • Item 1 — second spelling: pr_status.py:254 _fence_opening / _is_closing_fence (one other fence parser in the same scripts/ dir) already applies the same opener/closer rule. The description gives a reason not to reuse it: "they do not know list items". Subtraction: none for now, because list-item support is the real difference.

What this change ships

Inventory (6 items) — 4 justified

Intent: stop --check-body refusing a PR body because of words or table rows inside valid tilde, indented or four-backtick code fences; FIX.

  1. Tilde, indented (1–3 space) and four-or-more-backtick fences no longer count as prose or table rows — justified
  2. Fences inside list items are skipped and close at the item's content indent — justified
  3. Unclosed fences, and fences cut off by a line further left, still count as prose — justified
  4. A closed fence pair inside an HTML block is now counted (main skipped it) — rides along
  5. A column-0 block that main hid, closed by an indented or longer closer, or a backtick opener with a backtick in its info string, now counts — rides along
  6. A long - - - line is rejected in linear time (possessive quantifiers) — justified

[FIRST-PRINCIPLES-REVIEWED] db00cdc

Description read

[DESCRIPTION-READ] 2b9f01aea527d0a2169710f9deaf8af055c66035e223547e7109b15d34903daf

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed db00cdc39d10c597c615671f4aa44f057180d436 — this comment is updated in place on each push.

Review details

No findings.

Notes:

  • _strip_fences still undercounts when a top-level fence is indented 1–3 spaces, its content and closer sit at column 0, and another fence follows. This happens rarely and the base branch did the same, so it is not a regression. The docstring is wrong to call this form an overcount.

[OPUS-REVIEWED] db00cdc

Verdict parsed from the review's SHA-scoped output markers for commit db00cdc39d10c597c615671f4aa44f057180d436.

False positive or not applicable? A repository writer can comment:
/ai-review override fable db00cdc39d10c597c615671f4aa44f057180d436: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings (all downgraded on adjudication)

GPT 6.1 flagged blocking issues on db00cdc39d10c597c615671f4aa44f057180d436; Opus 5.5 adjudication downgraded every one of them. Downgraded: the remedy each one needs is disproportionate to the harm it prevents. Adjudication downgraded all 1 blocking finding(s): the remedy each one requires is disproportionate to the harm it prevents.

This comment is updated in place on each push.

Review details

BLOCKING -- src/kiro_crew/builtin_skills/kirocrew-dev/kirocrew-prepare-pr/scripts/diff_signals.py:260 -- List-prefix matching strips rendered paragraph text

_LIST_PREFIX = r"(?: {0,3}+(?:[-+*]|\d{1,9}+[.)]) {1,4}+)*+"
Trigger: In a template-compliant body’s ## What changed, use x/y.py changes.\n2. ~~~\n, followed by 501 words indented three spaces, then ~~~\n~~~\n. --check-body → check_body → _what_changed_unfenced → _strip_fences accepts 2. ~~~ as a list fence, although CommonMark forbids a non-1 ordered marker from interrupting an existing paragraph.
Outcome: The rendered paragraph contains 505 words, but the check counts only three and returns 0 instead of exit 21; the template check also passes.
Anchor: defect
Fix: Before stripping a list-prefixed fence, verify that its marker can start a list in the current paragraph context; otherwise retain those lines as prose.

[BLOCK-MERGE-DOWNGRADED] db00cdc
[GPT-REVIEWED] db00cdc

Adjudication (Opus 5.5) — is blocking on each finding proportionate?

F1 — LOW. If this goes wrong, a PR description longer than the advisory 500-word limit gets through a local prepare-pr style check without warning. The script's exit 21 just says "too long"; nothing gets corrupted and no security boundary is involved.
Conditions confirmed: _LIST_PREFIX at diff_signals.py:260 accepts any ordered marker (\d{1,9}+[.)]), with no check of what the previous line was. _strip_fences (:291–:358) then strips the closed block. The word count runs on what's left (:443–:450), and its only effect is the exit 21 at :462–:463. The trigger is a hand-crafted body: a non-1 ordered marker opening a fence directly under a prose line, with a long indented block inside, which ordinary PR bodies don't produce. Recovery: none automatic. The reviewer still sees the full rendered body.
Fix cost: the line scanner would need to track paragraph state (whether the previous line was paragraph text, and which markers may interrupt it), adding CommonMark block-context state to a scanner whose docstring already carries a long list of edge-case rules. That load is permanent and outweighs a cosmetic length check missing an adversarial input.

[ADJUDICATION] db00cdc39d10c597c615671f4aa44f057180d436 total=1 uphold=0 downgrade=1
DOWNGRADE F1 src/kiro_crew/builtin_skills/kirocrew-dev/kirocrew-prepare-pr/scripts/diff_signals.py:260 reason=disproportionate-remedy
[GPT-ADJUDICATED] db00cdc39d10c597c615671f4aa44f057180d436

False positive or not applicable? A repository writer can comment:
/ai-review override gpt db00cdc39d10c597c615671f4aa44f057180d436: <one-sentence reason>

@buluoray
buluoray force-pushed the fix/check-body-fences-22112 branch from a287fbf to e21a498 Compare October 21, 2026 18:30
@buluoray

Copy link
Copy Markdown
Contributor Author

🤖 Kiro Crew Auto-Pipeline [operator: buluoray#ce473fca]: review dispositions for e21a498e51.

  • GPT 6.1, list-contained fences (blocking): fixed. A fence behind list markers (- ~~~, 1. ```py, nested - - ~~~) now records its item's content indent; the closer must sit at that indent, and the block ends when a non-blank line falls below it. Your exact trigger is test_a_list_item_fence_closes_at_its_own_indent_and_keeps_the_prose_between (tilde and backtick); it fails on a287fbfa81 and passes now.
  • First Principles, duplicate of pr_status.py _fence_opening / _is_closing_fence (note): kept separate. Those helpers do not track list items, so reusing them would bring the GPT case back, and loading pr_status.py runs its own sibling loads at import time. The Pattern harvest section now names them.

@buluoray

Copy link
Copy Markdown
Contributor Author

🤖 Kiro Crew Auto-Pipeline [operator: buluoray#ce473fca]: disposition for the downgraded GPT 6.1 finding on e21a498e51.

  • Ordered marker after paragraph text (Before.\n2. ~~~), advisory after adjudication: confirmed real and left as is. CommonMark lets only a 1. item interrupt a paragraph, so 2. ~~~ there is paragraph text, and this scanner reads it as a fence. Fixing it means tracking paragraph state and the interruption rules in a line scanner, for a body shape that is rare and still visible to the reviewer reading the body. Main has the opposite failure today (every indented or tilde fence is counted), which is the defect prepare-pr: --check-body fence stripping skips tilde and indented code fences #22112 asked to fix. If the owner wants it closed, it is a follow-up, not this PR.

@buluoray
buluoray marked this pull request as ready for review October 21, 2026 20:01
@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners October 21, 2026 20:01
@buluoray
buluoray requested a review from mbriones98 October 21, 2026 20:01
@buluoray
buluoray enabled auto-merge (squash) October 21, 2026 20:01
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 21, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HOLD

Two issues need fixing before merge.

  1. The new fence scanner can fail open. In valid GitHub Markdown list and HTML cases, it treats rendered prose as an unclosed code block and removes it. A body over the limit can then pass with only a few counted words. Please count an ambiguous unclosed fence as prose instead of stripping it.
  2. _FENCE_OPEN has exponential backtracking. A roughly 70-character marker line can hold --check-body for several seconds. Please make the repeated groups possessive or replace the expression with a linear parser, then add a bounded-time regression test.

Please also add tests that make the backtick-info and closing-indent mutations fail.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: passed Eligible automated validation passed for the current revision labels Oct 21, 2026
@buluoray
buluoray force-pushed the fix/check-body-fences-22112 branch from e21a498 to 34dd854 Compare October 22, 2026 12:07
@buluoray

Copy link
Copy Markdown
Contributor Author

🤖 Kiro Crew Auto-Pipeline [operator: buluoray#ce473fca]: @bolichen97 thanks, both points held. Head is now 34dd854953 (rebased onto main, still two commits).

1. Unclosed fence fails open: fixed. Confirmed at e21a498e51: a <details> line followed by a ``` line, or a list-item fence that never closes, removed every later line in the section, so a 50-word body passed a 40-word limit. _strip_fences now holds a block's lines until it sees the closer. A block that ends with its list item or with the section is put back, opener included, and counted as prose. Tests: test_an_unclosed_fence_counts_as_prose_so_a_long_body_fails (html-details, html-div, list-backtick, list-tilde, each asserting exit 21) and the updated test_list_fences_nest_and_end_with_their_item. Removing the end-of-section put-back fails 7 cases; removing the list-item put-back fails 2.

2. _FENCE_OPEN backtracking: fixed. Measured at e21a498e51: "- " * n + "x" took 1.2 s at 57 characters, 10.7 s at 65 and 96 s at 73. The list-prefix group and its quantifiers are now possessive (*+, {1,4}+, ...; Python 3.12 is the floor). test_a_long_list_marker_line_is_scanned_in_linear_time uses conftest.assert_rejected_without_backtracking, which ramps the pump one unit at a time on thread CPU, as testing-conventions.md asks, so the regression fails the test instead of hanging it. Putting the old expression back fails that test (8 s for the whole file).

Mutations you asked for: both now fail.

  • Dropping the backtick info-string lookahead (?=[^]*$)failstest_a_backtick_in_the_info_string_is_not_an_opener (```` ```ab ```` must stay prose, so a later fence line cannot hide two rows).
  • Dropping the closer's item indent (^ {%d}) fails test_a_deep_list_closer_must_reach_the_item_content_indent and test_list_fences_nest_and_end_with_their_item.

Each mutation was applied alone and restored. With the fix, test/test_prepare_pr_diff_signals.py passes 60 of 60, three runs. The PR body's table, tests and decision section are updated to the fail-closed rule.

@buluoray
buluoray requested a review from bolichen97 October 22, 2026 12:07
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 22, 2026
@buluoray

buluoray commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Kiro Crew Auto-Pipeline [operator: buluoray#ce473fca]: disposition for the two downgraded GPT 6.1 findings on 34dd854953. Both are fixed at db00cdc39d.

  • F1, a closed ~~~ pair inside a <div> block: fixed. No fence opens inside an HTML block, a run from a line starting with < (after any list markers) to the next blank line, or to a raw block's end marker (</pre>, -->, ...). Tests: test_a_closed_fence_pair_inside_html_is_counted (div, list-div, pre-past-blank) and test_a_fence_after_an_html_block_ends_still_strips.
  • F2, a tab-indented line inside a list fence: fixed. Indent is measured with tabs expanded to four-column stops. Test: test_a_tab_indented_line_stays_inside_its_list_fence.

A third case in the same class turned up while probing: a fence on a list item's continuation line, followed by text after the item. markdown-it-py in CommonMark mode renders that text as a paragraph, and the scanner hid it. Rather than patch more cases, the scanner now follows one fail-closed rule: when unsure, count it as prose. A non-blank line left of the opener's fence column ends the block unclosed, and an unclosed block is counted. Test: test_a_line_left_of_the_fence_ends_it_and_is_counted.

This overcounts one valid form: a fence indented one to three spaces whose content starts at column 0. CommonMark renders that as code. test_an_indented_fence_with_column_zero_content_is_counted pins it, and the PR body names it. Overcounting only makes the length gate stricter.

Each fix was reverted alone and restored. Every revert fails the named tests; the full table is in the PR body. With the fixes, test/test_prepare_pr_diff_signals.py passes 67 of 67, three runs.

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to ship. Head reviewed: 34dd854.

My earlier change request is resolved on this head: an unclosed fence is now counted as prose, the list prefix in the opener is possessive with a linear time regression test, and new tests fail if the info string lookahead or the closer item indent is removed. I ran the test file locally on this head (60 passed) and timed the opener on a 64000 character marker line (about 1.5 ms).

One advisory, not blocking: a tab indented line inside a list item fence still ends the item early, so a later fence line can hide prose. I reproduced the GPT lane case: 60 words are counted with spaces, 5 with a tab. Expanding tabs before measuring the indent fixes it and keeps every test green. Details inline.

Verified: the linked issue is tier T1, no security path is touched, base is main, and no AI lane has a blocking finding on this head. Every CI check on this head is green after the shard 1 rerun (the first attempt failed on an unrelated test that passes locally). Remaining before approval: PR Readiness is still evaluating this head; I will approve once it reports passed.

width = 0
for line in text.splitlines():
if close is not None:
if line.strip() and len(line) - len(line.lstrip(" ")) < width:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 A tab indent ends a list item fence early, so a later fence can hide prose

The item end test counts only leading spaces. A list item fence whose content is indented with a tab measures as indent 0, so the item ends unclosed on that line. The real closer two lines down is then read as a new top level opener and swallows everything up to the next fence line. This is the one case left where an ambiguous body still passes instead of failing closed.

if line.strip() and len(line) - len(line.lstrip(" ")) < width:

Why it matters: with - ~~~, a tab indented code line, ~~~, then 60 words of prose and a later ~~~ example, what_changed_prose counts 5 words instead of 60, so an over limit body passes --check-body.

Suggestion: expand tabs once at the top of the loop, line = line.expandtabs(4), so the indent test and the closer regex both see columns. With that line added the case counts 60 words and the test file still passes (60 passed). A parametrized case with a tab indented item line would pin it.

@bolichen97
bolichen97 dismissed their stale review October 22, 2026 13:29

Our earlier findings are addressed at the current head; see the latest review.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 22, 2026
… their indent

A list-item fence closes only at the item's content indent. When unsure, the
scanner counts the block as prose instead of stripping it, since stripping
rendered prose lets an over-limit body pass --check-body:

- a fence that never meets its closer is counted, opener included;
- a non-blank line left of the opener's fence column ends the block unclosed,
  which covers a fence on a list item's continuation line followed by text
  after the item;
- no fence opens inside an HTML block (a line starting with "<" after any list
  markers, to the next blank line or a raw block's end marker);
- indent is measured with tabs expanded to four-column stops.

This overcounts one valid form: a fence indented one to three spaces whose
content starts at column 0.

The list-prefix quantifiers are possessive. A marker's trailing spaces and the
next marker's indent share the space character, so a 65-character
"-   -   ..." line took about 10 s to reject; the guard ramps that pump.
@buluoray
buluoray force-pushed the fix/check-body-fences-22112 branch from 34dd854 to db00cdc Compare October 22, 2026 13:31
@buluoray
buluoray requested a review from bolichen97 October 22, 2026 13:31
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision labels Oct 22, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to ship. Head reviewed: db00cdc.

The tab indent point from my last review is fixed on this head. Lines are now measured with tabs expanded to four column stops, and test_a_tab_indented_line_stays_inside_its_list_fence pins it. I ran that case against the old and new code: the previous head counted 5 words, this head counts all 50.

Also checked: the module test file passes locally (67 passed), and the new rule that ends a block at a line left of the fence column, plus the HTML block guard, only ever count more than before, never less.

One remaining check before approval: the readiness label and PR Readiness are still pending on this head, with backend test shards running. I will come back once they finish.

@buluoray
buluoray disabled auto-merge October 22, 2026 14:27
@buluoray
buluoray marked this pull request as draft October 22, 2026 14:27
@buluoray

Copy link
Copy Markdown
Contributor Author

🤖 Kiro Crew Auto-Pipeline [operator: buluoray#ce473fca]: parking this PR. It is not merged, auto-merge is off, and it is back in draft at db00cdc39d.

Why. Each review round found a new body that --check-body under-counts: text GitHub renders as prose is stripped as code, so an over-limit body passes. Four such cases so far:

# input in ## What changed words counted status at db00cdc39d
1 <details> then an unclosed ```, then text rest of section dropped fixed: an unclosed fence is counted
2 <div>, ~~~, 60 words, ~~~, </div> 1 of 61 fixed: no fence opens in an HTML block
3 - ~~~, a tab-indented line, ~~~, blank, 60 words, then a ~~~ pair 0 of 60 fixed: tabs expand to four-column stops
4 x/y.py changes., 2. ~~~, 60 words indented 3 spaces, ~~~, ~~~ 3 of 63 open

A case found while probing between 2 and 4 is also fixed: - a, blank, ```` ``` ````, code, blank, 60 words, then a ```` ``` ```` pair. It is covered by rule B: a non-blank line left of the opener's fence column ends the block unclosed, and an unclosed block is counted. Rule B, the HTML-block rule and the tab rule are in at db00cdc`. Each has a test that fails when the fix is reverted; the table is in the PR body.

Case 4 renders as one paragraph in CommonMark, because a list starting at a number other than 1 cannot interrupt a paragraph. The scanner reads 2. ~~~ as a list fence.

Root cause. A line scanner cannot know CommonMark's paragraph or list-container state, and each new case is another spelling of that gap. Another patch for case 4 would be the fifth of these, so none will be made.

Next step. Replace the scanner with a real block parser: a stdlib port of the CommonMark block phase, or a vendored parser. The script runs in user repos and is stdlib-only today, so it should not gain a pip dependency.

@buluoray

Copy link
Copy Markdown
Contributor Author

🤖 Kiro Crew Auto-Pipeline [operator: buluoray#ce473fca]: @bolichen97 an update on your HOLD: this PR is now parked, not merged. Auto-merge is off and it is back in draft. Both of your points are fixed at db00cdc39d, but a fourth fail-open case turned up, so the scanner needs a real block parser rather than more patches. Details: #22848 (comment)

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 24, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

Thanks for this, @buluoray. The fix landed on main another way: #22961 (merge commit 5a48314) makes --check-body strip ~~~ fences and backtick fences indented up to three spaces before counting, and issue #22112 is closed as completed. This draft was parked on 10-22, so closing it as superseded.

@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

prepare-pr: --check-body fence stripping skips tilde and indented code fences

3 participants