fix(ralph-wiggum): make stop hook's jq error handling reachable under set -e#77443
Open
Yigtwxx wants to merge 1 commit into
Open
fix(ralph-wiggum): make stop hook's jq error handling reachable under set -e#77443Yigtwxx wants to merge 1 commit into
Yigtwxx wants to merge 1 commit into
Conversation
The stop hook runs with set -euo pipefail. When jq failed to parse the last transcript line, the LAST_OUTPUT assignment itself exited nonzero and set -e aborted the script right there, so the recovery branch below (friendly message, state-file cleanup, exit 0) never ran and the loop state file was left behind. Guard the assignment with '|| JQ_EXIT=$?' so the existing error branch executes.
This was referenced Jul 14, 2026
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.
Problem
plugins/ralph-wiggum/hooks/stop-hook.shruns underset -euo pipefailand parses the last assistant transcript line with:A plain
VAR=$(cmd)assignment takescmd's exit status, so if jq fails to parse (malformed/truncated transcript line),set -eaborts the script at the assignment — the$?check and the whole recovery branch below it are unreachable. Instead of the designed graceful stop (message to the user,.claude/ralph-loop.local.mdcleaned up,exit 0), the hook dies with an unhandled nonzero exit and leaves the loop state file behind.Fix
Guard the assignment so the failure is captured instead of fatal:
Behavior is otherwise identical:
2>&1still captures jq's error text intoLAST_OUTPUTfor the diagnostic message.Verification
bash -npasses.set -euo pipefail: with the guard, a failing command substitution reaches the error branch with the right exit code; without it, the shell exits at the assignment.