Skip to content

fix(cli): prevent duplicated prompt rows after terminal resize#6766

Closed
g-guthrie wants to merge 1 commit into
NousResearch:mainfrom
g-guthrie:fix/resize-prompt-duplication
Closed

fix(cli): prevent duplicated prompt rows after terminal resize#6766
g-guthrie wants to merge 1 commit into
NousResearch:mainfrom
g-guthrie:fix/resize-prompt-duplication

Conversation

@g-guthrie

@g-guthrie g-guthrie commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • replace the coarse resize reflow multiplier with row-aware shrink estimation
  • prevent duplicated prompt/input rows from accumulating after repeated terminal resizes
  • add a regression test for resize reflow math

Problem

The current resize workaround in cli.py estimates extra reflowed rows as last_height * (reflow_factor - 1). That coarse estimate can under/over-shoot when rendered rows have different widths, leaving old prompt/input rows behind after repeated shrink/expand cycles.

Fix

Use the actual widths of the previously rendered physical rows from renderer._last_screen.data_buffer to estimate how many extra rows narrowing will create, then inflate renderer._cursor_pos.y by that exact extra-row count before prompt_toolkit erases/redraws.

Test Plan

  • ~/.hermes/Hermes-Agent/venv/bin/python -m py_compile cli.py tests/cli/test_cli_resize_reflow.py
  • ~/.hermes/Hermes-Agent/venv/bin/python -m pytest tests/cli/test_cli_resize_reflow.py tests/cli/test_cli_loading_indicator.py -q

Notes

  • observed locally while resizing the Hermes CLI window on macOS
  • fix is intentionally scoped to terminal shrink reflow, which is the case the previous workaround was targeting

- replace the coarse shrink reflow multiplier with row-by-row estimation
- prevent duplicated prompt/input rows after repeated terminal resizes
- add a regression test covering resize reflow math
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/cli CLI entry point, hermes_cli/, setup wizard labels Apr 29, 2026
@liw71750-dotcom

Copy link
Copy Markdown

This PR addresses one specific symptom of a broader issue: the CLI/TUI does not reflow content on terminal resize. There are 34+ open bugs about various manifestations of this problem.

I've opened a tracking feature request (#24164) that proposes a comprehensive solution — a SIGWINCH handler triggering full re-render at new viewport dimensions, comparable to how opencode and Claude Code handle resize smoothly.

If this PR gets merged, please consider whether the underlying architecture supports full reflow, or if we still need a systematic fix. The tracking issue consolidates all related work:

#24164

@teknium1

Copy link
Copy Markdown
Contributor

Closing — the helper math is good but unanchored on current main. This PR was built on the old _resize_clear_ghosts design that mutated renderer._cursor_pos.y to inflate the cursor-up count. That whole approach has been replaced: _resize_clear_ghosts (now cli.py:13050) just calls self._schedule_resize_recovery(app, _original_on_resize), which delegates to _recover_after_resize — a debounced renderer.reset + invalidate + original_on_resize path with no manual cursor accounting. Your _estimate_reflowed_height_for_narrower_width helper no longer has a host function to live in.

If a follow-up shrink-reflow drift appears that the current debounced path can't catch, we can extract the helper from this closed PR for a fresh implementation against the new architecture. Thanks @g-guthrie!

@teknium1 teknium1 closed this May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants