fix: Handle API overload errors gracefully

- Detect Claude API 500 Overloaded errors
- Continue processing other files on error instead of aborting
- Log errors to stderr for visibility

This allows commits to succeed even if some AI requests fail due to rate limiting.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
rob 2025-10-31 10:15:48 -03:00
parent 429174f6e4
commit c231edcd82
2 changed files with 16 additions and 8 deletions

View File

@ -232,6 +232,9 @@ def call_model(model: ModelConfig, prompt: str, cwd: Path) -> str:
# Check if we got output even if returncode is non-zero
# (claude CLI returns 1 even on successful prompt responses)
if result.stdout.strip():
# Check for API errors in the output
if "API Error:" in result.stdout and "Overloaded" in result.stdout:
raise PatchGenerationError("Claude API is overloaded (500 error) - please retry later")
return result.stdout
# Only raise error if we got nothing useful

View File

@ -72,6 +72,7 @@ def process(repo_root: Path, rules: RulesConfig, model: ModelConfig) -> int:
final_instruction = merge_instructions(source_instruction, instruction, append)
try:
generate_output(
repo_root=repo_root,
rules=rules,
@ -80,6 +81,10 @@ def process(repo_root: Path, rules: RulesConfig, model: ModelConfig) -> int:
output_rel=output_rel,
instruction=final_instruction,
)
except Exception as e:
# Log error but continue processing other files
print(f"[runner] error generating {output_rel}: {e}", file=sys.stderr)
continue
return 0