Skip to content

fix: Render conversation history in the UI#602

Open
sjathin wants to merge 5 commits intoOpenHands:mainfrom
sjathin:open-hands-cli-287
Open

fix: Render conversation history in the UI#602
sjathin wants to merge 5 commits intoOpenHands:mainfrom
sjathin:open-hands-cli-287

Conversation

@sjathin
Copy link
Copy Markdown
Contributor

@sjathin sjathin commented Mar 22, 2026

Summary of PR

  • ConversationRunner.replay_events() — new method that iterates persisted events and renders them through the visualizer. User messages get special handling via render_user_message() since on_event()
    intentionally skips them (they're normally rendered separately by the UI layer).
  • OpenHandsApp._replay_conversation_history() — called during _initialize_main_ui() when --resume is used. Eagerly creates the runner and replays events.
  • ConversationSwitchController._prepare_switch() — now calls runner.replay_events() after get_or_create() so switching via the history panel also shows prior conversation history.

Demo Screenshots/Videos

Screen.Recording.2026-03-22.at.18.57.01.mov

Change Type

  • Bug fix
  • New feature
  • Breaking change
  • Refactor
  • Other (dependency update, docs, typo fixes, etc.)

Checklist

  • I have read and reviewed the code and I understand what the code is doing.
  • I have tested the code to the best of my ability and ensured it works as expected.

Fixes

Resolves #287

Release Notes

  • Include this change in the Release Notes.

Renders conversation history in the UI

@sjathin sjathin marked this pull request as ready for review March 22, 2026 14:29
"""Replay persisted events through the visualizer.

User messages are rendered via render_user_message since on_event
skips them (they are normally rendered separately by the UI).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It seems this only shows user messages. I think conversation history has many other events, since it's the history of agent's run.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The code handles all event types — the replay_events method sends every non-user event through on_event, which renders ActionEvent, ObservationEvent, MessageEvent (assistant), ConversationErrorEvent, FinishAction, ThinkAction, etc.

See

Screen.Recording.2026-03-22.at.18.57.01.mov

Comment thread openhands_cli/tui/core/conversation_runner.py Outdated
Copy link
Copy Markdown
Collaborator

@enyst enyst left a comment

Choose a reason for hiding this comment

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

Thank you for looking into this!

I left a few comments inline. Sorry, the PR doesn't currently render conversation history, which can have many more agent events.

The video you posted shows an error only. If you add an LLM and run the agent, for real, it will not render conversation history, I think?

I will mark this PR as draft, please feel free to set it ready when it's ready for review.

@enyst enyst marked this pull request as draft March 22, 2026 14:50
@sjathin
Copy link
Copy Markdown
Contributor Author

sjathin commented Mar 22, 2026

@enyst

Thanks for reviewing the PR.

Marking it as Ready for review again. I have addressed the comments above:

PR doesn't currently render conversation history

The code handles all event types — the replay_events method sends every non-user event through on_event, which renders ActionEvent, ObservationEvent, MessageEvent (assistant), ConversationErrorEvent, FinishAction, ThinkAction, etc.

attempting to go through ALL events in history has O(n) complexity

Added a cap to replay_events() so we only replay the tail end of the history.

@sjathin sjathin marked this pull request as ready for review March 22, 2026 18:06
@sjathin
Copy link
Copy Markdown
Contributor Author

sjathin commented Apr 16, 2026

@enyst

Looked into the PR #562 there has been no updates on it since the last month. Could we prioritize this PR?

@cbagwell
Copy link
Copy Markdown
Contributor

cbagwell commented Apr 30, 2026

I am interested in this feature so I gave it a test. I tested this PR because I can wrap my head around what the 3 file changes are doing while the other PR modifies 24 files. I also thought it would help reviews if broken into 3 incremental features:

  1. Replay X newest events on resume.
  2. Add a way to click and load X more older events incrementally.
  3. Implement an infinite style scroll to replace clicking.

This PR does 1 and works great for me. A review comment is some tests might be good. Maybe a snapshot test showing the restored text? Not sure exactly.

I had an agent rebase this patch to latest main and then create a draft patch for 2. It needs closer review and more testing (for example, loading only works with mouse I think). https://github.com/cbagwell/OpenHands-CLI/tree/feat/history-on-restore

Feel free to incorporate that patch into this PR or if this one is merged as-is I can create a follow up PR.

@cbagwell
Copy link
Copy Markdown
Contributor

As a data point about the limit of 50: I have an older machine where the SDK itself takes 10 seconds to load on its own before openhands loads. So it's on the slow side. I then made the cutoff limit very high to basically disable it and I loaded a conversation with 1K events. I didn't notice all that much of a lag or memory usage. It did take maybe 4 seconds to load the full conversation which I didn't feel was bad. Also, it did a better job because it also seemed to have restored the fact that the planner pane was last open... whereas when cutoff was hit, that wasn't done.

I wonder what a proper cutoff value is and if 50 is to low?

sjathin and others added 3 commits May 1, 2026 01:00
Rich's highlighter was applying ANSI codes to the error message text
(e.g. 'variable(s)'), breaking plain-text assertions in tests.
Use rich_escape() and highlight=False to prevent markup interpretation.
Also update snapshots for SDK 1.19.0 changes.
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.

[CLI] Cannot condense resumed conversation

3 participants