Skip to content

Fix long-response fallback in Rich streaming#133

Merged
chauncygu merged 1 commit into
SafeRL-Lab:mainfrom
tsint:fix-rich-live
Jun 4, 2026
Merged

Fix long-response fallback in Rich streaming#133
chauncygu merged 1 commit into
SafeRL-Lab:mainfrom
tsint:fix-rich-live

Conversation

@tsint
Copy link
Copy Markdown
Contributor

@tsint tsint commented Jun 4, 2026

Summary

Fix Rich Live streaming fallback for long responses.

Problem

Large streamed responses can exceed the practical redraw area for Rich Live. In some terminals, this may leave stale or duplicated output while the response is still streaming. The previous fallback logic also did not fully isolate fallback mode to the current response.

Changes

  • Added per-response plain streaming fallback state.
  • Estimate rendered line count with Rich instead of relying only on newline counts.
  • Make the Live line limit aware of terminal height.
  • Stop and clear the active Live frame before falling back to plain output.
  • Clear the accumulated buffer after fallback to avoid duplicate output.
  • Reset fallback state in flush_response() so the next response can use Live again.
  • Added focused tests for normal Live streaming, first-chunk fallback, and active-Live fallback.

Test Plan

uv run pytest -q tests/test_render_streaming.py

@chauncygu chauncygu merged commit e7ed1db into SafeRL-Lab:main Jun 4, 2026
6 checks passed
yanfeng98 pushed a commit to yanfeng98/pycode that referenced this pull request Jun 5, 2026
Follow-up to the long-response Rich Live fallback (PR SafeRL-Lab#133).

ui/render.py: _rendered_line_count now uses a cheap per-line wrap estimate
to short-circuit the expensive full console.render_lines() measurement while
a response stays comfortably under the limit. Normal responses no longer pay
an extra full Markdown re-render on every streamed chunk (was O(n^2) on the
hot path); the precise render only runs as output nears the fallback limit.
On render failure it now falls back to the cheap estimate instead of 0 so
oversized content still triggers the plain-streaming fallback.

Docs: document the automatic per-response plain-streaming fallback (wrap- /
terminal-height aware) across README News, docs/news.md, features.md,
advanced.md, and the 7 i18n READMEs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

2 participants