-
Notifications
You must be signed in to change notification settings - Fork 0
fix: Cap fix retries and classify failures instead of retrying forever #13
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
Open
Senna46
wants to merge
2
commits into
main
Choose a base branch
from
fix/retry-policy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // Classifies fix-generation failures so the daemon can decide whether | ||
| // retrying is worth another full fix generation. | ||
| // permanent — the same run will fail the same way (push rejected by a | ||
| // branch rule, missing token scope). Give up immediately. | ||
| // transient — an outage unrelated to the bug (usage limit, expired auth, | ||
| // network). Retry later without spending a retry attempt. | ||
| // retryable — anything else. Retry, but count it against the cap. | ||
|
|
||
| export type FailureKind = "permanent" | "transient" | "retryable"; | ||
|
|
||
| export interface FailureClassification { | ||
| kind: FailureKind; | ||
| // Short human-readable cause, used in logs and the PR comment. | ||
| reason: string; | ||
| } | ||
|
|
||
| const PERMANENT_PATTERNS: Array<{ pattern: RegExp; reason: string }> = [ | ||
| { | ||
| pattern: /without .?workflow.? scope/i, | ||
| reason: "The push token lacks the `workflow` scope required to update .github/workflows files.", | ||
| }, | ||
| { | ||
| pattern: /protected branch|GH006|pre-receive hook declined/i, | ||
| reason: "The PR head branch rejects pushes (branch protection or a pre-receive hook).", | ||
| }, | ||
| { | ||
| pattern: /permission to .+ denied|403 Forbidden/i, | ||
| reason: "The push credentials are not allowed to write to this repository.", | ||
| }, | ||
| { | ||
| pattern: /remote rejected|refusing to allow/i, | ||
| reason: "GitHub rejected the push to the PR head branch.", | ||
| }, | ||
| ]; | ||
|
|
||
| const TRANSIENT_PATTERNS: Array<{ pattern: RegExp; reason: string }> = [ | ||
| { | ||
| pattern: /hit your limit|usage limit|rate limit|\b429\b/i, | ||
| reason: "Claude usage limit reached.", | ||
| }, | ||
| { | ||
| // Bad push credentials break every repo at once, so this must not be | ||
| // treated as a per-bug fault: it would abandon unrelated bugs and post | ||
| // give-up comments everywhere while the token is being rotated. | ||
| pattern: | ||
| /invalid username or token|authentication failed for|could not read Username/i, | ||
| reason: "The git push token is invalid or expired (AUTOFIX_PUSH_TOKEN).", | ||
| }, | ||
| { | ||
| pattern: | ||
| /oauth (?:access )?(?:token|session) (?:has )?expired|invalid authentication credentials|\b401\b/i, | ||
| reason: "Claude authentication expired or was rejected.", | ||
| }, | ||
| { | ||
| pattern: | ||
| /ECONNRESET|ETIMEDOUT|ENOTFOUND|EADDRNOTAVAIL|EAI_AGAIN|socket hang up|\b50[234]\b/i, | ||
| reason: "Network or upstream service error.", | ||
| }, | ||
| ]; | ||
|
|
||
| export function classifyFailure(message: string): FailureClassification { | ||
| for (const { pattern, reason } of PERMANENT_PATTERNS) { | ||
| if (pattern.test(message)) return { kind: "permanent", reason }; | ||
| } | ||
|
|
||
| for (const { pattern, reason } of TRANSIENT_PATTERNS) { | ||
| if (pattern.test(message)) return { kind: "transient", reason }; | ||
| } | ||
|
|
||
| return { kind: "retryable", reason: "Fix generation failed." }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.