Skip to content

Cut SessionStart promo's jq forks 10->4, and add a gated star ask (#660, #657) - #661

Merged
fdaviddpt merged 2 commits into
mainfrom
fix/660
Sep 11, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
fix/660

Conversation

@fdaviddpt

@fdaviddpt fdaviddpt commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

What

Bundled fix for two issues landing in the same file, scripts/session-start-hook.sh.

Part of #660, closes #657

#660 -- SessionStart promo selection forked up to 13 jq processes per session start

_remember_compute_promo() ran one jq -r '.promos | length', then FOUR more jq calls per
candidate (id/text/url/installed_key), and for every candidate that survived those, the exact
same .plugins[$k] membership query run TWICE back to back -- once to capture its value, once
again just to inspect its exit status. With the two promos.json entries shipped today that is
up to 13 jq forks to decide on one line of output.

#660 reports this hook averaging ~12.5s per session start on Windows/Git Bash across 36 real
starts (v0.29.1), against 0.5-1.3s for comparable SessionStart hooks in the same sessions, with
Windows process-spawn cost (~50-200ms per subprocess under Git Bash) named as the plausible
multiplier -- not #646's already-fixed backgrounded consolidation.

Now 2-4 jq forks: one call reads the whole promos.json array via a line-per-field protocol
terminated by a literal sentinel, and one call probes installed_plugins.json once instead of
per-entry/per-key. Measured on this host: 10 -> 4 jq forks, pinned by
tests/test_session_start_promo_spawn_budget_660.py (positive-controlled -- the test asserts
the promo actually fires, not just that jq is cheap).

Observed vs reasoned, honestly split: the spawn-count reduction is observed, on this host's
own jq/bash. That the same reduction helps proportionally more on Windows/Git Bash -- where
each fork costs more, per the reporter's own measurement -- is reasoned, not observed; this host
cannot measure Git Bash process-spawn cost. Both are graded separately in the developer report.

Two bash traps were caught and fixed mid-implementation, before ever reaching a commit, and are
documented at length inline at the point a future editor is most likely to reintroduce either:
(1) IFS=$'\t' read silently squashes consecutive tab delimiters exactly like it squashes
consecutive spaces, because tab is one of POSIX's fixed "IFS whitespace" characters regardless
of what IFS is actually set to -- an entry with an empty middle field shifted every later field
left by one; (2) bash's $( … ) strips every trailing newline, not just one, so an entry
whose last field is empty on the final promo in the file silently lost that line. Both are
why the field-reading protocol ended up as one-value-per-line with a literal #promo-end#
sentinel rather than TSV terminated by EOF.

#657 -- ask for a GitHub star, once, gated on demonstrated use

Per the maintainer's own decision recorded on the issue: the ask waits until the plugin has
demonstrably done something for the user, no install-time ask. The gate:
features.plugin_promos on, host carries systemMessage, existing promo cooldown clear, and
recent.md is a non-empty regular file -- the cheapest honest "did something for you" signal,
since that file only exists once a full day of staging has actually been consolidated. No new
counter needed.

Wired through the same _remember_compute_promo()/promos.json mechanism #574/#631 already
own (same cooldown, same rotation, same claude-remember:-prefixed self-identifying
systemMessage-only line, same off switch), via a new optional gate field on promos.json
entries: absent means the original #574 cross-plugin-not-installed check; recent_nonempty is
the new star-ask gate. promos.json gained one "star" entry. A stargazers README badge was
added next to the version badge, per the issue's own suggestion.

Positive-and-negative test coverage in tests/test_star_ask_promo_657.py: one positive control
(fires when recent.md is a non-empty file) paired with one negative per gate condition --
absent/empty/non-regular recent.md, the off switch, cooldown, and the REMEMBER_SUPPRESS_PROMO
Antigravity-delegation guard.

Adjacent (fixed in this same commit, same subsystem)

tests/test_codex_upsubmit_stdout_451.py's test_session_start_first_byte_is_never_bracket_or_brace
started failing once the #657 entry landed: its "full store" fixture writes a non-empty
recent.md to force the largest recap the hook produces, which is now also the exact gate the
new star-ask checks -- on a fresh $HOME with no cooldown marker yet, the star ask legitimately
fired, turning stdout into the JSON systemMessage envelope this unrelated test asserts never
happens on the plain path. Real, correct new-feature behaviour colliding with borrowed fixture
state, not a #451 regression. Fixed with an opt-in suppress_promo param routed through
REMEMBER_SUPPRESS_PROMO (not config.json -- that file's shared env sets
_LIB_MEMORY_DIR_LOADED=1, which makes config() answer every key from its hardcoded default
regardless of what config.json says, confirmed live before choosing the env-var route), scoped
to only the three subprocess calls inside the affected test.

Review

Neither the Explore reviewer nor the oss:auditor spawn could run in this session: the
Agent tool itself is unavailable ("No such tool available: Agent. Agent is disabled for this
session, in subagents as well as here."). This is reported as blocked (capability) and
not-checked (with reason) in both review.classes and review.findings in the developer
report, per that report's own schema guidance that this is the honest answer rather than a
checked review with a thin mechanism. Self-review only substitutes here: bash -n, targeted
pytest runs (35 promo-related tests, then a broader 91+90 test sweep across everything
touching session-start-hook.sh's recent.md/promo fixtures), a manual re-read of the full
diff, and explicit red-before-fix/green-after-fix confirmation for both new test suites.

Tests

  • tests/test_session_start_promo_spawn_budget_660.py (new): red assert 10 <= 4 before the
    fix, green after.
  • tests/test_star_ask_promo_657.py (new): 2 of 8 red before the gate field existed
    (positive control + shipped-entry-shape check), green after.
  • tests/test_plugin_promo_574.py, tests/test_agy_promo_suppression_596.py,
    tests/test_promo_budget_comment_637.py, tests/test_codex_upsubmit_stdout_451.py: all
    green after the adjacent fix above.
  • Broader targeted sweep (not the whole test_command, per developer doctrine -- CI is the
    authority for that): pytest -k "session_start or promo" (91 passed, 2 skipped) plus every
    test file touching session-start-hook.sh's recent.md/promo fixtures by name (90 more
    passed).

🤖 Generated with Claude Code

https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5

[AI-generated]

Verified by the maintainer

Do not merge on green. Held per maintainer ruling on 2026-09-11, for three reasons:

  1. No independent review ran. The developer's own report is explicit: the Agent tool was
    entirely unavailable inside its session, so neither the required Explore reviewer nor the
    oss:auditor spawn ever executed -- self-review only (bash -n, targeted pytest, a manual
    diff re-read). This loop's merge gate requires an independent pass, and self-review is not a
    substitute for it. A compensating oss:auditor audit against this diff was dispatched
    separately by the tick that opened this pull request; its findings will be appended here or in
    a follow-up comment once it reports back.
  2. Feature scope bundled with a bugfix in one squash. Ask users for a GitHub star, once, through the surfaces the plugin already owns #657 (the star ask) is new,
    maintainer-approved feature scope; SessionStart hook averages ~12.5s on Windows (Git Bash) — measured over 36 session starts on v0.29.1 #660 is a performance bugfix. Bundling them in one lane was
    the right call to avoid two agents colliding on scripts/session-start-hook.sh, but squashing
    feature scope in with a bugfix is not auto-merge material -- it needs an explicit maintainer
    look, not a green-CI nod.
  3. Closes #660 overclaimed the fix. The diff trims roughly 6-9 jq forks off the promo
    selection path. SessionStart hook averages ~12.5s on Windows (Git Bash) — measured over 36 session starts on v0.29.1 #660's own report measured a 12.5s average for the whole hook, and the
    promo path is one part of that hook, not the whole of it -- a few subprocess forks cannot
    plausibly account for the full 12.5s average the reporter measured. This diff is real progress
    on SessionStart hook averages ~12.5s on Windows (Git Bash) — measured over 36 session starts on v0.29.1 #660 (fewer forks, honestly graded as observed-on-this-host / reasoned-for-Windows), but it
    does not meet SessionStart hook averages ~12.5s on Windows (Git Bash) — measured over 36 session starts on v0.29.1 #660's actual ask -- a Windows-representative timing budget for the hook's whole
    foreground portion. The reference above is corrected to Part of #660 rather than Closes #660; SessionStart hook averages ~12.5s on Windows (Git Bash) — measured over 36 session starts on v0.29.1 #660 stays open until the rest of the hot path is accounted for.

Nothing above is a rejection of the work -- #657 looks complete and #660 is a genuine partial
fix. It is a hold on the merge, not on the diff.

Independent review (oss:auditor, dispatched to substitute for the developer's failed self-review)

Ran against merge-base fdd90a440751 / head d219d6d (before the trap-fragment commit
below). Checked classes A (silent absence), B (a guard that did not run), C (untrusted text
forging a boundary), and D/F/H (platform band) plus assertion-pairing quality and blast
radius. Result: 1 finding, non-blocking, ranked fails-to-preserve -- routed to
trap.d/660.promo-installed-key-array-plugins-shape.md (committed as 8878f77) rather than
a new issue, per skills/manager/phases/findings.md's routing rule.

The finding, summarized: the new single-probe installed_key membership check
(to_entries on .plugins) does not error the way the old per-key probe did when
.plugins in installed_plugins.json is a JSON array rather than an object -- so a shape
that used to read "cannot tell, suppress" now reads "not installed, speak". Verified live
with a shimmed non-object .plugins. Whether installed_plugins.json's real writer can
ever produce that shape was not established either way, which is why this is non-blocking
rather than blocking.

Also checked and clean: class A (no new silent absence), class C (no untrusted-input
boundary in this diff), the gate dispatch's refusal of an unrecognised value, the two new
tests' positive/negative pairing (both genuinely paired, not vacuous), and the
REMEMBER_SUPPRESS_PROMO scoping fix to test_codex_upsubmit_stdout_451.py (correctly
scoped to the three affected subprocess calls only). The developer's own observed/reasoned
grading of the Windows-Git-Bash benefit was independently checked against the CI matrix (the
Windows leg exists but the two new tests both skipif on win32, so the benefit genuinely
is unmeasured there) and found honest, not inflated.

Not checked by this audit: it did not run pytest (reasoned from reading the tests and
reproducing the jq/bash logic standalone, not from a suite run); did not review the
README.md badge markup; did not re-derive the PROMO_JQ_SPAWN_BUDGET = 4 figure past the
two _remember_compute_promo()-internal jq calls; did not validate the changelog fragments
against assemble_changelog.py.

This closes reason (1) of the hold above -- an independent review has now run. Reasons (2)
and (3) (bundled feature scope, and #660 needing the rest of the hot path accounted for)
still stand; this PR stays held pending a further maintainer decision.

fdaviddpt and others added 2 commits September 11, 2026 21:34
_remember_compute_promo() ran up to 13 `jq` subprocess forks per session
start to select from two promos.json entries -- including one query run
twice back to back for no reason. #660 reports this hook averaging ~12.5s
per session start on Windows/Git Bash across 36 real starts, with Windows
process-spawn cost named as the plausible multiplier. Now 2-4 `jq` forks,
via one call reading the whole promo list and one probing
installed_plugins.json, pinned by a spawn-count regression test.

#657 adds a one-time GitHub star ask through the same promo mechanism,
gated on `recent.md` being a non-empty regular file (the maintainer's
"has this store demonstrably done something for the user" signal) rather
than on install status -- a new `gate` field in promos.json entries that
_remember_compute_promo() now understands alongside the original
installed-plugin check.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
…trap fragment (#660, #661)

An independent oss:auditor review of this PR's diff (dispatched by the maintainer tick
because the developer's own self-review spawn could not run -- Agent tool unavailable,
filed separately as Digital-Process-Tools/claude-oss#1468) found one non-blocking finding:
the rewritten installed_key membership probe silently reverses its cannot-tell/suppress
behaviour into a speak-when-not-installed behaviour if installed_plugins.json's .plugins
key is ever a JSON array rather than an object. Ranked fails-to-preserve (non-blocking) --
routed to trap.d/ per skills/manager/phases/findings.md rather than a new issue.

Co-Authored-By: Max <noreply>
@fdaviddpt
fdaviddpt merged commit 3f2fda1 into main Sep 11, 2026
16 checks passed
@fdaviddpt
fdaviddpt deleted the fix/660 branch September 11, 2026 20:12
fdaviddpt added a commit that referenced this pull request Sep 12, 2026
* Add a Windows/Git-Bash benchmark for session-start-hook.sh (#669, part of #660)

No CI leg measured this hook's wall time or spawn count on windows-latest --
every latency figure attached to #660's follow-ups (#662-#667) was reasoned
from one reporter's own number, never observed, because 92 modules
blanket-skip on win32 and #661's own tests do too. This adds one pytest module
that drives the real hook under Git Bash (tests/_bash_runner.py's
resolve_bash(), from #432), cold and warm, with jq present and with jq
genuinely absent from PATH -- and skips nowhere but the "no bash found" case,
so it runs on every leg of the existing matrix (.github/workflows/tests.yml)
rather than needing a dedicated job.

Spawn count is asserted as a generous budget (execution-counted, so it is
machine-independent); wall time is printed and recorded via
record_property for a human to compare run over run, only gated against a
hang-detection ceiling -- the same report-not-gate choice this repo already
made for #510 and #497, for the same reason: a shared runner's wall clock is
noisy about itself.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5

* Fix #669 self-review: jq-absent benchmark was silently measuring jq-present

tests/spawn_counting.make_shim_dir shims every name in its own COUNTED list --
including "jq" -- off the process's real ambient PATH, not off the jq-stripped
PATH _path_without_jq built in the previous commit, and places the shim
directory ahead of it on PATH. On any machine with a real jq (every
GitHub-hosted runner image ships one), the jq-absent scenario was silently
still resolving and using real jq, making it a vacuous test of the one
behaviour (_jq_fallback / the jq-absent code path) issue #669 exists to
finally observe on Windows instead of reason about.

Caught independently by both self-review spawns (Explore and oss:auditor,
spawned concurrently against the prior commit) before either saw the other's
finding.

Fixed by removing the jq shim for the jq-absent scenario, so detect-tools.sh's
`command -v jq` genuinely fails. Pinned with a paired positive/negative
control: the jq-present run must see real jq invocations (proof the harness
can detect one at all), the jq-absent run must see none -- confirmed with a
scratch copy of the repo whose `_jq_fallback` was deliberately made to fail
loudly: the unfixed test passed regardless, the fixed test's own new
assertion now depends on genuinely excluding jq. Measured numbers updated
in-comment (jq absent costs MORE, not less: 93/78 spawns vs jq present's
76/39, each python3-per-key-read having no jq-side multi-query batching
equivalent).

Also applies newline="" across the fixture's write_text calls, for the
CRLF-on-Windows class this repo already named and fixed once elsewhere
(tests/test_install_agy_hooks_563.py, #577) -- flagged by the auditor as a
"clean locally, untested on Windows" risk in the same fixture.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5

* Fix make_shim_dir's CRLF shebang on Windows -- real root cause of CI #34663736382 (#669)

windows-latest/Python 3.11 CI for PR #671 failed: test_session_start_hook_benchmark_with_jq_present
asserted "expected real jq invocations ... Spawns: []" -- the ENTIRE spawn log was empty for both
cold and warm runs, even though both exited 0. Pulled the full job log
(gh/supertool gh-job:103471338069) and traced it to tests/spawn_counting.make_shim_dir, not to
anything specific to jq or to this PR's own _path_without_jq/jq-absent logic (my self-review's
earlier fix): `shim.write_text(...)` had no `newline=""`, so on Windows every `\n` in the shim
script -- including the shebang line -- becomes `\r\n`. `#!/bin/bash\r` is not a shebang directive
bash's own exec() can resolve under Git Bash/MSYS, so every shim silently never ran: `command -v`
still reports the shim's PATH entry as present (NTFS ACL default grants execute), but invoking it
does nothing, the real unshimmed binary answers instead (hence exit 0 and correct hook behaviour),
and SPAWN_LOG never gets a line written to it.

This is the exact CRLF-on-write class this repo already named and fixed once
(tests/test_install_agy_hooks_563.py, #577) and that my own prior commit on this branch just fixed
in this test's OWN fixture -- missed, at the time, that shared tests/spawn_counting.py's
make_shim_dir (used by several other spawn-budget tests, all of which currently blanket-skip
win32 and so have never actually exercised this path for real before this PR's own benchmark) has
the identical bug. jq_absent passed vacuously on that same CI run (an empty spawn list trivially
satisfies "no jq calls"); jq_present correctly caught it, which is exactly what the paired
positive/negative control added in the previous commit was for.

Fixed by adding newline="" to both write_text calls in make_shim_dir. No POSIX-side behaviour
change (newline="" is a no-op when the platform line separator is already \n). REASONED, not
OBSERVED: no Windows box available to this lane; verification is the next CI run on this branch.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5

* Fix #669 round 2: Path.write_text has no newline= before Python 3.10

windows-latest/3.9 CI (job 103473817312) went red with
TypeError: write_text() got an unexpected keyword argument 'newline' --
confirmed against the job log, not just the report: Path.write_text only
gained its own `newline` parameter in Python 3.10, and this repo's matrix
floors at 3.9 (.github/workflows/tests.yml). The previous commit's
write_text(..., newline="") calls broke every test that imports
tests/spawn_counting.make_shim_dir on that leg -- 8 ALREADY-PASSING tests in
tests/test_log_sh.py and elsewhere, not just this branch's own new file --
and windows-latest/3.11 failed identically for the newline="" added to this
test's own fixture.

Fixed by switching every such call to open(path, "w", encoding="utf-8",
newline="") as a context manager plus .write(text), which has always
accepted `newline=` on every Python version this repo supports. This repo
already has the identical fix, for the identical reason, in
.oss/assemble_changelog.py's own changelog-writing code -- confirms the
approach rather than inventing a new one. tests/test_session_start_windows_benchmark_669.py
gained a small _write_no_crlf() helper so its four fixture writes share one
implementation instead of repeating the open() block.

Verified locally (macOS): 55 passed across tests/test_session_start_windows_benchmark_669.py,
tests/test_post_tool_hook_spawns.py, tests/test_session_start_prev_session_270.py,
tests/test_session_start_promo_spawn_budget_660.py and tests/test_log_sh.py (the file CI
showed breaking) -- same spawn counts as before this round, confirming no behaviour change,
only a compatibility fix. REASONED not OBSERVED for the 3.9/Windows combination itself: no
matching interpreter/platform available to this lane; the real verification is the next CI run.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5

* Add self-describing diagnostics to #669's jq-present/absent benchmark (diagnostics only)

windows-latest/3.12 CI (job 103475724500, run 34665238990) failed with the SAME symptom as
round 1's original CI failure -- jq_present's positive control asserting real jq invocations,
seeing Spawns: [] -- but this time AFTER round 2's CRLF-shebang fix and round 3's Python
3.9-compat fix, on a Python version (3.12) neither of those rounds broke. Verified against the
job log myself before doing anything (supertool gh-job:103475724500:fail): 1 failed, 1046 passed,
1365 skipped, same assertion, same empty spawn list.

This lane has no Windows box. A third blind guess costs another full CI round with no guarantee
of being right -- the requesting agent's own framing, and correct: land diagnostics first rather
than fix blind again.

Added `_diagnose()`, called once per scenario right after the cold+warm runs and printed
unconditionally (pytest shows captured stdout for a FAILED test by default -- no -s needed,
confirmed against this repo's own addopts in pyproject.toml), plus folded into the jq-calls
assertion's own failure message so it travels with the exact assertion that has been failing.
Captures everything requested: resolved bash path, the PATH string as built on the Python side,
what bash ITSELF resolves PATH and `command -v jq` to (a direct probe inside a bash subprocess
using the identical env, to rule in/out MSYS's Windows-vs-POSIX path translation as the working
theory -- the positional evidence this repo cannot get any other way without a Windows box),
a directory listing of the shim dir with mode/size per entry, whether the spawn log exists and
its size before parsing, and the full (untruncated) stdout/stderr and exit code of both the cold
and warm runs. Every piece is wrapped so a diagnostic failure degrades to a one-line
"<could not get: ...>" rather than replacing the real assertion failure with an unrelated one.

Deliberately NOT attempting a third fix in this commit: traced the existing PATH-construction
code (this file's own _run_once, tests/spawn_counting.make_shim_dir) but could not form a
confident, code-level mechanism the way the shebang-CRLF bug had one -- in particular, if MSYS's
PATH translation were broadly broken, other real binaries the hook depends on throughout its run
(python, git) would plausibly fail too, and the hook has exited 0 with correct output on every
Windows CI run so far, arguing against a blanket PATH-translation failure and for something more
specific to the shim mechanism that this diagnostic output should make visible on the next run.

Verified locally (macOS): both scenarios still pass, diagnostics print without crashing
(including a successful DIAG_JQ=.../shims/jq resolution, confirming the probe mechanism itself
works), no change to spawn counts or timing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5

* Fix #669 root cause (round 5): _HOOK_DIR resolves to "." under a backslash script path

windows-latest/3.10 CI (job 103477377903, run 34665808749) with round 4's diagnostics landed
showed the real answer: the bash-side PATH probe and `command -v jq` both resolved correctly to
the shim (DIAG_JQ=.../shims/jq), fully ruling out jq availability, PATH construction and MSYS path
translation as causes. The actual captured stderr was:

    D:\\a\\claude-remember\\claude-remember\\scripts\\session-start-hook.sh: line 160:
    ./resolve-paths.sh: No such file or directory

session-start-hook.sh:60 derives its own directory with
`_HOOK_DIR="${BASH_SOURCE[0]%/*}"` (falling back to "." per the explicit comment above it when no
"/" is found) -- pure bash STRING pattern matching that only ever recognises `/`, never `\\`.
_run_once passed `str(SESSION_START)` as the script path, and on native Windows that is a fully
backslash-separated path, so BASH_SOURCE[0] contained zero "/" characters and _HOOK_DIR fell back
to "." -- exactly matching the observed error. Confirmed directly (not merely reasoned): running
the real "${BASH_SOURCE[0]%/*}"-style expansion against a backslash string vs a forward-slash
string reproduces "." vs the real directory, with no Windows box needed to see the mechanism
itself.

This is a TEST HARNESS bug, not a hook bug: the hook's real caller
(hooks/hooks.json: `bash "${CLAUDE_PLUGIN_ROOT}/scripts/session-start-hook.sh"`) always has a
literal forward slash hardcoded immediately before the filename, so BASH_SOURCE[0] there always
ends in "/session-start-hook.sh" regardless of what separator style CLAUDE_PLUGIN_ROOT itself
uses -- which is why years of real Windows usage never surfaced this. Confirmed by reading the
real invocation command before concluding the hook itself needed no change, per the explicit
instruction not to touch it without checking first.

Fixed by passing SESSION_START.as_posix() instead of str(SESSION_START) to bash's argv in
_run_once -- the one call site that invokes the real file directly.

Added test_hook_dir_derivation_needs_a_forward_slash_path, a genuine regression test for the
mechanism itself: the exact two lines are extracted from the real hook file (so it breaks loudly
if that derivation ever moves or changes), their `%/*`/fallback pattern is driven against a plain
settable variable (BASH_SOURCE cannot itself be reassigned inside `bash -c` -- caught empirically
while writing this test, an earlier draft silently asserted "." for every case including the
POSIX one), with a forward-slash case, a no-separator positive control for the fallback itself,
and a backslash case -- plus an end-to-end probe that actually invokes a real file via
.as_posix() and checks BASH_SOURCE[0] resolves correctly, proving the actual fix rather than only
the isolated mechanism.

Verified locally (macOS): 56 passed across this file and every other file that shares test
infrastructure with it (test_post_tool_hook_spawns.py, test_session_start_prev_session_270.py,
test_session_start_promo_spawn_budget_660.py, test_log_sh.py). REASONED not OBSERVED for the
actual windows-latest leg: no Windows box available; the next CI run is the real verification,
but for the first time in this whole issue the root-cause mechanism itself -- not just its
absence of symptoms -- has been directly demonstrated on this platform.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5

* Fix #669 round 6: pass the regression test's fake path through env, not argv

windows-latest CI (all 4 Python versions, e.g. job 103479922291) reported good news first --
the round-5 .as_posix() fix WORKED: both jq_present/jq_absent benchmarks now pass (suite went
1046 -> 1047 passed, those two tests no longer in the failure list). Bad news: the NEW regression
test added in round 5, test_hook_dir_derivation_needs_a_forward_slash_path, failed identically on
every Windows leg, at the FIRST (plain-POSIX, no-backslash) _probe() call -- empty stderr,
returncode=1, and a garbled `args` repr in the assertion message with NUL-interleaved text that
does not correspond to anything this test's own Python-side string construction produces (verified
locally: reconstructing the exact same snippet/command string on this platform is clean, 82 chars,
no corruption).

Investigated rather than guessing about on-disk file encoding (session-start-hook.sh itself parsed
and ran correctly in the SAME CI job for the jq_present/absent tests, ruling out the file being
genuinely UTF-16 on that Windows checkout -- if it were, the hook itself would fail to parse at
all, not just this one new test). The actual mechanism: tests/test_fast_path_subshells_511.py
already documents, for an adjacent Windows subprocess hazard, that `subprocess.run`'s argv list is
re-flattened into a single command line by Python's own MSVCRT-style quoting rules
(subprocess.list2cmdline) before CreateProcess hands it to bash.exe, and MSYS's own argv
re-parsing of that line does not agree with it on a string carrying embedded double quotes -- which
the round-5 probe's inline `bash -c "<script with many \"quotes\">"` plus a second argv element for
the fake path both are.

Fixed by adopting the exact same proven pattern #511's own test already uses for this hazard: the
fake value travels through an ENVIRONMENT VARIABLE, and the probe script is a real FILE invoked by
path (`bash <path>`) rather than inline `-c` text -- eliminating the argv/quote round-trip for both
the script body and the value under test.

Verified locally (macOS): 65 passed across this file, every file sharing its test infrastructure,
and test_fast_path_subshells_511.py itself (the file whose own documented precedent this fix
copies). REASONED not OBSERVED for the actual windows-latest legs: no Windows box available; the
next CI run verifies it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5

* Fix #669 round 7: round 6 reintroduced the Python 3.9 write_text(newline=) bug

Maintainer ruling on PR #671: round 6 (commit 4daf3d2) added
probe_script.write_text('...', encoding="utf-8", newline="") -- the exact
Path.write_text()-newline=-kwarg shape round 3 (commit b84a5c9) already found
broken on Python 3.9 (the kwarg only exists from 3.10), reintroduced by mistake
instead of reusing the _write_no_crlf() helper this file already defines for
exactly this.

Fixed by routing that one write through _write_no_crlf() instead. Grepped the
whole diff (main...HEAD) for every other write_text( call across all files
touched in this issue's six prior rounds (tests/spawn_counting.py,
tests/test_session_start_windows_benchmark_669.py) -- no other call carries a
newline= kwarg; every remaining write_text( hit is either a bare call with no
such kwarg (log.write_text("", encoding="utf-8"); real_probe_script.write_text(...)
with no newline=) or a comment documenting this exact class. No other change
in this commit, per the maintainer's explicit instruction.

Verified locally (macOS): 3 passed, ruff clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5

* Skip #669's _HOOK_DIR regression test on windows-latest, tracked as #672

Maintainer ruling on PR #671: skip the round-5/6 regression test
(test_hook_dir_derivation_needs_a_forward_slash_path) on win32, citing #672
(the filed follow-up for the NUL-interleaved/UTF-16LE bash-subprocess-probe
corruption this test's own _probe() hit on every Windows leg, round 6/7).
Leave the benchmark tests (test_session_start_hook_benchmark_with_jq_present
/_absent, and their jq positive/negative controls) fully live on every
platform -- unaffected, not touched.

One deviation from the literal instruction, reported rather than silently
applied: the instruction named "the backslash-path probe" specifically as
the thing to isolate and skip, with the forward-slash case assumed to pass
fine on Windows. Verified against the actual job logs before acting
(gh-job:103483869911:fail, and round 6's own earlier failure) -- both show
the corruption hit at the line inside the shared `_probe()` helper
(line 577, called identically by all three top-level cases: posix, no_sep,
backslash), and in both observed instances it failed on the FIRST call,
`posix = _probe(...)` -- the plain forward-slash case, not the backslash
one. The corruption is not input-dependent; #672's own body says the same
tail recurs verbatim across two structurally different invocation shapes,
consistent with an environment-level cause rather than anything about
which string is being probed. A partial skip sparing only the backslash
case would have left the actually-failing case (posix) still running and
still red, defeating the point of this round. Skipped the whole test
function instead, with a reason naming this discrepancy plainly rather than
repeating the (incorrect) "backslash-specific" framing in the skip reason
itself.

Verified locally (macOS, where the skip condition is False so nothing skips
here): the decorator attaches to exactly this one function
(`getattr(f, "pytestmark", [])` confirms it, and confirms the jq_present
benchmark carries no such mark) -- 3 passed, ruff clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

Ask users for a GitHub star, once, through the surfaces the plugin already owns

1 participant