Implement confirm-only PR panel composer with classified error blocking (#9428)
* Clarify PR panel guidance: classify errors and confirm-only composer Replace the ambiguous GitHub hosted-review boolean with a four-state evidence model (found/positive_unresolved/not_found/unknown) so "No PR found" never appears without an accepted lookup result. Classify GitHub refresh failures into types (rate_limited, auth, network, permission, repo_unavailable, gh_unavailable, unknown) for stable, honest copy. Confirmed-only composer: preserve drafts across transient failures; hide Create during hard errors and positive-unresolved evidence. Hard errors clear only when an eligibility request starts after the error and returns an accepted outcome. Propagate error types and unified retry schedule through the store. Sync mobile parity with shouldOpenChecksPanelCreateComposer gating. Localize all new copy. * Clarify PR panel guidance: classify errors and confirm-only composer Add reviewLookupOutcome to hosted-review eligibility and thread it through the panel so it never claims "No PR found" without accepted evidence. A failed lookup is unavailable, not a settled no-PR. Fail closed on positive unresolved evidence, hard refresh errors, and unavailable lookups. Add structured GitHub refresh-error classification with Retry-After parsing. Implement confirmed-only composer gating based on fresh, matching-context eligibility with hard-error clearing. Mobile gates on reviewLookupOutcome to prevent false Create claims. Surface throwOnFailure variants for each provider so transport failures cross the RPC boundary instead of collapsing to null. (Design success criteria 1–4; invariant 8.) * Add exec-error helpers for subprocess error classification Extracts stderr/stdout parsing and Retry-After detection into a lightweight module that can be imported without pulling in the heavier runner machinery. Supports PR-refresh error classification and proper rate-limit handling for gh commands. * test(mobile): include reviewLookupOutcome in create eligibility fixtures Create / Push & Create now fails closed unless the lookup is not_found. Update mobile test fixtures so accepted-no-PR cases can still proceed. * Add OrThrow mock variants to forge-provider test mocks forge-provider resolves branch reviews via the OrThrow variant so lookup failures surface as unavailable instead of "no PR found".
This commit is contained in:
+20
-47
@@ -39,6 +39,10 @@ import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
||||
import { join } from 'node:path'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { sliceCheckLogTail } from './check-job-log-tail-slice'
|
||||
import {
|
||||
classifyPRRefreshError,
|
||||
safePRRefreshErrorMessage
|
||||
} from './pr-refresh-error-classification'
|
||||
import { getPRConflictSummary } from './conflict-summary'
|
||||
import { getSshFilesystemProvider } from '../providers/ssh-filesystem-dispatch'
|
||||
import { joinWorktreeRelativePath } from '../runtime/runtime-relative-paths'
|
||||
@@ -47,7 +51,6 @@ import {
|
||||
execFileAsync,
|
||||
ghExecFileAsync,
|
||||
gitExecFileAsync,
|
||||
extractExecError,
|
||||
acquire,
|
||||
release,
|
||||
getOwnerRepo,
|
||||
@@ -63,6 +66,9 @@ import {
|
||||
type LocalGitExecOptions,
|
||||
type OwnerRepo
|
||||
} from './gh-utils'
|
||||
// Import the pure error-parsing helpers from the lightweight module, not
|
||||
// `./gh-utils`, so tests that mock gh-utils still resolve the real functions.
|
||||
import { extractExecError, parseRetryAfterMs } from '../git/exec-error'
|
||||
import {
|
||||
isCommitPartOfMergedPR,
|
||||
type MergedPRCommitMembership
|
||||
@@ -181,61 +187,28 @@ async function assertRateLimitBudget(bucket: RateLimitBucketKind): Promise<void>
|
||||
}
|
||||
}
|
||||
|
||||
function classifyPRRefreshError(
|
||||
err: unknown
|
||||
): Extract<PRRefreshOutcome, { kind: 'upstream-error' }>['errorType'] {
|
||||
const message = err instanceof Error ? err.message : String(err)
|
||||
// Why: GitHub-unreachable buckets (5xx outage / network / rate limit) share
|
||||
// one detector with the Tasks work-item path so both surfaces attribute an
|
||||
// outage to GitHub identically. Rate-limit responses also carry "HTTP 403",
|
||||
// so this must run before the permission check below.
|
||||
const unavailable = classifyGitHubUnavailable(message)
|
||||
if (unavailable) {
|
||||
return unavailable
|
||||
}
|
||||
const lower = message.toLowerCase()
|
||||
if (lower.includes('http 403') || lower.includes('resource not accessible')) {
|
||||
return 'permission'
|
||||
}
|
||||
if (lower.includes('http 404') || lower.includes('could not resolve to a repository')) {
|
||||
return 'repo_unavailable'
|
||||
}
|
||||
return /auth|login|credential/i.test(message) ? 'auth' : 'unknown'
|
||||
}
|
||||
|
||||
function safePRRefreshErrorMessage(
|
||||
errorType: Extract<PRRefreshOutcome, { kind: 'upstream-error' }>['errorType']
|
||||
): string {
|
||||
switch (errorType) {
|
||||
case 'rate_limited':
|
||||
return 'GitHub rate limit is low. Try again after the limit resets.'
|
||||
case 'auth':
|
||||
return 'GitHub authentication is unavailable. Check your gh login.'
|
||||
case 'network':
|
||||
return 'GitHub is unreachable right now. Check your network and try again.'
|
||||
case 'server_error':
|
||||
return "GitHub's API is temporarily unavailable (server error). This is a GitHub-side issue."
|
||||
case 'permission':
|
||||
return 'GitHub did not allow access to this pull request.'
|
||||
case 'repo_unavailable':
|
||||
return 'The GitHub repository is unavailable or cannot be resolved.'
|
||||
case 'gh_unavailable':
|
||||
return 'GitHub CLI is unavailable.'
|
||||
case 'unknown':
|
||||
return 'GitHub pull request refresh failed.'
|
||||
}
|
||||
}
|
||||
|
||||
function prRefreshUpstreamError(
|
||||
err: unknown
|
||||
): Extract<PRRefreshOutcome, { kind: 'upstream-error' }> {
|
||||
const errorType = classifyPRRefreshError(err)
|
||||
return {
|
||||
const outcome: Extract<PRRefreshOutcome, { kind: 'upstream-error' }> = {
|
||||
kind: 'upstream-error',
|
||||
errorType,
|
||||
message: safePRRefreshErrorMessage(errorType),
|
||||
fetchedAt: Date.now()
|
||||
}
|
||||
// Why: a rate limit that carries a Retry-After is a real cooldown — surface it
|
||||
// as the retry schedule so the renderer disables manual Retry until the reset
|
||||
// and shows a truthful auto-retry time, instead of retrying into another 429.
|
||||
if (errorType === 'rate_limited') {
|
||||
const retryAfterMs = parseRetryAfterMs(extractExecError(err).stderr)
|
||||
if (retryAfterMs !== null && retryAfterMs > 0) {
|
||||
const retryAt = Date.now() + retryAfterMs
|
||||
outcome.nextAutoRetryAt = retryAt
|
||||
outcome.retryDisabledUntil = retryAt
|
||||
}
|
||||
}
|
||||
return outcome
|
||||
}
|
||||
|
||||
function isNoPullRequestError(err: unknown): boolean {
|
||||
|
||||
Reference in New Issue
Block a user