From c231edcd82c932f5e6880d0beb9eb6f73253f082 Mon Sep 17 00:00:00 2001 From: rob Date: Fri, 31 Oct 2025 10:15:48 -0300 Subject: [PATCH] fix: Handle API overload errors gracefully MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- automation/patcher.py | 3 +++ automation/runner.py | 21 +++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/automation/patcher.py b/automation/patcher.py index 543fe21..f8fb3f2 100644 --- a/automation/patcher.py +++ b/automation/patcher.py @@ -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 diff --git a/automation/runner.py b/automation/runner.py index c859dbb..102e49a 100644 --- a/automation/runner.py +++ b/automation/runner.py @@ -72,14 +72,19 @@ def process(repo_root: Path, rules: RulesConfig, model: ModelConfig) -> int: final_instruction = merge_instructions(source_instruction, instruction, append) - generate_output( - repo_root=repo_root, - rules=rules, - model=model, - source_rel=src_rel, - output_rel=output_rel, - instruction=final_instruction, - ) + try: + generate_output( + repo_root=repo_root, + rules=rules, + model=model, + source_rel=src_rel, + 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