Repository navigation
fix: don't crash the nested Haiku session on unresolvable project root - #137
Conversation
|
Thanks for this — the diagnosis is right and the comments you added to I checked the thing most likely to break with this change: callers that relied on the sourced Two things before this goes in: 1. It changes failure semantics for three hooks and adds no test. The natural one: run each hook with 2. The failure is now quiet in the place it's most likely to happen. For the nested-session case you're fixing, silent is exactly right. For a real project it's a regression in observability. Would you consider distinguishing the two — e.g. no-op silently when Happy to merge once there's a test; the rest is solid. Reviewed by Max (AI dev partner at Digital Process Tools) — happy to answer follow-ups here. |
|
Follow-up: I approved the workflow run (outside-contributor PRs on this repo sit at
So this isn't a matter of updating a stale assertion — it surfaces the actual design question:
A middle path that keeps both properties: have Whichever direction you prefer, the tests need to change deliberately as part of this PR rather than as a follow-up, since they're the written record of the old contract. One more thing worth separating: a nested Reviewed by Max (AI dev partner at Digital Process Tools) — happy to answer follow-ups here. |
haiku.py's call_haiku() spawns a nested `claude -p` process to summarize each save. Because plugins are installed globally, that nested session also loads this plugin and fires its own SessionStart (and, if it ever uses a tool, PostToolUse) hook — an unintended recursive activation. That nested session runs with cwd=tempdir and no real project, so CLAUDE_PROJECT_DIR is unset for it. resolve-paths.sh correctly detects it can't guess a project root from a marketplace-cache layout, but signals that with a bare `exit 1` inside a script that is always `source`d. Since `exit` inside a sourced script terminates the *caller's* whole process, this killed session-start-hook.sh outright — even though its own docs promise "EXIT CODES: 0 Always (hook must not block session startup)". Claude Code then reports the whole nested `claude -p` invocation as failed, which call_haiku() surfaces as "claude exited 1", so the outer save silently never reaches now.md. Fix: resolve-paths.sh now signals failure via `return 1` (correct for a sourced library) instead of `exit 1`. The three hook entrypoints that are documented to never block the host session (session-start-hook.sh, post-tool-hook.sh, user-prompt-hook.sh) now guard the source call with `|| exit 0`, matching their own contract. save-session.sh and run-consolidation.sh need no change — they already run under `set -e`, so a failed `return 1` still correctly aborts them.
Reconciles Digital-Process-Tools#137 with the five tests in test_path_resolution.py that encode the "a sourced resolve-paths.sh must always fail loud" contract. Switching every failure to `return 1` fixed the hook crash but made the contract opt-in: a caller without `set -e` or an explicit guard now sails past a failed resolution and continues with empty PROJECT_DIR/PIPELINE_DIR — the silent write-to-the-wrong-directory class we just fixed in Digital-Process-Tools#138. The probe wrappers in the test suite are exactly such a caller, which is why they went red. Invert the default instead. resolve-paths.sh exits the caller on failure as it always did; a caller that must never take its host process down sets REMEMBER_PATHS_SOFT_FAIL=1 and gets `return 1` to handle itself. Only the three hooks opt in — they are the ones documented "EXIT CODES: 0 Always", and the nested Haiku session is the caller that was crashing. Two of the five tests now pass untouched (the contract they pin is intact). The other three asserted that hooks must exit non-zero, which is precisely what this PR changes: they now assert hooks exit 0, emit nothing, and still report FATAL on stderr for the hooks.json redirect to capture. Co-Authored-By: Max <noreply>
a21b421 to
b037a7f
Compare
|
Thanks for this — the diagnosis is exactly right, and it's a good catch. A bare Rather than send it back for a round trip, I pushed a commit onto your branch (maintainer edits were on) and rebased it on current main. Two things it changes: 1. Five existing tests in 2. So the default is inverted instead of relaxed. Two of the five tests went green untouched after that (the contract they pin is intact). The other three genuinely needed updating — they asserted hooks exit non-zero, which is the thing your PR fixes; they now assert the hooks exit 0, emit nothing, and still print FATAL to stderr so the 12/12 green across the matrix. Merging now, shipping in the next release — your commit and authorship stay on it. One note for next time: run Nice work — genuinely useful fix. — Max |
Summary
haiku.py'scall_haiku()spawns a nestedclaude -pprocess to summarize each save. Since plugins are installed globally, that nested session also loads this plugin and fires its ownSessionStarthook — an unintended recursive activation.cwd=tempdirand no real project, soCLAUDE_PROJECT_DIRis unset for it.resolve-paths.shcorrectly detects it can't guess a project root from a marketplace-cache layout, but signals that with a bareexit 1inside a script that is alwayssourced — which kills the caller's whole process, even thoughsession-start-hook.shdocuments "EXIT CODES: 0 Always (hook must not block session startup)".claude -pinvocation as failed, whichcall_haiku()surfaces asclaude exited 1, so the outer save silently never reachesnow.md.Fix
resolve-paths.shnow signals failure viareturn 1(correct for a sourced library) instead ofexit 1.session-start-hook.sh,post-tool-hook.sh,user-prompt-hook.sh— the three entrypoints documented to never block the host session — now guard the source call with|| exit 0, matching their own contract.save-session.sh/run-consolidation.shneeded no change: they already run underset -e, so a failedreturn 1still correctly aborts them.Test plan
CLAUDE_PROJECT_DIRunset in the nested hook context, confirmed[resolve] FATAL+claude exited 1in logs.source resolve-paths.shnow returns 1 without killing the sourcing shell.session-start-hook.shexits 0 cleanly instead of crashing when project root can't be resolved.save-session.sh --forceend-to-end after the fix: no more[resolve] FATAL, Haiku call succeeds,now.mdgets a real appended entry.