Skip to content

On Windows Hush writes a small log file, panics too, since it has no console - #289

Merged
pitis merged 3 commits into
mainfrom
feat/windows-log-file
Nov 29, 2026
Merged

pitis merged 3 commits into
mainfrom
feat/windows-log-file

Conversation

@pitis

@pitis pitis commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

What changed

  • Windows keeps a log file: the core's log (the same scrubbed lines: errors and opaque ids, never message content) goes to hush.log in the data folder as well as stderr, about 1 MB: the line that would pass it first moves the file to hush.log.1 (replacing the one there) and starts a new one. While that move is refused (another program has a file open without delete sharing, as a viewer following the log may), lines go on in hush.log past the cap rather than nowhere, and the next line tries again. A HUSH_DATA_DIR run writes it in that folder. (core/sig-core/src/logging.rs: LogFile, keep_in; init tees the fmt layer's writer to it on Windows only.)
  • Each Windows launch's first line in the file is Hush started version=… (logged right after keep_in): a bug report says which version wrote it, and the release check has a line it can require.
  • From main's first line: the desktop app now starts the core's log first thing (sig_core::logging::init(), which Client::open used to be the first to call). The data folder isn't known that early, so lines wait in memory (1 MB at most) until app::folder() has settled it, then go into the file first. Waiting is on purpose: making Hush before home() has run would stop its one-time move of an old "Hush Desktop" folder into its place.
  • Panics (Windows): a panic hook logs panicked at <file>:<line>:<col>: <message> through the same scrubbed log (so into the file), then calls std's hook as before.
  • The file is opened for each line and never held open: unlinking, restoring a backup and the old-folder move are untouched by it, and a line that can't be written at all is dropped, as tracing-subscriber's fmt layer drops write errors, and the next one tries again. A failure at keep_in is logged to stderr only.
  • Release workflow: the Windows start check also requires hush.log in the app's data folder with its Hush started line, and prints it; the stderr capture is renamed stderr.log so the two aren't confused. Nothing else in the workflow changed (same pinned actions, permissions and token scope).
  • README: where the log is on Windows and to attach hush.log and hush.log.1 to a bug report (Download: a panic in Hush is in it, not a native crash), and how the log works there (Development).
  • home.rs: the shortcut: saying its warnings were lost before the core's log was up is gone (the log is up first now), and left_alone's doc no longer says nothing is logged before the core opens.

macOS and Linux: no file, no panic hook. The one difference there is that the log starts at main's first line, not at the core's open, so home()'s two warnings (the old login item, the old key) now reach Console.app / stderr instead of being dropped.

Why

Owner's decision of 2026-11-29: since #285 the Windows build has windows_subsystem = "windows", so launched from Explorer, the Start menu or the Run key the log and any panic went nowhere, and a failure before the window opened left no trace.

Panic messages: what I checked

Every panic!, expect, unwrap, unreachable! and assert! outside tests in core/sig-core and core/desktop: each carries a fixed text ("the window opens", "HMAC takes any key length", ...) or, in one case, a database file's path (ProjectionDb's encryption assert); none formats a message, a name or a number. Panics from dependencies (GPUI's RefCell already borrowed, an index out of bounds) carry their own code's text. Either way, the line goes through the same Scrub as every log line, which blanks service ids, keys and other long hex, phone numbers and byte dumps (the panic test checks a UUID is blanked).

How it was tested

  • Tests first (logging.rs), each seen failing against a stub (no rotation, nothing kept waiting, no hook) and passing with the change:
    • lines_wait_for_the_folder_and_go_first_into_its_file: lines logged before open_in reach the file first, as many as fit in the cap; nothing is made before the folder is known.
    • past_its_cap_the_log_starts_over_keeping_the_one_before: the file is there from the start, fills to exactly the cap, then becomes hush.log.1; a second LogFile on the folder (the next launch) goes on in the same file; only one older file is kept; a line longer than the cap goes in whole, alone.
    • a_panic_is_logged_with_its_place_and_scrubbed: a real panic, caught, logs a line with panicked at sig-core/src/logging.rs:<line>: and its message with the service id in it blanked, and no line has the raw id.
    • After the review, a_log_that_cant_be_moved_goes_on_past_its_cap: a non-empty folder in place of hush.log.1 makes the move fail on any OS; the line past the cap stays in hush.log, and the next line moves it once it can. It failed before that fix (the line was dropped) and passes after.
  • Windows type-check: the core can't cross-build here (SQLCipher's and RingRTC's C builds), so a scratch crate holding this logging.rs as it is (by symlink) and main.rs's new lines, with the core's Cargo.lock versions: cargo clippy --offline --target x86_64-pc-windows-msvc --lib --bins -- -D warnings is clean, and a deliberately wrong use of the Windows-only static fails there, which shows that code is compiled.
  • Gate on the head merged with main: make format (no changes), make check passes on a1e5b2c (fmt, both clippy runs, 386 + 550 tests). The workflow's YAML parses (actionlint isn't installed here; the change is PowerShell lines in an existing step). The macOS --snapshot run (which goes through the new start of main) rendered all 88 screens; chat-light looked at, unchanged.
  • On Windows, for real: run 46309832317, both jobs green (Windows built in 12m44s, Linux in 8m47s). A throwaway test-287-1 pre-release ran it on a throwaway branch: this PR's head (db2a2ad) plus one temporary probe commit (a panic on demand in main, behind an env var, and an extra workflow step). The release, its tag and the branch were deleted after the run; the probe never touched this PR's branch.
    • The real start check (this PR's step, unchanged in the probe): hush.exe still running after 20 s, and hush-data\hush.log held INFO hush: Hush started version=test-287-1 and GPUI's three RefCell already borrowed errors, line for line what stderr got.
    • The probe step: hush.exe started with Start-Process and no redirect (no stderr, as from Explorer), HUSH_PROBE_PANIC=1: it exited 101, and its hush.log held Hush started then ERROR sig_core::logging: panicked at desktop\src\main.rs:48:9: a probe panic. So the file is written under windows_subsystem with no console, and the panic hook reaches it.
  • Not run on Windows: the 1 MB rotation, and a rename refused by a real viewer (both covered by the tests on macOS with the same code); a launch from Explorer or the Run key (the probe's launch without handles stands in for it); a second launch handing over to a running Hush (both append to the one file).

Closes #287

@pitis

pitis commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner Author

Review (pr-review-toolkit:review-pr: code, error handling, tests, comments)

No Critical findings. Fixed in db2a2ad:

Important

  • A refused rename at the cap dropped every line from then on (error handling, comments; the code review had it as a suggestion). Once hush.log was full, each line tried to move it to hush.log.1; while another program held either file open without delete sharing (a viewer following the log, say), every rename failed and every line was dropped, for exactly the user watching the log. Now the line goes on in hush.log past the cap and the next line tries the move again. New test a_log_that_cant_be_moved_goes_on_past_its_cap (a non-empty folder in place of hush.log.1 makes the move fail on any OS): it failed before the fix and passes after.
  • The release check couldn't fail if no line reached the file (error handling, tests, code). keep_in makes hush.log even with nothing to write, and a fresh unlinked start logs nothing in 20 s (v0.1's run printed an empty stderr). Now each Windows launch logs Hush started version=… right after keep_in, which also tells a bug report which version wrote the log. The workflow requires that line in hush.log.
  • The panic test failed on Windows in a full cargo test (tests). There, a test that opens a core first runs init, which installs the hook too, so the panic was logged twice and lines.len() == 1 failed. It now asserts that some line has the place and the scrubbed message, and that no line has the raw id. It is renamed a_panic_is_logged_with_its_place_and_scrubbed.
  • The README promised "a crash too" (comments, error handling, code). Only Rust panics are logged; a native fault, a stack overflow or an abort leaves nothing. It now says "a panic in Hush too", and "errors and opaque ids only".

Suggestions taken (comments): the LogFile doc (about cap, a longer line alone, the refused move, waiting lines dropped once the cap is full, why it's opened for each line without overclaiming); lock's comment names the real hazard (the panic hook logs on the same thread and would wait forever); log_panics doesn't promise the message is the code's own; init has a doc; keep_in says the waiting lines are dropped if they can't be written; "one event at a time"; left_alone's doc says why it's asked after home; the workflow comment says why stderr is still captured.

Declined, with reasons

  • Keep the waiting lines when the first write fails and show a keep_in failure in the Core Log (error handling): a data folder keep_in can't make is one the core can't open either, and that already shows on the window's Failed screen. What's left is a hush.log made unwritable by hand in a working folder, too rare to need new UI. The doc says the waiting lines are dropped then.
  • Count dropped lines into the file (error handling): with the rename fix, the case that dropped lines for good is gone. What's left is a line failing while the file can't be opened at all, and then nothing more could be written anyway.
  • Keep the file open instead of opening it per line (code): the core logs received at info for each envelope, but each envelope already costs a decryption and a SQLite transaction, far more than an open, an append and a close. Kept simple, and measurable if a catch-up on Windows ever feels slow.
  • The thread's name in the panic line (error handling): the place already names the code, and thread::current() inside a hook can itself panic while a thread is being torn down.
  • Pin the len > 0 guard, the waiting buffer's exact boundary, Drop guards on the tests' temp folders (tests, all below 5): the folders are removed at each test's end, as in files.rs's tests.

Noted (code): the throwaway pre-release used to run the release workflow on real Windows is public while it lasts. It was done as #285's were: a test-287-1 pre-release on a throwaway branch's commit, deleted with its tag and the branch once the run ended. make publish ignores non-v tags.

For the owner, not fixed (outside this issue): on macOS a Hush.app opened from Finder also has no stderr, and the panic hook is Windows-only as asked, so a macOS panic still goes nowhere. Since its log is the unified log, a macOS hook would only need to log the panic (no file).

Checks after the fixes: make format (no changes), make check passes on a1e5b2c (fmt, both clippy runs, 386 + 550 tests); the log tests pass, the new one included; the Windows type-check (scratch crate, x86_64-pc-windows-msvc, clippy -D warnings) is clean again; and the release workflow ran green on real Windows and Linux with this code (run 46309832317: hush.log held the start line and, with no stderr, a panic's line). The PR body has the details.

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.

On Windows Hush writes a small log file, since it has no console

1 participant