Skip to content

Run dies after the first iteration because of ((line_count++)) under set -e #5

Description

@tjdrabek

Took me a while to track this one down. ralph.sh runs with set -e, and display_final_summary in scripts/lib/output.sh bumps its counter with ((line_count++)). That form returns the value before the increment, so when line_count is 0 the arithmetic command exits 1 and set -e kills the whole script.

$ bash -c 'set -e; n=0; echo before; ((n++)); echo after'
before
$ echo $?
1

Net effect is the run dies partway through printing the first summary and never reaches iteration 2, no matter what you pass to -n. What you see:

─────────────────────────────────────────────────────────────────
Iteration Summary
─────────────────────────────────────────────────────────────────
Bash command=find .agent/screenshots -type f 2>&1
  📦 Stopping sandbox ralph-claude-...

Note the missing closing separator and no └── ✓ Iteration 1 complete. It exits 1, which is the same as EXIT_MAX_ITERATIONS, so at a glance it just looks like the run ended normally. That's what threw me for a while.

Both hits are in display_final_summary, lines 164 and 168. Swapping them for line_count=$((line_count + 1)) fixes it since assignment always returns 0.

preview.sh:70 also has an i++ but it's the for ((...)) form, where the status isn't propagated, so that one's fine.

Nothing Windows-specific here, should hit any bash.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions