Skip to content

fix(tui): compensate scroll on message prune - #41247

Closed
Lauri-Nomme wants to merge 1 commit into
anomalyco:devfrom
Lauri-Nomme:scroll-prune-compensation
Closed

Lauri-Nomme wants to merge 1 commit into
anomalyco:devfrom
Lauri-Nomme:scroll-prune-compensation

Conversation

@Lauri-Nomme

@Lauri-Nomme Lauri-Nomme commented Aug 8, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #41243

Type of change

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

What does this PR do?

While the agent is producing output, a user can scroll up to read earlier messages. Once a session exceeds 100 messages, every new message prunes the oldest one off the top of the message store (packages/tui/src/context/sync.tsx). The scrollbox holds scrollTop fixed while scrolled up, so removing content above the reading position drifts the viewport down the transcript on every new message.

This PR compensates the scroll position when the oldest messages are pruned, keeping the reading position stable while the user is scrolled up:

  • packages/tui/src/util/scroll.ts: compensatePruneScrollTop returns a scrollTop moved up by the height of content that disappeared above the first surviving message, computed from the layout captured before the prune.
  • packages/tui/src/routes/session/index.tsx: runs it in a createComputed watching the message list, so it executes before the list re-renders while the pre-prune child layout is still available. Sticky-bottom following is untouched — when the user is at the bottom, compensation is skipped and the scrollbox re-sticks as usual.
  • AssistantMessage now wraps its parts in <box id={message.id}> so every message (user and assistant) renders an identifiable box. Previously only user messages carried an id, so pruned assistant messages could not be measured.

How did you verify your code works?

Added packages/tui/test/util/scroll-prune.test.tsx: unit tests for compensatePruneScrollTop plus a render test (testRender from @opentui/solid) mirroring the session wiring. It fills 100 alternating user/assistant messages, scrolls up 10 lines, then simulates the sync.tsx prune on each new message and asserts the message pinned at the top of the viewport stays at the same viewport line — without the fix it drifts from y = 2 to y = -22 across 6 prunes.

Verified bun typecheck (packages/tui) passes and the full packages/tui suite passes (200 tests, 8 snapshots unchanged).

Screenshots / recordings

N/A (terminal UI; no recording).

Checklist

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

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Aug 8, 2026
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@Lauri-Nomme

Copy link
Copy Markdown
Author

hi, @kommander @simonklee could you please have a look?

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Root cause analysis: viewport drifts while reading a backlog during generation (ref #29094)

1 participant