Skip to content

fix: scope Studio markdown renders from the repaired document - #10924

Closed
apurv-1 wants to merge 4 commits into
unslothai:mainfrom
apurv-1:fix/studio-markdown-repaired-document-scope
Closed

apurv-1 wants to merge 4 commits into
unslothai:mainfrom
apurv-1:fix/studio-markdown-repaired-document-scope

Conversation

@apurv-1

@apurv-1 apurv-1 commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Test plan

  • studio/frontend streaming-render-schedule and link-definition-oracle tests (51 pass)
  • New test "a mid-stream reference is scoped from the repaired document": fails on main, passes here
  • New test "a reference the stream abandons does not stick to the full-document path": fails on main and on the original head, passes here
  • 120-reply corpus (5 definition shapes x 12 reference shapes x 2 orders, every prefix): block mismatches 27 on main, 0 here; replies left on the sticky path 51 on main, 51 here

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 24cd479cc8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

FOOTNOTE_REFERENCE_RE.test(repaired) ||
FOOTNOTE_DEFINITION_RE.test(repaired) ||
markdownRenderScope(markdown) === "document"
markdownRenderScope(repairedDocument) === "document"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid making repaired-only document scope sticky

When a stream contains a definition and temporarily ends in an incomplete reference such as [ref]: /docs\n\nSee [docs][ref, remend synthesizes the final ], so this condition calls renderFullDocument and sets fullDocumentMode. If the next appended character makes the reference invalid (for example, a newline before its closing bracket), the repaired document returns to block scope, but the early return at line 1341 keeps rendering the entire document for every subsequent append. Thus a final reply that should use block rendering permanently loses per-block code controls and incremental performance; repaired-only scope needs to be re-evaluated as the stream grows rather than entering the sticky path.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in e7fe6eb: only a source-level pair enters the sticky path; a repaired-only document renders once and is re-scoped on the next frame.

@apurv-1

apurv-1 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for spelling that out.

The scoping change is independent of #10688. Once that one lands, this PR is only IncrementalMarkdownCache.update reading markdownRenderScope off the repaired document, so a mid-stream [docs][ref that remend closes is one document instead of a retained prefix plus tail. Replies that stay on the blocks path stay incremental.

I dropped the extra blank lines in test_transformers_version_optional_tiktoken.py. They were not part of this change.

I also merged main in, so the three red checks from the uv-cache workflow guards should clear with #10826.

@apurv-1
apurv-1 force-pushed the fix/studio-markdown-repaired-document-scope branch from 5a4484a to 3b27f31 Compare September 15, 2026 02:29
@danielhanchen danielhanchen self-assigned this Oct 5, 2026
… non-sticky

Resolve conflicts toward main: the link probe rewrites on main (unslothai#9645,
unslothai#11375) replace unslothai#10688's hunks, and the repaired-document scope does not
depend on them. A reference that remend closes early now renders as one
document, but only a source-level pair enters the sticky full-document
path, so a stream that abandons the reference returns to blocks.
@danielhanchen

Copy link
Copy Markdown
Member

Thank you for the PR and the careful test case. Closing this one because #12104 has since removed the condition it fixes.

This PR scoped the render from the repaired document because remend used to close a mid-stream [docs][ref early, so the displayed text was already one document while the source scope still said blocks. Since #12104 (keep unfinished chat links as text), an incomplete link is repaired with remend's link pass turned off (repairStreamingMarkdown / repairTailKeepingLinks), so the bracket is no longer synthesised and the repaired and source scopes agree.

Measured on current main (d1f6cb5cf), without this change:

  • the "mid-stream reference is scoped from the repaired document" test from this PR passes (49/49 in streaming-render-schedule.test.ts, against the main oracle repairStreamingMarkdown)
  • a 120-reply corpus (5 definition shapes x 12 reference shapes x 2 orders) streamed one character at a time: 0 block mismatches, and the repaired-document branch this PR adds would fire on 0 frames

So merging it now would add a second scope check per frame with no behaviour change. Happy to reopen if a case turns up where the repaired and source scopes still diverge.

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.

2 participants