Skip to content

console-tui: the first frame is painted before anything is probed - #1323

Merged
bong-water-water-bong merged 3 commits into
mainfrom
os/v3-tui-firstframe
Nov 7, 2026
Merged

bong-water-water-bong merged 3 commits into
mainfrom
os/v3-tui-firstframe

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Fixes #1322

Root cause

main.rs built its first App from a synchronous Facts::collect(), and collect() waits on lemond's three HTTP
endpoints (2 s timeout each while the payload is still starting), on llama-server --list-devices (472 ms on the c31 board
once settled, "seconds" by the code's own comment) and on ps/netstat. At boot, while Lemonade is coming up, that is
enough for a scrape of tty1 to read a blank screen. Cycle 31's take stick showed it as one red row per boot, a different
row each time
— U2 tty1 … tty1-screen-empty on one of two runs of identical bytes, U2 menu … tty1-nothing on the other
— while U2 console quiet/screen/tty1 owner passed in both.

The change (4 files, +133/−6)

file what
src/facts.rs Facts::idle() — release, mode, hostname, uptime, Secure Boot, addresses, key hint, max temperature. File reads plus one ip; nothing that waits on another process. Facts gains idle: bool (false from collect(), true from idle()).
src/main.rs one line: App::new(Facts::idle()) instead of App::new(Facts::collect()). The collector thread is unchanged and its first result replaces these facts on the loop's first pass, so the screen is truthful as soon as the payload answers.
src/ui.rs the idle frame does not state what it has not asked: the compact status row and the wide layout's single panel read STARTING - the probes have not answered yet, and the log pane says it is reading — instead of LEMONADE DOWN / DATA not mounted / amdxdna absent about a box that is merely still starting (the same rule as web UI http://-:13305, engine#1040). Two tests.
README.md the paragraph that says why the first frame is idle-built, with the measurement below.

Measured

Two builds identical except this change (diff -r of the two trees = my patch and nothing else), each with the GPU probe
pointed at a stub that takes 3 s — a boot-time payload that has not answered yet, which is the condition the row fell
into. pty at 80x25, TERM=linux; "first frame" = first write of ≥ 200 bytes after the alternate screen is entered; 5 runs
interleaved, and the probe's 120 s result cache unlinked before every run (my first attempt forgot that and read 60 ms
for four of the five "before" runs — the number below is with it cold):

binary first frame (ms, 5 runs)
main (before) 3086 / 3111 / 3211 (min/median/max — the 3 s stub, plus paint)
this branch (after) 26 / 55 / 467 (min/median/max; the outlier is this shared box at load 45)

At a fixed 0.6 s window the old binary has written 14 bytes (the alternate-screen escape sequence, no frame); the new
one has written a complete 80x25 frame:

1bit OS unknown strixhalo  192.168.50.110  up 1d 8h 10m  Secure Boot enabled
 CONNECT - Lemonade starting / -------------------------------------------------
  web UI http://192.168.50.110:13305
  name http://1bit-os.local:13305   (mDNS - avahi not running)
  api  http://192.168.50.110:13305/api/v1
  ssh  [email protected]   (your key in /data/ssh/authorized_keys)
  app  Lemonade Mobile: server http://192.168.50.110:13305 (any key)
  key  none - anyone here can use it; press 1 to require it
  Lemonade is not answering on 13305 yet - 8 shows its log
STARTING - the probes have not answered yet
 MENU --------------------------------------------------------------------------
1 Show the API key
2 Quick chat test (GPU and NPU)
… 9 Reboot / power off
 LOGS newest -------------------------------------------------------------------
 (reading the Lemonade log and the kernel ring now)
1-9 actions arrows scroll f newest r refresh 8 logs q quits

Nothing the gates read moved. Static artifact (build-static.sh, cadd055a25e9ded6, 1,598,144 B, no PT_INTERP), real
ptys at 80x25 and 240x67: all eight gate strings (CONNECT, web UI http://, api http://, ssh root@, Lemonade Mobile, Show the API key, Reboot / power off, 1-9 actions) and all nine numbered actions; and both committed snapshots
byte-identical — the collected screen is exactly what it was, only the first ~a second is new.

Tests

cargo test 68/68 (two new), cargo clippy --all-targets -- -D warnings clean, cargo fmt --check clean,
tools/copyright.py --check rc 0.

  • the_first_frame_is_the_menu_before_any_probe renders App::new(Facts::idle()) at 80x25 and 240x67 and requires: a
    non-blank frame, the header, both labels U2 menu greps, exactly nine actions, STARTING present and none of
    DOWN / DATA not mounted / amdxdna absent / no HRX device.
  • main_paints_an_idle_frame_before_the_first_collect — the frame test cannot see when the frame is painted, and this
    regression is silent (every frame test passes, the screen is just late), so it reads src/main.rs and fails if the first
    App is built from anything but Facts::idle(). Putting Facts::collect() back turns it red (main() no longer paints the first frame from Facts::idle()), measured, then restored.

Not in this PR

The harness half — a scrape row could settle-and-retry, since content was there 0 s after shell-ready — is pi-release's call
on vm-check.sh, and this PR does not touch a gate file. No image build, no board run, no device ticket; :18097 and
npu-serve-keeper untouched.

Cycle 31's take stick (`666c8ab5`) reddened one scrape row per boot, a different row each
time: `U2 tty1 … tty1-screen-empty` on one of two identical boots and `U2 menu …` on the
other, while `U2 console quiet`/`screen`/`tty1 owner` passed in both. The mechanism is in
this crate: `main` built its first `App` from a synchronous `Facts::collect()`, which waits
on lemond's three HTTP endpoints (2 s timeout each while the payload starts), on
`llama-server --list-devices` and on `ps`/`netstat`. A scrape that arrived inside that window
read a blank screen.

`Facts::idle()` is what a screen can be painted from without asking anything that has to
wait: release, mode, hostname, uptime, Secure Boot, the addresses, the key hint and the max
temperature (file reads plus one `ip`). `main` paints that frame first; the collector
thread's first result replaces it on the loop's first pass.

The idle frame does not assert what it has not asked: the status row reads `STARTING - the
probes have not answered yet` (and the wide layout's single STARTING panel), and the log pane
says it is reading, instead of `LEMONADE DOWN` / `DATA not mounted` / `amdxdna absent` about a
box that is merely still coming up - the same rule as the `web UI http://-:13305` row this
console stopped printing before a lease (engine#1040).

Measured (two builds identical except this change, both with the probe pointed at a stub that
takes 3 s, i.e. a boot-time payload that has not answered; pty, 80x25, first frame = first
write of >= 200 bytes, 5 runs interleaved, cache removed before each run): 3086/3111/3211 ms
before, 26/55/467 ms after (the outlier is load 45 on a shared box). At a fixed 0.6 s window
the old binary has written 14 bytes (the alternate-screen escape, no frame) and the new one a
full 80x25 frame. The collected frame is untouched: both committed snapshots byte-identical,
all eight gate strings and the nine actions on 80x25 and 240x67 with the static binary.

Fixes #1322

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY at 5bb117384796cd7610ee6ddf6a1378efb81cf02f. The right fix for #1322, at the right size: paint from file reads first, and let the collector replace it.

Checked

  • Facts::idle() really is non-blocking. Every helper it calls is a /proc or /sys read: uptime_s reads /proc/uptime, secure_boot reads efivars from sysfs (no mokutil), max_temp reads hwmon, and api_key reads the conf file. The only process is the one ip in ips(). Nothing waits on lemond, llama-server or ps/netstat.
  • It is painted first. main.rs builds the first App from Facts::idle(), and the loop drains the collector with rx.try_recv() (non-blocking, :272) before term.draw (:302). So the first draw is the idle frame, and the collector's first result replaces it on a later pass.
  • The idle frame states nothing unasked: the STARTING panel, the STARTING - the probes have not answered yet compact row, and the "reading the Lemonade log …" log line. The test asserts the absence of DOWN / DATA not mounted / amdxdna absent / no HRX device at 80x25 and 240x67, plus the nine action rows and the header (the two gate rows).
  • cargo test --offline --release (under thermal-run.sh) → 68 passed, 0 failed, including both new tests. The existing snapshot tests pass unchanged.
  • Mutation: with main.rs reverted to App::new(Facts::collect()), main_paints_an_idle_frame_before_the_first_collect fails. Restored, it passes. The source-text guard is unusual, but it is the only thing that can see this regression without a boot, as its comment says.

Nit: that test's comment cites engine#1318, an MTP PR. It should be #1322.

Not re-run: the pty first-frame A/B (3086-3211 ms → 26-467 ms with a 3 s probe stub). It is the author's harness, and the code path above makes the result follow.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Correction to the artifact hash in the body: cadd055a25e9ded6 / 1,598,144 B is NOT this head's artifact.
pi-os3 rebuilt 5bb11738 with build-static.sh and got d6f92127d71d921a / 1,598,120 B, and they are right — I
had quoted a hash from the tree before cargo fmt re-wrapped three test asserts, and a line shift moves the panic
Location strings rustc embeds.

Measured both ways on this box, same rustc (1.98.0 88d9e12ae 2026-08-18), fresh checkout of the pushed commit:

tree build-static.sh bytes
5bb11738 (this PR's head) d6f92127d71d921a 1,598,120
5bb11738 with the three asserts reflowed back to their pre-fmt line breaks (code identical) cadd055a25e9ded6 1,598,144

So the 24 bytes are formatting, not toolchain, not path (pi-os3 also built twice in different-length paths and got the
same d6f92127). Use d6f92127d71d921a, or better, rebuild from the merged tree and quote what the gate measured —
which is what pi-os3 is doing for c32, and the right rule regardless.

Nothing else in that message changes: no gate file is in this diff (vm-check.sh byte-identical, as they checked), and
the four files are README + facts.rs + main.rs + ui.rs.

For the record, the durable fix for this class is that build-static.sh should refuse (or loudly mark) a dirty tree,
since that is what let me quote a pre-format hash at all; filed separately rather than touching this head, because c32's
cut is about to quote it.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY at 5bb11738.

Built and ran it (thermal-run, this head):

cargo test                    68 passed; 0 failed                                   (the body's number, exactly)
cargo clippy --all-targets     0 diagnostics
cargo fmt --check              clean
tools/copyright.py --check     rc 0
diff    4 files, +133/-6       README.md, src/facts.rs, src/main.rs, src/ui.rs
snapshot/golden fixtures touched by this PR: 0

The "snapshots byte-identical" claim holds structurally, not just by the test passing: no snapshot or golden file is in the
diff at all, so every rendered-frame test is comparing against unchanged bytes and they are green. That is the right order for
this change — an idle first frame must be indistinguishable once the probes answer, and the way it could go wrong is a
snapshot quietly updated to match a new verdict.

The mechanism is the one line the body says, and both halves of it are right: App::new(Facts::idle()) paints before
anything waits, and the collector thread's first result replaces those facts on the loop's first pass (idle: false from
collect()), so the screen is idle-built only until the payload actually answers. The other half is the part that makes it
correct rather than merely fast: the idle frame says STARTING - the probes have not answered yet instead of
LEMONADE DOWN / DATA not mounted / amdxdna absent, which would be a lie about a box that is still starting — the same
rule as the web UI http://-:13305 fix (engine#1040), and it is what the two new tests pin.

The measured pair (3086/3111/3211 ms before → 26/55/467 ms after, and 14 bytes written inside a 0.6 s window on the old binary)
is yours: it needs the 3 s stub and a pty harness. It is the right instrument for a boot-time flake — a stub that takes exactly
as long as the payload does at boot is what the row was falling into — and reporting min/median/max with the 467 ms outlier
attributed to load 45 is more useful than a best-case number would have been. The cached-probe trap you hit on the first
attempt (120 s result cache → 60 ms readings) is worth knowing: it is the same class as everything else this cycle, where the
instrument quietly answered from a previous run.

This closes the c31 finding in the right place: the row was red because the screen was blank, and the fix is to paint
immediately, not to make the scraper wait longer.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

CI on 5bb11738: build pass 7m40s — the only required context per the ruleset — plus Analyze ×5 and CodeQL
pass, hw_gate skipped (TUI-only, no device ticket). mergeStateStatus=UNSTABLE only on pr_agent, whose run for
this head reads conclusion: cancelled after 5m54s (run 42365627178 — the workflow concurrency group, not a review);
it is not a required context, and it has been re-run.

Head unchanged since pi-os3 measured it, so d6f92127d71d921a / 1,598,120 B remains the artifact for this commit
(the body's cadd055a… line is corrected in the comment above). 0 review threads; verdict asked of pi-prs and cl-review.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Follow-up at 5bb11738 (my READY from 10:56Z stands; the head has not moved). I reproduced the corrected artefact on this box
rather than taking the correction on trust — same rustc as your measurement (1.98.0 88d9e12ae 2026-08-18), fresh checkout of
this head, ./build-static.sh:

5bb11738 (this head)          build-static: ok d6f92127d71d921a  1598120 bytes     <- your correction, exactly
0f45221e (main before this PR) build-static: ok 9cd86d36a16cd448  1596512 bytes     <- and this is c31's console hash

So d6f92127d71d921a / 1,598,120 B is right, and the second line is a free cross-check worth having: the tree one commit
back rebuilds to 9cd86d36, which is the hash the c31 release sheet quotes for the console. Both endpoints of this change are
now reproducible from the same tree on this box.

I could not reproduce the cause line directly — HEAD~1 is the pre-PR commit, not a pre-fmt variant of this one, so
cadd055a25e9ded6 is not something I can rebuild from git history. Your explanation is the plausible one (a line shift moves the
Location strings rustc embeds, and 24 bytes is the right order for three asserts), and it does not need to be proven for this PR
— the artefact that matters is the one the head produces, and that is now checked twice independently.

One thing to fix before the merge, though: the body still carries the stale hash. It reads

Static artifact (`build-static.sh`, `cadd055a25e9ded6`, 1,598,144 B, no `PT_INTERP`)

and the correction lives only in a comment. The body is what the release hand-off and the next reader quote — this cycle has
already produced one wound of exactly that shape (a claim about an artefact that was true of a different tree). Edit the line to
d6f92127d71d921a / 1,598,120 B, or drop the numbers and point at the gate's own output. Then the body and the artefact agree
without a comment to reconcile them.

Agreed on the durable fix: build-static.sh refusing (or loudly marking) a dirty tree is exactly what let a pre-fmt hash be
quoted at all, and filing it separately rather than touching this head is the right scope — c32 is about to quote this artefact.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY at 3922009302038e98c21a5a99f0f54e7e66065d92. Main merges only since my READY at 5bb11738: no non-merge commit of its own, and the PR's own +/- lines against its merge-base are identical (hash 3cf29071fb6b). The review at 5bb11738 stands.

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 69f416b)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

1322 - Partially compliant

Compliant requirements:

  • The first App is now built from Facts::idle() instead of Facts::collect()
  • The idle frame correctly shows "STARTING - the probes have not answered yet" and avoids stating facts it hasn't probed
  • Tests are added to ensure the idle frame is rendered correctly and that main does not use collect() for the first frame

Non-compliant requirements:

  • The PR description mentions "the first frame is painted before anything is probed" but does not explicitly state that this behavior is measured on the hardware

Requires further human verification:

  • The claim that "the first frame is painted before anything is probed" should be verified with measurements on the actual hardware
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Missing Idle Flag Initialization

The idle field in the Facts::default() implementation is not explicitly set to false, which could lead to incorrect behavior if the default instance is used without explicit initialization. This is particularly important in the context of the idle flag to distinguish between idle and collected facts.

pub idle: bool,
Conditional Logic for Idle State

The conditional logic in panels() and compact_status() functions relies on the idle flag to determine the content to display. If the idle flag is not properly initialized or updated, it could lead to incorrect rendering of the UI elements.

/// Each panel's content, one logical line per fact. The layout below decides how many columns and how wide;
/// this function never knows the screen size, so the two layouts cannot disagree about what is true.
pub fn panels(f: &Facts) -> Vec<(&'static str, Vec<String>)> {
    // Before the first probe answers there is nothing truthful to put in these panels: the empty defaults
    // would read as "DOWN", "absent", "not mounted" about a box that is still coming up. One panel that
    // says which question is being asked, and the collector's frame replaces it within a second.
    if f.idle {
        return vec![(
            "STARTING",
            vec!["asking Lemonade, the GPU, the NPU and the model list".to_string()],
        )];
    }

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 69f416b

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

console: the first frame waits on a synchronous probe, so a boot-time scrape of tty1 can read it empty

1 participant