Repository navigation
fix(tui): keep the view in place when an older page is measured late - #273
Conversation
ThreadView.show(prepended=True) scrolls past the added height in one call_after_refresh. On a loaded loop that refresh can run before the layout that measures the new rows, so the height had not grown, the scroll moved by 0, and the reader was left at the top of the longer thread. That is the remaining failure of test_older_rows_keep_the_view_where_it_was after pepper-cli#195 made it wait (merge-queue run 43496483442: "condition not reached" after 5s). keep_place now waits for up to five more refreshes while the height has not grown. Running keep_place before the layout (instead of after the refresh) fails the test on the old code and passes it with this change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ALQbQ2fKvgEPYLj9LMKnnH
Vycari ReviewRound 4 on 9b8d772. The verdict is the Vycari Review check run, and each open finding is an inline thread. Reply on every P0 and P1 thread: Open: P0 0 · P1 0 · P2 1 · disputed 0 · confirmed fixed 0 · withdrawn 0 Hand-off: Greptile requested on 9b8d772. Greptile follow-through
No open P0 or P1 findings this round. P2s, judge's notes and closed findingsOpen P2 findings
Judge's notes No new findings at this head, and both Greptile findings are fixed: stale retries now stop when a different conversation is opened, and a new test exercises the retry path. One P2 is still open: if layout takes longer than five refreshes, the reader can still end up at the top of the longer thread. The author declined that change as a deliberate trade-off. |
| def keep_place(tries: int = _KEEP_PLACE_TRIES) -> None: | ||
| grown = scroller.virtual_size.height - old_height | ||
| if grown <= 0 and tries > 1: | ||
| # The refresh this waited for can land before the layout that measures | ||
| # the new rows (a loaded loop); scrolling by 0 would leave the reader at | ||
| # the top of the longer thread. Wait for the next one. | ||
| scroller.call_after_refresh(keep_place, tries - 1) | ||
| return | ||
| scroller.scroll_to(y=old_y + max(grown, 0), animate=False) | ||
|
|
||
| scroller.call_after_refresh(keep_place) |
There was a problem hiding this comment.
P2 · VR-9a84a806 · Older-page keep-place still lands at the top when layout lags past the retry budget
On a very slow machine, if the older page still isn't laid out after five screen refreshes, the view still jumps to the top of the thread. The fix waits for a set number of refreshes rather than for the new rows' height.
Reply Fixed in <sha> or Disputed: with a reason.
Details for agents: evidence, failure scenario, verification, proving test
keep_place waits a fixed count of call_after_refresh callbacks (_KEEP_PLACE_TRIES = 5) for virtual_size.height to grow, then scrolls by max(grown, 0). The wait is counted in refresh callbacks, not in measured layout. If the new rows are still unmeasured after the 5th callback, grown is 0 and the scroll is to old_y, i.e. the top of the longer thread, which is the exact bug this PR claims to fix. The patch narrows the window; it does not make the scroll depend on the measurement.
Evidence: Read thread.py:142-161. Retry is bounded by tries > 1 (line 150) and the fallback is scroll_to(old_y + max(grown, 0)) (line 156). Callers: app.py:936-942 and app.py:1829 (prepended=bool(added)). No wall-clock or layout-based wait exists. Textual sources are not in the checkout, so I could not confirm how many layout passes a call_after_refresh cycle actually spans; the claim rests only on the bounded count in this file.
Failure scenario
User is at the top of a thread and scrolls up, triggering an older page (app.py:1829 passes prepended=True). On a heavily loaded machine the Static body's new height is not laid out within the 5 scheduled refreshes. keep_place runs on the 5th callback with grown == 0, scrolls to old_y, and the reader is left at the top of the longer thread with the same lines no longer in view.
How this was verified (read-only-reasoning)
I read thread.py:142-161. The retry is bounded at 5 and the fallback is scroll_to(old_y + max(grown, 0)). I did not open the app.py callers; I took them from the candidate's evidence. Textual's layout timing is not in the checkout, so I could not check how many layouts a refresh spans. Reachable from: ThreadView.show(prepended=True), called from the app older-page load path.
Proving test
Unit test on ThreadView: mount, show a short thread, then show a prepended longer body while patching virtual_size so the height only grows after the 6th call_after_refresh callback. Assert scroll_y equals the old offset plus the added height. On head this fails because keep_place gives up after 5 tries and scrolls by 0.
lens concurrency-time · symbol ThreadView.show
There was a problem hiding this comment.
Declined: an unbounded wait has no end in the case where the prepended rows really add no height, and a time-based wait would read the wall clock in a path the tests drive by refresh. Five refreshes is several times what the merge-queue repro needed (it failed with zero retries and passed with one). If a reader still lands at the top, the view is no worse than before this PR, and the new scroll-guard means a reader who moves isn't overridden.
Generated by Claude Code
|
@greptileai review |
Answers VR-6b3a8f9f on pepper-cli#273. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ALQbQ2fKvgEPYLj9LMKnnH
…etry branch directly Answers Greptile's P1 and P2 on pepper-cli#273. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ALQbQ2fKvgEPYLj9LMKnnH
…e load The Windows run loaded an older page while the test waited at the top, so the view moved for a reason the test was not about. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ALQbQ2fKvgEPYLj9LMKnnH
|
@greptileai review |
Requested by Allen · project thread
Human overview
test_older_rows_keep_the_view_where_it_wasfailed in the merge queue on 11-13, even after pepper-cli#195 made it wait for the scroll. This time it was a real bug in the app. When you scroll up and an older page of messages loads, the app is meant to keep showing the same lines. On a busy machine it measured the thread before the new rows had been laid out, scrolled by zero, and left you at the very top. It now waits up to a few more screen refreshes for the new height before scrolling.AI reviewer
await until(pilot, lambda: scroller.scroll_y > 0)withcondition not reachedafter 5s, in a suite that took 8m41s (loaded). Polling for 5s and never seeing a scroll meanskeep_placeran withgrown == 0, not that the test read too early. test: wait for the older-page scroll instead of reading it after one pause #195 already fixed the reading-too-early case.src/pepper_cli/tui/thread.py):keep_place(tries=_KEEP_PLACE_TRIES)re-defers itself withcall_after_refreshwhilevirtual_size.heighthas not grown, up to 5 refreshes.max(grown, 0), so a page that really added no height still ends up where it did before.call_after_refresh(keep_place)scheduling with an immediatekeep_place(), which simulates the refresh running before layout. The old code then fails the test; the new code passes it 3 of 3.tests/test_tui_parity.pyandtests/test_tui_live.py: 53 passed. ruff format/check andty check src/pepper_cli/are clean.Checklist (repo-specific)
uv run ruff format --checkanduv run ruff checkclean (no new lint ignores)uv run ty check src/pepper_cli/cleanuv run pytestpasses for the TUI files; coverage floor not loweredGenerated by Claude Code


Confidence Score: 5/5
The PR appears safe to merge; both previous findings are addressed and no new blocking issue was found.Summary
The PR keeps older-page scroll retries from overriding a conversation switch or a reader's later scroll.
Reviews (2) · Last reviewed commit: "Make the reset keep-place test independe..." · Reviewed by Greptile