You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Studio: a link reference definition with a label over 200 characters can be committed away, breaking the reference #9540
updateLinkDefinitionParity uses it to hold link reference definitions in the live tail, so Marked's document-wide definition map stays consistent. A definition whose label is longer than 200 characters is not recognised, so the incremental cache can commit it into an independently parsed block. A later reference in the live tail then has no definition to resolve against and renders as literal text.
CommonMark caps a link label at 999 characters, so every label from 201 to 999 is valid and missed.
Reproduced by streaming a definition, then enough prose to clear the rollback window, then the reference:
label length
definition committed away
reference still in the live tail
link resolves
180
no
yes
yes
250
yes
yes
no
600
yes
yes
no
Raising the bound to 999 is the obvious fix, but it is not free and should not land without a measurement. parity.linkDefinition blocks commits, so a wider bound keeps more text in the live tail for longer, and the live tail is re-repaired and re-lexed on every token. Whoever takes this should put the per-chunk cost next to it, on a reply that actually contains a long definition label, before and after.
Found by Codex review on #9477, which touches that file but not those lines. Filing separately so it does not ride on a contributor's performance PR.
One finding worth surfacing before it lands, since it changes the shape of the fix. Raising the bound to 999 is right, but not because CommonMark caps the label there. Marked's own def rule has no cap at all:
so it registers labels past 999, and 999 leaves the divergence reachable — measured at 1000, 1200 and 2000.
Unbounded is the exact match for the lexer and does close those, but I measured it before reaching for it and it is the wrong trade: the bound is what keeps the scan linear. Every [ on a line is a start position, so a bound of B costs O(n·B) per line while no bound costs O(n²). On one long line dense with [ that never reaches ]::
line
200
999
unbounded
50k
3.01ms
14.56ms
360.44ms
100k
6.51ms
27.72ms
1257.36ms
Ordinary multi-line text is identical across all three (0.53ms per 50k), since the class excludes \n and the scan is capped by the line.
So the PR takes 999 and documents the residual past it as deliberate, rather than silently leaving it.
On the per-chunk cost you asked for: the honest comparison is not before/after on the same label, since a 250-character label was cheap before precisely because it was committed away. Against the 200-character label that is already held today at 75.1us/chunk, a 250-character label after the fix costs 51.5us/chunk on the same reply. Replies with no long definition come out at +6% or below. Full numbers in the PR.
Also filed #9633 for an adjacent gap found while measuring this: Marked's [^\]]+ admits a newline, so a label spanning lines is registered by Marked and missed by every bound here. It reproduces at 200 too, so it is not introduced by this fix, and it needs its own measurement — keeping it off this PR.
Update: folding #9633 into this PR after measuring it.
I said above I would keep it off this one. That was based on a cost argument I have since measured and found wrong — the {1,999} bound still caps the scan when the newline exclusion goes, so it stays linear, and per chunk through the cache the difference is 0%. Details on #9633.
Both are the same probe having drifted from Marked's def rule ([^\]]+: no length cap, no exclusion of a line ending), each independently reachable through the same code path, and independent of each other — with the bound already at 999 and \n still excluded, the newline case still diverges at prefix 127. One regex, one rationale, so one PR.
Activity
HughScott2002 commentedon Aug 24, 2026
Working on this — PR shortly.
One finding worth surfacing before it lands, since it changes the shape of the fix. Raising the bound to 999 is right, but not because CommonMark caps the label there. Marked's own
defrule has no cap at all:so it registers labels past 999, and 999 leaves the divergence reachable — measured at 1000, 1200 and 2000.
Unbounded is the exact match for the lexer and does close those, but I measured it before reaching for it and it is the wrong trade: the bound is what keeps the scan linear. Every
[on a line is a start position, so a bound of B costs O(n·B) per line while no bound costs O(n²). On one long line dense with[that never reaches]::Ordinary multi-line text is identical across all three (0.53ms per 50k), since the class excludes
\nand the scan is capped by the line.So the PR takes 999 and documents the residual past it as deliberate, rather than silently leaving it.
On the per-chunk cost you asked for: the honest comparison is not before/after on the same label, since a 250-character label was cheap before precisely because it was committed away. Against the 200-character label that is already held today at 75.1us/chunk, a 250-character label after the fix costs 51.5us/chunk on the same reply. Replies with no long definition come out at +6% or below. Full numbers in the PR.
Also filed #9633 for an adjacent gap found while measuring this: Marked's
[^\]]+admits a newline, so a label spanning lines is registered by Marked and missed by every bound here. It reproduces at 200 too, so it is not introduced by this fix, and it needs its own measurement — keeping it off this PR.HughScott2002 commentedon Aug 24, 2026
Update: folding #9633 into this PR after measuring it.
I said above I would keep it off this one. That was based on a cost argument I have since measured and found wrong — the
{1,999}bound still caps the scan when the newline exclusion goes, so it stays linear, and per chunk through the cache the difference is 0%. Details on #9633.Both are the same probe having drifted from Marked's
defrule ([^\]]+: no length cap, no exclusion of a line ending), each independently reachable through the same code path, and independent of each other — with the bound already at 999 and\nstill excluded, the newline case still diverges at prefix 127. One regex, one rationale, so one PR.fix(studio): track Marked's def rule in the link definition probe
fix(studio): track Marked's def rule in the link definition probe (un…
fix(studio): widen the link reference probe to match the definition p…
fix(studio): track Marked's def rule in the link definition probe (un…
fix(studio): widen the link reference probe to match the definition p…