Repository navigation
Conversation
… every startup (#667) session_was_saved() (scripts/session-start-hook.sh) calls `$JQ -r --arg id "$1" "$SAVED_QUERY" "$LAST_SAVE_FILE"`. When jq is not on PATH (the default on a fresh Git for Windows / Git Bash install, related to #660), $JQ is _jq_fallback (scripts/detect-tools.sh), whose shim consumes every leading `-*` token into a variable it never reads, then treats the next positional argument as the query and the one after that as the file -- fed --arg's pair, that lands on query="id", file="$1" (the session id, not a real file), and the shim always prints nothing. session_was_saved compared that empty output against "saved" and always got false, so every previous session read as unsaved and session-start-hook.sh's recovery block spawned save-session.sh --force on every single jq-less startup, regardless of whether the session had actually been saved. Fix: session_was_saved() gets its own jq-free branch (checked via `[ "$JQ" = "_jq_fallback" ]`) that reads last-save.json with one direct Python call carrying the session id as argv, mirroring $SAVED_QUERY's own isline semantics exactly (type, non-bool, finite, floor-equal). Every other $JQ/$JQ_BIN --arg call site under scripts/ already guards itself with `command -v jq` first, so this is the only call site that ever reached the fallback with --arg; teaching the generic shim a --arg parser would have been strictly more code for the same coverage. Tests: tests/test_jq_fallback_arg_667.py, paired negative ("saved" -> no re-save) and positive control ("not saved" -> re-save observed), each run with jq present and jq masked off PATH. Red before the fix: the jq-absent negative case spuriously observed a save-session.sh --force invocation; green after. Docs: changelog.d/667.fixed.md, and a one-paragraph note in docs/windows.md (not itself a docs_targets entry, but directly named by this issue and covering exactly the code path fixed here). Related to #660. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
…t stub Two findings from the Explore + oss:auditor pass over 869a901: - Explore: the jq-free branch's `isinstance(sessions, dict)` guard silently fell through to the legacy `.session`/`.line` check whenever `sessions` was present but malformed (e.g. a list) -- whereas real jq's own `(.sessions // {})[$id]` throws a hard runtime error the instant `.sessions` is present but not an object, aborting the WHOLE `$SAVED_QUERY` program with no fallback. A corrupted `sessions` value sitting next to an otherwise-valid legacy `session`/`line` pair therefore read as "saved" on the new Python path but "unsaved" on real jq for the same file. Fixed with an explicit short-circuit matching jq's abort behaviour, pinned by a new parametrized test (test_a_malformed_sessions_shape_reads_as_unsaved_on_both_paths) run with jq present and jq absent both. - oss:auditor: the new test's save-session.sh stub was written via Path.write_text's default universal-newline translation, which turns every `\n` into `\r\n` on Windows -- a broken `#!/bin/bash\r` shebang under Git Bash/MSYS, the exact defect class tests/spawn_counting.py's own make_shim_dir already exists to avoid (#669/#670). Unlike a shimmed COUNTED tool, this stub has no same-named real binary on PATH to silently fall through to, so a corrupted shebang would fail loudly with a "bad interpreter" error and break the positive-control assertion on windows-latest for a reason unrelated to #667. Fixed by writing it with newline="" instead. Both findings were argued as worth fixing directly (mechanism stated, one-file blast radius, same subsystem as the original fix) rather than filed or logged to trap.d/. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
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.
session_was_saved() (scripts/session-start-hook.sh) calls
$JQ -r --arg id "$1" "$SAVED_QUERY" "$LAST_SAVE_FILE". When jq is not on PATH -- the default on a fresh Git for Windows / Git Bash install, related to #660 -- $JQ is _jq_fallback (scripts/detect-tools.sh), whose shim consumes every leading-*token into a variable it never reads, then treats the next positional argument as the query and the one after that as the file. Fed --arg's flag+value pair, that lands on query="id", file="$1" (the session id, not a real file), and the shim always prints nothing.session_was_saved compared that empty output against "saved" and always got false, so every previous session read as unsaved on a jq-less install, and session-start-hook.sh's recovery block spawned save-session.sh --force in the background on every single startup, regardless of whether the session had actually been saved.
Fix
session_was_saved() gets its own jq-free branch (checked via
[ "$JQ" = "_jq_fallback" ]) that reads last-save.json with one direct Python call carrying the session id as argv, mirroring $SAVED_QUERY's ownislinesemantics exactly (a JSON number, never a bool, finite, equal to its own floor). Every other $JQ/$JQ_BIN --arg call site under scripts/ already guards itself withcommand -v jqfirst, so this was the only call site that ever reached the fallback with --arg -- teaching the generic shim a full --arg parser would have been strictly more code for the same coverage.Tests
tests/test_jq_fallback_arg_667.py drives the real hook via subprocess, with jq present and with jq masked off PATH (a real PATH-stripping repro, not a mock, using a shim dir to keep coreutils working per tests/spawn_counting.py's own convention). Paired negative ("saved" -> no re-save invocation) and positive control ("not saved" -> re-save invocation observed with the correct argv), plus a third case pinning a self-review finding (a malformed
sessionsshape must read as unsaved on both the jq and jq-free paths, matching jq's own hard-error-abort behaviour on that shape).Red before the fix: the jq-absent negative case spuriously observed a
save-session.sh --forceinvocation for a session that genuinely had been saved. Green after, 6/6.Docs
changelog.d/667.fixed.md, and a paragraph in docs/windows.md (not itself a docs_targets entry -- .oss.json's docs_targets lists only README.md -- but directly named by this issue and covering exactly the code path fixed here; README.md itself was read and needs no change, its jq-recommendation language is still accurate and this fix does not make jq unnecessary elsewhere in the codebase).
Self-review
Explore and oss:auditor both reviewed the committed diff. Explore found a jq/Python parity gap in the new branch's handling of a malformed
sessionsshape (fixed, with a new pinning test). The auditor found that the new test's save-session.sh stub was written with default newline translation, risking a CRLF-corrupted shebang on Git Bash/MSYS windows-latest CI (fixed, written with newline="" instead, following the convention tests/spawn_counting.py's own make_shim_dir already established for the identical defect class).Closes #667. Related to #660.
🤖 Generated with Claude Code
[AI-generated]