Repository navigation
Conversation
…eady fixed the other two hooks (#372) log.sh returns before defining log(), report_error() or dispatch() when $REMEMBER_DIR/logs cannot be created; session-end-hook.sh called both unguarded, so on an unwritable store its documented "reported loudly, never swallowed" promise was inverted exactly where it mattered -- a `command not found` on the degraded path, and on macOS a shelled-out call to Apple's /usr/bin/log first. The declare -F guard now matches post-tool-hook.sh and user-prompt-hook.sh, with fallbacks that still write a WARNING to stderr instead of going silent, since neither hook-errors.log nor the notice channel is reachable on this path. Co-Authored-By: Max <noreply>
Review found two adjacent nits in the #372 fix: the new must-fire test relied on os.chmod(0o555) to force mkdir to fail, but this repo's own convention for that exact technique (five other test files) skips under root, since root ignores directory write-permission bits -- add the matching geteuid()==0 skip guard. The guard's own comment in session-end-hook.sh referenced "line 158" for the report_error call by line number, which drifted as comment lines were added around it -- reworded to name the branch instead of a line number. Co-Authored-By: Max <noreply>
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 #372.
What was broken
scripts/session-end-hook.shsourcesscripts/log.shwith stderr suppressed and then callslog/report_errorunguarded (lines 148, 158, 164, 209).log.shreturns before it defineslog(),report_error()ordispatch()when it cannot create$REMEMBER_DIR/logs-- so on a store that can never be created, both calls hit an undefined function. On macOSlogadditionally resolves to Apple's/usr/bin/logunified-logging CLI even when undefined as a shell function (type logis true either way), so the first call dumps 19 lines of usage text to stderr and exits 64; the second,report_error, fails outright withcommand not found. Neither changes the hook's exit status, which stays 0 either way -- so this was fully silent to anything that only checksreturncode, including/remember:doctor, which readshook-errors.logand reports nothing wrong.Sibling hooks
post-tool-hook.shanduser-prompt-hook.shalready carry adeclare -Fguard for exactly this (#365, added 15 minutes before #368 registered this fourth hook without it) --declare -F, nottype/command -v, is required specifically because of the macOS/usr/bin/logcollision.The judgment call
Unlike the no-op stubs the hot paths in the other two hooks install, the fallback here is not a no-op:
session-end-hook.sh's own docstring (EXIT CODES) promises a failed flush is "reported loudly ... rather than swallowed silently", and the guardedreport_errorcall is reachable only on the path where that promise is being broken.log.sh's ownlog()documents "Falls back to stderr if log file is unwritable" -- the stub reproduces exactly that fallback, for exactly that reason:hook-errors.logand the notices channeluser-prompt-hook.shreads (#200, #253) both live under$REMEMBER_DIR, the same directory that failed to get created, so stderr is the only channel actually available. Confirmed by readingbootstrap-dirs.sh:225-231, which only redirects this hook's own stderr intohook-errors.logonce that directory exists.Tests
The existing test at
tests/test_session_end_hook_345.py:227(test_missing_remember_dir_on_a_real_project_still_exits_zero) removes.rememberbut leaves the project directory itself writable --bootstrap-dirs.sh'smkdir -precreates it successfully, so this test never actually reaches the guardedreport_errorcall, contrary to a literal reading of the issue's framing. Verified empirically. It is now the paired must-not-fire positive control ("WARNING" not in result.stderr).A new test,
test_must_fire_unwritable_store_reports_a_warning, chmods the project directory itself to0o555after removing.remember, which genuinely forcesbootstrap-dirs.sh'smkdirto fail. Watched red against the unfixed script (reproducinglog: Unknown subcommand 'hook'thenreport_error: command not found, exactly the issue's mechanism) and green against the fix.The sibling at line 200 (
test_no_project_at_all_still_exits_zero) does not have the same defect: with noCLAUDE_PROJECT_DIR,resolve-paths.sh's soft-fail mode exits the hook at line 144, beforelog.shis even sourced -- a different, pre-existing, out-of-scope early-exit path. Left unmodified.Review
Both spawned reviewers (Explore + oss:auditor) converged on the same finding: the new must-fire test's
os.chmod(0o555)technique had no root-uid skip guard, unlike five sibling test files in this repo that use the identical technique. root ignores directory write-permission bits, so under a root CI runner the test would fail for an unrelated reason instead of skipping. Fixed with the matching@pytest.mark.skipif(hasattr(os, "geteuid") and os.geteuid() == 0, ...)guard, in a second commit, along with a stale "line 158" reference in the new guard's own comment (drifted after other comment lines were added around it).Below-bar item (no reachable caller beyond a doc nicety): none.
Docs
README.md(the repo's onlydocs_targetsentry) gets two new sentences distinguishing this narrow "store could never be created at all" case from the broader flush-failure case the file already documents -- the warning here goes to stderr, nothook-errors.log, and will not show up in/remember:doctor. A changelog fragment is atchangelog.d/372.fixed.md, checked with.oss/assemble_changelog.py --check.