Repository navigation
Conversation
…#663, part of #660) session-start-hook.sh sources log.sh (and its lib-memory-dir.sh merge) before dispatching before_session_start hooks, but 50-git-restore.sh ignored that inherited work entirely: because _LIB_MEMORY_DIR_LOADED is not exported to the child, sourcing log.sh unconditionally re-ran the whole three-layer config merge (mktemp, per-layer jq reads, jq -s deep merge, log.sh's own one-pass flatten) before ever checking whether git_restore.enabled was even true -- paid on every dispatch, on every install with the (default) setting off. Now the hook reads git_restore.enabled with a single jq (or python) call straight out of the already-merged REMEMBER_CONFIG the parent process already exported, before sourcing anything. Only when that says "true" (or the cheap read cannot answer at all) does it fall through to the unconditional source + config() gate, unchanged, so correctness never depends on the fast path. Measured (external data_dir layout, real re-source, disabled): 11 spawns before, 2 after; a positive control in the same fixture confirms git_restore.enabled=true still reaches the real restore logic. Also folds dispatch()'s two per-hook subprocess calls (stat for ownership, find -perm -002 for world-writable) into one stat call, and replaces the per-loop `$(id -u)` with the bash builtin $EUID. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
…U stat (#663 self-review) Both the independent reviewer and the auditor spawned against dfe1f34 found the same bug in the stat/find fold: GNU `stat -c '%a'` (unlike BSD's `%Lp`) prefixes the three permission digits with the setuid/setgid/sticky bit whenever one is set, so a hook at mode 1777/2777/4777 reports as the four-digit "1777", not "777". The `case "$hook_perm" in [0-7][0-7][0-7])` pattern only matched exactly three digits, so a four-digit value fell through unmatched and was silently treated as "cannot tell" -- fail-open, letting a genuinely world-writable (and additionally setuid/sticky) hook run. The pre-fix `find -maxdepth 0 -perm -002` tested the bit directly and never had this failure mode. Fixed by trimming to the last 3 characters (`${hook_perm: -3}`) before the pattern match and the arithmetic, which is a no-op for the ordinary 3-digit case. Pinned by a new regression test that fakes `stat` to emit the GNU 4-digit shape regardless of the platform this test actually runs on (confirmed red without the trim, green with it). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
…hree characters
`${hook_perm: -3}` returns "" for a string shorter than three characters on
every bash (tested on 3.2), not the string unchanged as the comment claimed,
and GNU `%a` prints no leading zeros ("22" for mode 0022). Unreachable for an
executable hook, but the trim was never needed: `8#$mode & 2` ignores the
special bits by construction. Accept any all-octal string and test that.
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.
Closes #663. Part of #660.
What
hooks.d/before_session_start/50-git-restore.shis dispatched as a CHILD process ofscripts/log.sh'sdispatch()during SessionStart. The parent (session-start-hook.sh) already sourcedlog.sh-- which resolves and merges the three-layer config and exportsREMEMBER_CONFIG-- before dispatching, but the hook ignored that inheritance entirely: because_LIB_MEMORY_DIR_LOADEDis not exported to a child process,source "$PIPELINE_DIR/scripts/log.sh"unconditionally re-ran the WHOLE merge (lib-memory-dir.sh's ownmktemp+ severaljqcalls, pluslog.sh's one-pass flatten and its cache publish) before ever reading whethergit_restore.enabledwas even true -- on every dispatch, on every install with the (default) setting off.Now the hook reads
git_restore.enabledwith a singlejq(orpython3) call straight out of the already-exportedREMEMBER_CONFIG, before sourcing anything. If that says "false", it exits immediately. If it says "true", or the cheap read cannot answer at all (missing/unreadableREMEMBER_CONFIG, nojq/python3), it falls through unchanged to the originalsource log.sh+config()gate, which stays authoritative.Separately,
dispatch()(scripts/log.sh) now reads the current UID with the bash builtin$EUIDinstead of forkingid -u, and folds the two per-hook subprocess calls (statfor ownership,find -perm -002for world-writable) into onestatcall.Measured
Spawn-counting harness, external
data_dirlayout, real re-source (_LIB_MEMORY_DIR_LOADEDdeliberately unset),git_restore.enabled=false: 11 spawns before this fix, 2 after (tests/test_git_restore_no_resource_when_disabled_663.py). A positive control in the same fixture confirmsgit_restore.enabled=truestill reaches the real restore logic (the layered merge and thegit rev-list --left-right --countdivergence check both still run).The
#669benchmark (tests/test_session_start_windows_benchmark_669.py -k benchmark) does not move: its fixture exercises LEGACY layout, where this hook already exits at an earlier, pre-existing guard before reaching either the old or the new gate. The defect this issue names is specific to EXTERNALdata_dirlayout.Self-review finding, fixed in a follow-up commit on this branch
Both spawned reviewers (an independent
Explorereview and anoss:auditoraudit) found the same real bug in thestat/findfold: GNUstat -c '%a'(unlike BSD's%Lp) prefixes the three permission digits with the setuid/setgid/sticky bit when one is set, so a hook at mode 1777/2777/4777 reported as the four-digit "1777", which thecase "$hook_perm" in [0-7][0-7][0-7])pattern did not match -- silently treating a genuinely world-writable (plus special-bit) hook as "cannot tell" and letting it run. Fixed by trimming to the last 3 characters before the pattern match; pinned by a new regression test that fakesstatto emit the GNU 4-digit shape regardless of platform (confirmed red without the trim, green with it).below-bar note
No below-bar findings in this run -- both reviewer findings on the fold bug were fixed, not deferred.
🤖 Generated with Claude Code
https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
[AI-generated]