Skip to content

Fix Rich markup corrupting/crashing streamed answers and echoed input#1

Open
rajamohan1950 wants to merge 1 commit into
kunaldeo:mainfrom
rajamohan1950:fix/rich-markup-answer-corruption
Open

Fix Rich markup corrupting/crashing streamed answers and echoed input#1
rajamohan1950 wants to merge 1 commit into
kunaldeo:mainfrom
rajamohan1950:fix/rich-markup-answer-corruption

Conversation

@rajamohan1950

@rajamohan1950 rajamohan1950 commented Jul 8, 2026

Copy link
Copy Markdown

Summary

The tool's own output is fed to rich's Console.print with markup enabled, so bracketed text is interpreted as Rich style tags. For a code Q&A tool this is common in both answers and questions (type hints like List[str], decorators, list literals, closing-tag-like sequences), which leads to silent content loss and, in some cases, an outright crash.

Root cause & impact

  • Streamed answers (-s / CODE_QNA_STREAM=true) — each chunk was printed via console.print(chunk) with markup enabled:
    • List[str] renders as List — the [str] is swallowed as a bogus style tag, so the user sees a subtly wrong answer.
    • Tag-like text such as [/close] raises rich.errors.MarkupError, aborting the response mid-stream.
  • Echoed question (default, non-streaming path)console.print(f"...{question}") embeds raw user input inside a markup string, so e.g. code-qna "what is List[str]?" corrupts the echo and code-qna "[/x]" crashes before answering.
  • Debug keywords line — same class of issue for question-derived text.

The non-streaming answer path is unaffected because it wraps output in Markdown(answer).

Changes

  • Print streamed chunks with markup=False, highlight=False.
  • Escape the echoed question and debug keywords with rich.markup.escape.

Test plan

  • List[str], a[0]+b[1], and [/close] now stream through intact with no loss and no MarkupError.
  • Questions containing List[str] and [/x] echo correctly and no longer crash.
  • Manual run of code-qna -s "what does List[str] mean?" against a sample repo.

Streamed AI answers were emitted via console.print(chunk) with Rich markup enabled, so any bracketed text in the model output (e.g. List[str], decorators, list literals) was interpreted as style tags. This silently dropped content (List[str] rendered as "List ") and could raise MarkupError on tag-like sequences such as [/close], aborting the response mid-stream.

The same class of bug affected the echoed user question (default, non-streaming path) and the debug keywords line, where untrusted text was embedded inside markup f-strings.

- Print streamed chunks with markup=False, highlight=False
- Escape the question and keywords with rich.markup.escape
@rajamohan1950 rajamohan1950 force-pushed the fix/rich-markup-answer-corruption branch from 6bf97ed to 25af0df Compare July 8, 2026 05:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant