Skip to content

fix(tui): keep the view in place when an older page is measured late - #273

Merged
allenhutchison merged 4 commits into
mainfrom
claude/project-thread-60d62o-keep-place-retry
Nov 16, 2026
Merged

allenhutchison merged 4 commits into
mainfrom
claude/project-thread-60d62o-keep-place-retry

Conversation

@allenhutchison

@allenhutchison allenhutchison commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Allen · project thread

Human overview

test_older_rows_keep_the_view_where_it_was failed 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

  • Evidence: merge-queue run 43496483442. The test failed at await until(pilot, lambda: scroller.scroll_y > 0) with condition not reached after 5s, in a suite that took 8m41s (loaded). Polling for 5s and never seeing a scroll means keep_place ran with grown == 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.
  • Change (src/pepper_cli/tui/thread.py):
    • keep_place(tries=_KEEP_PLACE_TRIES) re-defers itself with call_after_refresh while virtual_size.height has not grown, up to 5 refreshes.
    • After that it scrolls as before, using max(grown, 0), so a page that really added no height still ends up where it did before.
  • Repro: I replaced the call_after_refresh(keep_place) scheduling with an immediate keep_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.py and tests/test_tui_live.py: 53 passed. ruff format/check and ty check src/pepper_cli/ are clean.
  • Risk: a prepend whose rows render zero lines costs up to 5 extra refresh callbacks, then the same no-op scroll as before.

Checklist (repo-specific)

  • uv run ruff format --check and uv run ruff check clean (no new lint ignores)
  • uv run ty check src/pepper_cli/ clean
  • uv run pytest passes for the TUI files; coverage floor not lowered
  • Server-contract changes (N/A)
  • No token or credential is logged, printed, or put in a fixture
  • README / SKILL.md (N/A: no command change)

Generated by Claude Code

RetriggerView in GreptileConfidence 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.

  • Older pages keep the reader on the same messages while their rows are measured.

Reviews (2) · Last reviewed commit: "Make the reset keep-place test independe..." · Reviewed by Greptile

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
@allenhutchison allenhutchison self-assigned this Nov 16, 2026
@vycari-review

vycari-review Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Vycari Review

Round 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: Fixed in <sha>, or Disputed: with a reason. P2s are the author's call: fix one, or reply Deferred: #<issue> (the PR's one follow-up issue) or Declined: with a reason, and VR stops re-raising it. From round 2 on, VR raises no new P2s: it checks the fixes and looks for P0s and P1s.

Open: P0 0 · P1 0 · P2 1 · disputed 0 · confirmed fixed 0 · withdrawn 0

Hand-off: Greptile requested on 9b8d772.

Greptile follow-through

  • P1 · GR-4588800578 · src/pepper_cli/tui/thread.py:166 · fixed (confirmed), thread answered · fixed-confirmed: Greptile reported that a pending retry from an older page could still fire after the user switched conversations, and scroll the new conversation back to the old position. At this head, opening a different conversation bumps a counter. Each pending retry checks that counter first and stops if it ha…
  • P2 · GR-4588800593 · src/pepper_cli/tui/thread.py:166 · fixed (confirmed), thread answered · fixed-confirmed: Greptile reported that no test reliably exercised the retry path. A new test now holds the measured height unchanged for the first callback, checks that it does not scroll and waits for the next refresh instead, then lets the height grow and checks the view scrolls by exactly the added rows. It als…

No open P0 or P1 findings this round.

P2s, judge's notes and closed findings

Open P2 findings

  • P2 · VR-9a84a806 · Older-page keep-place still lands at the top when layout lags past the retry budget · src/pepper_cli/tui/thread.py lines 148–158 (deferred by the author)

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.

Comment on lines +148 to 158
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)

@vycari-review vycari-review Bot Nov 16, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

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.

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

Comment thread src/pepper_cli/tui/thread.py Resolved
@vycari-review

vycari-review Bot commented Nov 16, 2026

Copy link
Copy Markdown

@greptileai review

Comment thread src/pepper_cli/tui/thread.py Resolved
Comment thread src/pepper_cli/tui/thread.py Resolved
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
@vycari-review

vycari-review Bot commented Nov 16, 2026

Copy link
Copy Markdown

@greptileai review

@allenhutchison
allenhutchison added this pull request to the merge queue Nov 16, 2026
Merged via the queue into main with commit fbb5390 Nov 16, 2026
5 checks passed
@allenhutchison
allenhutchison deleted the claude/project-thread-60d62o-keep-place-retry branch November 16, 2026 18:54
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.

2 participants