Skip to content

[0.0.27] fix(runtime,term-state): resize follow-ups from #2534 (#2543) - #2551

Merged
Xuepoo merged 3 commits into
mainfrom
ctx-2543/fix-resize-followups
Oct 23, 2026
Merged

Xuepoo merged 3 commits into
mainfrom
ctx-2543/fix-resize-followups

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Priority: P2 | Area: render | Labels: fix, P2, area:render | Milestone: v0.0.27 | RFC: — | Task: CTX-1464

Summary

Implements the five follow-ups tracked in #2543 from the independent review of #2534:

  • Selection follows height-driven content shifts. State::resize now reports the signed primary-content row shift (ResizeReport), and the runtime remaps a held non-buffer selection by that shift before clamping. Selections whose endpoints are pushed into scrollback are dropped fail-closed; width-changing reflows keep the existing clamp path (a reflow is not a constant shift). Buffer-anchored pointer selections remain on their combined-buffer anchors.
  • Scrollback module doc corrected. The module now documents height-only shrink pushes, width-reflow drain/rebuild, clear_last_wrap, pop_back_line, and the ED 3/FullReset clear instead of claiming append-only immutability.
  • resize_scrollback added to the nextest live-pty group in both the default and CI profiles (it spawns /bin/sh).
  • Cursor-detach edge documented and regressed. resize_height_only now states the exact condition: the cursor detaches iff new_rows < used_rows - cursor_row, and attachment needs used_rows - cursor_row rows. Regressions cover both directions (detach clamps to row 0 with content preserved; attachment shifts the cursor with its row).
  • 1-column reflow + max_lines documented and tested. The bounded-memory tradeoff sits next to the width-1 wide-pair limitation, and a 500-line fixture with a 64-line cap proves the cap is enforced without panic, orphan wide halves, or lost retained suffix.
  • Pane-owned selection remap regressed. A vertical divider shrink keeps a pane selection on its content, not just a primary-grid selection.

Verification

  • cargo test -p bitty-term-state --locked — all suites pass (14 in resize_reflow_2529, including the new cursor and 1-column-cap regressions).
  • cargo test -p bitty-runtime --test resize_scrollback --locked — 8 passed, including the selection remap/drop and pane-owned remap regressions.
  • cargo test -p bitty-runtime --test selection_scrollback --test scrollback_search_selection_persistence --test scrollback_search_ui_integration --test selection_clipboard --locked — all pass.
  • cargo test -p bitty-runtime --lib — 1237 passed.
  • cargo nextest show-config test-groups --groups live-pty — bitty-runtime::resize_scrollback is in the group under both profiles.
  • cargo nextest run -p bitty-runtime --test resize_scrollback --profile ci — 7 passed (before the pane regression landed; the direct suite now covers 8).
  • cargo fmt --all -- --check and both workspace clippy recipes (-D warnings, plus bitty-terminal --features dev-tools --all-targets) pass.

Docs follow-up (separate repository PR)

bitty-terminal-docs/specifications/terminal-state-rfc.md still says height-only shrink "moves the cursor with its content" unconditionally (Resize and reflow implementation evidence). It needs the same condition: detach iff new_rows < used_rows - cursor_row; attachment needs used_rows - cursor_row rows. Invariant 4 in the same file also still says lines enter scrollback only via scroll-under-region operations, which the height-only push path contradicts. Not edited here (Core-only scope).

Scoped CARGO_TARGET_DIR=$BITTY_WORKSPACE/.targets/ctx-2543; removed after the task. just ci-local was not run for this scoped subagent pass; remote CI is the remaining gate.

Closes #2543

@Xuepoo Xuepoo added this to the v0.0.27 milestone Oct 23, 2026
@Xuepoo Xuepoo added fix Bug fix area:render Area: rendering P2 Priority: medium labels Oct 23, 2026
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 47 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f8c01a35-6b74-4121-b16a-1902dc605e6c
📥 Commits

Reviewing files that changed from the base of the PR and between fa57b5b and 7a0febe.

📒 Files selected for processing: 10
  • .config/nextest.toml
  • crates/bitty-runtime/src/runtime.rs
  • crates/bitty-runtime/src/runtime/layout_focus.rs
  • crates/bitty-runtime/src/runtime/panes.rs
  • crates/bitty-runtime/src/runtime/resize.rs
  • crates/bitty-runtime/tests/resize_scrollback.rs
  • crates/bitty-term-state/src/lib.rs
  • crates/bitty-term-state/src/scrollback.rs
  • crates/bitty-term-state/src/state.rs
  • crates/bitty-term-state/tests/resize_reflow_2529.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Xuepoo Xuepoo left a comment

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.

Independent review — NEEDS-FIX

Reviewed head 2d11166e (base 101efbc4, 10 files, +352/−26) for 0.0.27 / #2543. No changes pushed, nothing merged.

Method: full diff read; targeted suites on the PR head; scoped
CARGO_TARGET_DIR=$BITTY_WORKSPACE/.targets/review-2551; nextest group/profile
listing; a local remap-disabled probe to prove the new runtime regressions are
not vacuous; throwaway term-state and pane probes for the cursor-detach and
pane-remap edges (both removed before finishing).

Verified behavior

  • Height-only selection remap (primary). resize_with_report reports the
    signed content shift only for height-only changes; reflow_content_to_chrome,
    resize_primary_grid, the panel-rule path, and sync_pane_geometry_to all
    remap before the existing clamp. A pushed endpoint drops fail-closed; a
    retained endpoint shifts. The width path returns early, so the prior
    reflow/DPI clamp behavior is unchanged. height_resize_keeps_held_selection_on_its_content
    proves anchor/focus rows, copied text, and buffer_row/matched_text
    identity across shrink and grow; height_shrink_drops_selection_pushed_into_scrollback
    proves the fail-closed drop.
  • Non-vacuity. Disabling remap_selection_for_resize locally makes both new
    runtime tests fail (2 failed / 1 passed in the height_ filter; the pass is
    the pre-existing two-pane test), so they genuinely gate the fix. The tree was
    restored (git status clean) and the suite re-ran green.
  • Pane path. A throwaway split-pane probe holding a non-buffer selection
    across a divider shrink/grow preserved its text; the new
    sync_pane_geometry_to remap works. No committed regression covers it (see
    follow-up 2).
  • Cursor-detach behavior. Term-state probes confirm the implementation:
    content-full shrink with the cursor above the pushed prefix shifts the cursor
    (24→12, cursor 20→8); a shrink whose push reaches the cursor clamps it to row
    0 (24→5 with cursor row 4); all content rows remain present exactly once in
    order. The committed regression proves the clamped case and row survival.
  • resize_scrollback nextest group. cargo nextest show-config test-groups --groups live-pty lists bitty-runtime::resize_scrollback (all 7 tests,
    including the two new ones) under both the default and ci overrides;
    cargo nextest run -p bitty-runtime --test resize_scrollback --profile ci
    ran 7/7 green.
  • 1-column reflow + cap. The committed 500-line/64-line-cap test passes:
    cap enforced, oldest-first pruning keeps the newest logical line, invariants
    hold after 1→80, and no panic. A throwaway wide-glyph-tail variant also
    passed (no orphan halves, text preserved). The committed fixture is ASCII,
    so its wide assertions are vacuous (follow-up 1).
  • Scrollback module doc. It now matches height-only pushes with wrap flags,
    the width-reflow drain/rebuild, clear_last_wrap, pop_back_line, and the
    ED 3/FullReset clear; the stale "append-only / scroll-under only" claim
    is gone.
  • Remote CI is green on this head (Quality gates 1/2, Windows, macOS ARM64,
    MSRV, CodeQL, Linux X11/Wayland, Supply chain, compat matrices). CodeRabbit
    was rate-limited with no review comments to disposition.

Gates run on 2d11166e

cargo fmt --all -- --check                                             # exit 0
cargo clippy -p bitty-term-state -p bitty-runtime --all-targets --locked -- -D warnings  # exit 0
cargo test -p bitty-term-state --locked                                # 225 lib + all suites, resize_reflow_2529 14 passed
cargo test -p bitty-runtime --lib --locked                             # 1237 passed
cargo test -p bitty-runtime --test resize_scrollback --test selection_scrollback \
  --test scrollback_search_selection_persistence --test scrollback_search_ui_integration \
  --test selection_clipboard --locked                                  # 7 / 6 / 9 / 9 / 29 passed
cargo nextest run -p bitty-runtime --test resize_scrollback --profile ci --locked  # 7 passed

Blocker — cursor-detach documentation states the wrong condition and the “only when” is not gated

crates/bitty-term-state/src/state.rs:703-712 says detach happens when
non-blank content exists below the cursor and the shrink exceeds the absorbable
bottom padding, and that callers needing attachment must leave
cursor_row + 1 rows. Both are false:

  • Trigger counterexample. 10 content rows, cursor row 2, resize 24→8:
    padding = 14, shrink = 16 (> padding), push = 2, cursor 2−2 = 0, still
    attached. Content below the cursor and shrink > padding are necessary but not
    sufficient.
  • Attachment-bound counterexample. 24 full rows, cursor row 2, resize 24→3
    (cursor_row + 1 rows left): push = 21, cursor clamps to 0. Leaving
    cursor_row + 1 rows is not sufficient.

The correct condition is push = max(0, used_rows − new_rows); the cursor is
detached iff push > cursor_row, i.e. new_rows < used_rows − cursor_row, and
attachment requires at least used_rows − cursor_row rows (from the cursor
through the last used row), not cursor_row + 1.

The committed regression only proves the clamped case. No test asserts the
opposite: an attached cursor must shift rather than clamp (for example fill 10
rows, cursor row 2, resize(80, 8) → scrollback 2, cursor row 0; or full 24
rows, cursor row 20, resize(80, 12) → scrollback 12, cursor row 8). Add that
regression and correct the doc; a sentence on the public State::resize would
make the edge discoverable too.

Non-blocking findings

  1. 1-column test/doc precision. crates/bitty-term-state/tests/resize_reflow_2529.rs:463
    uses an ASCII fixture, so the spacer/width <= 1 assertions and
    assert_no_orphan_wides never exercise a wide pair, and the comment at
    state.rs:3859 / the test doc say the retained suffix “reflows back
    losslessly” although width-1 wide leads stay narrow. The behavior is fine
    (a wide-tail probe passed); qualify the wording and add a wide glyph to the
    cap fixture so the assertions are not vacuous.
  2. Pane selection remap has no committed test. crates/bitty-runtime/src/runtime/panes.rs:984
    is a new caller; the throwaway probe passes, but a future regression would
    not be caught. Add a split-pane variant of the primary selection test
    (divider shrink/grow, non-buffer selection, same text).
  3. Nextest filter collateral. .config/nextest.toml:38,45 matches by binary
    name, so resize_scrollback also pulls the 13 in-memory
    bitty-ui::resize_scrollback tests into the live-pty group (max 2 threads,
    ci retries). If unintended, scope the runtime suite with
    package(bitty-runtime) & binary(resize_scrollback).
  4. Canonical docs still claim unconditional cursor attachment. The
    bitty-terminal-docs specifications/terminal-state-rfc.md height-only
    bullet says the shrink “moves the cursor with its content”; add the
    pushed-cursor detach exception (or track it as a docs follow-up).
  5. Residual edge (pre-existing). A non-buffer selection on a scrolled
    viewport is left untouched by the remap (is_viewport_scrolled returns
    early) and is only reclamped, so it can retarget; pointer selections are
    buffer-anchored, so this is reachable through the direct APIs only. Worth a
    follow-up, not a blocker for this PR.

@Xuepoo

Xuepoo commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Review fixes pushed at 4e5a8a77:

  • Corrected the cursor-detach doc to new_rows < used_rows - cursor_row and attachment to used_rows - cursor_row rows.
  • Added the "only when" regression: 12-row fixture, cursor row 4, used=12, shrink to 10 rows -> push 2, cursor row 2 (not clamped), row content body-04 intact.
  • Strengthened the 1-column cap assertions (geometry + grid cell count).
  • Added a pane-owned selection remap regression (vertical divider 0.5 -> 0.7 keeps the selected pane text and row mapping).
  • Docs follow-up reported in the PR body: terminal-state-rfc.md needs the same detach condition (and its invariant 4 scrollback wording is stale). Not edited here.

Gates: resize_reflow_2529 15 passed; resize_scrollback 8 passed; cargo fmt --check; both workspace clippy recipes -D warnings clean.

@Xuepoo
Xuepoo force-pushed the ctx-2543/fix-resize-followups branch from 4e5a8a7 to fa7b090 Compare October 23, 2026 07:36
@Xuepoo

Xuepoo commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto latest origin/main (fa57b5b7) to clear the BEHIND state. New head: fa7b0900ec46cbbd57a80ebd314c9d1fa9ff5e91. Re-ran resize_reflow_2529 (15 passed), resize_scrollback (8 passed), fmt, and both clippy recipes; all green.

@Xuepoo Xuepoo left a comment

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.

Independent review — NEEDS-FIX (delta recheck)

Rechecked head fa7b0900 against its parent 5d49773c (3 files, +145/−9).
The head was force-pushed from 4e5a8a77 onto fa57b5b7 during the recheck;
the delta patch is byte-identical (diff -q of the two patches is clean), so
the reviewed content is unchanged. The delta is documentation and tests only: a
-U0 diff of crates/bitty-term-state/src/state.rs contains only /// lines,
and the runtime delta is one test plus its import. No resize behavior changed.

Previous blocker — fixed

  • The condition is now exact. Under resize_height_only,
    absorb = old_rows - used_rows and push = used_rows - new_rows on a shrink,
    so detachment (push > cursor_row) is exactly
    new_rows < used_rows - cursor_row. The old “any shrink beyond the
    absorbable padding detaches” claim and the false cursor_row + 1 attachment
    bound are gone. The new text correctly says attachment needs
    used_rows - cursor_row rows (the cursor row plus every used row below it).
    Grow and absorb-only resizes make the predicate false, so they cannot detach.
  • The new regression gates the behavior.
    shrink_that_keeps_cursor_row_attaches_cursor_to_shifted_content uses 12
    content rows with the cursor on row 4 and resizes 24→10: shrink = 14 >
    padding = 12 (the old false trigger), push = 2, and it requires the cursor on
    row 2 with body-04 still under it and every row present once in order. It
    passes. Locally forcing an unconditional cursor clamp makes it fail
    (left: 0, right: 2); restored and re-ran green.
  • No behavior change. The only source edit is doc text; all other delta
    lines are test code.

Blocker — Windows -D warnings compile failure from the new test import

crates/bitty-runtime/tests/resize_scrollback.rs:9 now has:

use bitty_ui::{CellPos, Selection, ViewId};

Selection is used only by the new #[cfg(unix)]
pane_height_resize_remaps_pane_owned_selection test. On Windows the test is
compiled out, so the import is unused and RUSTFLAGS=-D warnings fails:

error: unused import: `Selection`
 --> crates\bitty-runtime\tests\resize_scrollback.rs:9:25
  = note: `-D unused-imports` implied by `-D warnings`
error: could not compile `bitty-runtime` (test "resize_scrollback")

Evidence: the Windows check and test job on fa7b0900
(actions/runs/39918910489/job/120300126355, step “Check workspace compilation”)
failed for exactly this, and all later Windows steps were skipped. Fix by
gating the import:

use bitty_ui::{CellPos, ViewId};
#[cfg(unix)]
use bitty_ui::Selection;

(or import Selection inside the #[cfg(unix)] test). Re-run the Windows job.

Verified non-vacuous additions

  • Pane remap test. pane_height_resize_remaps_pane_owned_selection installs
    a non-buffer selection on the bottom pane, drags the divider, and requires the
    pane-owned selection to move to the shifted row and keep pane-39. It passes
    on both heads. Locally disabling remap_selection_for_resize makes it fail
    with the selection retargeted to a blank row; restored, suite green. This is
    the new pane code path, not a primary-grid proxy.
  • 1-column additions. The new assertions require 1×24 after the 1-column
    pass, 80×24 after widening, and an 80*24 snapshot; a no-op or truncating
    resize fails them. The fixture is still ASCII, so the wide-pair assertions
    remain unexercised; that is the pre-existing non-blocking nit, not a new
    regression.

Gates run

cargo fmt --all -- --check                                             # exit 0 (rebased head)
cargo test -p bitty-term-state --locked                                # 225 lib + suites; resize_reflow_2529 15 (source identical to 4e5a8a77)
cargo test -p bitty-runtime --test resize_scrollback --locked          # 8 passed (incl. new pane test; rebased head)
# vacuity probes: cursor clamp -> new term-state test fails; remap disabled -> pane test fails
# both restored; targeted tests re-ran green
cargo clippy -p bitty-term-state -p bitty-runtime --all-targets --locked -- -D warnings  # Linux exit 0

Remote CI restarted on the force-pushed head: Windows check and test failed
on the unused import above; the remaining jobs were still running at review
time. CodeRabbit is rate-limited with no comments to disposition.

Residual non-blocking notes

  1. The 1-column fixture remains ASCII, so assert_no_orphan_wides and the
    width/spacer assertions do not exercise a wide pair; a wide-tail variant
    passes, so this is coverage-only.
  2. The canonical bitty-terminal-docs height-only bullet still says the
    cursor moves with its content unconditionally; record the detach exception.
  3. .config/nextest.toml binary(resize_scrollback) still pulls the 13
    in-memory bitty-ui tests into live-pty; scope to bitty-runtime if
    unintended.
  4. Non-buffer selections on scrolled viewports remain on the old clamp path
    (direct APIs only; pointer selections are buffer-anchored).

@Xuepoo

Xuepoo commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Windows fix pushed at 7a0febe8: Selection is now imported under #[cfg(unix)] in resize_scrollback.rs (only the pane regression uses it). Verified: resize_scrollback 8 passed on Linux, cargo check --target x86_64-pc-windows-gnu --all-targets --locked clean, fmt and both clippy recipes clean.

@Xuepoo
Xuepoo merged commit d014721 into main Oct 23, 2026
20 checks passed
@Xuepoo
Xuepoo deleted the ctx-2543/fix-resize-followups branch October 23, 2026 08:48
@Xuepoo Xuepoo mentioned this pull request Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:render Area: rendering fix Bug fix P2 Priority: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[0.0.27] Resize follow-ups: selection remap, scrollback docs, nextest pty group, cursor and 1-col edges (#2529)

1 participant