Skip to content

Write the Windows GUI log to its file directly and stop helper consoles flashing (closes #3768) - #3773

Merged
malibio merged 2 commits into
mainfrom
issue-3768-windows-start-menu-logs
Oct 13, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-3768-windows-start-menu-logs

Conversation

@malibio

@malibio malibio commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes #3768.

A Windows launch from the Start menu lost all of the app's own log output (nodespace-app.log stayed empty), while launches from PowerShell, the installer finish screen or an Explorer-opened shortcut logged fine.

Root cause (reproduced and measured on a Windows 11 VM with a standalone harness plus a kernel file-I/O trace): a Start-menu launch starts the process with STARTF_HASSHELLDATA set, which parks a monitor handle in the stdout slot. While that flag is set, GetStdHandle(STD_OUTPUT_HANDLE) reads back NULL even after SetStdHandle stored the log file, so tracing and println! write nowhere. stderr is unaffected. The handles were open and the redirect had succeeded, which is why it looked like a log-level or file problem. Clearing the flag in the harness made stdout readable again.

Changes

  • A Windows release build gives the tracing subscriber the log file directly (daemon_setup::gui_log_writer, no ANSI codes), so the log no longer depends on how the app was started. The stdout/stderr slot redirect stays for stderr, and its doc comment now states the stdout caveat.
  • The three menu-event println! calls become tracing::info!.
  • reg, taskkill, the CLI check and both skill-installer launches go through hide_console_window (CREATE_NO_WINDOW). A GUI process has no console, so Windows opened and flashed one per child at every startup.
  • Two source-pin tests; each was confirmed to fail with its fix removed.

Verification

  • bun run test:changed passes.
  • cargo xwin check of nodespace-app-lib for x86_64-pc-windows-msvc passes in the dev and release profiles (the log writer is gated on not(debug_assertions)).
  • Not yet run: the installed app from a Start-menu click. A non-release Windows build from this branch is the next step.

🤖 Generated with Claude Code

@malibio

malibio commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

Verdict: APPROVE with improvements (self-authored PR, so posted as a comment). This is a net improvement and the root-cause fix is the right one: tracing owns the file directly instead of depending on a slot the shell launch poisons. The change is small, cohesive, correctly gated (cfg(all(windows, not(debug_assertions))) keeps tauri dev on its terminal), and adds no compatibility code. Nothing blocks merge. The main gaps are incomplete coverage of the "no console flash" half of the change and one unrotated, now-growing log file.

Scrutiny points you asked about:

  • Second open alongside the SetStdHandle'd handle: safe. open_daemon_log uses append(true), which on Windows is FILE_APPEND_DATA with Rust's default share mode (read|write|delete). Each write is positioned atomically at EOF, so the two handles cannot overwrite each other, only interleave at write granularity.
  • Fallback to stdout: acceptable. io::stdout on a NULL/invalid handle is a silent sink in std, so a failed open degrades to the previous behaviour and never aborts startup.
  • Mutex poisoning: tracing-subscriber 0.3's MakeWriter for Mutex<W> does lock().expect("lock poisoned"). The lock is held only across write_all of an already formatted buffer, so risk is very low. Not worth a custom writer.
  • ANSI: with_ansi(false) is correct for a file.

Findings

Critical Issues

None.

Suggested Improvements

  • [Improvement] packages/desktop-app/app-lib/src/commands/onboarding.rs:482 (the identity-prefill config lookup): the tokio::process::Command spawn of the version-control CLI is reachable on Windows from the GUI process and will flash a console window exactly like reg/taskkill did. id -F (~line 503) is attempted on Windows too; it normally fails to spawn, but if a Unix-tools dir is on PATH it resolves and flashes as well. Same defect class as this PR's goal; fold it in. hide_console_window takes std::process::Command; for tokio use creation_flags (inherent on Windows) or cfg(windows)-skip id.
  • [Improvement] packages/daemon/src/tray.rs:136 (signal_ui_to_quit): the daemon is spawned DETACHED_PROCESS (no console), so its taskkill child allocates a console window the same way the app's did. User-visible when choosing Quit from the tray. Needs CREATE_NO_WINDOW too; hide_console_window is pub(crate) in the app crate, so the daemon needs its own two-line equivalent or a shared helper.
  • [Improvement] daemon_setup.rs (GUI_LOG_FILE, rotate_daemon_logs): nodespace-app.log is not covered by log rotation (rotate_daemon_logs and the live watcher handle only nodespaced*.log). Previously that file received almost nothing after a Start-menu launch; now every tracing event goes there, so it grows without bound. At minimum rotate it at app startup before gui_log_writer opens it (files closed at that point, mirroring the existing rule). Acceptable as a follow-up, but it is a direct consequence of this change.
  • [Improvement] stale doc comments now contradict the new behaviour: the redirect_gui_stdio_to_log_files doc still opens with "so eprintln!/println! output ... isn't silently discarded", and its "Confirmed on a real Windows box ... both streams land correctly" and "Windows never attaches ... any standard handle" paragraphs describe the pre-fix model; the new bold paragraph at the end corrects it but a reader hits the old claim first. Reword those to say it was verified for a cmd /c start launch and that stdout is unreliable after a shell launch. The run() comment in lib.rs (~lines 450-460) likewise says the redirect means println diagnostics are not lost.
  • [Improvement] windows_helper_processes_open_no_console_window: the exact count skill_setup.matches("hide_console_window(").count() == 3 also matches doc comments and any legitimate fourth call, so it fails for the wrong reason and invites editing the number. It also cannot see spawns it was not told about (it passes while the onboarding and tray spawns above are unhidden). Treat it as a tripwire: drop the exact count or say so in the message.

Nitpicks

  • Nit: run_writes_the_windows_release_log_to_the_file_not_the_stdout_slot matches a multi-line literal including rustfmt's indentation. Stable under enforced rustfmt, but matching .with_writer(daemon_setup::gui_log_writer()) and the cfg attribute separately would be less fragile. The !run.contains("println!(") check is useful.
  • Nit: declare GUI_LOG_FILE / GUI_ERROR_LOG_FILE above redirect_gui_stdio_to_log_files.

Testing / verification

  • The source-pin tests were mutation-verified, which is appropriate for Windows-runtime-only behaviour; they are tripwires, not proofs.
  • The decisive check is still manual: install the release build, launch via a Start-menu click, confirm ~/.nodespace/logs/nodespace-app.log receives tracing lines and no console window flashes (also exercise onboarding identity prefill and tray Quit given the findings above). Please record that result on the issue before merge.

Docs / process

  • No node-type, schema or sync-boundary surface touched.

@malibio malibio 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.

Review posted in the comment above. Verdict: APPROVE with improvements; no blockers.

@malibio

malibio commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed (61d0575)

Addressed (6 of 6, nothing skipped):

  • App log never rotated — nodespace-app.log and its error log are now rotated at startup (rotate_gui_logs, before this process opens either file). Not periodic: the app log holds a handful of lines per session, unlike the daemon's. New test rotate_gui_logs_rotates_only_the_oversized_file.
  • Identity prefill spawns — git config now sets CREATE_NO_WINDOW (tokio's Command has creation_flags itself; the shared constant is daemon_setup::CREATE_NO_WINDOW). id -F is deliberately left alone: it can't start on Windows (the existing doc comment says so), and a spawn that fails creates no console. Revisit if id ever ships on the Windows PATH.
  • Daemon tray taskkill — packages/daemon/src/tray.rs now sets CREATE_NO_WINDOW (the daemon is DETACHED_PROCESS, so it flashed on tray Quit). Inline, since hide_console_window is private to the app crate and a one-line flag does not justify a shared crate.
  • Stale docs — the redirect_gui_stdio_to_log_files doc and the run() comment no longer claim println! is reliable; they state what was measured and why the code avoids the stdout slot.
  • Brittle tests — the exact == 3 count is gone in favour of a rule: every non-test Command::new( in skill_setup has hide_console_window beside it (Unix absolute-path spawns excluded). The tracing-writer test matches its gate structurally, not by rustfmt indentation. Mutation-checked: removing one skill-installer hide call fails the test.
  • Constant ordering — GUI_LOG_FILE / GUI_ERROR_LOG_FILE now sit above their first use.

Verification: bun run test:changed passes; cargo xwin check --release of nodespace-app-lib for x86_64-pc-windows-msvc passes. The daemon crate was not Windows-checked locally (its llama.cpp C++ build does not cross-compile here); the tray edit is a single creation_flags call of the same shape the daemon's own spawn already uses.

Still open: the manual Start-menu click on an installed build (log lines appear, no flashing consoles, onboarding prefill and tray Quit exercised).

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: every change is a small, mechanical application of the already-reviewed approach (one more flag at two spawn sites, a rotation call that reuses rotate_log_file, comment rewrites and test hardening). No new design or control flow beyond one startup call to the existing rotation helper.

@malibio

malibio commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

Verified on Windows 11 (VM), from a non-release build of this branch

Installed the windows-x86 build from workflow run 38371331313 and launched it from the Start menu (parent: explorer.exe, the launch path that was silent before).

  • nodespace-app.log received 23 lines starting at the first moment of startup (gRPC client (lazy) …), no ANSI codes. Before this change the same launch path wrote none.
  • nodespace-app-error.log stays empty, as expected.
  • The log also surfaced a database-incompatibility sequence (daemon refused an older database; the app moved it aside), which a Start-menu launch previously hid. Expected behaviour, unrelated to this change.

Still to record: the number of console windows flashing at startup (previously about 3), reported by the person at the keyboard.

@malibio

malibio commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

Console windows: none noticed at startup on the same Start-menu launch (previously about 3). Both halves of the change are verified on Windows; ready for merge.

malibio and others added 2 commits October 13, 2026 11:41
…es flashing (closes #3768)

A launch from the Start menu starts the process with STARTF_HASSHELLDATA, which
parks a monitor handle in the stdout slot. While that flag is set,
GetStdHandle(STD_OUTPUT_HANDLE) reads back NULL even after SetStdHandle stored
the log file, so tracing and println! went nowhere. stderr is unaffected, and
launches from PowerShell, the installer finish screen or an Explorer-opened
shortcut don't set the flag, which is why only Start-menu launches lost output.

- A Windows release build now gives the tracing subscriber the log file itself
  (no ANSI codes) instead of relying on the stdout slot.
- The three menu println! calls become tracing::info!.
- reg, taskkill, the CLI check and both skill-installer launches set
  CREATE_NO_WINDOW; a GUI process has no console, so each child flashed one.
- Source-pin tests for both; each fails with its fix removed.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…s, fix stale docs

- Rotate nodespace-app.log and its error log at startup, before this process
  opens them. Tracing now writes to the app log for the whole session, and the
  daemon's rotation never covered it.
- Hide the console of the identity-prefill `git` spawn (tokio Command) and the
  daemon tray's `taskkill`; the daemon is DETACHED_PROCESS so it flashed too.
  `id -F` is left alone: it cannot start on Windows, so no console is created.
- Reword the redirect and run() comments that still described stdout as
  reliable; they now state what was measured and why the code avoids the slot.
- Tests: drop the exact `hide_console_window(` count in favour of a rule that
  every non-test Command::new in skill_setup has the helper beside it (Unix
  absolute-path spawns excluded); match the tracing writer's gate by structure
  rather than rustfmt indentation; add a rotation test for the app log.
- Move the log-file constants above their first use.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@malibio
malibio force-pushed the issue-3768-windows-start-menu-logs branch from 61d0575 to 3416b25 Compare October 13, 2026 09:41
@malibio
malibio merged commit 08ef1fc into main Oct 13, 2026
@malibio
malibio deleted the issue-3768-windows-start-menu-logs branch October 13, 2026 09:41
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.

Windows GUI app's log redirect delivers no output when the app is launched from the Start menu

1 participant