Skip to content

fix(top): render --snapshot frames to stdout without terminal control - #1575

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
fix/top-snapshot-no-raw-mode
Sep 26, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
fix/top-snapshot-no-raw-mode

Conversation

@FlorentinDUBOIS

@FlorentinDUBOIS FlorentinDUBOIS commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1574

Cause

sozu top --snapshot N is documented in bin/src/cli.rs as a "test affordance, no terminal control", but render::run installed RawModeGuard unconditionally (bin/src/ctl/top/render.rs, let _guard = RawModeGuard::install(cfg.mouse)?;). Its enable_raw_mode() reaches crossterm 0.29's tty_fd(), which opens /dev/tty when stdin is not a terminal. Without a controlling terminal that open fails with ENXIO, and ctl/top/mod.rs wraps it as ResolvePath("sozu top render loop", … os error 6).

Removing the guard alone would not be enough: event::poll lazily builds crossterm's event source, which calls tty_fd() too, and Terminal::new (a fullscreen viewport) asks the backend for the terminal size.

Fix

Only when --snapshot is set, render::run now:

  • enters neither raw mode nor the alternate screen, and captures no mouse (no RawModeGuard);
  • installs no terminal-restoring panic hook, since there is nothing to restore;
  • reads no input: the loop sleeps for its pacing interval instead of calling poll/read;
  • draws into a fixed 80x24 Viewport::Fixed, which ratatui 0.30 neither sizes from nor resizes to the terminal (Terminal::with_options and autoresize both skip backend.size() for a fixed viewport). 80x24 is the smaller of the two sizes the insta tests render every pane at.

Frames go to stdout as ANSI escape sequences. Interactive mode and --tick-once are unchanged.

CI

sozu_top_e2e now passes without a pty, so a new step runs it on the msrv-full cell only. That cell already resolves the tui feature for cargo doc --all-features, so the added cost is one build of the sozu binary with tui, once per pipeline. The step also runs the two non-ignored sozu top tests, which no cell ran before. The .github/workflows/ci.yml comment that kept the test out, the test's doc comment, and the last sentence of #1573's CHANGELOG entry now say it runs.

Verification

Run outside a pty (tty reports "not a tty"):

  • before the fix: cargo test -p sozu --features tui --test sozu_top_e2e -- --include-ignored exits 101, sozu_top_tick_once_against_real_master fails with could not resolve path for sozu top render loop : No such device or address (os error 6);
  • after the fix, the same command: exit 0, 3 passed. The new CI step's command, cargo test -p sozu --locked --features opentelemetry,splice,simd --features tui --test sozu_top_e2e -- --include-ignored, run with stdin at /dev/null: exit 0, 3 passed;
  • cargo build, cargo clippy --all-targets -D warnings (crypto-ring,opentelemetry,splice,simd, and -p sozu --features tui), cargo +nightly fmt --check, cargo test -p sozu (ring features, 226 passed), the three other bin/tests/*_e2e with --ignored, cargo test -p sozu-command-lib (184 passed), the four check_doc_citations.py invocations and RUSTDOCFLAGS="-D warnings" cargo doc --all-features: all exit 0.

Out of scope

  • cargo test -p sozu --features tui fails on snapshot_h2_120x40: the H2 pane now lists rst_stream_dropped (since fix(mux-h2): cap enqueue_rst per insert so a mass reap cannot grow the pending RST queue past its bound #1434) but the .snap file does not. It fails identically with this PR's render.rs reverted, origin/main's snapshot lacks the row too, and no CI cell runs that suite.
  • The e2e takes about 30 s both before and after this change. It already did when the render loop failed on its first call, so the time is spent outside the loop; its cause was not investigated here.

Signed-off-by: Florentin Dubois [email protected]

FlorentinDUBOIS added a commit that referenced this pull request Sep 26, 2026
…sts in CI

snapshot_h2_120x40 has failed under `cargo test -p sozu --features tui`
since #1434, which added the h2.rst_stream_dropped row to the H2 pane's
flood table (bin/src/ctl/top/panes/h2.rs) without updating the stored
insta snapshot:

  $ cargo test -p sozu --features tui
  test ctl::top::snapshot_tests::snapshot_h2_120x40 ... FAILED
  +││rst_stream_dropped      0      —      ││
  test result: FAILED. 134 passed; 1 failed                   [exit 101]

The row itself is intended: #1434 gives the RST_STREAM control queue the
same drop + metric + log shape h2.window_update_dropped already has, and
the pane lists both. Its trend cell is not: it printed `—` where every
sibling row draws a sparkline, because #1434 did not add the key to
H2_TRACKED_KEYS (bin/src/ctl/top/app.rs), the list App::fold_h2_trends
samples, whose own doc-comment says it exists so a key cannot silently
lose its sparkline. Accepting the snapshot as rendered would have frozen
that gap. The key is now tracked beside WINDOW_UPDATE_DROPPED, and the
snapshot is regenerated with INSTA_UPDATE=always to the corrected frame:
the new row with a `▁▁` trend, one fewer blank line below it.

Seen red with only the H2_TRACKED_KEYS line removed:

  $ cargo test -p sozu --features tui --lib snapshot_h2
  -││rst_stream_dropped      0      ▁▁     ││
  +││rst_stream_dropped      0      —      ││
  test result: FAILED. 0 passed; 1 failed                     [exit 101]

No other snapshot was stale: the full tui suite passes, 135 tests.

The drift went unnoticed because no CI cell enables `tui`, so `Test sozu`
compiles every `top` unit test out. A new step on the msrv-full cell runs
`cargo test -p sozu --features tui --lib`: that cell already resolves the
tui dependencies for `cargo doc --all-features`, nothing in `top` varies
by crypto provider, and `--lib` bounds the cost to one extra build of the
sozu library test binary (41 s locally with warm dependencies). The
sozu_top_e2e step proposed separately in #1575 is left to that PR.

Closes #1576

Signed-off-by: Florentin Dubois <[email protected]>
`sozu top --snapshot N` is documented as a "test affordance, no terminal
control", but `render::run` installed `RawModeGuard` unconditionally. Its
`enable_raw_mode()` reaches crossterm's `tty_fd()`, which opens /dev/tty
when stdin is not a terminal, so without a controlling terminal (CI, a
pipe, `ssh -T`) the run failed with `ResolvePath("sozu top render loop",
... os error 6)` (ENXIO).

In snapshot mode the renderer now enters neither raw mode nor the
alternate screen, captures no mouse and installs no terminal-restoring
panic hook. It also reads no input, because crossterm's event reader
opens /dev/tty as well: the loop sleeps for its pacing interval instead.
It draws into a fixed 80x24 viewport, which ratatui neither sizes from
nor resizes to the terminal, since a pipe has no size to query. Frames
go to stdout. Interactive mode is unchanged.

`sozu_top_e2e` now passes without a pty, so CI runs it on the
`msrv-full` cell, which already resolves the `tui` feature for
`cargo doc --all-features`.

Closes #1574

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS force-pushed the fix/top-snapshot-no-raw-mode branch from 137f0d2 to 1d9c4c5 Compare September 26, 2026 16:59
FlorentinDUBOIS added a commit that referenced this pull request Sep 26, 2026
…sts in CI

snapshot_h2_120x40 has failed under `cargo test -p sozu --features tui`
since #1434, which added the h2.rst_stream_dropped row to the H2 pane's
flood table (bin/src/ctl/top/panes/h2.rs) without updating the stored
insta snapshot:

  $ cargo test -p sozu --features tui
  test ctl::top::snapshot_tests::snapshot_h2_120x40 ... FAILED
  +││rst_stream_dropped      0      —      ││
  test result: FAILED. 134 passed; 1 failed                   [exit 101]

The row itself is intended: #1434 gives the RST_STREAM control queue the
same drop + metric + log shape h2.window_update_dropped already has, and
the pane lists both. Its trend cell is not: it printed `—` where every
sibling row draws a sparkline, because #1434 did not add the key to
H2_TRACKED_KEYS (bin/src/ctl/top/app.rs), the list App::fold_h2_trends
samples, whose own doc-comment says it exists so a key cannot silently
lose its sparkline. Accepting the snapshot as rendered would have frozen
that gap. The key is now tracked beside WINDOW_UPDATE_DROPPED, and the
snapshot is regenerated with INSTA_UPDATE=always to the corrected frame:
the new row with a `▁▁` trend, one fewer blank line below it.

Seen red with only the H2_TRACKED_KEYS line removed:

  $ cargo test -p sozu --features tui --lib snapshot_h2
  -││rst_stream_dropped      0      ▁▁     ││
  +││rst_stream_dropped      0      —      ││
  test result: FAILED. 0 passed; 1 failed                     [exit 101]

No other snapshot was stale: the full tui suite passes, 135 tests.

The drift went unnoticed because no CI cell enables `tui`, so `Test sozu`
compiles every `top` unit test out. A new step on the msrv-full cell runs
`cargo test -p sozu --features tui --lib`: that cell already resolves the
tui dependencies for `cargo doc --all-features`, nothing in `top` varies
by crypto provider, and `--lib` bounds the cost to one extra build of the
sozu library test binary (41 s locally with warm dependencies). The
sozu_top_e2e step proposed separately in #1575 is left to that PR.

Closes #1576

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit ba2aeac into main Sep 26, 2026
28 checks passed
@FlorentinDUBOIS
FlorentinDUBOIS deleted the fix/top-snapshot-no-raw-mode branch September 26, 2026 17:59
pull Bot pushed a commit to jrcribb/sozu that referenced this pull request Sep 26, 2026
…sts in CI (sozu-proxy#1577)

`snapshot_h2_120x40` fails on `main` under `cargo test -p sozu --features tui` since sozu-proxy#1434 added the `h2.rst_stream_dropped` row to the H2 pane without updating the stored insta snapshot.

## Why not just accept the snapshot

The row is intended: sozu-proxy#1434 gives the RST_STREAM control queue the same drop + metric + log shape as `h2.window_update_dropped`, and the pane lists both. Its trend cell was not: it rendered `—` where every sibling row draws `▁▁`, because `h2.rst_stream_dropped` was never added to `H2_TRACKED_KEYS` (`bin/src/ctl/top/app.rs`), the list `App::fold_h2_trends` samples. That constant's own doc-comment says it exists so a key cannot silently lose its sparkline. Accepting the frame as rendered would have frozen the gap.

## Changes

- `bin/src/ctl/top/app.rs`: track `names::h2::RST_STREAM_DROPPED` beside `WINDOW_UPDATE_DROPPED`.
- `snapshot_h2_120x40.snap`: regenerated with `INSTA_UPDATE=always`. The new row now has a `▁▁` trend, and the frame has one fewer blank line below it. No other snapshot was stale.
- `.github/workflows/ci.yml`: new `msrv-full` step `cargo test -p sozu --locked ${{ matrix.flags }} --features tui --lib`. No cell enabled `tui`, so `Test sozu` compiled every `top` unit test out. That cell already resolves the tui dependencies for `cargo doc --all-features`, and `--lib` keeps the cost to one extra build of the library test binary (41 s locally with warm deps). The `sozu_top_e2e` step stays with sozu-proxy#1575, and this PR does not touch that hunk.
- `CHANGELOG.md`: Fixed entry.

## Red, then green

Before (origin/main 57c9269): `cargo test -p sozu --features tui`: `134 passed; 1 failed` (exit 101), and the diff shows `+rst_stream_dropped … —`.
With only the `H2_TRACKED_KEYS` line removed, `cargo test -p sozu --features tui --lib snapshot_h2` also fails (`-… ▁▁` / `+… —`, exit 101).
After: `cargo test -p sozu --features tui` gives `135 passed; 0 failed` (exit 0).

Also exit 0: `cargo build --locked --no-default-features --features crypto-ring,opentelemetry,splice,simd`, `cargo +nightly fmt --all -- --check`, `cargo clippy -p sozu --features tui --all-targets -- -D warnings`, `cargo test -p sozu`, the four `check_doc_citations.py` invocations (the broken fixture exits 1 as expected), and `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --locked`.

Closes sozu-proxy#1576

Signed-off-by: Florentin Dubois <[email protected]>
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.

sozu top --snapshot still enables raw mode, so it fails without a terminal

1 participant