Model behavior: agent-authored CI watcher script hangs forever when PR merge is rejected by strict branch protection
Environment
- Claude Code (agent SDK session), model
claude-fable-5 - Task: agent was orchestrating a PR pipeline via a background Bash script it authored: wait for CI checks →
gh pr merge→ wait for merge-commit checks → trigger deploy workflow.
What happened
The PR's CI passed, but between CI start and the merge attempt another PR was merged into main. The repo has strict branch protection ("Require branches to be up to date"), so gh pr merge failed with:
Pull request ... is not mergeable: the head branch is not up to date with the base branch.
The agent-authored script did not handle this failure path. It proceeded to the next step, read an empty merge-commit SHA (gh pr view --json mergeCommit on the still-open PR), and entered an infinite polling loop waiting for check-runs on that empty SHA — a condition that can never become true. To the user the background job simply looked hung, with no error surfaced, until they killed it manually.
Expected behavior
When the model writes long-running polling/orchestration scripts, it should treat every intermediate command as fallible: check gh pr merge's exit status/output, guard against empty SHAs before polling, and bound loops with a timeout or terminal condition so failure surfaces as an explicit error instead of a silent hang.
Notes
The model diagnosed and fixed its own script on the next turn (retry with gh pr update-branch on the "not up to date" case, bail out with a clear log after N attempts). Filing per the user's request as model-behavior feedback: the initial script generation lacked failure-path handling for a common race (strict branch protection + base advancing during CI).