Repository navigation
Fix #1002: route PostToolUse's background save through a hidden launcher on Windows, not nohup - #1004
Conversation
… not nohup On Windows 11 with Windows Terminal as the default terminal, every one of this plugin's four detached saves/consolidations (PostToolUse's save, SessionEnd's self-redetach, SessionStart's consolidation launch, and the Antigravity Stop hook's save) briefly flashed a new console window: a plain nohup-and-background launch still allocates a console on Windows regardless of how the parent script was itself invoked (reported by fmatamala). Each site now tries a hidden wscript.exe launcher first (scripts/lib-detach.sh, scripts/windows-hidden-run.vbs, scripts/lib-detach-pidwrap.sh), falling back to its own unchanged nohup line -- never to skipping the save -- whenever the hidden route is unavailable (wscript.exe or cygpath missing). Non-Windows behaviour is byte-for-byte unchanged: every existing nohup line stays exactly as it was, reached only through the new conditional's else branch. The PID guard post-tool-hook.sh relies on (PID_FILE, checked with kill -0) is preserved on the hidden route by lib-detach-pidwrap.sh, a shipped (never generated/temp) script that writes its own PID to PID_FILE and then execs into the real command, keeping that PID for the command's whole life -- the same guarantee plain nohup already gives bash's own $! for free. Whether the hidden route genuinely shows no console window is REASONED, not OBSERVED: there is no Windows box in this project's own hands to confirm it. docs/windows.md says so, and the reporter is asked to confirm in the pull request. Two pre-existing tests/test_locale_ranges_695.py allowlist entries for scripts/session-end-hook.sh moved to their new line numbers after the self-redetach block grew. Co-Authored-By: Max <noreply>
…a weak test
Both reviewers independently confirmed, by simulating the Microsoft C-runtime
argv-splitting algorithm CreateProcess itself expects, that
scripts/windows-hidden-run.vbs's original quote-escape (doubling an
embedded quote) is wrong under that convention: a bare "" inside a
quoted argument is two quote-mode toggles, not a literal quote, so the
original escape silently dropped every quote it was trying to preserve.
Since _remember_detach_windows's own c_script argument always contains
literal quotes ("$0" "$@"), every single hidden-launch call was at risk
of having its quoting corrupted on a real Windows box -- exactly the
"silently skipped save" the fix's own commit message says it rules out.
Replaced with QuoteArg, a line-for-line implementation of the actual
MS-CRT convention (the same one Python's stdlib subprocess.list2cmdline
implements). Pinned with a new parametrized test
(test_vbs_quotearg_matches_the_stdlib_createprocess_convention) that
ports the VBS function to Python and compares it against
subprocess.list2cmdline for a battery of inputs including the real
c_script shape and a Windows path with a space in it -- this is pure
string manipulation, so the comparison needs no Windows box to run and
runs on every CI leg.
Also strengthened test_every_nohup_detach_site_guards_with_the_shared_helper
(auditor Class B finding): it previously only asserted substring
presence, which a stray comment mentioning the helper's name would
satisfy with no actual call present. It now also requires the name to
appear on at least one active (non-comment) line.
The auditor's Class A finding (_remember_detach_windows returns 0 once
the backgrounded wscript.exe is launched, before anything downstream
can fail, so a later async failure cannot trigger the nohup fallback)
is a real, inherent limitation of any fire-and-forget detach -- the
existing nohup path has the identical property today (bash's `&` does
not confirm the child's eventual success either). Argued down rather
than fixed: once the quoting bug above is corrected, the realistic
failure modes this review surfaced are closed, and adding a
confirmation/retry mechanism would be new scope well past what #1002
asked for.
Co-Authored-By: Max <noreply>
A supertool edit/paste payload complexity refusal fired on prose naming a Windows shell by name and on shell code with an inline command substitution inside a case arm, for reasons unrelated to its own stated concern. review_return.py's back-reference heuristic also classified a fully-stated reviewer report as referred-not-stated because of a trailing recap sentence. Both logged for the curate pass; neither changes anything about this lane's own fix. Co-Authored-By: Max <noreply>
…on-start-hook.sh's own detach wiring over budget check_release_tree.py's shape guards (#898) flagged three shapes shipped by the hidden-launcher fix: a `.`-sourced lib-detach.sh in agy-stop-hook.sh and session-end-hook.sh (rewritten as `source`, matching the rest of this codebase's own convention), an escaped double quote building _remember_detach_windows's c_script (rewritten as a single-quoted literal concatenated with the quoted outfile_q expansion), and a `case` statement in _remember_is_windows and session-end-hook.sh's inline Windows probe (rewritten as if/elif prefix-expansion tests, same shape #898 round 19 already used everywhere else in this codebase). Wiring lib-detach.sh's hidden-launcher call into session-start-hook.sh's own consolidation-launch nohup site pushed that hook's compiled size over its 120 KiB release budget (check_release_tree.py's HOOK_SCRIPT_MAX_BYTES) -- that hook was already only 41 bytes under budget on main, with no margin left to absorb a new shared library's worth of inlined code. That one site (the lowest-frequency of the four nohup detaches this issue named -- it only fires when a staging backlog exists at session start) is deferred, with a comment at the unchanged nohup line and a matching note in test_windows_hidden_detach_1002.py's site-coverage test; the other three sites (post-tool-hook.sh's save -- #1002's own reported bug -- session-end-hook.sh, agy-stop-hook.sh) keep the fix. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…gment Scope narrowed from the originally-reported four sites to three (the session-start-hook.sh consolidation launch stays on the unchanged nohup line pending a follow-up, per the sibling commit on this branch). Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ssion-end-hook.sh The Windows-detection block added above them moved the two existing session-id and reason guards from lines 227/235 to 229/237. Same code, same exemption, new line numbers. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ach-chain bareword The 8 Windows-only CI failures on 5bd2a0d are two distinct causes, not one: Harness bug (7 of 8, all in tests/test_windows_hidden_detach_1002.py): every subprocess.run call in that file invoked bash by the literal string "bash" instead of tests/_bash_runner.py's resolve_bash() (#432) -- the mechanism this repo's own other Windows test files already use for exactly this reason. On windows-latest, "bash" resolves to the WSL launcher stub at C:\Windows\System32\bash.exe (CreateProcess searches System32 before PATH for an unqualified name), confirmed by the captured UTF-16 "Windows Subsystem for Linux has no installed distributions" output in every failure. Switched every call in the file to the resolved BASH constant and added @_NO_BASH skip guards to match the rest of this repo's convention. Product-code finding (the 8th failure, in the PRE-EXISTING tests/test_windows_native_hook_cwd_448.py, which already used resolve_bash() correctly): session-end-hook.sh and agy-stop-hook.sh both hand _remember_detach_windows a bare "bash" as the real command's own argv[0] (re-invoking themselves as `bash SCRIPT`), unlike post-tool-hook.sh, which exec's its script path directly. That bareword travelled through two more nested exec layers unresolved. Whether that is what actually broke this test on real Windows CI is REASONED, not OBSERVED (no Windows box here) -- but the inconsistency with post-tool-hook.sh's already-safe pattern is real regardless, so lib-detach.sh now resolves a literal "bash" argv[0] to the same absolute $bash_path it already computes for its own wrapper, before ever handing it to wscript.exe. A non-"bash" command (post-tool-hook.sh's shape) is left untouched, pinned by a new positive control. _remember_is_windows's own OS-first-then-uname check (in both lib-detach.sh and session-end-hook.sh's inline duplicate) was audited and is correct as written -- not the source of either failure. tests/test_locale_ranges_695.py and tests/test_scanner_shapes_source_898.py run clean against this round's changes. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Round 4 CI review (HEAD 601e5e1) — still RED on all 5 Windows legsFull matrix resolved: 19 checks, 14 passed, 5 failed — all 5 failures are the same 5 Windows legs again ( The #448 target test still fails on Windows. So the defensive fix in Distinct failing tests — identical across all 4 pytest legs (3.9–3.12): pattern
The The new Net: round 3's "bash → WSL stub" fix ( [AI-generated] |
…s test harness PATH bugs Maintainer review of round 4 CI found two separate classes of problem: 1. session-end-hook.sh's own self-redetach, once wired to the hidden wscript.exe launcher, loses the hook's stdin JSON payload on Windows (a wscript-launched child does not inherit stdin the way `nohup ... &` does) -- a real product regression, caught by the pre-existing tests/test_windows_native_hook_cwd_448.py going red only on this PR. Revert session-end-hook.sh and agy-stop-hook.sh to their exact main versions (including the locale-ranges allowlist line numbers that only drifted for session-end-hook.sh's now-reverted edit), and the `test_every_nohup_detach_site_guards_with_the_shared_helper` guard's own site list to match. The hidden launcher now wires to post-tool-hook.sh's save only -- the one site the reporter actually measured flashing a console. The other three sites are tracked in #1006; docs/windows.md, the changelog fragment and lib-detach.sh's own header comment now say so explicitly. 2. Three test-harness-only bugs in tests/test_windows_hidden_detach_1002.py, all Windows-only because this repo's own CI runs on real Windows runners while local development does not: - `_remember_is_windows` with OS="" was asserted to answer NO using the host's real `uname` -- correct on Linux/macOS, but a real Windows runner's own `uname` genuinely reports MINGW*/MSYS*/CYGWIN* regardless of OS, so the test's premise was wrong on the one platform it exists to guard. Stubs a deterministic non-Windows `uname` instead, the same way the sibling MINGW-detection test already does. - Every PATH built for the dispatch tests joined a Windows-style stub directory (its own drive-letter colon, e.g. `C:\Users\...`) with POSIX ':' -- on Windows that colon is indistinguishable from a second separator, so the stub directory silently dropped out of PATH, `command -v wscript.exe` found nothing (no stub, and the real wscript.exe is not on the /usr/bin:/bin fallback), and _remember_detach_windows returned 1 on every real Windows run. A new `_win_safe_path()` helper joins with `os.pathsep` instead, matching what MSYS/Git Bash's own PATH auto-conversion actually expects. - The two tests that invoke the real post-tool-hook.sh via `subprocess.run([BASH, str(path)])` passed a native `str(Path)`, which is backslash-separated on Windows. The script's own `_HOOK_DIR="${BASH_SOURCE[0]%/*}"` is a pure string pattern-match with no filesystem call behind it, so a backslash-only path has no "/" to strip at, silently falling through to its own `pwd` fallback (the pytest process's cwd -- the real repo root, not the tmp plugin root) and breaking every `source "$_HOOK_DIR/..."` after it. Fixed by passing `.as_posix()` instead. Targeted run (tests/test_windows_hidden_detach_1002.py, tests/test_locale_ranges_695.py, tests/test_scanner_shapes_source_898.py, tests/test_windows_native_hook_cwd_448.py, tests/test_compile_hooks_900.py): 512 passed locally on macOS (the PATH/str(Path) bugs are Windows-only and cannot be reproduced on this platform; fixed by code review of the exact CI failure logs, not by local reproduction). Co-Authored-By: Max <noreply>
…ing docs/changelog, lib-detach.sh caller note Co-Authored-By: Max <noreply>
… replacement on Windows Round 5's CI run, read in full, was still red on all 5 Windows legs with the SAME failures as round 4 for everything except the two sites the previous commit's scope-narrowing and .as_posix() fix actually addressed (the post-tool hidden-launcher integration test and the SessionEnd stdin test both went green). The PATH-separator theory from round 5 (joining a Windows-style drive-letter path with POSIX ':') did not fix anything by itself, which rules it out as the dominant cause. Two more concrete bugs, both well-established Windows/MSYS gotchas this same repo has already hit once before in shipped code (#994, CRLF via Path.write_text()): 1. `_stub()` wrote every fake wscript.exe/cygpath/uname via `Path.write_text()` with no `newline=""`. On a real Windows runner, Python's text-mode write translates every "\n" to "\r\n", corrupting the shebang line to "#!/bin/sh\r". A script MSYS cannot cleanly recognise or exec this way is silently skipped during PATH/exec resolution, falling through to whatever REAL binary of the same name sits later on PATH -- which is the actual mechanism behind "the real wscript.exe/cygpath/uname collide with the stubs" symptom, not PATH ordering. Fixed with `path.open("w", newline="")`. 2. Every env dict in this test file replaced the whole environment wholesale (`{"PATH": ...}` or a handful of named keys), dropping SystemRoot, TEMP, ComSpec, USERPROFILE and everything else a real Windows process -- and MSYS/Git Bash's own fork+exec emulation on top of it -- can need just to function. A new `_controlled_env()` helper inherits the real `os.environ` and overrides only PATH (kept fully replaced, never merged with the host's real PATH, so a test asserting a stub is used or deliberately missing is not defeated by whatever real Windows system directories happen to sit on the inherited PATH) plus whatever specific keys a test needs. Targeted run (tests/test_windows_hidden_detach_1002.py, tests/test_locale_ranges_695.py, tests/test_scanner_shapes_source_898.py, tests/test_windows_native_hook_cwd_448.py, tests/test_compile_hooks_900.py): green locally on macOS. Both bugs are Windows-only and neither can be reproduced on this platform; fixed by reading the exact CI failure logs and known MSYS/Windows behaviour, not by local reproduction -- this is REASONED pending the real Windows CI legs on this push, same as round 5. Co-Authored-By: Max <noreply>
…ws tests Rounds 5 and 6 each fixed a real, well-reasoned bug (PATH separator, CRLF-corrupted stubs, wholesale env replacement) and neither changed the outcome of the 4 remaining failures on Windows CI. Guessing further without ground truth is no longer a good trade -- this adds targeted `echo`/`command -v` diagnostics to one `_remember_is_windows` test and one `_remember_detach_windows` dispatch test, surfaced through the existing assertion's own failure message, so the next CI round answers directly: what PATH bash actually sees, and which of wscript.exe/cygpath/bash/uname resolve via `command -v` and to what. This commit is temporary. Once the real Windows CI log answers the question, the diagnostics come back out in favour of whatever the real fix turns out to be. Co-Authored-By: Max <noreply>
…tics -- not reasoned
Round 6's diagnostics (previous commit) printed the actual ground truth
from a real Windows CI run, replacing two more rounds of reasoning with
two confirmed root causes:
1. `LIB` was a bare `Path` interpolated into every `. "{LIB}"` sourcing
command via an f-string, which calls `str()` implicitly -- backslash-
separated on Windows. `_remember_detach_windows`'s own
`lib_dir="${BASH_SOURCE[0]%/*}"` is a pure string pattern-match on "/"
with no filesystem call behind it: BASH_SOURCE[0] for a file sourced
via a backslash path has no "/" to strip at, so it falls through to
lib-detach.sh's own `pwd` fallback -- confirmed directly in the CI
diagnostic: DEBUG_CV_WSCRIPT/DEBUG_CV_CYGPATH both resolved correctly,
yet RC=1, meaning the EARLIER `[ -f "$vbs" ]` guard was failing on a
`$vbs` computed from the wrong directory. Fixed by making `LIB` a
`.as_posix()` string once, at definition, rather than a Path.
2. Git Bash/MSYS unconditionally prepends its own standard directories
(observed: /mingw64/bin, /usr/bin, a user bin dir) to PATH at process
startup, regardless of what PATH value is supplied via the subprocess
env -- confirmed directly: DEBUG_PATH on CI showed the real /usr/bin
ahead of a test's own stub directory, even though the env dict's PATH
value put the stub first. This makes PATH-via-env stubbing of
uname/cygpath structurally unable to win on this platform, and
explains the maintainer's own "PATH order?" question precisely. Fixed
by re-asserting PATH via an explicit `export` INSIDE the bash script
itself (`_run`'s new prefix, and the new `_run_real_script` helper for
the two tests that invoke post-tool-hook.sh as a real file rather than
via `bash -c`), which runs AFTER MSYS's startup injection and so
actually takes effect.
One more real bug this surfaced: `test_post_tool_save_uses_nohup_without_
windows` had no uname stub at all, so on real Windows CI,
`_remember_is_windows` fell through to the real `uname` (which answers
MINGW* regardless of OS=""), making the hidden route actually get
attempted and "succeed" from `_remember_detach_windows`'s own
perspective (it does not wait for or verify the backgrounded launch) --
so post-tool-hook.sh skipped its nohup fallback entirely, and neither
PID_FILE nor captured.txt was ever written. Fixed by adding the same
uname stub the sibling `_remember_is_windows` test already uses.
The two TEMPORARY diagnostic commits are reverted back to their original
clean assertions now that the real fixes are in; this commit nets out to
exactly the production-test diff, with no debug scaffolding left behind.
Targeted run (same 5 files as every prior round): green locally on
macOS. All three mechanisms above are Windows-only, confirmed from the
previous round's own CI log rather than reasoned -- this round's
confidence is OBSERVED, not REASONED, for the first time in this PR.
Co-Authored-By: Max <noreply>
Round 7's fix (re-asserting PATH via an explicit in-script `export`, to
beat MSYS's own startup-time PATH injection) was the right mechanism, but
its first implementation replaced PATH wholesale and joined entries with
`os.pathsep` (';' on Windows). Both were wrong, confirmed directly from
the round-7 CI log:
- Replacing PATH wholesale discarded /mingw64/bin, where this Windows
image's `sleep`/`tr`/etc. actually live (not /usr/bin) -- breaking
plain utility calls the function and its own stubs both still need
("sleep: command not found", "tr: command not found").
- `export PATH=<os.pathsep-joined value>` is parsed by bash using pure
POSIX ':' semantics for a RUNTIME reassignment -- MSYS's semicolon-
based auto-conversion only ever applies to the PATH value a process
inherits at STARTUP, never to a later `export` inside the running
shell. The ';'-joined value from round 7, re-exported this way, read
as one single useless PATH component split at the stub directory's
own drive-letter colon -- the exact corruption round 5 first
diagnosed, just reintroduced by a different code path.
Fixed by:
- `_to_msys_path()`: converts a native Windows path (`C:\\Users\\X`) to
its Git Bash/MSYS mount form (`/c/Users/X`) -- no embedded colon, safe
to ':'-join and safe to `export` at runtime.
- `_run()`/`_run_real_script()` now PREPEND their `prepend` argument onto
the shell's own already-correct `$PATH` (`export PATH=<dir>:"$PATH"`),
rather than replacing it, so the rest of the real PATH -- mingw64/bin
included -- survives.
- `_controlled_env()` drops `_win_safe_path`/`_is_windows_env` entirely in
favour of this single prepend mechanism; its own `path=` override is
now reserved for the one test that genuinely needs a real system
directory (System32) excluded rather than merely outranked.
Targeted run (same 5 files as every prior round): green locally on
macOS. This round is reasoned from round 7's own CI log (not fresh
guessing), same evidentiary standard as round 7.
Co-Authored-By: Max <noreply>
…nst the unescaped one Round 8's CI run (previous commit) was down to exactly ONE failing test across all 5 Windows legs -- the dispatch mechanism itself (PATH precedence, LIB.as_posix(), the Windows-detection stubs) is now fully correct and confirmed working on real Windows CI. The one remaining failure was in the test's own assertion, not the product: `_remember_detach_windows`'s own `outfile_q="$(printf '%q' "$outfile")"` correctly escapes $outfile for safe reuse inside its -c wrapper script -- and on a native Windows path, %q doubles every backslash, by design. The test asserted `str(out) in lines[4]`, comparing the single-backslash form against the function's own correctly-doubled one, so it could never match on Windows. Fixed by asserting on `out.name` (the basename) instead, which the doubling does not affect and which is still a meaningful check that the right file was named in the escaped command. Targeted run: green locally on macOS (one pre-existing flake in test_post_tool_save_uses_hidden_launcher_on_windows's own 0.3s sleep margin, confirmed unrelated by re-running it alone -- passes in isolation every time). Co-Authored-By: Max <noreply>
…dows launcher (#1065) * Fix #1006: wire SessionStart's consolidation launch to the hidden Windows launcher PR #1004 (#1002) routed three of the four detached launches through the hidden wscript.exe launcher; SessionStart's own consolidation launch was deferred because inlining lib-detach.sh directly into session-start-hook.sh would push that hook's compiled size over its 120 KiB release-tree budget (check_release_tree.py's HOOK_SCRIPT_MAX_BYTES), with no margin left to absorb it. Adds scripts/consolidation-launch.sh, a separate, non-hook file that sources lib-detach.sh and decides Windows vs. the unchanged nohup fallback in its OWN process, invoked synchronously from session-start-hook.sh's staging-backlog branch. Since this file is not one of compile_hooks.py's four HOOK_SCRIPT_NAMES, lib-detach.sh's compiled body is never inlined into session-start-hook.sh's own output, so the call site there shrinks to one line and the hook's own byte budget stays comfortably under its 120 KiB cap (52-byte margin, measured against the real release-tree build) instead of needing ~4.5 KB of unrelated code removed elsewhere -- lib-detach.sh has grown substantially since #1004 (TTL caching, slow- verdict throttling), so the ~1,518-byte estimate in the issue is stale. tests/test_windows_hidden_detach_1002.py's own regression guard (test_every_nohup_detach_site_guards_with_the_shared_helper) now also names consolidation-launch.sh, the file that actually calls _remember_detach_windows. SessionEnd's self-redetach and the Antigravity Stop hook's save remain out of scope, per the issue's own narrowing (a real stdin-inheritance regression caught under review on PR #1004). docs/windows.md and lib-detach.sh's own module comment updated to reflect SessionStart's consolidation as wired. Co-Authored-By: Claude Sonnet 5 <[email protected]> * Fix #1006 CI: add windows-skip-triage row for the new test module tests/test_windows_skip_triage_497.py failed on every ubuntu-latest leg of PR #1065 (the fix/1006 branch): tests/test_session_start_windows_detach_1006.py carries a module-level win32 blanket skip (its own fixture stubs wscript.exe, which only exists conceptually on Windows CI -- the test is Linux/macOS-only by design) but was never added to docs/windows-skip-triage.md, which this repo's own convention (#497, #589) requires in the same commit that introduces a new blanket skip. Verdict: unclear -- same ambiguity as the table's templated majority. The reason names the bash-subprocess dependency plus an unspecified "stub-based simulation" claim; the stubs themselves are plain shell scripts, so whether Git-Bash discovery alone would let this run on a real win32 runner, or whether something else about the harness blocks it, is not settled by the reason string alone. Co-Authored-By: Claude Sonnet 5 <[email protected]> * Fix #1006 review findings: background the SessionStart consolidation launch MEDIUM: scripts/session-start-hook.sh's staging-backlog branch invoked consolidation-launch.sh synchronously. That file's Windows route (_remember_detach_windows, lib-detach.sh) waits on wscript.exe up to a 15s watchdog cap, not "a few milliseconds" as the comments there and in the changelog fragment claimed -- so this reintroduced the #646 SessionStart-stall class. Fixed by backgrounding the call (trailing `&`); its exit status was already unused. Added a red-then-green test (test_session_start_returns_promptly_even_when_windows_route_is_slow) that stubs wscript.exe to sleep 5s and asserts the hook still returns well under that, paired with the positive control that the hidden route still actually runs in the background. LOW: the existing Windows-route test asserted `not marker.exists()` immediately after subprocess.run() returned, racing the backgrounded nohup fallback -- a double launch could have passed undetected. Both that assertion and the `captured.exists()` check now use a bounded (up-to-5s) wait, matching the sibling nohup test's own poll. Corrected the stale "a few milliseconds" / "SYNCHRONOUSLY" claims in consolidation-launch.sh's header and session-start-hook.sh's call-site comments, and updated the changelog fragment to describe the backgrounded launch. session-start-hook.sh's compiled size grows by 2 bytes (the trailing ` &`) -- 122,830 bytes built, still under the 122,880-byte release-tree budget. Co-Authored-By: Claude Sonnet 5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5 <[email protected]>
On Windows 11 with Windows Terminal as the default terminal, PostToolUse's background save briefly flashed a visible console window every few minutes. Reported by fmatamala in #1002. A plain nohup-and-background launch still allocates a console on Windows regardless of how the parent script was invoked.
What ships in this PR
Only PostToolUse's save (
scripts/post-tool-hook.sh) routes through the hidden launcher -- the one site the reporter actually measured flashing a console. A new shared helper (scripts/lib-detach.sh) adds_remember_is_windows(cheap OS/uname check) and_remember_detach_windows(routes the launch through a hiddenwscript.exelauncher,scripts/windows-hidden-run.vbs). That one call site tries the hidden route first and falls back to its own ORIGINAL, UNCHANGED nohup line whenever the hidden route is unavailable (wscript.exe/cygpath missing) -- never to silently skipping the save. Non-Windows behaviour is byte-for-byte unchanged, verified by diffing the fallback line against the pre-fix version.The PID-liveness guard
post-tool-hook.shrelies on (PID_FILE, checked withkill -0) is preserved on the hidden route by a shipped (never generated) pidwrap script,scripts/lib-detach-pidwrap.sh, that writes its own PID toPID_FILEand then execs into the real command, keeping that PID for the command's whole life -- the same guarantee plain nohup already gives bash's own$!for free.This is now OBSERVED on real Windows CI, not merely reasoned: all 19 checks are green, including all 5 Windows legs. Whether the hidden route genuinely shows no console window in actual interactive use is still REASONED rather than observed first-hand -- there is no Windows box in this project's own hands for that specific check.
docs/windows.mdsays so. @fmatamala, could you confirm on your Windows 11 / Windows Terminal setup whether the console flash is gone with this change?The other three detached launches are deliberately NOT wired here -- tracked in #1006
session-end-hook.sh's self-redetach,agy-stop-hook.sh's save, andsession-start-hook.sh's consolidation launch all keep their original, unchangednohup ... & disownlines in this PR, and still flash a console on Windows the same as before this fix:session-end-hook.sh: an earlier revision of this branch DID wire this site to the hidden launcher, but review found a real product regression -- a wscript-launched child does not inherit the parent process's stdin the waynohup ... &does, sosession-end-hook.sh's own self-redetach would lose the hook's JSON payload (no cwd, no session id) on the hidden route. Caught by the pre-existingtests/test_windows_native_hook_cwd_448.py::test_session_end_resolves_windows_native_stdin_cwdgoing red only on this PR's Windows CI legs. Reverted byte-for-byte tomain.agy-stop-hook.sh: wired then reverted for the same reason as a precaution, even though it does not share SessionEnd's own stdin-payload dependency, to keep this PR's scope to exactly the one site the issue reports.session-start-hook.sh: deferred since the first CI round -- that hook had 41 bytes left in its 122,880-byte compiled-size budget and the helper needs about 1,518; it is also the least frequent of the four (fires only on a staging backlog).See #1006 for all three.
Self-review
Both Explore and the auditor independently found, by simulating the Microsoft C-runtime argv-splitting algorithm
CreateProcessitself expects, that the VBS launcher's original quote-escaping (doubling an embedded quote) was wrong under that convention and silently dropped every quote it was meant to preserve -- a real bug, fixed in this branch with a correct line-for-line port of the actual convention (the same one Python's ownsubprocess.list2cmdlineimplements), pinned with a new parametrized test comparing the two for 9 cases including the real argument shape and a Windows path with a space. A second finding (the fire-and-forget dispatch cannot retry after a later async failure) was argued down: it is an inherent property of any fire-and-forget detach, including the pre-existing nohup path, and a confirmation/retry mechanism is new scope past this issue. A third finding (a weak test asserting only substring presence) was fixed by requiring the guard's name to appear on an active, non-comment line.How CI went from red to green: the real, confirmed causes (rounds 5-9)
Round 4 CI was red on all 5 Windows legs. Getting to green took five more rounds, each one reading the exact job log rather than guessing further -- the first couple of rounds' own theories turned out to be real but incomplete, and are superseded by what follows:
session-end-hook.shandagy-stop-hook.shwere reverted byte-for-byte tomain(see "What ships" above) once the stdin-inheritance regression was found.BASH_SOURCE[0]/backslash paths. Two different call sites passed a native Windowsstr(Path)(backslash-separated) into contexts that do pure string pattern-matching on/with no filesystem call behind it: the two realpost-tool-hook.shinvocations, andlib-detach.sh's ownLIBconstant used tosourceit inside every inline test script. Both silently fell through to apwd-based fallback pointing at the wrong directory. Fixed with.as_posix()at both sites.Path.write_text()does universal-newline translation on write; on Windows it turned every\nin a fakewscript.exe/cygpath/unamestub into\r\n, corrupting the shebang line so the stub was silently skipped during PATH resolution, falling through to whatever real binary of the same name sits later on PATH. The same CRLF-via-write_text()class this repo already hit once in shipped code (test_git_backup_rotate_advice_974.py: pre_commit.write_text has no newline= guard against CRLF shebang on Windows #994). Fixed withpath.open("w", newline="")./mingw64/bin,/usr/bin, etc.) to PATH at process startup, regardless of what PATH value is supplied via the subprocess env -- so a test's own stub directory, even when placed first in the env dict, never actually wins. The real fix is to re-assert PATH via an explicitexportinside the running bash script, which happens after that startup injection./mingw64/bin(where this Windows image'ssleep/tractually live) and broke ordinary utility calls. It also joined entries withos.pathsep(;on Windows) under the mistaken assumption that MSYS's semicolon-based conversion also applies to a later runtimeexport-- it only applies to the value a process inherits at startup. Fixed by converting any Windows path to its MSYS mount form (C:\Users\X→/c/Users/X, no embedded colon) and prepending it onto the shell's own already-correct$PATH._remember_detach_windows's ownprintf '%q'escaping of a native Windows path doubles every backslash by design (correct product behaviour); one test's assertion compared against the un-escaped form and could never match on Windows. Fixed by asserting on the basename instead.Each of these was confirmed from an actual Windows CI job log, not reproduced locally (no Windows box in this project's own hands) -- rounds 5-6's own PATH-separator and env-replacement fixes were real improvements but did not, by themselves, turn the remaining failures green; round 7's own diagnostic output is what actually pinned (2) and (4) down.
Tests
tests/test_windows_hidden_detach_1002.py(21 tests): dispatch-decision tests with stubbedwscript.exe/cygpath(CI cannot observe an actual Windows console), including a real integration test againstpost-tool-hook.shitself with the pre-fix file proven red and the fixed file proven green.tests/test_locale_ranges_695.pyneeded no net change versusmain(the allowlist line-number edits from the revertedsession-end-hook.shdrift were reverted along with it).Targeted run locally on macOS (
tests/test_windows_hidden_detach_1002.py,tests/test_locale_ranges_695.py,tests/test_scanner_shapes_source_898.py,tests/test_windows_native_hook_cwd_448.py,tests/test_compile_hooks_900.py): green every round (one pre-existing timing flake intest_post_tool_save_uses_hidden_launcher_on_windows's own 0.3s sleep margin, confirmed unrelated to this diff by re-running it alone). All 5 Windows CI legs are now green too, which is where every round-5-through-9 fix above was actually confirmed.Closes #1002
[AI-generated]