Repository navigation
Merged
Conversation
#358 -- _remember_env_cache_publish() defaulted REMEMBER_SAVE_COOLDOWN and REMEMBER_DELTA_THRESHOLD to 120/50 at the point of writing, so a store whose logs/ dir log.sh could not create published those digits as though config.json had said so -- indistinguishable, on the load side, from a real answer. The publish is now refused outright unless log.sh actually set both. #361 -- post-tool-hook.sh's fast path already guarded `log` (`declare -F`, not `type`, because macOS's own /usr/bin/log makes `type log` true regardless) and stubbed `dispatch()` unconditionally. Its slow path -- taken by every session's first tool call -- did neither, and shelled out to the system log binary and a "command not found" dispatch on exactly the store #358 is about. Same guard added there, and adjacent to it, the identical unguarded dispatch() call in user-prompt-hook.sh's own slow path. Closes #358, closes #361 Co-Authored-By: Max <noreply>
fdaviddpt
added a commit
that referenced
this pull request
Aug 27, 2026
… fixed the other two hooks (#374) * fix: guard session-end-hook.sh log/report_error the same way #365 already 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> * fix: guard the new #372 test against root, and correct a stale line ref 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.
Both issues were filed by the release audit of v0.20.0..HEAD as
misreports. Both are the same shape:scripts/log.shreturns early, before it sets anything, on a store whoselogs/directory it cannot create -- and two call sites downstream trusted that it had.#358 -- a fabricated cooldown/threshold
_remember_env_cache_publish()inscripts/lib-env-cache.shused to writeREMEMBER_SAVE_COOLDOWN/REMEMBER_DELTA_THRESHOLDwith shell defaults (${VAR:-120},${VAR:-50}) even when log.sh never set them. So an unwritable store silently published 120/50 into the env-resolution cache as thoughconfig.jsonhad asked for exactly that -- and the load side cannot tell a default from a real answer, because both are just digits. Fixed by refusing the whole publish (return 0, no file written) unless both variables are genuinely non-empty, and removing the now-redundant:-120/:-50defaults from the printf lines, so a default at the point of writing can never happen again.#361 -- log/dispatch called on an undefined function
scripts/post-tool-hook.sh's fast path already guarded alogcall withdeclare -F log >/dev/null 2>&1 || log() { :; }-- nottype log, because on macOS/usr/bin/log(Apple's unified logging CLI) makestype logtrue whether or not a shell function exists -- and stubbeddispatch()outright. Its SLOW path, taken by every session's first tool call because there is nothing yet to replay, called both unconditionally. On a store whoselogs/cannot be created that shells out to the reallogbinary (22 lines of usage text on stderr) and then hitsdispatch: command not found, from a hook documented "EXIT CODES: 0 Always" -- and an installedafter_post_toollistener silently never runs. Fixed with the identical guard on the slow path'slogcall and a singledeclare -F dispatchguard placed right before the onedispatch "after_post_tool"call site (which correctly covers both branches -- a no-op on the fast path, where dispatch is already stubbed).Adjacent, fixed in the same commit
While reproducing #361, the identical unguarded
dispatch "after_user_prompt"call turned up inscripts/user-prompt-hook.sh's own slow path (reached only when a user has installed anafter_user_promptlistener AND the store cannot writelogs/-- a narrower window than post-tool-hook.sh's, but the same file already open for #358's guard, the same mechanism, and a one-line fix). Given its own test (tests/test_prompt_hook_spawns.py::test_an_unwritable_logs_dir_does_not_break_after_user_prompt_dispatch), verified red before the fix and green after. Flagging it explicitly here rather than letting it ride silently: this is outside both issues' own text, in scope only because it is the same subsystem and the same file.The judgment calls the brief asked me to make and state
Shared helper or not: I did not add one shared guard function used by both #358 and #361's fixes. #358 guards a publish (a value that outlives the process and must never lie); #361 guards a call (a function invocation that must never crash or shell out to a system binary). They are checked with the same primitive (
declare -F/[ -n ]non-empty checks) but at different call sites with different consequences on failure, and a shared helper risked collapsing that distinction -- guarding the cheap half (the call) with the same weight as the expensive half (the durable file), or vice versa. Each fix is local to its own call site.What the guard does when it fires: #358 skips the publish entirely rather than publishing without the two keys -- the load side (
_remember_env_cache_load) already requires both keys non-empty and all-digits, so a cache missing them would be refused on load anyway; skipping the write outright is strictly cheaper for the identical outcome. #361 stubslog/dispatchas no-ops rather than exiting non-zero (unlike session-start-hook.sh's ownexit 127guard for the same underlying hazard) -- both post-tool-hook.sh and user-prompt-hook.sh are documented "EXIT CODES: 0 Always", and post-tool-hook.sh in particular must never block a tool call. An installed listener silently does not run on this one degraded call, which is the same tradeoff #358 makes (a stale-but-honest cache beats a live-but-fabricated one; a call that is silently skipped once beats a hook that crashes the agent's tool call).Below-bar finding, in this same body
While reading
scripts/post-tool-hook.sharound the fix, I noticed the FATAL echo inscripts/log.shat the point of the early return (echo "FATAL: cannot create $REMEMBER_LOG_DIR" >&2) reaches the terminal unredirected on exactly the slow-path first-call case this PR fixes noise for -- it is not wrong, and it is the one honest signal a user gets that their store is broken, but it is one more line of stderr on an already-noisy failure mode nobody asked me to quiet further. I judged this below the bar to file or fix: it is a single honest diagnostic line, not a defect, and touching it would be a scope decision (should a hook this degraded print anything at all?) the two issues did not ask for. No class-level reachable bug here -- just a true statement worth having on record.Closes #358
Closes #361
Verified by the maintainer
Independent red re-run, because the lane's own red is a claim I did not watch. Built a detached worktree at
main(df3e35c), checked out only the three test files fromfix/358onto it so every source fix was absent, and ran them:Three failures, one per fix — including the adjacent
user-prompt-hook.shone, which is the fix nobody filed an issue for and therefore the one with the weakest external check. The 26 pre-existing tests in those same files still passed with the fixes absent, which is the positive control: the harness was working, so the three failures are the tests biting rather than a broken run.Observed on darwin / Python 3.13.15. The
logs/-unwritable premise is built with POSIX permission semantics; whether it reproduces on Windows is reasoned, not observed.Pre-flight premise checked before dispatch and both issues were still open against the code:
declare -F logmatched atpost-tool-hook.sh:201(the fast-path guard the issue says exists), and did not match at the slow path or at either publish site.