Repository navigation
fix(#204): don't walk into file I/O against a store that was never created - #218
Merged
Merged
Conversation
…eated bootstrap-dirs.sh ran `mkdir -p "$REMEMBER_DIR/…" 2>/dev/null` best-effort, never checked the status, then wrote .gitignore into that directory. On an unwritable memory root — a session opened at `/`, where legacy mode makes REMEMBER_DIR `//.remember` on macOS's read-only root volume — the mkdir failed silently and the write hit a directory that did not exist. The `2>/dev/null` did not suppress the result. The shell opens a redirection target BEFORE running the command, so the failure to open the target is reported by the shell itself, outside the scope of the redirect meant to silence it. Users saw bootstrap-dirs.sh: line 101: //.remember/.gitignore: No such file or directory as a non-blocking hook failure at every session start. The write is now gated on the store existing, and the redirect is wrapped in braces so the shell's own diagnostic falls inside the suppressed scope — which also covers the residual race (store removed between the check and the write) where no directory test is left to make. Not changed: the `exit 127` that follows on such a root. With no writable store log.sh cannot be sourced, and session-start-hook.sh reports that deliberately rather than crashing later on an undefined function — the documented degraded-env contract tolerating rc in (0, 127). Silencing a bash-level leak is not a licence to silence the plugin's own reporting. tests/test_bootstrap_readonly_root.py pins both directions: the leak is gone, and a writable project still gets tmp/, logs/, logs/autonomous/, .gitignore and its context injection. A bootstrap that quietly no-ops itself would be a worse bug than the noise it fixed. The nested-summarizer recursion in the same issue was already closed by #202 and #205, both verified present and correct on main; this is the part of @BlockX-P2P's report that had not been picked up. Co-Authored-By: Max <noreply>
fdaviddpt
force-pushed
the
fix/204-nested-hook-recursion
branch
from
July 29, 2026 13:59
8ddab31 to
12148dc
Compare
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.
What this changes
Only the secondary defect in #204:
bootstrap-dirs.shleaking a bash diagnostic to stderr at every session start when the memory root is unwritable. The recursion that the issue leads with is already fixed onmain— see the re-derivation below.What I re-derived, and what came out different
The report is from outside the allowlist and cites 0.8.8 line numbers, so I re-checked every claim against current
main(0.9.0) rather than trusting it. Two of its three central claims are correct; its headline conclusion is stale.Confirmed, live, on this machine. I drove a real nested
claude -pusing the plugin's own_child_env(), fromcwd=$TMPDIR, against a scratch project carrying a hook that dumps its environment:Three things fall out of those two lines:
CLAUDE_PROJECT_DIRis not absent in the child._child_env()strips it from the inherited environment and Claude Code sets it afresh from the sandbox cwd — as the physical/private/...path, exactly as reported. Soresolve-paths.shsucceeded and the soft-fail never fired.SessionStartandUserPromptSubmit), each of which alone scaffolds the directory. Verified rather than taken on trust.REMEMBER_NESTED_SUMMARIZER=1propagates intact into the nested session's hook environment. This was the assumption the whole design rests on and the one that would have collapsed it, so it needed observing rather than assuming.Different from the issue: the fix it asks for is already merged, twice over, at both layers.
resolve-paths.shcarries the marker guard (fix: the summarizer erased the only proof it was a summarizer #205) — in the one file all three hooks source, which is the layer the report itself argues for.haiku.pysets the marker in_child_env()and passes--setting-sources ''(Hook-blocked prompt is stored as the consolidation result, corrupting recent.md recursively #202).The report's primary recommendation was
--setting-sources ''alone. That alone would have been the wrong call, andmainis right not to have taken it that way: an older CLI exits non-zero on an unknown option, which becomes aRuntimeError, which means no session ever saves again — a cosmetic junk directory traded for a silent total outage.mainhandles this by failing open (dropping isolation and retrying, loudly). Which is precisely why the marker guard matters: it is the layer that still holds on the degraded path, where--setting-sourceshas been dropped and the user's hooks are live. Two independent layers, one of which can be degraded away and one of which cannot.tests/test_nested_summarizer.pyalready pins all of this, including the misfire case. I added nothing there.The part that had not been picked up
The issue's second half.
bootstrap-dirs.sh:The
2>/dev/nulldoes not do what it looks like it does. The shell opens a redirection target before running the command, so the failure to open it is reported by the shell itself — outside the scope of the redirect being asked to hide it. Reproduced standalone before touching anything:Red, before the fix existed
The one that passed is the regression control — it passes before and after, which is the point of it.
Green, after
Full suite: 947 passed, 41 skipped, coverage 93.98%.
The fix, and why at that layer
In
bootstrap-dirs.sh, not in the hooks: it is the only place that knows whether the store was created, and all three hooks reach the write through it. The.gitignorewrite is gated on[ -d "$REMEMBER_DIR" ], and the redirect is brace-wrapped so the shell's diagnostic lands inside the suppressed scope — which also covers the residual race where the store disappears between the check and the write, and there is no directory test left to make.How I ruled out the misfire case
The failure mode that would be far worse than the bug is a guard that silently no-ops a real session — turning "stray directory" into "memory stops working". Three things rule it out:
[ -d "$REMEMBER_DIR" ]is false only whenmkdir -pjust failed. In a normal session the directory was created microseconds earlier by the line above; there is no environment, config mode or platform in which a healthy session reaches that test with the directory missing.return, noexit, no early bail. Everything else in bootstrap — migration, the stderr redirect, every export — is untouched and still runs. The blast radius is a single.gitignorewrite.test_a_writable_project_still_gets_its_full_treeasserts a normal project still getstmp/,logs/,logs/autonomous/, a.gitignorecontaining*, and=== REMEMBER ===in stdout. If the guard ever swallowed a real session, that test goes red rather than the user going quietly memoryless.I also left
exit 127alone deliberately. On such a rootlog.shcannot be sourced andsession-start-hook.shsays so with its own diagnostic instead of dying later on an undefined function — the documented contract toleratingrc in (0, 127), pinned intest_path_resolution.py. Suppressing a bash-level leak is not a licence to suppress the plugin's deliberate reporting, so the test asserts(0, 127)rather than demanding0.Scope
Part of #204, not
Closes. The code side of this issue is now complete — recursion fixed at both layers onmain, secondary leak fixed here — but the maintainer comments scope what remains as confirm on a current cache, and that is a delivery question this PR cannot settle: the nested summarizer loads the plugin from the marketplace cache, not from a checkout.Worth recording, though: the verification at the top of this PR did not need a refreshed cache. Driving the hook directly with the child's real environment sidesteps the cache entirely and answers the mechanism question — the marker propagates, both hooks fire,
CLAUDE_PROJECT_DIRis set from the sandbox cwd. What a rolled-forward cache would add is end-to-end confirmation, not new information about whether the guard works.Reported by @BlockX-P2P.