Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: stop link definition lookalikes forcing full-document streaming renders (#10688)
Apurv Guptadf4eb295796a
diff --git a/studio/frontend/src/components/assistant-ui/streaming-render-schedule.ts b/studio/frontend/src/components/assistant-ui/streaming-render-schedule.tsindex 07b9f34f828..64ce20140be 100644--- a/studio/frontend/src/components/assistant-ui/streaming-render-schedule.ts+++ b/studio/frontend/src/components/assistant-ui/streaming-render-schedule.ts@@ -212,8 +212,6 @@ function hasLinkReference(text: string): boolean {}return false;}-// Still the first line of a single block, for `updateLinkDefinitionParity` below.-const FENCED_CODE_BLOCK_RE = /^ {0,3}(?:```|~~~)/;const WORD_CHARACTER_RE = /[\p{L}\p{N}_]/u;const HTML_TAG_START_RE = /[a-zA-Z/]/;@@ -374,9 +372,10 @@ const createRepairParity = (// Marked keeps link reference definitions in one document-wide map and emits no token for a label// it has already seen, so a definition retained while its twin is still live would be lexed apart// and shown as a literal line. Keeping every definition in the live tail makes the two lexes agree.-// Marked reads a fenced block as code, so those do not count.+// Same test as `documentProse`: a bare `[...]:` probe also caught `list[str]:` in a list-nested+// fence or `d["key"]: int`, stalling the tail into the sticky full-document path (#10529).function updateLinkDefinitionParity(parity: RepairParity, text: string): void {- if (!FENCED_CODE_BLOCK_RE.test(text) && hasLinkDefinition(text)) {+ if (!isCodeBlock(text) && LINK_DEFINITION_LINE_RE.test(text)) {parity.linkDefinition = true;}}@@ -1465,10 +1464,13 @@ export class IncrementalMarkdownCache {// full-document mode -- answer without it, and the precise scope costs a lex of everything// received so far. Reaching this point means the reply is still a retention candidate,// which is the only case where the answer is used.+ // `updateLinkDefinitionParity` never commits a block `documentProse` would read as a+ // definition, so with no `]:` left in the tail the whole-reply lex can only say `blocks`.if (FOOTNOTE_REFERENCE_RE.test(repaired) ||FOOTNOTE_DEFINITION_RE.test(repaired) ||- markdownRenderScope(markdown) === "document"+ (hasLinkDefinition(this.tail) &&+ markdownRenderScope(markdown) === "document")) {return this.renderFullDocument(markdown);}diff --git a/studio/frontend/tests/link-definition-oracle.test.ts b/studio/frontend/tests/link-definition-oracle.test.tsindex 9a5289527c1..86791e6f8de 100644--- a/studio/frontend/tests/link-definition-oracle.test.ts+++ b/studio/frontend/tests/link-definition-oracle.test.ts@@ -234,6 +234,20 @@ test("a definition lookalike that no parser registers keeps block rendering", ()}});+test("a live reference pair inside a list or quote still resolves", () => {+ for (const definition of [+ "- [g]: /guide",+ "> [g]: /guide",+ "- - [g]: /guide",+ "- > [g]: /guide",+ "> - [g]: /guide",+ ]) {+ const reply = `See [guide][g].\n\n${definition}\n`;+ assert.ok(asOneDocument(reply) > asBlocks(reply), definition);+ assert.equal(markdownRenderScope(reply), "document", definition);+ }+});+test("ordinary code is still rendered per block", () => {// The regression this path exists for: nothing here is a definition, so each of these must// keep its per-block Copy code / Download file controls.@@ -242,6 +256,11 @@ test("ordinary code is still rendered per block", () => {"Compare [one][two].\n\n```css\na[href]:hover { color: red; }\n```\n","Compare [one][two].\n\n [two]: not-a-definition\n","How:\n\n```md\n[two]: https://example.com/two\n```\n\nText [one][two].\n",+ "See [a][ref].\n\n1. item\n ```python\n def f() -> list[str]:\n return []\n ```\n",+ "See [a][ref].\n\n- item\n ```python\n def f() -> list[str]:\n return []\n ```\n",+ "See [a][ref].\n\n```python\nlist[\n str\n]:\n```\n",+ 'See [a][ref].\n\nd[\n "key"\n]: int\n',+ 'See [a][ref].\n\nd["key"]: int\n',]) {assert.equal(markdownRenderScope(reply), "blocks", reply);assert.equal(diff --git a/studio/frontend/tests/streaming-render-schedule.test.ts b/studio/frontend/tests/streaming-render-schedule.test.tsindex a267e152c74..892ad1f40ce 100644--- a/studio/frontend/tests/streaming-render-schedule.test.ts+++ b/studio/frontend/tests/streaming-render-schedule.test.ts@@ -98,6 +98,9 @@ const MARKDOWN_CASES = [`a \`\`\` b\n\nc \\\`\`\` d${SHORT_GAP}- >= 4 GB`,`[x]: https://e.test\n\n${paragraphs(12)}[x]: https://e.test\n\nq\n\n`,`\`\`\`md\n[x]: https://e.test\n\`\`\`\n\n${paragraphs(12)}[x]: https://e.test\n\nq\n\n`,+ // A Python return annotation inside a list-nested fence is code, not a+ // definition, so the incremental path has to keep retaining past it.+ `See [a][ref].\n\n1. item\n \`\`\`python\n def f() -> list[str]:\n return []\n \`\`\`\n\n${paragraphs(12)}end`,// A label may contain an escaped bracket, and Marked registers it.`[foo\\]bar]: /url\n\n${paragraphs(12)}[foo\\]bar]: /url\n\nq\n\n`,// Every label to CommonMark's 999 is registered, so one past 200 must be held.@@ -277,6 +280,9 @@ test("a definition inside a block quote or a list is still document-wide", () =>"- [g]: /guide","1. [g]: /guide","> > [g]: /guide",+ "- - [g]: /guide",+ "- > [g]: /guide",+ "> - [g]: /guide",]) {assert.equal(markdownRenderScope(`See [guide][g].\n\n${container}\n`),@@ -728,7 +734,14 @@ test("a definition shown inside a fenced example still retains", () => {// A real definition is never retained, whatever block it sits in, so Marked// always lexes it together with a later twin and absorbs the duplicate.- for (const first of ["[x]: https://e.test", "> [x]: https://e.test"]) {+ for (const first of [+ "[x]: https://e.test",+ "[x\ny]: https://e.test",+ "> [x]: https://e.test",+ "- [x]: https://e.test",+ "- - [x]: https://e.test",+ "> - [x]: https://e.test",+ ]) {const repeated = `${first}\n\n${paragraphs(30)}[x]: https://e.test\n\nend`;const cache = new IncrementalMarkdownCache();let repeatedRender = cache.update("");@@ -741,6 +754,8 @@ test("a definition shown inside a fenced example still retains", () => {repeatedRender.parseMarkdownIntoBlocks(repeatedRender.markdown),parseMarkdownIntoBlocks(remend(processStreamingText(repeated))),);+ // Held in the live tail, not committed into an independently parsed prefix.+ assert.ok(repeatedRender.markdown.length > repeated.length / 2, first);}});@@ -964,3 +979,60 @@ test("a seam whose reference label is past the cap is rejected once, not per `[`const label = "L".repeat(400);assert.equal(markdownRenderScope(`See [guide][${label}].\n\n[${label}]: /u\n`), "document");});++const STREAM_CHUNK = 24;+const LOOKALIKE_PROSE = paragraphs(1_200);++const streamInChunks = (source: string) => {+ const cache = new IncrementalMarkdownCache();+ for (let length = 0; length < source.length; length += STREAM_CHUNK) {+ cache.update(source.slice(0, length));+ }+ return { cache, render: cache.update(source) };+};++const isFullDocumentMode = (cache: IncrementalMarkdownCache): boolean =>+ (cache as unknown as { fullDocumentMode: boolean }).fullDocumentMode;++test("a list-nested Python annotation does not stick to the full-document path", () => {+ // The block opens with the list marker, not the fence (#10529).+ for (const block of [+ "1. item\n ```python\n def f() -> list[str]:\n return []\n ```",+ "- item\n ```python\n def f() -> list[str]:\n return []\n ```",+ "10. item\n ```python\n def f() -> list[str]:\n return []\n ```",+ ]) {+ const source = `See [a][ref].\n\n${block}\n\n${LOOKALIKE_PROSE}`;+ const { cache, render } = streamInChunks(source);+ assert.equal(markdownRenderScope(source), "blocks", block);+ assert.equal(isFullDocumentMode(cache), false, block);+ assert.ok(render.markdown.length < source.length / 4, block);+ }+});++test("wrapped and unfenced lookalikes do not force the document path", () => {+ for (const block of [+ "```python\nlist[\n str\n]:\n```",+ 'd[\n "key"\n]: int',+ 'd["key"]: int',+ ]) {+ const source = `See [a][ref].\n\n${block}\n\n${LOOKALIKE_PROSE}`;+ const { cache, render } = streamInChunks(source);+ assert.equal(markdownRenderScope(source), "blocks", block);+ assert.equal(isFullDocumentMode(cache), false, block);+ assert.ok(render.markdown.length < source.length / 4, block);+ }+});++test("a live reference pair inside a list or quote still holds as one document", () => {+ for (const definition of [+ "- [g]: /guide",+ "> [g]: /guide",+ "- - [g]: /guide",+ "- > [g]: /guide",+ ]) {+ const source = `See [guide][g].\n\n${definition}\n\n${paragraphs(12)}end`;+ const { cache } = streamInChunks(source);+ assert.equal(markdownRenderScope(source), "document", definition);+ assert.equal(isFullDocumentMode(cache), true, definition);+ }+});