-
Notifications
You must be signed in to change notification settings - Fork 42
feat(automation): add retry logic for GitHub API label addition in Amber workflow #388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(automation): add retry logic for GitHub API label addition in Amber workflow #388
Conversation
…ber workflow Add exponential backoff retry pattern to harden PR label addition against transient GitHub API failures (HTTP 500 errors, JSON parse errors). - Add retryWithBackoff() helper function (3 attempts, 1s/2s/4s delays) - Wrap github.rest.issues.addLabels() with retry logic - Only retry on retriable errors (5xx, JSON), fail fast on client errors - Log retry attempts for debugging Fixes intermittent 'Unexpected end of JSON input, status: 500' errors during PR creation workflow. 🤖 Generated with Claude Code (https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
Improvements based on automated review: 1. Enhanced retry detection to handle network errors - Now retries on: !error.status (network errors), 5xx errors - Simplified logic: assume all errors retriable except 4xx 2. Added error details to retry logs - Include error status and message in console output - Format: 'Attempt N failed (status: message), retrying in Xms...' 3. Added explicit final throw for defensive coding - Prevents unreachable code path (should never occur) - Makes function behavior crystal clear Addresses review feedback from Claude Code Review on PR ambient-code#388 🤖 Generated with Claude Code (https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Review Feedback Addressed ✅I've addressed the high-priority feedback from the automated code review: 1. Enhanced Retry Detection for Network ErrorsBefore: const isRetriable = error.status >= 500 || error.message.includes('JSON');After: // Retry on: network errors (undefined status), 5xx errors, or specific error patterns
const isRetriable = \!error.status || error.status >= 500;Why: Network errors (timeouts, connection resets, DNS failures) don't have a 2. Added Error Details to LogsBefore: console.log(`Attempt ${i + 1} failed, retrying in ${delay}ms...`);After: const errorMsg = error.message || 'Unknown error';
const errorStatus = error.status || 'network error';
console.log(`Attempt ${i + 1} failed (${errorStatus}: ${errorMsg}), retrying in ${delay}ms...`);Why: Debugging is much easier when you can see exactly what error occurred on each retry attempt. 3. Added Explicit Final ThrowAfter the loop: // Defensive: Should never reach here due to throw in loop, but explicit for clarity
throw new Error('retryWithBackoff: max retries exceeded');Why: Makes the function's contract crystal clear and prevents unreachable code paths. These changes make the retry logic more robust against network failures while improving debuggability. Ready for re-review! 🚀 |
Claude Code ReviewSummaryThis PR implements a robust retry mechanism with exponential backoff to handle transient GitHub API failures when adding labels to PRs in the Amber workflow. The implementation has been iterated based on previous review feedback and now includes comprehensive error handling for network failures, detailed logging, and defensive coding practices. Overall Assessment: ✅ APPROVED WITH CONFIDENCE - This is production-ready defensive code that addresses a real issue with minimal risk. Issues by SeverityNo blocking, critical, or major issues found. All previous concerns have been addressed. 🔵 Minor Issues1. Retry Logic Could Be Applied to Other GitHub API Calls The workflow makes several other GitHub API calls that could benefit from the same retry logic:
Impact: Low - These are in error handling paths or less critical flows. Label addition was the observed failure point. Recommendation: Consider wrapping the PR creation call (line 352) with retry logic in a future enhancement, as it's the most critical operation. Comment additions are less critical but could be hardened as well. Reference: Lines 258, 298, 352, 396, 409, 434. 2. Retry Helper Function Is Duplicated in Workflow The Impact: Very Low - Currently only used in one place, and GitHub Actions doesn't have great patterns for sharing JavaScript code between workflows. Recommendation: Document this as a reusable pattern if other workflows need similar reliability. For now, keeping it inline is pragmatic. 3. Max Retries Constant Is Embedded The function signature has Impact: Very Low - The default is sensible (3 retries = 1s + 2s + 4s = 7s total max delay). Recommendation: Consider adding a comment explaining why 3 retries was chosen (based on typical transient API failure patterns). Reference: Line 326. Positive Highlights✅ Addresses Real Production Issue - Directly solves the transient API failure observed in PR #387 ( ✅ Comprehensive Error Handling - Now handles:
✅ Excellent Retry Strategy - Exponential backoff with sensible defaults:
✅ Detailed Logging - Retry attempts include error status and message for debugging ✅ Defensive Coding - Explicit final throw ensures no unreachable code paths ✅ Minimal Scope - Only touches the label addition logic, reducing risk ✅ Well-Documented - Inline comments explain retry strategy and rationale ✅ Follows Repository Patterns - Similar to retry logic in:
✅ No Security Concerns - No user input, no credential handling, no injection risks ✅ No Performance Impact - Only adds latency on failure (which already fails the workflow) ✅ Iterative Improvement - Author addressed all previous review feedback comprehensively RecommendationsBefore Merge (Optional)
Future Enhancements (Not This PR)
Code Quality Assessment
Architecture & Design NotesPattern Alignment:
The workflow implementation uses the same exponential backoff formula ( Why This Approach:
Test Plan ValidationFrom PR description:
Recommendation: The next Amber workflow run will validate this in production. Consider manually triggering a test issue with the Final VerdictThis PR represents high-quality defensive programming that:
The code is production-ready and ready to merge. 🚀 The only suggestions are minor documentation enhancements and future considerations for applying this pattern more broadly. 🤖 Generated by Claude Code Review |
Summary
Add exponential backoff retry pattern to harden PR label addition against transient GitHub API failures.
Problem
Amber workflow occasionally fails with
RequestError [HttpError]: Unexpected end of JSON input, status: 500when adding labels to PRs. This is a transient GitHub API error that should be retried.Solution
retryWithBackoff()helper function with exponential backoffTest Plan
Changes
.github/workflows/amber-issue-handler.yml:References
🤖 Generated with Claude Code (https://claude.com/claude-code)