Skip to content

Long rendered responses are duplicated in terminal scrollback because Rich Live uses vertical_overflow="visible" #266

Description

@muhammadyaseen

Long responses appear multiple times in the terminal window

Long responses from openkb chat and openkb query appear repeatedly in terminal scrollback.

The problem reproduces in both iTerm2 and the VS Code integrated terminal on macOS. I have verified the persisted chat JSON logs and they contain (correctly) the response only once, confirming that the model output and stored session are correct and that the duplication is introduced by terminal rendering (see verification screenshots below).

jq -r '.assistant_texts[]' .openkb/chats/<session-id>.json

How to reproduce

  1. Open a terminal with a relatively short viewport e.g. on a laptop.
  2. Run: openkb chat OR openkb query "any query which would lead to a longer response..."
  3. Generate a response substantially longer than the terminal viewport.
  4. After the response completes, scroll upward through the terminal history.

Reason for the current behaviour

OpenKB creates its Rich live display with:

# In agent/chat.py and agent/query.py
Live(console=console, vertical_overflow="visible")

but Rich already documents that a live display cannot be properly cleared when vertical_overflow="visible" is used:

"visible" will allow the whole renderable to be shown. Note that the display cannot be properly cleared in this mode.

Proposed fixed (verified by me locally)

I changed the overflow mode to "ellipsis" which fixes the scrollback / redraw issue in both terminals. (Ellipsis is default, I just made it explicit)

Actual behavior

I was able to reprodice this behavior in:

  • iTerm2
  • VS Code integrated terminal

Screenshot: Current visible behavior

Notice the repeated "G-Eval" lines

In VSCode Terminal:

Image

In iTerm:

Image

Fix

If this fix is acceptable, I'm happy to raise a PR: Use Rich’s bounded "ellipsis" overflow behavior:

diff --git a/openkb/agent/chat.py b/openkb/agent/chat.py
@@
-        lv = Live(console=console, vertical_overflow="visible")
+        lv = Live(console=console, vertical_overflow="ellipsis")

diff --git a/openkb/agent/query.py b/openkb/agent/query.py
@@
-        lv = Live(console=console, vertical_overflow="visible")
+        lv = Live(console=console, vertical_overflow="ellipsis")

Screenshot: Fixed ellipsis behavior

Image

Environment

  • OpenKB: 0.4.5
  • Python: 3.14.7
  • Rich: 15.0.0
  • macOS: 26.6.2 (25G83)
  • Architecture: Apple Silicon / arm64
  • iTerm2: 3.7.2
  • Visual Studio Code: 1.138.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions