Skip to content

Commit 9cb7362

Browse files
LeeCampbellclaude
andcommitted
fix: recover agent state on timeout instead of losing progress
When Claude timed out (exit 124), `set -euo pipefail` in agent-loop.sh prevented sync_state from running, so all work from that iteration was lost. Additionally, entrypoint.sh treated timeout as fatal and broke the loop, preventing any retry. Now run_claude captures the timeout exit code so sync_state always runs to preserve progress, and entrypoint.sh continues the loop on timeout so the next iteration can pick up where the previous one left off. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e7257c6 commit 9cb7362

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

autonomous/agent-loop.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ sync_state() {
5757
fi
5858
}
5959

60+
CLAUDE_RC=0
61+
6062
run_claude() {
6163
local prompt="$1"
6264
timeout "$CLAUDE_TIMEOUT" claude --dangerously-skip-permissions --print \
63-
--output-format stream-json --verbose "$prompt"
65+
--output-format stream-json --verbose "$prompt" || CLAUDE_RC=$?
6466
}
6567

6668
load_prompt() {
@@ -288,3 +290,5 @@ EOF
288290
fi
289291
;;
290292
esac
293+
294+
exit $CLAUDE_RC

autonomous/entrypoint.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ echo "Building..."
2727
dotnet build --no-restore
2828

2929
# ── Run the agent ──
30-
MAX_ITERATIONS="${MAX_ITERATIONS:-10}"
30+
MAX_ITERATIONS="${MAX_ITERATIONS:-30}"
3131
COOLDOWN="${COOLDOWN_SECONDS:-30}"
3232
export CLAUDE_TIMEOUT="${TIMEOUT_SECONDS:-1800}"
3333

@@ -39,9 +39,11 @@ for i in $(seq 1 "$MAX_ITERATIONS"); do
3939
EXIT_CODE=0
4040
bash /usr/local/bin/agent-loop.sh || EXIT_CODE=$?
4141

42-
if [ "$EXIT_CODE" -ne 0 ]; then
42+
if [ "$EXIT_CODE" -ne 0 ] && [ "$EXIT_CODE" -ne 124 ]; then
4343
echo "Iteration $i failed with exit code $EXIT_CODE"
4444
break
45+
elif [ "$EXIT_CODE" -eq 124 ]; then
46+
echo "Iteration $i timed out (exit code 124), continuing..."
4547
fi
4648

4749
# Done?

0 commit comments

Comments
 (0)