Repository navigation
Conversation
Once a day the CLI starts a hidden helper (proofline __update-check) to see whether a newer release exists, and doesn't wait for it. On Windows, Rust starts that helper with bInheritHandles=TRUE, so it also gets a copy of the pipe the parent's output goes into (rust-lang/rust#54760). When a script, CI step or editor reads proofline's output, it keeps waiting until the helper's network request finishes, which adds 1-3 s to the command. Linux and macOS are not affected. The direct fix (clearing the inherit flag) needs unsafe code, which this crate forbids, and std's safe option (inherit_handles) is still unstable. So on Windows the check now starts only when stdout and stderr are both consoles, where nothing waits for the pipe to close. The update notice is only shown in a console anyway, so nothing visible is lost. When the check can't start, prepare_check returns before writing the cache. Otherwise a script run would record "checked today" without checking, and the next console run would skip the check.
Proofline's review pointed out two things the tests didn't check: 1. The unit test only started the helper with interactive=true. If a later change skipped the update check whenever output is redirected, on every platform, the test would still pass. The call that should start the helper now uses interactive=false, so the test proves that only `detach` decides. 2. The subprocess test passes may_detach() to prepare_check itself, so it never checked that on_invocation does. A new Windows-only test runs the real proofline binary with its output captured (like a script) and an empty cache, and checks that no update.json is written. I checked that each test catches its mistake: with the mistake put in on purpose, the test failed; with it removed, it passed.
Proofline's second review found two more things the tests didn't check: 1. The Windows rule is "start the helper only if stdout AND stderr are both consoles". The subprocess test pipes both streams, so it would still pass if the rule checked only one stream or used OR. That mixed case is the common one: `$o = proofline ...` captures only stdout, while stderr stays on the console. The rule now lives in a small function, detachable(), and a new test checks all four console/pipe combinations on Windows (and that other platforms always allow the helper). 2. The Windows binary test would also pass if `--version` stopped running the update logic at all, since then no update.json is written either. It now also checks that update.lock exists: the lock is created before the decision, so it proves the decision ran. Each new check was confirmed by putting the mistake in on purpose (OR instead of AND, one stream only, skipping --version): the test failed, and passed again once the mistake was removed.
The comment above on_invocation said the check always continues in a background child. Since this change, on Windows it only does when both stdout and stderr are consoles; a redirected run leaves the check to a later run. The comment now says so.
This was referenced Nov 22, 2026
This was referenced Nov 27, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #78
The problem in one sentence
On Windows, when a script or CI job reads
proofline's output, every command can take 1–3 secondslonger than it should, because a hidden helper process that checks for updates keeps the output
"open" after
prooflineitself has already finished.See it yourself (PowerShell, Windows)
$o = …captures the output, the way a script or CI step does. Printing--versiontakes about10 ms; the rest is waiting.
Why it happens, step by step
Once a day, the CLI checks for a new release in the background.
update::on_invocationstarts a second copy of itself (
proofline __update-check). That helper asksproofline.shforthe latest version and writes the answer to a small cache file. The main command does not wait
for it; the idea is that the helper finishes quietly on its own.
Capturing output uses a pipe, and the reader waits until the pipe is closed. When PowerShell
runs
$o = proofline --version, it connectsproofline's output to a pipe and keeps reading untilthe pipe is closed. A pipe only closes when every process holding its writing end has let go.
On Windows, a new process can receive copies of its parent's handles. A handle is the
operating system's "ticket" that lets a process use a file or a pipe. Rust's
Command::spawnstarts processes on Windows with
bInheritHandles = TRUE, which means: give the new process acopy of every ticket the parent has marked as inheritable. The parent's stdout/stderr pipe
tickets are inheritable (they were inherited from PowerShell in the first place). The helper is
started with
Stdio::null(), which only decides where the helper's own output goes; it doesnot stop the extra copies from being handed over. This is a known Rust issue:
windows: when creating process with redirected stdio, make parent's std handles not inheritable rust-lang/rust#54760.
So the helper is still holding the pipe after
prooflineexits.proofline --versionfinishes in about 10 ms, but the pipe stays open until the helper's network request is done (up
to its 3-second timeout, longer if DNS is slow). PowerShell, a CI runner, or an editor reading
the output waits all that time.
Linux and macOS don't have this problem. There, Rust marks its own file descriptors
close-on-exec, so the helper doesn't keep the pipe. That's also why CI didn't notice: CI runs
cargo testonly on Ubuntu.The repository's own test already catches this. On Windows,
update::tests::detached_discovery_is_serialized_and_notices_arrive_on_the_next_invocationfailsevery time (it times out at
src/update/tests.rs:291). Its comment even says"Inherited output pipes would fail this too."
Who is affected
windows-*runners). Each job starts with an emptycache, so every
prooflinecommand in the job pays the extra seconds.$(...), pipes,editors and agents that talk to
proofline mcp. There it happens once a day (the cacheremembers the last check for 24 hours).
Why not the "obvious" fix
The direct fix is to tell Windows not to hand those pipe tickets to the helper
(
SetHandleInformation(..., HANDLE_FLAG_INHERIT, 0)on the three standard handles). I tried it:the failing test then passes in 0.09 s. But calling that Windows function needs
unsafecode, andthis crate sets
unsafe_code = "forbid"(Cargo.toml:67), so that's not an option. I alsochecked the alternatives:
CommandExt::inherit_handles), buton the pinned toolchain (1.100) it is still unstable (
windows_process_extensions_inherit_handles,#146407), so stable Rust can't use it.
What this PR changes
Start the background check on Windows only when nobody can be left waiting, which is when the
command's output goes straight to a console window that a person is looking at. A console isn't a
pipe, so nothing waits for it to "close".
src/update.rs, newmay_detach(): returnstrueon Linux/macOS (no change there). OnWindows it returns
trueonly if both stdout and stderr are consoles (is_terminal()).src/update.rs,prepare_check(..., detach, ...): whendetachisfalse, return beforewriting anything to the cache. The order matters. The cache records "I checked today". If a
script run wrote that note without actually checking, the next run in a console would think the
check was done and skip it, and the person wouldn't hear about a new release that day.
Why nothing is lost
The "a new version is available" message is only ever shown when output goes to a console
(
suggestion()returnsNoneotherwise). So a piped run on Windows never showed it anyway. Nowit just doesn't start the check either, and the next console run checks as before.
How I tested it (Windows 11, Rust 1.100.0)
Tests, failing first, then passing:
may_detach(), withtheir output piped to the test, as in a real script. Before: times out after 5 s. After:
passes. On Windows it checks the new behaviour: the processes exit quickly, no update request is
made, and nothing is written to the cache. On Linux/macOS the original scenario runs unchanged.
an_invocation_that_cannot_detach_leaves_discovery_to_the_next_one(all platforms):when the check can't be started, the launcher is never called and the cache stays empty. The
next run that can start it does start it and records it, even when its output isn't a console
(only
detachdecides). Before the change it failed because the attempt was recorded.windows_detaches_only_when_both_output_streams_are_consoles(all platforms): the ruleis a small function,
detachable(), so the test can check all four console/pipe combinations.On Windows, any redirected stream blocks the helper. That includes the common
$o = proofline …case, where only stdout is captured and stderr stays on the console. On otherplatforms, every combination allows it.
captured_windows_invocation_leaves_discovery_to_a_console_run(tests/update.rs,Windows only): runs the real
proofline --versionbinary with its output captured and an emptycache. It checks that
update.lockexists (so the update logic really ran and made its decision)and that no
update.jsonis written (so the decision was "don't start the helper"). This coversthe wiring inside
on_invocation, not justprepare_check.The real binary:
$o = proofline --version, empty cachePROOFLINE_NO_UPDATE_CHECK=1(baseline)After the change, no cache file was written in the piped runs, as intended. (The very first
launch of a freshly built
.exesometimes took ~1 s before and after; that's Windows scanning anew file, not the checker.)
A console run still checks for updates:
Start-Process proofline --version(which opens itsown console window) with an empty cache wrote the cache file within 5 s
(
{"checked":…,"latest":"0.4.7"}).Checks:
cargo fmt --checkpasses.cargo clippy --locked --all-targets -- -D warningsreports nothing in the changed code. Itdoes report two lints that already fail on
mainin Windows-only test code(
src/agent/tests.rs:526,:745). I left those alone to keep this PR focused.cargo test --locked --no-fail-fast: 147 passed, 7 failed. The 7 also fail onmainandare Windows test-setup problems unrelated to this change: 5 in
tests/mcp.rs(env_clear()removes
SYSTEMROOT),tests/agent_install.rs:77(short vs. long temp path) andtests/local_patch.rs:275(a file name Windows doesn't allow).mainhas 8 failures: these 7plus the update test this PR fixes.
Linux: the repository's CI passed on my fork (formatting, clippy,
cargo testandcargo denyon Ubuntu, plus the Windows build):https://github.com/Ahmar004/cli/actions/runs/45060272853. On Linux/macOS
may_detach()is alwaystrue, so the code path there is the same as before.Follow-up (separate issue, not this PR)
Run
cargo clippyandcargo teston the Windows CI job. Both would have caught this.Proofline review
I ran Proofline on this branch in my fork (Ahmar004#1). It made 7 comments over three review rounds; I accepted 5 and disagreed with 2:
src/update/tests.rs:104: the launch assertions only useinteractive = true, so a guard that skipped discovery for redirected output would still pass.detach) from "may a notice be shown" (interactive), but no test pinned that separation. The launching call now usesinteractive = false. Checked: with an!interactiveguard added on purpose, the old test passed and the new one fails (assert!(launched)); without it, it passes.src/update/tests.rssubprocess test: it passesmay_detach()toprepare_checkitself, bypassingon_invocation, so a CLI that always allowed discovery would still pass.on_invocationwas only checked by hand. Addedcaptured_windows_invocation_leaves_discovery_to_a_console_run(tests/update.rs), which runs the real binary with captured output and an empty cache and asserts that noupdate.jsonis written, as suggested. Checked: withon_invocationchanged on purpose to passtrue, it fails (and the run took 2.1 s instead of 1 s, the bug itself); restored, it passes. Windows-only, because on other platforms the binary would start a real network check (endpoint injection exists only in unit tests).src/update/tests.rs:256(second review): the fixture pipes both streams, so the Windows assertions still pass ifmay_detachchecks only one stream or uses OR instead of AND.$o = proofline …captures only stdout, while stderr stays on the console. Moved the rule into a puredetachable(windows, stdout_is_console, stderr_is_console)and addedwindows_detaches_only_when_both_output_streams_are_consoles, which checks all four combinations. A pure function is used because a test can't reliably give a child process a real console. Checked: with OR, stdout-only and stderr-only rules injected on purpose, all 7 old tests passed and the new test fails each time.tests/update.rs:19(second review): the binary test passes even if--versionstops running the update logic, since that also leaves noupdate.json.assert!(update.lock exists); the lock is created before the decision. Checked: withon_invocationmade to skip--versionon purpose, the old test passed and the new assertion fails; restored, it passes.prepare_check(…, true, …)call).prepare_checkdirectly on purpose: it checks one rule ("onlydetachdecides") and must inject a fake launcher, whichon_invocationcan't do. The realon_invocationpath is covered by the binary test from row 2, which fails whenon_invocationis broken on purpose.update.lockassertion was added).update.lockexists, andsrc/main.rs:13callson_invocation()beforeCli::try_parse(), so before clap handles--version. The injected "skip--version" mistake makes the test fail.on_invocationstill says discovery always continues in a child.may_detachallows it, and that on Windows both streams must be consoles (commita301ee2).