Skip to content

Fix incomplete links showing [blocked] during chat streaming - #12104

Merged
danielhanchen merged 8 commits into
unslothai:mainfrom
umran666:codex/streaming-markdown-placeholder-11848
Oct 5, 2026
Merged

danielhanchen merged 8 commits into
unslothai:mainfrom
umran666:codex/streaming-markdown-placeholder-11848

Conversation

@umran666

@umran666 umran666 commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #11848.

While a reply is streaming, an unfinished Markdown link gets a temporary streamdown:incomplete-link destination from Streamdown's repair step. That destination is treated as unsafe, so the chat shows [blocked] (and sometimes exposes the placeholder) even though the model is still writing the link.

This keeps an unfinished link as plain text until its destination is complete. The same check applies when a response ends mid-link, while other incomplete Markdown still uses the existing repair behavior. Completed links keep the normal URL safety checks.

I added rendered regression cases for partial and completed links, including an unsafe completed URL. The focused Markdown tests pass (51/51), and the frontend TypeScript build passes.

Before / after

Same scripted reply on both builds (merge base vs this branch, head 8b27b04). Mid-stream, the link destination is half written:

Mid-stream: BEFORE shows "release notes [blocked]", AFTER keeps the literal partial link

Settled, on a reply that ends with an unclosed [ (compare arr[i). The completed link still renders normally on both:

![Settled: BEFORE ends "arri [blocked]", AFTER ends "arri"

Follow-up commits

  • When remend would add the incomplete-link placeholder, the text is repaired again with remend's links and images passes off (LITERAL_LINK_REMEND), instead of being shown raw. Every other repair (comparison escapes, emphasis, inline code) still applies, so - >= 16 GB followed by See [foo stays a list item. The settled path passes the same options through Streamdown's remend prop, so parseIncompleteMarkdown is unchanged from main.
  • A tail with an unfinished link goes through the footnote and document-scope check, block retention and the stalled-tail fallback like any other tail; the post-commit tail repair uses the same rule.
  • Replies with no [ skip the extra settled remend pass.
  • The full-document split oracles from main now compare against repairStreamingMarkdown.

Copilot AI lite review requested due to automatic review settings September 27, 2026 10:41

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 5, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 5, 2026
@shimmyshimmer

Copy link
Copy Markdown
Member

Review record for #12104, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#418.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1: reviewed mirror 48817ce37 (no equivalent commit found on this PR)

chatgpt-codex-connector[bot] on studio/frontend/src/components/assistant-ui/streaming-render-schedule.ts (on the mirror)

@@ -911,6 +911,27 @@ export type IncrementalMarkdownRender = {
   parseMarkdownIntoBlocks: (markdown: string) => string[];
 };
 
+const INCOMPLETE_LINK_REPAIR = "](streamdown:incomplete-link)";
+
+export function hasIncompleteLinkRepair(
+  source: string,
+  repaired?: string,
+): boolean {
+  // Only an unclosed `[` gets the placeholder, so bracket-free replies skip the remend pass.
+  if (!source.includes("[")) return false;
+  const after = repaired ?? remend(source);
+  return (
+    after.split(INCOMPLETE_LINK_REPAIR).length >
+    source.split(INCOMPLETE_LINK_REPAIR).length
+  );
+}
+
+/** `remend`, except an unfinished link stays literal (see `hasIncompleteLinkRepair`). */
+export function repairStreamingMarkdown(source: string): string {
+  const repaired = remend(source);
+  return hasIncompleteLinkRepair(source, repaired) ? source : repaired;

P2 Badge Preserve earlier repairs when leaving links literal

When an unfinished link occurs alongside a construct repaired before Remend's link pass, returning the original source discards that unrelated repair. For example, while streaming - >= 16 GB\n\nSee [foo, Remend first escapes the comparison operator as - \>= 16 GB and then adds the incomplete-link placeholder; this branch restores the raw - >= 16 GB, which Streamdown 2.5 renders as a nested blockquote rather than the intended list text until the link completes. Suppress only the generated link placeholder while retaining Remend's preceding transformations.

Useful? React with 👍 / 👎.

Accepted on the mirror

Reply from danielhanchen:

Fixed in 7953d3a: the link pass is now skipped via remend's links/images options instead of returning the raw text, so earlier repairs such as the comparison escape still apply.

Round 2: reviewed mirror 59c69d65e (no equivalent commit found on this PR)

chatgpt-codex-connector[bot] on studio/frontend/src/components/assistant-ui/streaming-render-schedule.ts (on the mirror)

@@ -1458,6 +1487,12 @@ export class IncrementalMarkdownCache {
     const repaired =
       this.repairOpenFence() ?? repairTail(this.tail, this.context);
 
+    if (hasIncompleteLinkRepair(this.tail, repaired)) {
+      return this.render(
+        repairTail(this.tail, this.context, LITERAL_LINK_REMEND),
+      );

P2 Badge Preserve document scope before returning literal links

When the cache has already retained a block containing a reference such as [docs][r], and one coalesced update later adds both [r]: https://example.com and an unfinished link, this early return bypasses the document-scope check below. Streamdown then parses the retained reference separately from its definition, so the reference is displayed literally until the unfinished link completes. Check markdownRenderScope(markdown) before this return, or use the full-document render path when the reply requires document-wide parsing.

Useful? React with 👍 / 👎.

Accepted on the mirror

Reply from danielhanchen:

Fixed in b6ecf17: the footnote and document-scope check now runs before the literal-link render, so a reply needing document-wide parsing goes to the full-document path.

Round 3: reviewed mirror 4b391feaf (no equivalent commit found on this PR)

chatgpt-codex-connector[bot] on studio/frontend/src/components/assistant-ui/streaming-render-schedule.ts (on the mirror)

@@ -1472,6 +1505,9 @@ export class IncrementalMarkdownCache {
     ) {
       return this.renderFullDocument(markdown);
     }
+    if (linkPending) {
+      return this.render(repaired);

P2 Badge Bound the tail while a link remains unfinished

When a response contains an unmatched link opener and then continues for a long time (for example, See [foo followed by many paragraphs), this return prevents both block retention and the STALLED_TAIL_CHARACTERS fallback below from ever running. The live tail therefore grows to the full response, and every token update reruns Remend and Streamdown parsing over all accumulated text, making streaming work quadratic and potentially freezing long chats. Allow safe prefix commits while preserving the unfinished-link block, or apply the stalled-tail fallback before returning.

Useful? React with 👍 / 👎.

Accepted on the mirror

Reply from danielhanchen:

Fixed in 8b27b04: the early return is gone, so a tail with an unfinished link goes through block retention and the stalled-tail fallback like any other tail, and the post-commit tail repair uses the same literal-link rule. A stray unmatched [ early in a long reply still keeps its paragraph live on main too (same tail length and zero commits measured on both), so that part predates this change.

Round 4: reviewed mirror ae545919ee (this PR's 8b27b042d)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: ae545919ee

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror ae545919ee (this PR's 8b27b042d).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 5, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 5, 2026
@danielhanchen
danielhanchen merged commit 7aded1f into unslothai:main Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] "streamdown:incomplete-link" & "[blocked]" Showing In Streaming Response

4 participants