fix(ralph-wiggum): restore dead error handlers broken by set -euo pipefail#66573
Open
sridhar-3009 wants to merge 1 commit into
Open
fix(ralph-wiggum): restore dead error handlers broken by set -euo pipefail#66573sridhar-3009 wants to merge 1 commit into
sridhar-3009 wants to merge 1 commit into
Conversation
…efail
With `set -euo pipefail` active, two patterns in stop-hook.sh silently
exit the process before reaching the error-handling code:
1. `ITERATION=$(... | grep '^iteration:' | sed ...)` — with pipefail,
a grep no-match (exit 1) propagates as the pipeline exit code, so
the script exits immediately if any frontmatter field is absent from
the state file. The corruption-detection guards on lines 28–48 can
never be reached in that case, and the state file is left behind,
causing the loop to silently fail on every subsequent turn.
Fix: append `|| true` to each frontmatter-field extraction so a
missing field evaluates to an empty string rather than exiting.
The existing `[[ ! "$FIELD" =~ ^[0-9]+$ ]]` guards then handle
the empty-string case correctly.
2. `LAST_OUTPUT=$(... | jq ... 2>&1)` followed by `if [[ $? -ne 0 ]]`
— set -e exits the script when jq fails before $? can be checked,
leaving the state file un-cleaned and the loop stuck.
Fix: replace the separate `if [[ $? -ne 0 ]]` block with an inline
`|| { ... exit 0; }` so the error branch is reachable on jq failure.
$LAST_OUTPUT contains jq's stderr (via 2>&1) and is already set when
the || block executes, so the diagnostic message is preserved.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This was referenced Jun 9, 2026
stevei101
approved these changes
Jun 10, 2026
stevei101
left a comment
There was a problem hiding this comment.
Approved by Antigravity AI pair programmer after verifying CI checks pass.
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
stop-hook.shsetsset -euo pipefailon line 7, but two patterns in the script silently exit the process before reaching their own error-handling code.1. Frontmatter field extraction (lines 21–25)
ITERATION=$(echo "$FRONTMATTER" | grep '^iteration:' | sed 's/iteration: *//')With
pipefail, agrepno-match (exit 1) propagates as the pipeline exit code.set -ethen exits the whole script immediately if any frontmatter field is absent from the state file (e.g. due to corruption or manual editing).The corruption-detection guards on lines 28–48 can never be reached in that scenario, so the state file is left behind and the loop silently fails on every subsequent turn instead of cleaning up and stopping.
2. jq JSON parsing (lines 90–105)
If
jqfails (malformed transcript JSON),set -eexits the script before$?is ever checked. The state file is not cleaned up, and the loop remains stuck.Fix
Frontmatter extraction — append
|| trueto each pipeline so a missing field evaluates to an empty string rather than triggeringset -e. The existing[[ ! "$FIELD" =~ ^[0-9]+$ ]]guards then handle the empty-string case correctly.jq parsing — replace the separate
if [[ $? -ne 0 ]]block with an inline|| { ... exit 0; }.$LAST_OUTPUTis already set (via2>&1) when the||block executes, preserving the diagnostic message.Testing
bash -n stop-hook.shpasses. Manually verified the three scenarios:iteration:field in state file → corruption message printed, state file removed, hook exits 0jq→ parse-error message printed, state file removed, hook exits 0