Skip to content

feat(tui): add message_limit config and fix export truncation#15006

Closed
n24q02m wants to merge 2 commits into
anomalyco:devfrom
n24q02m:feat/tui-message-limit-and-export-fix
Closed

feat(tui): add message_limit config and fix export truncation#15006
n24q02m wants to merge 2 commits into
anomalyco:devfrom
n24q02m:feat/tui-message-limit-and-export-fix

Conversation

@n24q02m
Copy link
Copy Markdown

@n24q02m n24q02m commented Feb 25, 2026

Issue for this PR

Closes #9930
Closes #14948

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

  1. Fix TUI lag and 100% CPU on long sessions (Add configurable scrollback/message limit to reduce TUI lag #9930, High CPU usage (100%+) during LLM streaming in long sessions due to O(n) text buffer rendering #6172): Introduces the tui.message_limit config option. By setting this to an integer (e.g. 50), OpenTUI will only render the last N messages of a session. This completely avoids the O(n) layout calculation loops that previously crashed the app when scrolling long histories. The default remains "none" to preserve backwards compatibility.
  2. Fix JSON truncation on opencode export via piped stdout ([BUG] opencode export outputs truncated JSON when piped #14948, Bug: Intermittent truncated stdout when piping opencode export #2803): When users piped the output of opencode export to tools like jq, the main process often exited via process.exit() before NodeJS could fully flush the asynchronous stdout stream. This PR fixes it by properly awaiting a zero-length write callback in the export handler and introducing a setImmediate() microtask loop before the final app teardown.

How did you verify your code works?

Built and compiled locally.

  1. Export Test: Generated a massive session and piped opencode export <session> | jq . -> It successfully parsed the full 15MB file without premature truncation errors.
  2. TUI Test: Tested tui: {message_limit: 5} in opencode.json, opened a long session and observed that only the last 5 messages were rendered, with CPU usage dropping to near 0%.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@n24q02m n24q02m force-pushed the feat/tui-message-limit-and-export-fix branch from 9baae17 to 72710b1 Compare March 6, 2026 13:14
@n24q02m
Copy link
Copy Markdown
Author

n24q02m commented Mar 6, 2026

Rebased onto latest dev to resolve conflicts. Also removed the stale Closes #2803 reference (that issue was already fixed by #3049 in Oct 2025). The +13K lines addition is from the auto-generated openapi.json spec.

@n24q02m
Copy link
Copy Markdown
Author

n24q02m commented Apr 2, 2026

Closing — I'm no longer actively using OpenCode. Feel free to cherry-pick any changes if useful.

@n24q02m n24q02m closed this Apr 2, 2026
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.

[BUG] opencode export outputs truncated JSON when piped Add configurable scrollback/message limit to reduce TUI lag

1 participant