Skip to content

The files daemon's named-link rule parses Markdown with the window's own micromark/mdast pipeline #776

Open

Description

@SSFSKIM

Why

U6c's rule (src/shared/files/named.ts, used by src/services/files/named.ts) admits a read, and for a counted form a save, of a file outside a session's folders when the session's own transcript writes a link to that path. The rule's contract is one-way: every path it names must be a path chip the window draws. The window parses with micromark/mdast (Streamdown, remarkTranscriptSources); the rule reads the same text with a hand-written block scanner. While closing three gaps, UX wave landing U6b-4b (M1, branch ux-wave/U6b-4b) found and fixed 16 more places where the scanner named a link that the window draws as code or does not draw. Two remain open (U1, U2 below). Each such gap names a file a person never saw as a link, so this is a security class: it should be closed by construction, not chased string by string.

The fix

The daemon parses with the same pipeline the window uses (remark with the same plugins, then the same remarkTranscriptSources), reads the path links off that tree, and keeps the meter's bounds (the visit bound of named.ts, the 64 KiB stretches, NAMED_WAIT_MS, src/services/files/named.measure.test.ts). Every row of both tables below then goes away by construction. Keep the renderer differential (src/renderer/src/tools/code/named-links.test.tsx) as the proof.

Every divergence found so far (U6b-4b M1; strings run through the production renderer)

"Window" is what the production Markdown draws; "rule" is what linkPaths named at the time.

The rule named a link the window does not draw. All fixed in M1 unless marked:

# string window rule before fixed by
1 | a | b |\n|---|---|\n| x | y | [r](/work/x.md) | [] ['/work/x.md'] 070fefc (the head's width)
2 Title\n:---\ntext | [r](/out/x.md) [] ['/out/x.md'] d35a7b8 (a :-only delimiter row)
3 `a\n|\n|-|\n[r](/work/x.md)` (a one-pipe head; the window draws prose) [] ['/work/x.md'] d35a7b8
4  + ```\n[r](/work/x.md)\n``` [] ['/work/x.md'] f3568e3 (a leading byte order mark)
5 see [s](/work/s.md)\r```\r[r](/work/x.md)\r``` ['/work/s.md'] ['/work/s.md'] (names it from a fence it reads as prose) f3568e3, by refusal (see row L1 below)
6 - Title\n:---\n\a\nr`` [] ['/example/report.md'] fc181ce (a lazy delimiter row in a list item)
7 - Title\n :---\n\a\nr`` [] the same fc181ce (a table in an item, then a line outside it)
8 - item\n\n | a | b |\n |---|---|\n\a\nr`` [] ['/x'] fc181ce
9 > para \x\nT | u\n|-|-|\nr `` [] ['/x'] fc181ce (a lazy head in a quote)
10 T | u\n-|-\n> \x\nr`` [] ['/x'] fc181ce (a deeper quote ends a table)
11 > p \x\nr`\n:---` (from the line differential) [] ['/secret'] fc181ce
12 x \y\n2. r `, x `y\n10. r `` (an ordered item not starting at 1 cannot interrupt) [] ['/s'] d256818
13 x \y\n1.\nr `, the same with *and+` (an empty item cannot interrupt) [] ['/s'] d256818
14 - a\n\n x \y\n 2) r `` (the same inside a list item) [] ['/s'] d256818
15 > - a\n>\n> x \y\n> 2. # r `, and - a\n\n x `y\n 2.\t# r `` [] ['/x'] e11a519 (a block read past an unplaced marker)
16 x \y\n2. ```\n :---\n| x | y | r |` [] ['/x'] (at d256818 to e11a519 only) 4382edc (a regression of fix wave 1)
U1 | a | b |\n|---|---|\n [r](/s) [] ['/s'] not fixed
U2 -\n \a\nr `, 1.\n `a\nr `, - \n `a\n r\nx `y` [] ['/s'] not fixed

The rule names less than the window. These stand, as the side R1 accepts:

# string or shape window rule
L1 a text with a carriage return not before a line feed, e.g. see [s](/work/s.md)\r```\r[r](/work/x.md)\r``` ['/work/s.md'] [] (the text is refused whole)
L2 a table inside a list item, or under a quote's paragraph it would continue lazily, e.g. - item\n\n | a | b |\n |---|---|\n | [r](/x) | y | the cell's chip nothing of the table, nor of the paragraph it interrupts (by construction; this string was not run through the probe)
L3 a weak line the pass cannot place (a quote marker or a tab before its content; a paragraph that did not open its item, with the line less indented than its text; a weak line over a delimiter row), e.g. - a\n\n x \y\n2. r `` ['/x/r.md'] [] up to the next blank line or block start
L4 a fence an unplaced marker may open, e.g. - a\n\n x \y\n 2.\t```\n r\n\ns` includes '/x/s.md' [] (the text is refused whole)
L5 - \n [r](/s) (an empty item's content at four columns) ['/s'] [] (read as code; the mirror of U2)
L6 1. a \x\n2. r `` while fix wave 1, part two stood (d256818 only) ['/s'] []
L7 the fragment differential's window-only chips: 177 of 2000 strings at seed 1818848875, mostly from texts holding a lone carriage return (L1) and from links the rule's listed refusals do not name (U6c's percent-escapes, character references, URL-parse cases) — —

The two open cases (the rule names more than the window), with their failing tests

Both were confirmed with the real renderer (probe at b447f22). In both, the rule names a link the window does not draw.

U1. A line indented four columns after a table. The window ends the table and reads the line as indented code; the rule reads it as a body row.

string window rule
| a | b |\n|---|---|\n [r](/s) [] ['/s']
| a | b |\n|---|---|\n [r](/s) | x [] ['/s']

U2. A line indented four or more columns under an empty list item. The window reads it as the item's content (a paragraph). The rule reads indented code, then starts a paragraph on the next line.

string window rule
-\n \a\nr `` [] ['/s']
1.\n \a\nr `` [] ['/s']
- \n \a\n r\nx `y` [] ['/s']

To keep the committed line differential green without chasing these, a8c1991 removed the two lines indented four columns ( [r](/secret)\``, `a`) from its alphabet, with a comment that points here. This hides both classes from the seeded run until the structural fix.

Failing tests for both, not committed (they belong in named-links.test.tsx):

describe('reported, not fixed: lines indented four columns (M1 report, U1 and U2)', () => {
  it('U1: a line indented four columns ends a table; the rule reads it as a row', () => {
    for (const markdown of ['| a | b |\n|---|---|\n    [r](/s)', '| a | b |\n|---|---|\n    [r](/s) | x']) {
      expect(chipPaths(markdown), markdown).toEqual([]);
      expect(linkPaths(markdown), markdown).toEqual([]); // fails: ['/s']
    }
  });
  it('U2: under an empty list item a line indented four columns is its content; the rule reads code', () => {
    for (const markdown of ['-\n    `a\n[r](/s) `', '1.\n    `a\n[r](/s) `', '- \n    `a\n  [r](/s)\nx `y']) {
      expect(chipPaths(markdown), markdown).toEqual([]);
      expect(linkPaths(markdown), markdown).toEqual([]); // fails: ['/s']
    }
  });
});

Activity

  1. added
    enhancement
    status:ready-for-implementer
    priority:P2
    on Nov 19, 2026
  2. SSFSKIM commented on Nov 19, 2026

    @SSFSKIM
    OwnerAuthor

    Addition: the branch review's four (UX wave U6b-4b, 2026-11-19)

    The branch review of landing U6b-4b (an xhigh panel over daf06d208..796895fe8) found four more places where the rule (linkPaths, src/shared/files/named.ts) named a link that the window does not draw. ux-wave ruled that the scanner is not brought nearer to GFM case by case any more: these belong to the structural fix this ticket describes. Until then the scanner fails closed in the structures the four cases show. Commit b5a7d846c on ux-wave/U6b-4b makes all four name nothing (the failing tests are 212d44872).

    What it does now: where a line meets a container the scanner does not follow, it names nothing from the paragraph that line meets or opens up to the next blank line, or up to a line that is a fence, a heading or a thematic break by its own reading. Such a container is a quote marker after a list marker, a table candidate inside a list item (its delimiter row at any indentation) or under a deeper quote's paragraph, or an indented line that opens a deeper quote under a paragraph. If such a line could open a fence, it refuses the whole text.

    Each string was run through the production renderer (Markdown with live false and true, the differential's chipPaths). /s stands for both destination forms, [r](/s) and [r](file:///s). Both forms behave the same in every row. "Rule at 796895fe8" is what linkPaths named before the fix. "Base" is daf06d208, for the scheme-less form only, since the base read no file: destination.

    # string window rule at 796895fe8 base named nothing since
    P1 > a \x\n2. > `r`` (a quote after a list marker; the rule joined the line to the quote's paragraph, so the backticks paired across the item's start) [] ['/s'] [] b5a7d846c
    P2 > - a \x\n> T | u\n> -|-\nr `` (a table candidate in a quoted list item; the rule dropped it and read again once the quote ended, but the window's paragraph runs on lazily and its code span stays open) [] ['/s'] ['/s'] b5a7d846c
    P3 - a | b\n --|--\n x | y | [r](/s) (the delimiter row measured from the line's start, four columns, and not from the item's content, two; the window draws a table of two columns, and the link stands in a third cell, never drawn) [] ['/s'] ['/s'] b5a7d846c
    P4 a\n+\n> [r](/s) (after prose and a lone +, the indented line's branch appended a line that opens a deeper quote, whose content the window draws as indented code) [] ['/s'] [] b5a7d846c

    These neighbours have the same structures. They were confirmed the same way and are fixed rows beside the four:

    string window rule at 796895fe8 base
    - > a \x\n> `r`` [] ['/s'] ['/s']
    - a\n T | u\n -|-\n x | y | [r](/s) [] ['/s'] ['/s']
    - T | u\n -|-\n x | y | [r](/s) (probe only) [] ['/s'] ['/s']
    a\n> [r](/s) [] ['/s'] ['/s']
    - a\n> [r](/s) [] ['/s'] ['/s']

    Each fixed row has a control: the same string, then a blank line and [c](/c). The window draws /c and the rule names it, so the fail-closed stretch ends at the blank line.

    The tests are in src/shared/files/named.test.ts ("where a line meets a container the pass does not follow …") and in src/renderer/src/tools/code/named-links.test.tsx ("… no chip, nothing named, to the next blank line"), for each destination form.

    What failing closed costs at the committed seeds. The fragment differential (seed 0x6c696e6b, 2,000 strings): 0 strings changed, of 555 that named a path before. The line differential (seed 0x7461626c, 1,500 strings): 8 strings changed, of 906 that named a path before. 7 of them now name nothing and 1 names fewer paths; none names a path it did not name before. The window draws a chip for every path that is no longer named in those 8 strings, so each change costs a chip the rule now refuses. None of them is a fault. The structural fix gets all 8 back. SHA-256 of the 8 changed strings joined by NUL: 8e093cb0578bc43c669746a328cb8b8a78791f0907ab2c24314552c9c8110d58.

    Found while fixing, not fixed: U3, a fence four columns in, inside a list item. This is the class of U1 and U2: the scanner measures indentation from the start of the line, not from the item's content. In a list item whose content starts at column 4 or 5, a tilde fence on a continuation line is a fence to the window. The rule reads it as the paragraph's text, so it names a link inside the fence. (A backtick fence was not probed: the scanner probably reads its runs as a code span, but that is not verified.) Confirmed with the production renderer at b5a7d846c; the base daf06d208 names it too.

    string window rule at b5a7d846c base
    - a\n ~~~\n [r](/s)\n ~~~ [] ['/s'] ['/s']
    10. a\n ~~~\n [r](/s)\n ~~~ [] ['/s'] ['/s']

    The file:///s form is the same. The control - a\n # [r](/s) (a heading four columns in, inside the item) is a chip and is named.

  3. SSFSKIM commented on Nov 19, 2026

    @SSFSKIM
    OwnerAuthor

    Addition: the branch review's four (UX wave U6b-4b, 2026-11-19)

    The branch review of landing U6b-4b (an xhigh panel over daf06d208..796895fe8) found four more places where the rule (linkPaths, src/shared/files/named.ts) named a link that the window does not draw. ux-wave ruled that the scanner is not brought nearer to GFM case by case any more: these belong to the structural fix this ticket describes. Until then the scanner fails closed in the structures the four cases show. Commit b5a7d846c on ux-wave/U6b-4b makes all four name nothing (the failing tests are 212d44872).

    What it does now: where a line meets a container the scanner does not follow, it names nothing from the paragraph that line meets or opens up to the next blank line, or up to a line that is a fence, a heading or a thematic break by its own reading. Such a container is a quote marker after a list marker, a table candidate inside a list item (its delimiter row at any indentation) or under a deeper quote's paragraph, or an indented line that opens a deeper quote under a paragraph. If such a line could open a fence, it refuses the whole text.

    Each string was run through the production renderer (Markdown with live false and true, the differential's chipPaths). /s stands for both destination forms, [r](/s) and [r](file:///s). Both forms behave the same in every row. "Rule at 796895fe8" is what linkPaths named before the fix. "Base" is daf06d208, for the scheme-less form only, since the base read no file: destination.

    # string window rule at 796895fe8 base named nothing since
    P1 > a \x\n2. > `r`` (a quote after a list marker; the rule joined the line to the quote's paragraph, so the backticks paired across the item's start) [] ['/s'] [] b5a7d846c
    P2 > - a \x\n> T | u\n> -|-\nr `` (a table candidate in a quoted list item; the rule dropped it and read again once the quote ended, but the window's paragraph runs on lazily and its code span stays open) [] ['/s'] ['/s'] b5a7d846c
    P3 - a | b\n --|--\n x | y | [r](/s) (the delimiter row measured from the line's start, four columns, and not from the item's content, two; the window draws a table of two columns, and the link stands in a third cell, never drawn) [] ['/s'] ['/s'] b5a7d846c
    P4 a\n+\n> [r](/s) (after prose and a lone +, the indented line's branch appended a line that opens a deeper quote, whose content the window draws as indented code) [] ['/s'] [] b5a7d846c

    These neighbours have the same structures. They were confirmed the same way and are fixed rows beside the four:

    string window rule at 796895fe8 base
    - > a \x\n> `r`` [] ['/s'] ['/s']
    - a\n T | u\n -|-\n x | y | [r](/s) [] ['/s'] ['/s']
    - T | u\n -|-\n x | y | [r](/s) (probe only) [] ['/s'] ['/s']
    a\n> [r](/s) [] ['/s'] ['/s']
    - a\n> [r](/s) [] ['/s'] ['/s']

    Each fixed row has a control: the same string, then a blank line and [c](/c). The window draws /c and the rule names it, so the fail-closed stretch ends at the blank line.

    The tests are in src/shared/files/named.test.ts ("where a line meets a container the pass does not follow …") and in src/renderer/src/tools/code/named-links.test.tsx ("… no chip, nothing named, to the next blank line"), for each destination form.

    What failing closed costs at the committed seeds (at ed86f47dd, after fix wave 3, against 796895fe8). The fragment differential (seed 0x6c696e6b, 2,000 strings): 2 strings changed, of 555 that named a path before, and both now name nothing. Both hold a footnote's [^1]: beside a line the scan did not read; SHA-256 6583228ef78b53c6ea9922e8e0699de8273a1972f152a01ad227f56ec9dbc9ad. The line differential (seed 0x7461626c, 1,500 strings): 9 strings changed, of 906 that named a path before. 8 now name nothing and 1 names fewer; SHA-256 95f38c89481743ecbd8b14d4a1ba956472bcc694d404085f00a6caae4ed2a1f6. In neither differential does a string name a path it did not name before. The window draws a chip of every path no longer named in all 11, so each change costs a chip the rule now refuses. None of them is a fault. The structural fix gets them back. (The line differential changed 8 strings after wave 1 and 16 after wave 2. Wave 2's own head check refused every dropped head that began with [; wave 3 folds that check into its guard, which needs a ]:.)

    Fix wave 2 (f98ec0ad0; failing tests f503db32e). The delta review found that two discards of the first wave reset state the window's parse keeps. Both now name nothing. The rule is that a fail-closed discard never resets what the window keeps:

    • A weak line after a discarded table candidate. For - a \x\n T | u\n -|-\n 2. # r `the window draws [], and the rule atb5a7d84named ['/s']. The neighbours with2), with 10., in a quote, and with 2. ***then a lazy line, behave the same. The weak marker's block start had cleareddoubtful`.
    • A definition dropped as the candidate's head. For - [ref]: https://example.com/\n :---\n\n[outer [ref]](@) the window draws [], and the rule at b5a7d846c named ['/s']; the base names nothing. The second of two definitions, and the same in a quote, behave the same.

    Found while fixing, not fixed: U3, a fence four columns in, inside a list item. This is the class of U1 and U2: the scanner measures indentation from the start of the line, not from the item's content. In a list item whose content starts at column 4 or 5, a tilde fence on a continuation line is a fence to the window. The rule reads it as the paragraph's text, so it names a link inside the fence. (A backtick fence was not probed: the scanner probably reads its runs as a code span, but that is not verified.) Confirmed with the production renderer at b5a7d846c; the base daf06d208 names it too.

    string window rule at b5a7d846c base
    - a\n ~~~\n [r](/s)\n ~~~ [] ['/s'] ['/s']
    10. a\n ~~~\n [r](/s)\n ~~~ [] ['/s'] ['/s']

    The file:///s form is the same. The control - a\n # [r](/s) (a heading four columns in, inside the item) is a chip and is named.

    Fix wave 3 (ed86f47dd; failing tests 0fa0c40e6). Wave 2's weak-line path could still swallow a definition. For - > a\n2. [ref]: https://example.com\n\n[outer [ref]](@) the window draws [] and the rule at f98ec0ad0 named ['/s']; 796895fe8 names nothing. The case was fixed as a class, by one guard over the whole text: where the block pass left any line unread (doubtful was ever set) and the text holds ]: anywhere, the text names nothing. The same guard covers a definition over two lines that a dropped table read as its rows. For - T | u\n -|-\n[ref]:\n https://example.com\n\n[outer [ref]](@) and its variant with a title on the next line, the window draws [] and the rule named ['/s'], at 796895fe8 too.

  4. SSFSKIM commented on Nov 20, 2026

    @SSFSKIM
    OwnerAuthor

    [design] Route chosen for the build (2026-11-20, UX wave coordinator), from b8-bugs' measurements. The window's pipeline (remark-parse → mdast-util-from-markdown) parses in one synchronous call: one ordinary paragraph of 8,192 links made 1,875,980 visits with no point to pause, against the meter's pause at 65,536 visits and its hard stretch of 1,048,576. So the visit contract cannot hold on that parser.

    Build: the files daemon parses in one killable job off its event loop (a worker), with bounded input, a hard deadline, and no partial result accepted; a job past its deadline is killed and the read fails closed, as a link it could not judge. This is the stronger exit U6c's Decision Log 24 already named. Use plain unified/remark/micromark, not the streamdown entry (it pulls in React); move the pure transcript plugins into a neutral module both sides import; read the chips that survive the render gates, not every mdast link. The red tests for the U1/U2/U3 rows are on ux-wave/b8-776 (04a079038). Rejected: a resumable, metered parser (every parser upgrade becomes an instrumentation review); admitting only bounded independently parseable blocks (loses completeness).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementpriority:P2status:ready-for-implementer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions