Skip to content

The long-history drawing test and the quit test no longer fail just because the machine is busy - #305

Merged
pitis merged 4 commits into
mainfrom
fix/load-proof-tests
Nov 29, 2026
Merged

pitis merged 4 commits into
mainfrom
fix/load-proof-tests

Conversation

@pitis

@pitis pitis commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

What changed

  1. a_long_history_draws_only_the_rows_in_view (was a_long_history_draws_as_fast_as_a_short_one, core/desktop/src/app/paging.rs) no longer times frames. It counts the rows built while a history of 100, then 5,000, messages loads and is first drawn, and those built in the frame after. It asserts each count for 5,000 messages is less than twice the count for 100.
    • The counter, ROWS_BUILT, sits in Hush::row (core/desktop/src/app/view.rs), the function that promises rows are "built only for the rows on screen". It is compiled only for the snapshot tests.
    • Today the counts are 36 then 15, the same for 100 and 5,000 messages.
    • If a Row were built for every message on each frame (the code before The desktop app pages back through older messages and moves between chats from the keyboard #189), the counts would be (236, 115) and (10,036, 5,015).
    • What it no longer guards: per-frame work that grows with the history outside row building. The old test timed that, but a busy machine made the timing unreliable.
  2. The core lets go of the data folder's lock explicitly (core/sig-core/src/actor.rs). actor::lock now returns a FolderLock, which unlocks the file when dropped instead of only closing it. That covers every place sig-core lets go of the lock: stop, Client's drop, the relink, unlink and restore paths that hold it while they change the folder, and a core thread that panics. The types in client.rs follow.

Why

  1. The old test asserted that a 5,000-message frame took less than twice as long as a 100-message one, using real time. When the machine is busy, real time is noise. With the same unchanged binary and 12 × yes on top of other builds (load average 98–111), the old test failed 2 of 8 full runs. The property worth keeping is that only the rows in view get built, and a row count measures that without a clock.
  2. quit_stops_once_and_gpuis_own_quit_after_it_ends_at_once failed once with AlreadyOpen, while On Windows Hush writes a small log file, panics too, since it has no console #289 was being gated. The failing line is reopen (running.rs:350).
    • The stop wasn't late. In the unified log of the failing run (pid 81584, 22:00:28–36), the core stopped normally. Neither timeout fired (no "didn't stop in time", no extra "didn't answer quitting in time"), and there were as many "the core stopped" lines as in a passing run of the same binary (12 and 12). So the core had closed its lock before the test opened the data again, and the lock was still held anyway.

    • The cause: a child process holds a copy of the lock. When a program starts, the OS copies all of the parent's descriptors into it, the close-on-exec ones too, and closes those only once the program is running. A lock closed during that moment stays held by the child's copy. I wrote a probe (C, on this Mac) that takes an exclusive flock, closes it and locks again, 20,000 times:

      While the probe relocks Relocks refused
      Another thread runs /usr/bin/true in a loop 24 of 18,660
      Another thread runs /usr/bin/defaults in a loop 11 of 19,586
      No other thread starts programs 0 of 20,000
      LOCK_UN before each close 0 of 20,000
    • The tests start programs alongside it. the_mac_apps_user_defaults_are_read_by_their_kind runs /usr/bin/defaults three times. It is test 288 of 402, so it runs at about the same time as the quit tests (266 to 268), and a busy machine makes each start slower. I added a thread that starts programs during the quit test and ran it under load. Once in 80 runs without the fix, the reopen found the lock held, and it was free 831 ms later.

    • The fix is in sig-core, where the lock lives. Unlocking explicitly (LOCK_UN) frees the lock for every copy of the descriptor at once. Without the fix, the app recovers anyway, because a later launch already waits for the data. A core opened right after a relink, unlink or restore doesn't wait, though, so the fix helps there too.

How it was tested

  • make format && make check:
    • cargo fmt --check: passes.
    • cargo clippy --all-targets -q -- -D warnings: passes.
    • cargo clippy --all-targets --features hush-desktop/snapshot -q -- -D warnings: passes.
    • cargo test --features hush-desktop/snapshot -q: desktop 404 passed; sig-core 554 passed, 4 ignored. This is on the merged head, after A field's caret blinks only while Hush's window is active, minimised included #304.
    • On the first run, all 402 desktop tests passed, then the test binary crashed with SIGSEGV at exit. The crash report shows a sqlx worker running a query while SQLCipher's exit handler ran. This is a separate problem that was already there: a binary built without this change crashed the same way. The second run passed.
  • The new paging test fails when rows outside the view are built. I tried two temporary changes and restored the code after each:
    • rendering every message into the timeline: the first version of the test failed with 100 rows and 5,000 rows;
    • building a Row for every message on each frame: the test failed with (236, 115) and (10,036, 5,015).
  • The new sig-core test a_lock_let_go_is_free_while_a_copy_of_it_lives_on keeps a second descriptor of the lock open, as a starting program would. It failed before the fix with Err(AlreadyOpen) and passes after it.
  • Under load:
    • The full desktop test binary with the new paging test passed 20 of 20 runs at load 57–191. That build also carried temporary timing code in the quit test; the quit stop took at most 267 ms, and the lock was always free after it.
    • Three copies at once passed 8 of 8 rounds (24 runs) at load 48–132.
    • The gated binary of this branch, on the merged head:
      • With 12 × yes (one per core): 10 of 10 full runs passed at load 10–31. The binary gated before the merge also passed 10 of 10, at load 33–67.
      • With 84 × yes: in 10 full runs at load 73–128, the paging test and the quit test passed every time.
      • 5 of those 10 runs failed one other test: app::files::window_tests::a_click_on_a_file_presses_it_and_leaves_the_keys_in_the_composer ("nothing was said"). That failure was already there: I ran main's binary and this branch's one after the other at that load, and both failed it 4 of 4. Main's binary also failed the old paging test once.
      • Its cause: the helper said (core/desktop/src/app/view.rs) gives the core 2 s of real time to answer. That is a third test a busy machine breaks, outside this issue. It is left for its own issue.
    • The quit test's AlreadyOpen was rare even before the fix: 0 in those runs without a thread starting programs alongside. The deterministic sig-core test and the probe are the proof of the fix, not the load runs.

Closes #292

@pitis

pitis commented Nov 29, 2026

Copy link
Copy Markdown
Owner Author

Review (/pr-review-toolkit:review-pr on git diff origin/main...HEAD)

Three reviewers ran: code, tests, and comments and types. None found anything Critical. Below is each Important and Suggestion finding and what I did about it.

Important: fixed

  1. The counter was in render_row, so it would have missed the regression the old test was written for (code review).
  2. Only the frame after a warm-up draw was counted (test analysis). A list that measures every row on the frame right after a history loads, as GPUI's ListState::measure_all() does, would have passed.
    • Fix: the test now counts both the rows built while the history loads and is first drawn, and those built in the frame after. It asserts each count, for 5,000 messages, is less than twice the count for 100.
    • Today the counts are 36 then 15, the same for 100 and 5,000 messages.
  3. The FolderLock doc said a starting program holds a copy of every descriptor, without naming a platform (comments). That is true on Unix. On Windows, std opens files with handles that children don't inherit.
    • Fix: the doc now says "on Unix" and states that unlocking frees the lock for every copy at once. The unlock itself is harmless on Windows.

Suggestions

  • Fixed:
    • The Drop comment now says "every copy of its descriptor", not "of the file".
    • The lock test's doc points to FolderLock instead of repeating it.
    • The counter's doc now says what it counts (Hush::row).
  • Stated, not changed (tests): the row count bounds how many rows are built. Per-frame work that grows with the history outside row building is no longer timed by any test. That is the price of a test a busy machine can't fail, and the PR body now says so.
  • Declined: core/desktop/src/app/home.rs:105-112, the one-time move of the old "Hush Desktop" folder, still lets go of its lock probe by closing it.
    • Why: it is outside this issue. A launch that finds the folder AlreadyOpen already waits up to 6 s for it (app/mod.rs:316-320), and nothing starts programs on another thread at that point.
    • The PR body now says "every place sig-core lets go of the lock".
  • Noted: I didn't run the lock test on Windows or Linux. On Linux, flock frees every copy on LOCK_UN, as on macOS. On Windows, UnlockFile through the original handle frees it, and try_clone shares the file object.

Gate, on the merged head (make update brought in #304)

  • cargo fmt --check: passes.
  • cargo clippy --all-targets -q -- -D warnings: passes.
  • cargo clippy --all-targets --features hush-desktop/snapshot -q -- -D warnings: passes.
  • cargo test --features hush-desktop/snapshot -q: desktop 404 passed; sig-core 554 passed, 4 ignored.
  • Under load, this binary:
    • With 12 × yes (one per core): 10 of 10 full runs passed at load 10–31. The binary gated before the merge also passed 10 of 10, at load 33–67.
    • With 84 × yes: in 10 full runs at load 73–128, the paging test and the quit test passed every time.
    • 5 of those 10 runs failed one other test: app::files::window_tests::a_click_on_a_file_presses_it_and_leaves_the_keys_in_the_composer ("nothing was said"). That failure was already there: I ran main's binary and this branch's one after the other at that load, and both failed it 4 of 4. Main's binary also failed the old paging test once.
    • Its cause: the helper said (core/desktop/src/app/view.rs) gives the core 2 s of real time to answer. That is a third test a busy machine breaks, outside this issue. It is left for its own issue.

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.

The long-history drawing test doesn't fail just because the machine is busy

1 participant