-
Notifications
You must be signed in to change notification settings - Fork 0
fix: make agent and review failure handling resilient #27
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2c0dd63
fix(setup): harden Claude and Codex CLI installers
niranjan94 3dc40e8
fix(review): classify all-reviewer infrastructure failures as errored
niranjan94 92ac0dd
chore(build): rebuild dist bundle
niranjan94 ad53a41
fix(review): read persisted error count in the pipeline router
niranjan94 7170c43
chore(build): rebuild dist bundle
niranjan94 15eb03a
fix(review): reset consecutive-error count on a clean approval
niranjan94 6842e61
chore(build): rebuild dist bundle
niranjan94 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,84 @@ | ||
| import { spawn } from "node:child_process"; | ||
|
|
||
| // Shared helpers for the native-CLI installers (Claude and Codex). Both pull a | ||
| // binary over the network on a CI runner, so both need transient-failure retry | ||
| // and diagnostics that surface the real cause instead of a bare exit code. | ||
|
|
||
| export interface RetryOptions { | ||
| attempts: number; | ||
| baseDelayMs: number; | ||
| sleep?: (ms: number) => Promise<void>; | ||
| onRetry?: (attempt: number, error: Error) => void; | ||
| } | ||
|
|
||
| function defaultSleep(ms: number): Promise<void> { | ||
| return new Promise((resolve) => setTimeout(resolve, ms)); | ||
| } | ||
|
|
||
| export async function retryWithBackoff<T>( | ||
| fn: (attempt: number) => Promise<T>, | ||
| opts: RetryOptions, | ||
| ): Promise<T> { | ||
| const sleep = opts.sleep ?? defaultSleep; | ||
| let lastError: Error | undefined; | ||
| for (let attempt = 1; attempt <= opts.attempts; attempt++) { | ||
| try { | ||
| return await fn(attempt); | ||
| } catch (err) { | ||
| lastError = err instanceof Error ? err : new Error(String(err)); | ||
| if (attempt < opts.attempts) { | ||
| opts.onRetry?.(attempt, lastError); | ||
| await sleep(opts.baseDelayMs * attempt); | ||
| } | ||
| } | ||
| } | ||
| throw lastError ?? new Error("retryWithBackoff: no attempts were made"); | ||
| } | ||
|
|
||
| // Installers stream their own progress, but a thrown Error that carries only | ||
| // the exit code surfaces as the opaque "exited with code 1". Append the tail of | ||
| // the captured output (e.g. "getaddrinfo ESERVFAIL downloads.claude.ai") so the | ||
| // real cause is visible wherever the error is reported, including the review | ||
| // lens failure summary. | ||
| export function formatInstallerError( | ||
| label: string, | ||
| code: number | null, | ||
| output: string, | ||
| ): string { | ||
| const base = `${label} exited with code ${code}`; | ||
| const tail = output | ||
| .trim() | ||
| .split(/\r?\n/) | ||
| .map((line) => line.trim()) | ||
| .filter(Boolean) | ||
| .slice(-5) | ||
| .join(" | "); | ||
| return tail ? `${base}: ${tail}` : base; | ||
| } | ||
|
|
||
| // Spawn a command, capturing stdout/stderr for diagnostics while still | ||
| // streaming it to the action log, and reject with a formatted error (carrying | ||
| // the captured tail) on a non-zero exit. | ||
| export function runCapturing( | ||
| command: string, | ||
| args: string[], | ||
| label: string, | ||
| ): Promise<void> { | ||
| return new Promise((resolve, reject) => { | ||
| const proc = spawn(command, args, { stdio: ["ignore", "pipe", "pipe"] }); | ||
| let output = ""; | ||
| proc.stdout?.on("data", (chunk: Buffer) => { | ||
| output += chunk.toString(); | ||
| process.stdout.write(chunk); | ||
| }); | ||
| proc.stderr?.on("data", (chunk: Buffer) => { | ||
| output += chunk.toString(); | ||
| process.stderr.write(chunk); | ||
| }); | ||
| proc.on("error", reject); | ||
| proc.on("close", (code) => { | ||
| if (code === 0) resolve(); | ||
| else reject(new Error(formatInstallerError(label, code, output))); | ||
| }); | ||
| }); | ||
| } |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[bug / confidence 88]
The consecutive-error escalation backstop is dead in the normal pipeline (non-reviewOnly) path.
errorCountreadsrouted.reviewErrorCount, but that field is only ever set byresolveReviewOnly(machine.ts:608). The pipeline review stage is routed byresolvePullRequestEvent(machine.ts:444-449 and 471-476), which setsreviewIterationbut neverreviewErrorCount, andparsePrMetadata(metadata.ts:29-35) parses only the iteration line — notShopfloor-Review-Error-Count.Execution trace (pipeline mode): errored run #1 →
routed.reviewErrorCountis undefined →errorCount = 0→aggregateFindingscomputeserrorCount = 0 + 1 = 1,escalate = false→apply.tspersistsShopfloor-Review-Error-Count: 1to the PR footer. Next push firessynchronize→resolveStagereturns a review decision with noreviewErrorCount→ run #2 again reads 0 → computes 1 → never reachesMAX_CONSECUTIVE_REVIEW_ERRORS.review-stuckis therefore never applied, so a persistent infrastructure failure spins silently forever — exactly the failure mode this PR claims to fix. (reviewOnly mode also never escalates, but that is intended.)Fix needs
parsePrMetadatato parse the error-count line and the pipeline review decisions to passreviewErrorCountthrough, mirroring howreviewIterationis wired.