Repository navigation
fix(repo): preserve physical Markdown claim line numbers - #705
Conversation
Signed-off-by: Mangesh Raut <95149253+mangeshraut712@users.noreply.github.com>
Signed-off-by: Mangesh Raut <95149253+mangeshraut712@users.noreply.github.com>
|
OpenCodeReview: Commit e68d4a5 was not reviewed. This PR has reached its review limit (6 reviews). CI at To review this commit: re-request review from exai-bot in the Reviewers list. <details><summary>Last review (ff93e26): no findings</summary> Open threads from the bot: 0 </details> |
vlad-perevezentsev
left a comment
There was a problem hiding this comment.
LGTM
I checked 790da66. The fix is right: Markdown claims are now numbered by \n, \r\n and \r only, so a U+2028 (or \f, \x85, ...) no longer moves the links, spans and fences after it one line down, and no longer opens or closes a fence in the middle of a line.
Merge: safe now: it merges cleanly into current main, 0 commits behind. No open PR conflicts with it or shares its commits.
What I ran, at 790da66:
make ci-local --offline: 0 failed, 21 passed, 19 skipped (network and matrix jobs).tests/test_repo_l0_markdown_lines.pyon the merge-base: 12 of 15 cases fail, the 3 that pass are the trailing-blank-line fence cases, which guard the old behaviour.
Checked, no issues
- Callers: fence lines go on to
logical_lines, the dedent incore.pyand the Starlark and type checks, which all join with\nand count\n, so their line numbers stay in step with the new split. - End of file: dropping only the last empty piece keeps the old
splitlines()result for a trailing newline, and a fence keeps its blank last line. - Interval tests: the second commit only loosens two exact pins to one ulp and to the side of 0, which BLAS rounding can move; the new mocked test still checks that the row's own p places 0.
- Changelog: a
Fixedfragment; claim line numbers change only for files with these characters.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #705 +/- ##
==========================================
+ Coverage 95.79% 95.90% +0.10%
==========================================
Files 432 448 +16
Lines 57209 59394 +2185
Branches 9858 10238 +380
==========================================
+ Hits 54803 56959 +2156
- Misses 1495 1510 +15
- Partials 911 925 +14
🚀 New features to boost your workflow:
|
|
Thanks for the review. Current head |
napetrov
left a comment
There was a problem hiding this comment.
Change class: not computed (no receipt profile for this repo, or receipt.py failed)
Verdict: one blocking finding (fence and refdef matching regression, markdown.py:50 thread). Two questions. Not approving.
Provenance: the blocking finding is probed on both trees (base and head). Questions are read or probed as marked in the threads.
Raised before: the LGTM from vlad-perevezentsev checked the numbering, not the fence-close path, so the blocking item is not raised there.
Coverage: plain and edge passes on head 022e331; probes on base and head for the fence, refdef, span and info-string cases. Not run: the full suite (regex and scipy missing in my env; markdown tests 15/15 on head, 12 fail on base as expected), mypy, and the 7 interval tests (scipy stub fails on both trees).
Signed-off-by: Mangesh Raut <95149253+mangeshraut712@users.noreply.github.com>
…ical-lines Signed-off-by: Mangesh Raut <95149253+mangeshraut712@users.noreply.github.com>
antonwolfy
left a comment
There was a problem hiding this comment.
LGTM. The fix at 95fef45 is right: claims are numbered by physical \n, \r\n and \r only, while fence, span and reference-definition matching still runs on the universal line boundaries, so it matches the old behaviour except for the numbers. That closes the regression @napetrov found at 022e331.
What I ran, on a Linux review host at 95fef45:
make ci-local: 32 passed, 0 failed, 14 skipped (docker, network and matrix jobs); changed-line coverage passed.- A differential fuzz of
split()against the base: 300,000 random texts mixing fences, spans, links, reference definitions and all the separators, plus 50,000 texts with only\n,\r\nand\r. Everything except line numbers was identical to the base, and the numbers matched an independent count of physical newlines. For\n-family-only text the output was identical to the base, numbers included. - 14 mutants of the new code against the new tests (always or never incrementing,
\n-only, double count on\r\n, increment before use, splitting on\nonly, and others): 12 are killed; the survivors are an equivalent mutant and one that changes only trailing whitespace of a line. - 16 mutants of the sign-flip interval (
TOL,himoved by 1e-6 to 2 ulp,lomoved, the 1e-4 floor dropped or zeroed) against the changedtest_repo_compare_interval.py: all are killed, as by the base tests.
Checked, no issues
- Interval tests: the exact
lopin now lives in the caller test with a stubbedShiftTest.p, so it does not depend on BLAS; the newhicheck pins a real step point ofp. - Sign-offs: all three non-merge commits carry
Signed-off-by. - Changelog: a
Fixedfragment is present.
|
I approved this at
|
napetrov
left a comment
There was a problem hiding this comment.
Change class: not computed (no receipt profile for this repo, or receipt.py failed)
Re-review at 95fef45: the earlier blocking (fence and refdef matching) is fixed on head. No new findings.
Still there from my earlier question on markdown.py:53: a U+2028 inside a fence info string still drops the language. The new test asserts "", so the test pins that behaviour; it is pre-existing and can be a follow-up.
Approval held: CI is pending (Intel CI, agent-quality, ci and cli-interface await approval), and the interval-test question on test_repo_compare_interval.py has no answer yet.
Coverage: plain and edge passes; the markdown tests pass on head; the interval tests were not run (no scipy here).
vchamarthi
left a comment
There was a problem hiding this comment.
Reviewed 95fef45: Not approved yet: waiting on napetrov's open thread; 1 unverified behaviour. Nothing to fix in the code.
Blocking
- Open question, not answered: thread by @napetrov – The new
hicheck passes on95fef45and pins the end to one step ofp;lois pinned only in the callers test through a stubbedShiftTest.p, and the row test checks only the sign ofloon real deltas. For @mangeshraut712. - Not verified: The description says the interval tests verify numerical stability across BLAS backends. Reword that sentence to say what the tests stub, or add a test that runs the interval under a second backend.
Follow-ups, not blocking
dokimi/dokimi/repos/l0/markdown.py:54– Input: a fence opener of three backticks, U+2028, thenbash, followed bymake alland a closing fence (main has it too).dokimi/dokimi/task_formats/source.py:142– Input: one valid JSONL row with U+2028 inside a string,{"a": "x<U+2028>y"}(main has it too).
Verified on 95fef45: 10 checks pass
| Area | What holds | How |
|---|---|---|
| Claim line numbers | Claims after U+2028, U+2029, U+0085, \v, \f, \x1c-\x1e take their physical line: all 8 cases of test_unicode_separators_do_not_shift_markdown_claims pass on 95fef45 |
tests on the head |
| Claim line numbers | The same 8 cases of test_unicode_separators_do_not_shift_markdown_claims fail on main, so they pin the change |
same tests on main |
| Fence and reference matching | A closing fence followed by U+2028 closes, and [docs](missing.md) on the line after it is checked on line 4; a reference definition followed by U+2028 is still a link |
ran it |
| Counting mutant | Counting every chunk as a line (next_line += 1) fails the changed Markdown tests, so they pin the physical count |
broke the code, tests caught it |
| Cr and crlf endings | The \r and \r\n cases of test_fences_keep_physical_newlines_and_trailing_blank_line and test_scan_keeps_physical_line_numbers_after_unicode_separator pass on 95fef45: a fence and a claim after a separator keep their physical lines in files ending lines with \r or \r\n |
tests on the head |
| End of file | Intro<U+2028>[a](missing.md) with no final newline gives the link on line 1 |
ran it |
| Interval ends | test_an_end_is_bounded_at_deltas_too_large_to_move_by_one passes on 95fef45: lo is 1e16, hi is within one ulp of 2e16, and test.p(hi) >= ALPHA > test.p(nextafter(hi)) holds for the real ShiftTest |
tests on the head |
| Interval backend case | test_the_callers_p_places_zero_when_the_backend_disagrees passes on 95fef45 with ShiftTest.p stubbed: lo is 0.0 or 1e-4 as the row's p is above or below 0.05, and hi is 1.5 |
tests on the head |
| Merge | The PR merges onto current main with no conflict | merge onto main |
| Full suite | The full suite on 95fef45 merged with main passes: 21755 passed, 0 failed |
full suite, main merged in |
|
Thanks @vchamarthi for the thorough re-review! The PR description has been aligned to specify exactly what the tests stub ( |
vlad-perevezentsev
left a comment
There was a problem hiding this comment.
Review at 95fef45. The code is right now: 3b1cb2b matches fences, spans and reference definitions as main does and changes only the claim line numbers. My first-round LGTM missed the fence-close and refdef regression that @napetrov found; it is fixed. What is left is the description, in the line comment.
Agreed with @napetrov on the interval-test question: the author's answer holds, lo is pinned exactly in the stubbed test and hi to one step of the real p.
What I ran, at 95fef45:
make ci-local --offline: 1 failed, 20 passed, 20 skipped. The failure isschema_compatagainst a stale localmain: it reports schema files this PR does not touch.
Checked, no issues
- Counting: a line number moves on only at
\r,\nor\r\n(a\r\nchunk ends in\n, so it counts once). A last line without a newline keeps its number. - Callers: the fence lines keep one entry per logical piece, so
logical_linesand the Starlark check index them as before.
vlad-perevezentsev
left a comment
There was a problem hiding this comment.
LGTM
I checked f5a8db6. Since my last round only main was merged in; the description now says that fence, span and reference-definition matching is the same as on main and only claim line numbers move, which is what the code does.
Merge: safe now: it merges cleanly into current main, 5 commits behind, and main has not changed its files since. Once it is in, #867 conflicts with it in tests/test_repo_compare_interval.py and needs a rebase.
What I ran, at f5a8db6:
make ci-local --offline: 1 failed, 22 passed, 20 skipped. The failure isschema_compatagainst a stale localmain: it reports schema files this PR does not touch.
vchamarthi
left a comment
There was a problem hiding this comment.
🟡 Not approved yet · re-reviewed f5a8db6
Next: @mangeshraut712: answer 1 open thread from napetrov and settle 2 open questions (below).
Blocking
- Open question, not answered: thread by @napetrov – The row test
test_the_row_p_places_zero_where_large_deltas_round_p_at_zero_apartno longer asserts the row'slo, only that zero is inside exactly whenpis at least 0.05 (dokimi/tests/test_repo_compare_interval.py:140); the exact ends are asserted only withShiftTest.pstubbed (:144-150). - Open question for @mangeshraut712: Which line split the Markdown claim numbers use. State in the PR description which split the claim numbers use and why it differs from
rule_frontmatter.py, or change the count inmarkdown.py:51-53to match the reader. - Open question for @mangeshraut712: The description's Testing section counts
10,000 deterministic comparisons verified. Name the test or the run the count came from, or drop the count from the description.
Verified on f5a8db6: ✅ changed tests: 72 passed, fail on main · ❌ full suite on the head fails at ci.yml:static / schema_compat vs the PR base ·
7 checks behind it, each with its evidence
| Area | What holds | How |
|---|---|---|
| Claim line numbers | A claim after each of the eight separators keeps its physical line: Intro<sep>[a](missing.md) gives line 1 on the head for U+2028, U+2029, U+0085, \v, \f, \x1c, \x1d and \x1e, where main gives 2 |
ran it, edge input (text) |
| Matching unchanged | A link after a closing fence with U+2028 still gets checked on the head, as on main: the link missing.md is in the result |
ran it, edge input (text) |
| Empty input | Empty text and whitespace-only text give no links, spans or fences on the head | ran it, edge input (text) |
| Line endings and long lines | A non-ASCII line, CRLF and CR endings, and a line of 100,000 characters keep the claim on line 2 on the head | ran it, edge input (text) |
| Line counting | Counting every chunk as a line (next_line += 1) fails 45 of the 72 tests in the two changed test files, so the tests pin the physical count |
broke the code, tests caught it, edge input (text) |
| Line counting | Not counting a CR ending (chunk.endswith(("\n",))) fails 10 of the 72 tests in the two changed test files |
broke the code, tests caught it, edge input (text) |
| Line counting | Counting U+2028 as an ending (chr(0x2028) added to the tuple) fails 10 of the 72 tests in the two changed test files |
broke the code, tests caught it, edge input (text) |
napetrov
left a comment
There was a problem hiding this comment.
Change class: not computed (no receipt profile for this repo, or receipt.py failed)
Verdict: comment, 0 blocking. Re-review at f5a8db6: only main was merged in; the PR files are unchanged since 95fef45, so there is nothing new to find. Both of our earlier questions are answered, so approval is no longer held by us.
Coverage: PR files only; the main merge's 231 files not reviewed; interval tests read, not run (no scipy).
…ysical-lines Signed-off-by: Mangesh Raut <95149253+mangeshraut712@users.noreply.github.com>
|
Thanks @vchamarthi and @napetrov for the re-review! Pushed
All three answered review threads are now resolved, and CI + OpenCodeReview (0 findings) are green on |
vchamarthi
left a comment
There was a problem hiding this comment.
🔴 Changes needed: 3 earlier findings still fail · re-reviewed c08cade
Next: @mangeshraut712: fix the 3 earlier findings below; then push for a re-review.
Blocking
- Still fails: earlier finding –
Intro<U+2028>[a](missing.md)now gives line 1 on the head where main gives 2, and the description states the split. - Still fails: earlier finding – The description no longer states the 10,000 count; the changed test file collects 48 cases on the head.
- Still fails: earlier finding – The description no longer names BLAS backends; the interval row test it would have named passes on the head.
Verified on c08cade: ✅ changed tests: 48 passed, fail on main · ✅ full suite with main merged in: 23248 passed · ✅ merges onto main · 2 mutations tried · 7 edge inputs tried
14 checks behind it, each with its evidence
| Area | What holds | How |
|---|---|---|
| Leading separator | A leading U+2028, U+2029, U+0085, \v, \f, \x1c, \x1d or \x1e before [a](m.md) leaves the link on line 1 on the head; main gives line 2 |
ran it, edge input (line separator) |
| Span after separator | A code span after U+2028 in non-ASCII text (ß with a combining mark) keeps its physical line: src/x.py is on line 1 on the head and on line 2 on main |
ran it, edge input (text) |
| Empty and blank text | Empty text, and text of spaces, tabs, line breaks and U+2028 only, gives no links, spans or fences on the head and on main | ran it, edge input (text) |
| Crlf and cr files | A file with CRLF endings keeps m.md on line 2 and n.md on line 3; a file with CR endings keeps o.md on line 2. Head and main agree |
ran it, edge input (text) |
| Non-utf-8 bytes | A file with bytes that are not UTF-8 is read with replacement characters, and the link after them stays on line 2 on the head and on main | ran it, edge input (text) |
| Long line | A line of 100000 characters keeps a claim on line 2 after a line feed and on line 1 after U+2028; main gives line 2 after U+2028 | ran it, edge input (text) |
| Matching across separators | A closing fence followed by U+2028, a reference definition followed by U+2028, and a span across U+2028 match as on main: missing.md and other.md are found, and the span is not matched |
ran it, edge input (text) |
| Claim counting | Counting every chunk as a line (next_line += 1) fails 45 of the 48 cases in tests/test_repo_l0_markdown_lines.py, so the tests pin the physical count |
broke the code, tests caught it |
| Line ending count | Counting only \n as a line ending (chunk.endswith(("\n",))) fails 10 of the 48 cases in tests/test_repo_l0_markdown_lines.py |
broke the code, tests caught it |
| Changed tests | The 48 cases of tests/test_repo_l0_markdown_lines.py pass on the head. They pin the physical line of a claim after U+2028, U+2029, U+0085, \v, \f, \x1c-\x1e, and the matching of fences, spans and reference definitions |
tests on the head |
| Changed tests on main | 45 of the 48 cases fail on main |
same tests on main |
| Merge | The head merges onto current main with no conflict |
merge onto main |
| Full test run | The full test run with main merged in passes: 23248 passed, 0 failed |
full suite, main merged in |
| Rule frontmatter | test_a_line_break_character_in_rule_frontmatter_counts_as_a_line, which the description cites for rule_frontmatter.py, passes on the head and on main |
ran it |
vlad-perevezentsev
left a comment
There was a problem hiding this comment.
LGTM
I checked c08cade. Only main was merged in: tests/test_repo_compare_interval.py is now main's (#867), so the PR is the Markdown fix alone, and markdown.py and its tests are unchanged since my last round.
Merge: safe now: it merges cleanly into current main, 26 commits behind, and its tests pass on the merge. No open PR conflicts with it or shares its commits.
Disagreed with @vchamarthi on the three blocking points of the review at c08cade: a link after U+2028 on line 1 is the fix itself (it is on physical line 1), and the description no longer naming the case count or BLAS settles those two earlier points rather than failing them.
What I ran, at c08cade:
make ci-local --offline: 1 failed, 24 passed, 20 skipped. The failure isschema_compatagainst a stale localmain: it reports schema files this PR does not touch.- On the merge with current
main:tests/test_repo_l0_markdown_lines.pyandtests/test_repo_l0.py, 296 passed.
A U+2028 inside a Python fence splits the code the type checker reads, so fence.line + code line moved the claim down; map the code line through fence.lines, which carries physical line numbers. Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
|
Checked at c08cade merged with main 32a39f0 (Python 3.13): 45 of the 48 new cases fail on main and all 48 pass on the merge; the link, CRLF and CR examples give the physical lines the description claims. Full suite, ruff, mypy, bandit -ll and One case the head still numbered the old way, so I pushed ff93e26 on top:
|
|
@napetrov, could you take another look? Your review from 2026-11-13 (on 022e331) still shows as changes requested, so the PR is blocked, although your 2026-11-18 comment says you no longer hold it. Since then the fence/refdef point is fixed, the info-string U+2028 case is left as the follow-up you agreed to, and ff93e26 covers the Python-fence claim line after a U+2028. CI is green on ff93e26 and the PR has two approvals there. If it looks good to you, please dismiss or update your review and merge. |
antonwolfy
left a comment
There was a problem hiding this comment.
LGTM. The new commit ff93e26 is right: a Python fence error is now claimed on the physical line of the code line the type checker reported, so a U+2028 inside the fence no longer moves it down. One nit on the test.
What I ran, on a Linux review host at ff93e26:
make ci-local: 35 passed, 1 failed, 14 skipped; 22,912 tests; changed-line coverage 100%. The failure istests/test_repo_batch_lifecycle.py::test_ctrl_c_makes_the_repo_run_process_exit_nonzero, a Ctrl-C timing test (it saw one extra run,r3) in a file this PR does not touch; the file passes alone (14 passed).test_a_python_fence_error_is_claimed_on_its_physical_lineagainst the basetypecheck.py: the(3, 5)case fails (claim on line 6), so it pins the fix. The(0, 3)case passes on the base too, as it should.- The mutation step reports 9 mutants on the changed lines, 7 killed and 2 survived, both at
typecheck.py:138(see the inline comment). - The sign-off check: all four non-merge commits carry
Signed-off-by.
Checked, no issues
- Mapping: the code the checker reads is
"\n".joinof the texts infence.lines, dedent keeps the line count, so code line N isfence.lines[N-1]. Without a separator it equalsfence.line + N, as before. - Other users of
fence.line +: none left indokimi/dokimi/repos/l0/;adapters.pyandcore.pyalready indexfence.lines. - Changelog: the
Fixedfragment covers the fenced-code claim lines.
Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
antonwolfy
left a comment
There was a problem hiding this comment.
LGTM. I pushed a commit per nit, up to e68d4a5, which fix the nit from my review:
e68d4a5:dokimi/tests/test_repo_l0_markdown_lines.py:84: added the suggested test after the separator on the opening line, plus an out-of-range case (3, 4) so thefence.line - linemutant also fails.
make ci-local at e68d4a5: 0 failed, 36 passed, 14 skipped.
vchamarthi
left a comment
There was a problem hiding this comment.
🟢 Approved · re-reviewed e68d4a5
Next: nothing required from @mangeshraut712.
Verified on e68d4a5: ✅ changed tests: 53 passed, fail on main · ✅ full suite with main merged in: 24212 passed · ✅ merges onto main · ✅ 1 broken variant of the changed code: 1 caught by the tests · 1 mutation tried · 1 edge input tried
4 checks behind it, each with its evidence
| Area | What holds | How |
|---|---|---|
| Fence error line | 0 < line in _claims is pinned: changing it to 1 < line fails test_code_after_a_separator_on_the_opening_line_is_claimed_on_that_line[1-1] |
broke the code, tests caught it, edge input (text) |
| Fence error line | Dropping the scan.add call in _claims fails the changed tests |
tests on the head |
| Markdown line tests | The changed test_repo_l0_markdown_lines.py passes on the head (53 cases) and the separator cases fail on main |
same tests on main |
| Merge | The PR merges onto main without conflict | merge onto main |
Summary
Fixes #686. Markdown claims now use physical source line numbers (
\n,\r,\r\n) when text contains non-physical Unicode line breaks/separators. Matching of fences, inline spans, and reference definitions is unchanged frommain; only the reported claim line numbers move to reflect physical lines.Changes
text.splitlines(keepends=True)so matching behavior for fences, inline spans, and reference definitions stays identical tomain.dokimi/repos/l0/markdown.pyonly on physical line endings (chunk.endswith(("\r", "\n")), covering\n,\r, and\r\nper CommonMark §2.1 and editor / GitHub#L<n>line numbers), rather than incrementing on the 8 non-physical Unicodestr.splitlines()separators (\u2028,\u2029,\x85,\v,\f,\x1c,\x1d,\x1e).rule_frontmatter.py:rule_frontmatter.blank_frontmatterintentionally usesstr.splitlines(keepends=True)soU+2028and other universal breaks inside.claude/rulesfrontmatter cannot hide rule text or leave an unclosed code fence bleeding into the body (test_a_line_break_character_in_rule_frontmatter_counts_as_a_line), while preserving every original break character (\n,\r,\r\n,U+2028, etc.) verbatim in the emptied prefix. Whenmarkdown.splitsubsequently counts only\r/\n/\r\n, body claims still receive their exact physical editor line numbers without relaxing frontmatter stripping.dokimi/tests/test_repo_l0_markdown_lines.pyacross all 8 Unicode separators (\u2028,\u2029,\x85,\v,\f,\x1c,\x1d,\x1e) and all 3 physical line endings (\n,\r\n,\r) confirming claim line numbers track physical lines while fence, span, and reference-definition matching stay unchanged frommain.main(4ef41e70, including#867), keepingdokimi/tests/test_repo_compare_interval.pyidentical tomain(zero diff outside#686).Risk
The production change is confined to physical newline counting in
dokimi/repos/l0/markdown.py. Matching behavior for fences, spans, and reference definitions is preserved identically tomain. No stored schema or CLI interface changes (python -m dokimi.schema_compat --base upstream/mainreportsOK).Testing
Validated on head
c08caded7c8b04f188f8390db6c6d72da9238862:pytest tests/test_repo_l0_markdown_lines.py: 48 passed.pytest tests/test_repo_l0.py tests/test_repo_l0_local_action.py tests/test_repo_scan_loaded.py: 282 passed.python -m dokimi.schema_compat --base upstream/main:OK.Revert
Revert the Markdown line-counter change in
dokimi/repos/l0/markdown.pyanddokimi/tests/test_repo_l0_markdown_lines.py. No persisted-data migration is needed.Checklist