Fix terminal block missing first line via f32 tolerance#52111
Merged
Veykril merged 3 commits intozed-industries:mainfrom Mar 23, 2026
Merged
Conversation
Veykril
reviewed
Mar 23, 2026
…recision tolerance
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
TerminalBounds::num_lines()usesfloor(height / line_height)to compute the terminal grid row count. When the height is derived fromN * line_height(as it is for inline/embedded terminals in the Agent Panel), IEEE 754 float32 arithmetic can produceN - epsiloninstead ofN, causingfloor()to returnN - 1. This makes the terminal grid one row too small, leaving the first line of output in invisible scrollback (sincedisplay_offset = 0). The same issue applies tonum_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) innum_lines()andnum_columns()incrates/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
Release Notes: