Skip to content

Fix terminal block missing first line via f32 tolerance#52111

Merged
Veykril merged 3 commits intozed-industries:mainfrom
Dnreikronos:fix/terminal-block-first-line-missing-51609
Mar 23, 2026
Merged

Fix terminal block missing first line via f32 tolerance#52111
Veykril merged 3 commits intozed-industries:mainfrom
Dnreikronos:fix/terminal-block-first-line-missing-51609

Conversation

@Dnreikronos
Copy link
Copy Markdown
Contributor

Context

TerminalBounds::num_lines() uses floor(height / line_height) to compute the terminal grid row count. When the height is derived from N * line_height (as it is for inline/embedded terminals in the Agent Panel), IEEE 754 float32 arithmetic can produce N - epsilon instead of N, causing floor() to return N - 1. This makes the terminal grid one row too small, leaving the first line of output in invisible scrollback (since display_offset = 0). The same issue applies to num_columns().

The fix adds a small tolerance (0.01) before flooring, which absorbs float precision errors without affecting genuine fractional results.

Closes #51609

How to Review

Small PR — focus on the tolerance value (0.01) in num_lines() and num_columns() in crates/terminal/src/terminal.rs. The two new tests (test_num_lines_float_precision, test_num_columns_float_precision) verify the fix across 1,000+ float combinations that previously triggered the bug.

Self-Review Checklist

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Fixed the first line of terminal output sometimes missing in Agent Panel terminal blocks.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 22, 2026
@zed-codeowner-coordinator zed-codeowner-coordinator bot requested review from a team, Veykril and cole-miller and removed request for a team March 22, 2026 01:22
@maxdeviant maxdeviant changed the title fix: terminal block missing first line via f32 tolerance #51609 Fix terminal block missing first line via f32 tolerance Mar 22, 2026
@Dnreikronos Dnreikronos requested a review from Veykril March 23, 2026 13:19
@Veykril Veykril enabled auto-merge (squash) March 23, 2026 14:44
@Veykril Veykril merged commit aa63f8e into zed-industries:main Mar 23, 2026
31 checks passed
@Dnreikronos
Copy link
Copy Markdown
Contributor Author

@Veykril, thanks for your time invested and for working with me on that.

AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 23, 2026
…es#52111)

## Context

`TerminalBounds::num_lines()` uses `floor(height / line_height)` to
compute the terminal grid row count. When the height is derived from `N
* line_height` (as it is for inline/embedded terminals in the Agent
Panel), IEEE 754 float32 arithmetic can produce `N - epsilon` instead of
`N`, causing `floor()` to return `N - 1`. This makes the terminal grid
one row too small, leaving the first line of output in invisible
scrollback (since `display_offset = 0`). The same issue applies to
`num_columns()`.

The fix adds a small tolerance (`0.01`) before flooring, which absorbs
float precision errors without affecting genuine fractional results.

Closes zed-industries#51609

## How to Review

Small PR — focus on the tolerance value (`0.01`) in `num_lines()` and
`num_columns()` in `crates/terminal/src/terminal.rs`. The two new tests
(`test_num_lines_float_precision`, `test_num_columns_float_precision`)
verify the fix across 1,000+ float combinations that previously
triggered the bug.

## Self-Review Checklist

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [ ] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed the first line of terminal output sometimes missing in Agent
Panel terminal blocks.
maxbrunsfeld added a commit that referenced this pull request Mar 24, 2026
This PR fixes test flakiness introduced in
#52111

The flakiness was because the test was using its own RNG, rather than
using gpui's built-in support for consistently-seeded RNGs in tests. The
fix was just to adjust the test to use the same logic for computing row
and column count as was introduced in the above PR.

Release Notes:

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

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

First line of terminal block in Agent Panel is sometimes missing

2 participants