Skip to content

feat(cli): show progress on a terminal, and leave the outline from view (#63 part 1) - #84

Merged
gerchowl merged 5 commits into
mainfrom
feature/63-outline-first
Oct 13, 2026
Merged

gerchowl merged 5 commits into
mainfrom
feature/63-outline-first

Conversation

@gerchowl

@gerchowl gerchowl commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Refs #63 (part 1 of 2; does not close it). Part 2 is #85.

Why split

All of #63 is well over the ~400-line cap: part 1 alone is +376/−22. Following the brief's own suggestion, this PR is the CLI half. Part 2, the viewer's outline-first window, is #85: it opens before the run finishes, shows the tree, a progress indicator and an honest message when the run is killed or times out, uses a cached artifact before any kernel event, and swaps in the meshes on Done.

What changed

  • Progress on a terminal (Progress in src/main.rs). When stderr is a terminal, the run is streamed and one line there is redrawn in place:

    • stepv: reading
    • then stepv: N parts · reading, as soon as the outline arrives, or at once from a cached outline artifact, before the kernel writes anything
    • then · transferring P% and · meshing P%, redrawn on each whole percent
    • the line is erased when the run ends.

    A pipe gets nothing on stderr. Stdout's JSON line is unchanged.

  • stepv view writes the outline artifact. Its load is streamed like a cached CLI run's, keyed on the FileId taken before the run, and the box is added after the mesh decodes. --no-cache writes nothing.

  • Docs. plan.md has a "Viewer and CLI show the outline and progress before the geometry (#54 step 5) #63 part 1" section (what's shown when, the exact messages, known limits with their issues), and the artifact section's "view does not write it yet" limit is removed. CHANGELOG has an entry.

Tests (each fails on origin/main)

  • tests/progress.rs (stderr on a real pty via libc::openpty):
    • the terminal shows the part count and transferring 100% / meshing 100%, never a newline, and ends erased. The same run into a pipe writes no progress and gives the same JSON keys and values. Before the change: "stepv: reading" not in "".
    • a cached artifact names the parts with a kernel that never writes a byte; with no artifact, no count is shown. Before the change: no part count.
  • tests/cache.rs a_viewer_killed_after_its_outline_leaves_the_artifact: a view whose kernel stalls after the outline and is killed at a 10 s timeout leaves the artifact at the pre-run key, equal to occt::outline, with no box. Before the change the load wasn't streamed, the run completed, and a window opened ((-1, None) vs (4, "timeout")). STEPV_VIEW_SCREENSHOT now makes such a window close itself, so a regression fails instead of hanging.

Review round 1 (e15cb95)

  • Pty fd leak (blocker): the test's master and slave are close-on-exec from the moment they exist: posix_openpt(O_RDWR|O_NOCTTY|O_CLOEXEC), and the slave is opened through std::fs::OpenOptions, which always sets O_CLOEXEC. Setting FD_CLOEXEC after openpty would still leave a window in which a parallel test's spawn inherits them. The test asserts both flags.
  • Every view test is bounded (viewer: a test-launched stepv view likely reached ~38 GB within ~90 s and wedged the host #86) through Home::view:
    • the kernel runs under --memory-mb 1024
    • STEPV_VIEW_SCREENSHOT is set, so a window that opens closes itself
    • the viewer's own footprint is polled, and the run is killed and failed past 2 GiB or 120 s.
  • New tests:
    • view --no-cache leaves no artifact, while the same run with the cache on leaves one. It uses a kernel that crashes after a full run, so no window opens. A mutation that makes view ignore --no-cache fails it (--no-cache wrote an artifact).
    • a complete view stores the box, equal to the summary's.
  • Docs: plan.md now says what Ctrl-C leaves: stepv installs no signal handler, so the last state stays on the line. The "viewer still waits" known limit and the CHANGELOG point at viewer: open on the outline — tree and progress first, meshes on Done (#63 part 2) #85.

Fix round 3 (a420b8b): no window session (#84's CI failure)

  • What failed: in nix's macOS builder (_nixbld, with no window-server session), a_complete_view_adds_the_box saw null. That was the whole JSON report, not the box: the test panicked at its status assertion and never read the box. stepv view ran the kernel, then died inside eframe::run_native, where macOS's window layer aborts a process that has no session, and stdout's report died with it.

  • Fix (option A, decided): view::session checks before the kernel. On macOS it uses CGSessionCopyCurrentDictionary; elsewhere on Unix, DISPLAY or WAYLAND_DISPLAY. With no session, view fails at once: exit 3, error, "no window session: …" with the reason, and the header metadata.

  • Tests:

    • A new nextest test: with no session (the STEPV_VIEW_TEST_NO_SESSION hook, plus no DISPLAY), view fails that way and never starts the kernel. It fails without the check.
    • The four view tests that need a window are #[ignore = "needs a window session; run by just view-test"]. scripts/test-window-tests.sh runs them with --ignored, and fails unless every one of them ran and passed.
    • CI runs that script on the macOS runner, through just view-test in kernel.yml's "GPU viewer on Metal" step, and under Xvfb in the "Viewer (Linux, lavapipe)" job (scripts/test-linux-viewer.sh).
  • f391227: the first CI run of a420b8b failed a_terminal_sees_the_parts_and_each_stage_and_stdout_is_unchanged in nix's macOS sandbox. There the kernel's sandbox cannot nest (macos-outer), and stepv warns about it on stderr after erasing the progress line, which is the documented behavior. The test had forbidden any newline at all. It now checks the rule itself: no newline while redrawing, the erase right after the last redraw, and no progress after it.

  • CI at f391227 runs the window tests on both platforms: Kernel (macos-15), in its "GPU viewer on Metal" step (scripts/test-window-tests.sh), and Viewer (Linux, lavapipe), under Xvfb, each with 4 passed; 0 failed. Every check is green.

Gate

  • nix develop -c sh -c 'cargo fmt --check && cargo clippy --all-targets -- -D warnings && cargo test' → exit 0 (at f391227)
  • nix build -L --no-link .#checks.aarch64-darwin.nextest → exit 0 (246 passed, 7 skipped: the 3 existing #[ignore]s and the 4 window tests; at f391227)
  • No kernel change.

Part 1 of #63. When stderr is a terminal, the run is streamed and one
line there is redrawn in place: the part count (at once from a cached
outline artifact), then the transfer and mesh percentages, erased when
the run ends. A pipe gets nothing, and stdout's JSON line is unchanged.

`stepv view` now streams its load like a cached CLI run and writes the
outline artifact under the pre-run FileId, so a viewer killed after the
outline leaves the tree for the next preview.

The viewer's own outline-first window is part 2.

Refs: #63
The pty test's master and slave came from openpty without
close-on-exec, so a parallel test's stepv (and its kernel) could inherit
the other terminal's slave and hold it open. They are now
close-on-exec from the moment they exist (posix_openpt with O_CLOEXEC,
the slave opened by std), and the tests assert it.

Every view test goes through Home::view: the kernel under --memory-mb,
the screenshot hook set, and the viewer's own footprint polled and
failed past 2 GiB or 120 s (#86). New tests cover view --no-cache
leaving no artifact and a complete view adding the box.

plan.md now says what Ctrl-C leaves on the progress line, and points
the viewer's remaining work at #85.

Refs: #63
Home::view spawns stepv in its own process group. Past its footprint
cap or deadline the watchdog SIGKILLs the group: the kernel's caps are
stepv's own sampler, so killing stepv alone orphaned an uncapped kernel.
However a run ends, no member of its group may outlive it.

stepv gets --timeout 30 by default, so its own timeout fires before the
120 s watchdog, and the watchdog's panic names the limit that fired.
A new test runs a kernel that never finishes under a 2 s deadline and
checks that the kernel dies with stepv.

Refs: #63
In a process with no window-server session (nix's macOS builder runs
as _nixbld with none), stepv view ran the whole kernel and then died
inside the window layer, which aborts outright, so stdout's report was
lost. view::session now asks first (macOS: CGSessionCopyCurrentDictionary;
elsewhere on Unix: DISPLAY or WAYLAND_DISPLAY) and fails at once with
"no window session: ...", the reason and the header metadata.

The four tests/cache.rs tests that start view past the check need a
session: they are ignored in nix's sandbox and run by
scripts/test-window-tests.sh, which fails unless all of them ran and
passed, from just view-test (the macOS runner) and under Xvfb in the
Linux viewer job. A new nextest test covers the early failure.

Refs: #63
The terminal test forbade any newline and required the run's output to
end with the erase. In nix's macOS sandbox the kernel's sandbox cannot
nest (macos-outer), and stepv rightly warns about it on stderr, after
erasing the line: the documented rule. The test now checks exactly that
rule: no newline while redrawing, the erase right after the last redraw,
and no progress after it.

Refs: #63
@gerchowl
gerchowl merged commit f0e63e7 into main Oct 13, 2026
13 checks passed
@gerchowl
gerchowl deleted the feature/63-outline-first branch October 13, 2026 00:00
gerchowl added a commit that referenced this pull request Oct 13, 2026
…se (#85) (#93)

Closes #85

## What

`stepv view` opens its window **at once** and runs the kernel on a
thread of its own (`run_view` / `load_view` in `src/main.rs`), through
the CLI's own `tessellate`, so the artifact, the box and the progress
code are shared, not duplicated. The loader sends the window
`view::Load` messages over a channel:

- **`Tree`:** a cached outline artifact's tree, sent before the kernel
starts, then the run's `Event::Tree`. It's drawn in the tree panel
(`Tree::from_nodes`).
- **`Progress`:** "Transferring the shapes: P%" or "Meshing: P%", with a
progress bar.
- **`Done`:** the GPU scene is built and the viewer swaps in, with the
full title.
- **`Failed`:** the window closes and the report says why, as before.
#89 will keep the tree with its reason instead.

**Closing mid-load cancels the run (Q1).** `occt::run_streaming` gains a
`cancel: Option<&AtomicBool>` parameter. `supervise`'s tick may stop the
run and kill the kernel, which is the new `Outcome::Cancelled`. `view`
reports status `cancelled` with exit 0. This public API change is in the
rustdoc and the CHANGELOG.

**Known limits.** `--software`, or no usable GPU, still waits for the
whole run (#90). A failed run closes the window (#89).

## Tests (each new one fails on `origin/main`)

- `tests/stream.rs` `a_cancelled_run_is_killed_at_once` (nextest):
`Outcome::Cancelled`, no summary, within seconds of a 60 s cap.
- Window tests: `#[ignore = "needs a window session; …"]`, run by
`scripts/test-window-tests.sh`, which now counts 7. They go through
`Home::view` (process group, memory cap, `--timeout`, screenshot hook).
Under `STEPV_VIEW_SCREENSHOT` the window reports its frames on stderr,
because the macOS CI runner never presents a window:
- `the_viewer_shows_the_tree_before_the_geometry`: with the kernel
stalled 8 s, the loading frame shows the outline's rows and no geometry,
then the scene. On `main`: `no loading frame with the tree`.
- `a_cached_outline_shows_the_tree_before_any_kernel_event`: a cached
artifact with a mute kernel shows the artifact's rows. On `main`: no
loading frame.
- `closing_the_viewer_mid_load_cancels_the_kernel`:
`STEPV_VIEW_CLOSE_LOADING=1` with a stalled kernel gives `cancelled`,
exit 0, in under 20 s, and the kernel's process is gone. On `main`: `(4,
"timeout")` after 30 s.
- The existing watchdog test's deadline goes from 2 s to 10 s. The
window now opens alongside the run, and macOS's first-launch check of
the test's fresh kernel script was measured at up to 1.5 s, which made 2
s flaky. That's still far below stepv's own 30 s timeout.
- The no-session early failure (#84) is unchanged and still passes in
nextest.

## Review round 1 (ed150e9)

- **Software fallback (blocker):** the viewer's pipelines are now built
and validated in eframe's creator (`pipelines()` in `src/view/app.rs`),
before the window is the viewer's. A refusal hands the load back, and
`view::run` falls back to software, as on `main`. Only the scene's
buffers are checked after `Done`.
- New window test
`a_gpu_that_refuses_the_pipelines_falls_back_to_software`, using the
`STEPV_VIEW_REJECT_PIPELINES` hook: status `ok`, backend `software`, and
the screenshot is drawn. At f18f607 it fails with `backend: "metal"`.
- **Loader panic:** the loader takes the `Sender` by value, so a panic
closes the channel. A unit test checks that a panicking loader ends the
software viewer's wait.
- **`cancelled` report:** it carries `message`, not `error` (documented
in plan.md); the cancel test asserts it.
- **CHANGELOG:** the `run_streaming` change is under **Changed**, marked
breaking.
- **Harness:** `Outcome::Cancelled` maps to a `Crash` verdict with a
note, instead of `unreachable!`.

## Gate

- `cargo fmt --check && cargo clippy --all-targets -- -D warnings &&
cargo test` → exit 0
- `nix build -L --no-link .#checks.aarch64-darwin.nextest` → exit 0 (248
passed, 11 skipped: 3 existing ignores and the 8 window tests; at
ed150e9)
- `just view-test` → its test steps passed: 85 + 8 + the 8 window tests
(at ed150e9). Its last step failed only because the recipe hardcodes
`target/release/stepv`, while this build used `CARGO_TARGET_DIR`.
`scripts/test-viewer.sh <that build>` → exit 0, with every check `ok`
(both themes, software fallbacks, pick, measure, section, `--frames` on
every fixture, failed topology).
gerchowl added a commit that referenced this pull request Nov 8, 2026
## Description

Fixes #104. The Viewer (Linux, lavapipe) job's window tests
intermittently failed with `winit EventLoopError … Failed to open
connection to X server`.

**Root cause:** Xvfb was started by `xvfb-run` without `-noreset`. An X
server *resets* whenever its last client disconnects, and a connection
that arrives during the reset is dropped. `scripts/test-window-tests.sh`
runs the 14 window tests in parallel under one `xvfb-run`, and each
`stepv view` is its own short-lived client. When all the running clients
had closed at the same moment that another test's stepv connected,
winit's `XOpenDisplay` failed. The GPU viewer then fell back to software
for the wrong reason, and the test's note assertion
(tests/cache.rs:1034) failed.

**Ruled out:**
- *Start race:* `xvfb-run` starts the command only after Xvfb signals
readiness (SIGUSR1). Each failure was mid-suite, about 21 s in, after
other tests had already connected.
- *Server dying:* the same server served the software fallback in the
same test, which drew and passed.
- *Connection limit:* there are at most 4 clients at once, against
Xvfb's 256.
- *Display shared with another server:* there is one `xvfb-run -a` per
step, run in sequence.
- *#84 watchdog:* it kills the kernel only, never X.

**Occurrences (kernel.yml run history):** 38337928702 (#103),
38362262033 (#98), 38377606897 (main push), 38378915656, 38848855133.
Each time it was the same test and the same error.

## Type of Change

- [x] `fix` -- Bug fix
- [x] `ci` -- CI/CD pipeline changes

## Changes Made

- `scripts/test-linux-viewer.sh`: one `xvfb <size> <cmd>` helper,
`xvfb-run -a -s "-screen 0 <size>x24 -noreset"`, used for all three Xvfb
steps (window tests, `test-viewer.sh`, no-GPU fallback). There are no
sleeps, retries or skips.

## Demonstration

These ran on Linux x86_64 (vm-dev), in CI's own container
(`test-linux-viewer.sh`'s Debian trixie image and env). stepv was built
once, then CI's window-test step was looped: `xvfb-run -a -s "<args>"
scripts/test-window-tests.sh -q --release`.

| Xvfb args | runs | pass | X-server failures |
|---|---|---|---|
| `-screen 0 1600x1000x24` (main) | 40 | 39 | **1**: run 38,
`a_gpu_that_refuses_the_pipelines_falls_back_to_software`, `Failed to
open connection to X server`, tests/cache.rs:1034, the same failure as
CI |
| `… -noreset` (this PR) | 120 | 118 | **0** |

Neither of the 2 non-X failures after the fix was an X error.
- One was observed as `Text file busy (os error 26)`
(`closing_the_viewer_mid_load_cancels_the_kernel`, tests/cache.rs:992),
from the tests' `script()` helper. That race has a different root cause
and is filed as #117.
- The other (`a_viewer_with_no_cache_leaves_no_artifact`,
tests/cache.rs:862) failed on an exit-code/status mismatch, but its
output wasn't kept. It is only **inferred** to be the same ETXTBSY race,
because that test also execs a `script()` kernel.

**The reset, deterministically:** one client sets a root-window property
and disconnects, then a new client reads it back.
- Default: `STEPV_104: no such atom on any window.` The server reset
when its only client left.
- `-noreset`: `STEPV_104(STRING) = "still-here"`.

**Connections dropped during a reset:** 3 workers each opening and
closing `xdpyinfo` in a loop, 5 × 3000 connections. With the default
server, 3 were refused (`unable to open display ":99"`); with
`-noreset`, 0.

The Viewer (Linux, lavapipe) job passed on this PR.

## Changelog Entry

### Fixed
- **The Linux viewer job's Xvfb no longer drops a window test's
connection** ([#104](#104)):
- Each Xvfb runs with `-noreset`. An X server resets when its last
client disconnects and drops a connection that arrives during the reset.
The window tests run in parallel, so one could connect just then and
fail with `Failed to open connection to X server`

Refs: #104
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.

1 participant