Skip to content

fix(memory): a code span before an angle destination is not whitespace to the link check (#1343) - #1436

Merged
antonwolfy merged 8 commits into
intel:mainfrom
antonwolfy:fix/angle-link-blanked-span
Dec 1, 2026
Merged

antonwolfy merged 8 commits into
intel:mainfrom
antonwolfy:fix/angle-link-blanked-span

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The memory lint read the line with every blanked code span turned into spaces, and the angle-link pattern allows spaces between ]( and <, so a span before < made the line look like a link. On main:

Input Output on main Now
_blank_inline("[x]( a<yb>)", False) [x]( <y b>) [x]( <y >)
prose_lines("[x]( a\n<y b>)") ['[x]( ', '<y b>)'] ['[x]( ', '<y >)']
prose_lines("[x]( a<y z>)\nfoo bar") ['[x]( <y z>)', 'foo bar'] ['[x]( <y ', ' bar']
MemoryStore.index_targets() of an index [x]( a<yb>) [(1, 'y b', True)] on main; [(1, 'y ', True)] on this PR's first head []

In each, a is the destination and <y is no title, so the line is no link and the spans are code. The first row is the issue. The other two are the same read in the unpaired-run check at the end of _blank_inline and in the paragraph above a line.

The fix reads the angle link on a text where a blanked span is a filler character (\x00, one per column), not a space; the lines the lint returns stay blanked with spaces. The issue's other option (refuse a link whose blanks hide a span) is equivalent but needs a second pass, so it was not taken. The filler is not whitespace, bracket, parenthesis, quote, backtick or angle bracket, so it changes nothing _has_opener, _ANGLE_LINK or _BLANKS decide except the one wanted: it is no blank before <.

Closes #1343

Changes

  • dokimi/dokimi/memory/store.py: _BlankedLine._so_far (the text the angle-link check reads) fills a blanked range with _FILL; _BlankedLine.text takes a fill; _unpaired_run takes the line to read links on, which _blank_inline builds with the filler; _blank_blocks keeps a parallel list of its lines with spans filled, which is the paragraph above a line (_paragraph_above is unchanged). A line blanked whole by a fence, a comment or indented code keeps its spaces there, as Markdown starts a block of its own at it.
  • dokimi/tests/test_blank_inline.py: a test per input above, and the unchanged cases ([x]( <y b>), [x]( a <y b>), [x](<a b>), with a title, the destination on the next line, a span in the link label). The reference scan _rebuilding reads links on the filled line too.
  • Two cases of test_a_link_that_matches_only_once_a_code_span_is_blanked_still_holds_its_spans pinned the old output: [x](a<a>) was [x]( <a>) and [x](a <a>) b`` was [x]( <a`>) `. They now assert both spans blanked: `x` and `x `. The third case, `[x](<`<` `a`>)`, is unchanged.
  • dokimi/dokimi/memory/store.py: _blank_blocks returns the filled lines beside the blanked ones (prose_lines returns the blanked ones, spaces only), and MemoryStore.index_targets() matches _MD_LINK on the filled text, so a blanked span is not a space that ends a bare destination there either. The target is cut from the raw line, so a span inside a bare destination ([x](abc)) stays as written.
  • dokimi/tests/test_blank_inline.py: index_targets() is tested directly on the inputs above (and the destination on the next line, a bare destination holding a span, a real angle link), and _blank_blocks keeps one filled line per line of the text.
  • dokimi/dokimi/memory/store.py: index_targets() keeps a match on the filled text only when _MD_LINK also matches the raw text at the same offset, and reports the raw match's destination. The filled text reads a span as text, but its backticks and parentheses are plain characters of a destination: [x](foo(bar) and [x]((a) are no link (the parenthesis is never closed), and [x](a(b)c) is one with the destination a(b)c. test_index_targets_reject_a_link_whose_destination_follows_a_code_span gains these three cases.
  • Changelog fragment (Fixed).

Risk

The memory lint reads fewer links: a line such as [x]( a<yb>) is no link, so the backtick after <y opens a span as CommonMark reads it, which can blank more text on the line and the line below. Real angle links (a backtick in the destination, with or without a title, the destination on the next line) and a span in the link label are read as before. The returned lines keep their columns and spaces.

MemoryStore.index_targets() (and so index_links() and the memory lint's broken-link check) also reads fewer links: the same line gives no target, and a span inside a bare destination, [x](abc), is part of the target abc; a destination whose parentheses do not balance in the raw text ([x](foo(bar)) is no link. main's lazy paragraph above (cache(partial(_paragraph_above, ...))) is merged into this branch and built from the filled lines, not from out, or the line-above case reads spaces again. main is merged into this branch, with #1434's change to store.py and test_blank_inline.py in it: its one conflict, in index_targets, keeps main's link loop (_closing_openers, _merged) and cuts the target from the raw line as this branch does.

Testing

On a Linux review host, at 3015ee57 (on main e1f77404):

  • make ci-local: 38 passed, 0 failed, 16 skipped (steps that need docker, the network, or a PR: external-catalog-smoke, the matrix legs, semgrep, micromamba, the fuzz job). 32020 tests passed, 27 skipped; changed-line coverage 100% (26 lines). The mutation step lists 2 survivors, store.py:209 (filled.extend(out[len(filled):])) and store.py:223 (_fill_blanks's early return).
  • On main's code, the new and changed cases fail on the assertion (5 failed, 8 passed of the 13 selected): e.g. assert '[x]( <y b>)' == '[x]( <y >)'; the unchanged cases pass there. The new index_targets() test fails there on 4 of its 6 cases ([x]( a<yb>), [x]( a\n<y b>), [x]( a <y b>), [x](abc)).
  • Mutants, each failing the new tests: restoring spaces in _so_far fails 3 cases ([x]( a<yb>) and the two changed ones); reading the unpaired-run links on the spaced line fails the foo barcase; passing the spaced paragraph above fails the[x]( a\n<y b>)case; matchingindex_targets()on the blanked lines instead of the filled ones fails 4 of its 6 cases; cutting its target from the matched text instead of the raw line failsx; dropping the final filled.extendin_blank_blocksfails the one-filled-line-per-line test; dropping the raw-text match inindex_targets() fails 3 cases of the direct test ([x](foo(bar), [x]((a), x`), which also fail on the previous head's code.
  • Replacing the filled.extend(out[len(filled):]) in _blank_blocks (store.py:210 at 7c7b682d) with pass fails 3 tests of test_blank_inline.py: a fence above [x](\n<y b>) in the prose_lines test, and a fence or an HTML comment above it in the index_targets() test. index_targets() of [x]( a <y b>)\n\n[x]: missing.md gives [(3, 'missing.md', True)], of [x](abc)\n\n[x]: missing.md gives [(1, 'abc', True), (3, 'missing.md', False)], and of [x](a(b)[y](z)) gives the one target a`(`b)[y](z).
  • Not run: Python 3.11, 3.12 and 3.14 legs, and CI's merge commit.

Open questions

None.

Revert

A plain revert restores the old reading. Nothing is stored.

Checklist

  • Tests added/updated and pytest passes
  • ruff, mypy, and schema checks pass
  • Docs updated (or N/A) — see the docs-drift checklist in CONTRIBUTING.md
  • Self-reviewed per "Before opening a PR" in AGENTS.md
  • Each new raise/exit and test names the doc, contract or issue it traces to
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header (or are exempt in .github/.licenserc.yaml)

…e to the link check (intel#1343)

The link check read the line with every blanked span turned into spaces, and the angle-link pattern allows spaces between `](` and `<`, so `[x]( `a` <y `b`>)` was taken for a link and `b` stayed text, although `a` is the destination and `<y` is no title. The same read was made for the unpaired-run check at the end of the line and for the paragraph above the line.

The link check now reads a text in which a blanked span is a filler character (no space, bracket, parenthesis, quote, backtick or angle bracket), one per column; the lines the lint returns are still blanked with spaces. A line blanked whole by a fence or a comment keeps its spaces in the paragraph above.

Two cases of an existing test that pinned the old output for `[x](`a`<`a`>)` and `[x](`a` <`a`>) `b`` now pin both spans blanked.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy
antonwolfy requested a review from a team as a code owner November 30, 2026 12:47
@antonwolfy antonwolfy self-assigned this Nov 30, 2026
@exai-bot

exai-bot commented Nov 30, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Review complete: 0 finding(s) across 3 selected item(s).

CI at 7c7b682: 21 passing, 4 skipped.

Review limit reached. This PR has had 6 reviews, so it will only be reviewed again when you ask.
To ask: re-request review from exai-bot in the Reviewers list.

Test notes (1)
  • dokimi/dokimi/memory/store.py:229: With if m.start() >= end and live(m.start()) and (link := _MD_LINK.match(raw, m.start())) is not None: changed to if m.start() > end and live(m.start()) and (link := _MD_LINK.match(raw, m.start())) is not None:, the tests still pass: dokimi/tests/test_blank_inline.py. A value exactly at the boundary gives the same result either way here, so no test says which one is meant.
Review details
  • Commit reviewed: 7c7b682 against merge base 10b1a8f
  • Coverage: 3 files in 1 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 162k tokens (93k from cache), 1m14s
  • Tool calls: 11 (6 file_read, 1 ci_log_search, 1 ci_status, 1 code_search, 1 local_check_results, 1 pr_threads)
  • small change set: 3 files

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Mutation of changed lines

⚠️ Tests miss 11 of 80 small breaks of the lines this PR changes, and not every break was tried

At 7c7b682: 69 caught · 11 missed

Each row is a small deliberate break (a mutant) of a line this PR changes that every test reaching that line still passes. Add a test that fails on it or, if it cannot change behaviour, put # mutation-ok[<operator>]: <reason> at the end of the line or alone on the line above.

Where Operator Change no test notices Tests reaching the line
dokimi/dokimi/memory/store.py:227 bump-int 0 → 1 43
dokimi/dokimi/memory/store.py:580 drop-clause "\n" in m.group(1) and not explicit and not _escaped(pair, m.start()) and not _i → ('\n' in m.group(1) and (not _escaped(pair, m.start())) and (not _inline_link_at 19
dokimi/dokimi/memory/store.py:573 drop-clause not inside and not escaped and not text_of_explicit and not _inline_link_at(two, → (not inside and (not escaped) and (not _inline_link_at(two, raw, m.end()))) 35
dokimi/dokimi/memory/store.py:580 drop-clause "\n" in m.group(1) and not explicit and not _escaped(pair, m.start()) and not _i → ('\n' in m.group(1) and (not explicit) and (not _escaped(pair, m.start()))) 19
dokimi/dokimi/memory/store.py:684 return-none False → None 10
dokimi/dokimi/memory/store.py:686 drop-clause bool(link and _links([link], raw)) or _EMPTY_LINK.match(line, end - 1) is not No → (bool(link and _links([link], raw))) 30
dokimi/dokimi/memory/store.py:571 take-branch source[k] + "\n" + source[k + 1] if k + 1 < len(lines) else source[k] → (source[k]) 35
dokimi/dokimi/memory/store.py:580 drop-clause "\n" in m.group(1) and not explicit and not _escaped(pair, m.start()) and not _i → ('\n' in m.group(1) and (not explicit) and (not _inline_link_at(pair, source_pai 19
dokimi/dokimi/memory/store.py:571 swap-addsub k + 1 → k - 1 35
dokimi/dokimi/memory/store.py:573 drop-clause not inside and not escaped and not text_of_explicit and not _inline_link_at(two, → (not inside and (not text_of_explicit) and (not _inline_link_at(two, raw, m.end( 35
dokimi/dokimi/memory/store.py:229 shift-boundary m.start() >= end → m.start() > end 30

Not checked:

  • 29 more breaks of covered changed lines were over the limit and not tried

Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary.

@codecov-commenter

codecov-commenter commented Nov 30, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.31%. Comparing base (88288c6) to head (7c7b682).
⚠️ Report is 3 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1436      +/-   ##
==========================================
- Coverage   96.31%   96.31%   -0.01%     
==========================================
  Files         515      515              
  Lines       68908    68952      +44     
  Branches    11932    11936       +4     
==========================================
+ Hits        66369    66410      +41     
+ Misses       1564     1563       -1     
- Partials      975      979       +4     
Files with missing lines Coverage Δ
dokimi/dokimi/memory/store.py 97.90% <100.00%> (+0.09%) ⬆️

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@napetrov napetrov 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.

Change class: CONTRACT (head ad3600d)

  • Contract: candidate. defaults dokimi/dokimi/memory/store.py:304; defaults dokimi/dokimi/memory/store.py:416
  • Responsibility: none
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

All ten focused blanking cases passed. Checking the public index reader on the example from #1343 showed it still reports a file for the invalid link. I posted the observed output inline.

Comment thread dokimi/dokimi/memory/store.py Resolved
Conflict in dokimi/dokimi/memory/store.py: main now reads the paragraph above a line through a cached `_paragraph_above(out, start, i)` and `_unpaired_run` takes a callable `before`, while this branch passes the lines with a blanked span as a filler. Both are kept: `_blank_blocks` hands the cached call the filled lines, and `_unpaired_run` takes main's callable `before` with the branch's `linked` argument.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
…an as text (intel#1343)

Settles the review point that `MemoryStore.index_targets()` still matched the link on the space-filled lines: for ``[x]( `a` <y `b`>)`` it returned `[(1, 'y    ', True)]` although `prose_lines` blanked the spans correctly.

`_blank_blocks` now returns the filled lines beside the blanked ones, and `index_targets` matches `_MD_LINK` on the filled text, where a blanked span is not a space that ends a bare destination. The target is read from the raw line, so a span inside a destination is kept as written.

The regression test calls `index_targets()` directly.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy

Copy link
Copy Markdown
Contributor Author

(commented) ### Change class: CONTRACT (head ad3600d)

@napetrov (#1436 (review)): The review's one finding is the inline thread 4742743297, answered above. Its change-class lines ask for no change of their own.

Comment thread dokimi/dokimi/memory/store.py Resolved
Conflict in dokimi/dokimi/memory/store.py (MemoryStore.index_targets): main changed the link loop to match once, find the closing openers with _closing_openers and test the title spans through _merged; this branch reads each link's target from the raw text. Kept main's loop and its helpers, and took the target from the raw text (raw[m.start(1):m.end(1)]) as this branch does.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
…he filled one

Settles the review thread on store.py:123: the filled text reads a code span as text, so `[x](foo`(bar`)` matched with `foo` plus six fill characters and index_targets reported the raw slice `foo`(bar`` as a link target, though the destination's parenthesis is never closed.

A match on the filled text is now kept only when the link grammar also matches the raw text at the same offset, and the target is the raw match's destination. `[x](foo`(bar`)` and `[x](`(`a)` report no target, and `[x](a`(b`)c)` reports the destination `a`(b`)c` whose parentheses balance in the raw text.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy

Copy link
Copy Markdown
Contributor Author

Ready for another look at 3015ee5; 1 checks still pending (Windows smoke test (py3.13)); every other check passed.

@antonwolfy
antonwolfy requested a review from napetrov November 30, 2026 21:10

@vchamarthi vchamarthi 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.

@antonwolfy, could you fix the small thing I've marked fix before merge (in the line comments)? I'll approve once that's done.

What I checked on 3015ee5:

  • When I changed the code on purpose, the tests still passed for 1 of 11 changes, and no test pins this one down yet (non-blocking): dokimi/dokimi/memory/store.py:209 (the call is dropped).
  • The 204 changed tests pass, and fail on main as expected.
  • The full test suite passes with main merged in (36,137 tests), apart from failures main has too.
  • It merges cleanly onto main.

Comment thread dokimi/tests/test_blank_inline.py Resolved
Dropping the catch-up of the filled lines in _blank_blocks lost the
link on the line after a fenced block or an HTML comment, and no test
failed. One prose_lines case and two index_targets cases now fail then.

Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 08:47
@xaleryb

xaleryb commented Dec 1, 2026

Copy link
Copy Markdown
Contributor
  • Ran on Linux, Python 3.13, head 3015ee5 (which already contains main e1f7740): the full suite (32000 passed, 1 host-only failure that main also has), ruff, mypy, bandit -ll, check_growth, check_comment_blocks, docs check --strict, plus a probe of 19 link and span inputs against main.
  • The two resolved threads still hold: [x]( a<yb>) -> [] and [x](foo(bar) -> [].
  • The open store.py:209 thread reproduces. With that filled.extend replaced by pass, index_targets() of ~~~\nx\n~~~\n[x](\n<y b>) returns []. Expected: [(4, 'y b', True)]. An HTML comment above gives the same result, and the tests still pass.
  • Pushed 6235e6d: it adds the suggested prose_lines case plus two index_targets cases (fence above, comment above). All three fail under that mutant.
  • Left for the author: nothing for that thread. Note that fix(memory): lint a paragraph of many lines in linear time #1439 conflicts with this PR in memory/store.py.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Reference detection and raw-destination span handling still contain errors that can hide broken links, emit spurious targets, and incorrectly suppress orphan warnings.

2 open issues
What changed in this PR

2 new findings.

This PR addresses #1343 in dokimi’s memory lint by preventing blanked code spans from being mistaken for whitespace before angle-bracket link destinations.

Changes:

  • Uses non-whitespace filler for link recognition while preserving space-blanked prose output.
  • Validates index-link destinations against raw Markdown.
  • Adds regression cases for inline and multiline parsing, target extraction, and line alignment.
File Description
dokimi/​tests/​test_blank_inline.py Adds and updates parsing and target-extraction regression tests.
dokimi/​dokimi/​memory/​store.py Introduces filler-aware link recognition and raw-destination validation.
dokimi/​changelog.d/​20261130_140000_memory-angle-link-blanked-span.md Documents the memory-lint fix for #1343.

Review effort: Balanced

Comment thread dokimi/dokimi/memory/store.py Resolved
Comment thread dokimi/dokimi/memory/store.py Resolved
Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
…the raw text too

_used_labels read inline links on the space-blanked lines, so a span before an
angle destination hid a used definition, and a span in a bare destination marked
an unused one checked. A filled match inside an accepted raw destination is no
second link.

Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
@antonwolfy

Copy link
Copy Markdown
Contributor Author

(commented) @antonwolfy, could you fix the small thing I've marked fix before merge (in the line comments)? I'll approve once that's done.

@vchamarthi (#1436 (review)): The one blocking point is the store.py:209 mutant (the filled.extend call). It is pinned by three cases at the head (6235e6d): the prose_lines fence case and the index_targets() fence and comment cases. Dropping the call fails all three.

@antonwolfy

Copy link
Copy Markdown
Contributor Author
  • Ran on Linux, Python 3.13, head 3015ee5 (which already contains main e1f7740): the full suite (32000 passed, 1 host-only failure that main also has), ruff, mypy, bandit -ll, check_growth, check_comm

@xaleryb (#1436 (comment)): Checked at the head: 6235e6d is on the branch and its three cases fail under the store.py filled.extend mutant (3 failed, 208 passed). The two threads you list as resolved still hold. The conflict with #1439 in memory/store.py is for whichever of the two merges second.

@vchamarthi vchamarthi 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.

Approving 7c7b682.
Still open: when I changed the code on purpose, the tests still passed for 1 of 12 changes, and no test pins this one down yet (non-blocking): dokimi/dokimi/memory/store.py:684 (it returns None).
What I checked: the 211 changed tests pass, and fail on main as expected; the full test suite passes with main merged in (36,370 tests), apart from failures main has too; it merges cleanly onto main.
The earlier problem I raised is fixed now (link).

@antonwolfy

Copy link
Copy Markdown
Contributor Author

(approved) Approving 7c7b682.

@vchamarthi (#1436 (review)): No change. The surviving mutant at store.py:684 turns return False into return None in _inline_link_at. Both callers (store.py:573 and store.py:580) only use the result as not _inline_link_at(...), and not None and not False are the same, so no input can tell the two apart. The mutant is equivalent. The branch itself (a label not followed by () is exercised by the existing tests in tests/test_blank_inline.py.

@antonwolfy
antonwolfy merged commit bac7f7e into intel:main Dec 1, 2026
25 checks passed
@antonwolfy
antonwolfy deleted the fix/angle-link-blanked-span branch December 1, 2026 13:37
@xaleryb

xaleryb commented Dec 1, 2026

Copy link
Copy Markdown
Contributor
  • Pushed 7c7b682 (after merging main): _used_labels and _inline_link_at now read an inline link as index_targets does, on the filled text and checked on the raw text, through one _links helper; a filled match inside an accepted raw destination is skipped. Linear: one extra comparison per candidate.
  • Thread 1: [x]( `a` <y b>) + [x]: missing.md was a regression of this PR (main failed on y b, the head reported nothing); now missing.md is reported. [x](a`b`c) marking the unused definition checked was already on main; now unchecked.
  • Thread 2: the spurious z of [x](a`(`b)[y](z)) was already on main (main returned only z); now only the full destination.
  • Tests: test_a_label_and_a_link_are_read_as_index_targets_reads_a_destination, red without the fix and under three mutants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

memory lint: a code span before an angle destination makes the link check read [x]( a <y b>) as a link

7 participants