diff --git a/packages/shared/src/types/execution-projection.ts b/packages/shared/src/types/execution-projection.ts index 7a4b8567cb1..b336d357005 100644 --- a/packages/shared/src/types/execution-projection.ts +++ b/packages/shared/src/types/execution-projection.ts @@ -165,13 +165,14 @@ export interface TaskInterruptionPresentation { nextRetryAt: string | null; canRetry: boolean; retryAction?: "move_forward"; - userAction: "approval" | "reconnect" | "assign_agent" | "choose_model" | "resume" | "budget" | "project_access" + userAction: "approval" | "reconnect" | "assign_agent" | "choose_model" | "resume" | "budget" | "project_access" | "connect_github" /** Board confirms that a previous server, which can no longer report, stopped its workspace copyback. */ | "confirm_owner_stop" /** Board confirms that a run whose server restarted before it recorded the agent's process has stopped. */ | "confirm_run_stopped" | null; /** Only the task's own project id is exposed. Other source projects stay unnamed. */ projectAccess?: { agentId: string; projectId: string | null; ready: boolean }; + githubAccess?: "github_auth_required" | "github_repo_not_accessible"; sourceRunIds: string[]; observedRunId: string | null; /** The saved-work recovery step that must finish before the task continues. */ diff --git a/server/src/services/heartbeat/run-completion.test.ts b/server/src/services/heartbeat/run-completion.test.ts index fb4cbeefc52..7ccdf56ea9e 100644 --- a/server/src/services/heartbeat/run-completion.test.ts +++ b/server/src/services/heartbeat/run-completion.test.ts @@ -26,6 +26,7 @@ import { UnresolvedWorkspaceBaseRefError } from "../workspace-runtime.js"; import { LegacyControllerLeaseLostError } from "../legacy-controller-lease.js"; import { requestedRunCancellation } from "../run-cancellation.js"; import { ProjectAccessDeniedError } from "../project-access-denial.js"; +import { isSystemOwnedFailureCode } from "../continuation-cause.js"; import { RemoteWorkspaceOperationError, RemoteWorkspaceOperationTimeoutError, RemoteWorkspacePreparationTimeoutError, RemoteWorkspaceRestoreError } from "../remote-workspace-transport.js"; import { EnvironmentRunError, environmentRunOrchestrator } from "../environment-run-orchestrator.js"; import { ReusableSandboxResumeError } from "../reusable-sandbox-resume-error.js"; @@ -1131,6 +1132,32 @@ describe.skipIf(!support.supported && !process.env.PAPERCLIP_TEST_DATABASE_URL)( expect(f.deps.finalizeIssueCommentPolicy).not.toHaveBeenCalled(); }); + it.each([ + ["auth_failed", "github_auth_required"], + ["repository_not_found", "github_repo_not_accessible"], + ] as const)("names a clone that GitHub refused with git=%s as %s and does not retry it", async (git, errorCode) => { + const f = await fixture(); + const error = new RemoteWorkspaceOperationError( + `remote_workspace_operation_failed: operation=prepare exit=1; remote_workspace_prepare_failed: stage=clone git=${git} exit=128 program=git`); + await f.completion.failRunSetup(f.setup(error)); + const failed = await read(f.run.id); + expect(failed).toMatchObject({ status: "failed", errorCode, + resultJson: { executionRecovery: { kind: "bootstrap", providerWorkStarted: false } } }); + expect(isSystemOwnedFailureCode(failed.errorCode)).toBe(false); + expect(f.deps.scheduleBoundedRetryForRun).not.toHaveBeenCalled(); + expect(f.deps.enqueueWakeup).not.toHaveBeenCalled(); + }); + + it.each([ + new RemoteWorkspaceOperationError("remote_workspace_operation_failed: operation=prepare exit=1; remote_workspace_prepare_failed: stage=clone git=network exit=128 program=git"), + new RemoteWorkspaceOperationError("remote_workspace_operation_failed: operation=prepare exit=1; remote_workspace_prepare_failed: stage=fetch git=auth_failed exit=128 program=git"), + new Error("remote_workspace_operation_failed: operation=prepare exit=1; remote_workspace_prepare_failed: stage=clone git=auth_failed exit=128 program=git"), + ])("keeps another or untrusted workspace failure a generic setup failure: %s", async error => { + const f = await fixture(); + await f.completion.failRunSetup(f.setup(error)); + expect(await read(f.run.id)).toMatchObject({ status: "failed", errorCode: "setup_failed" }); + }); + it("records a setup configuration gap without inventing provider work or applying comment policy", async () => { const f = await fixture(); await f.completion.failRunSetup(f.setup(new ConfigurationIncompleteFailure("missing credential", { configurationIncomplete: { reason: "missing_binding" } }))); diff --git a/server/src/services/heartbeat/run-completion.ts b/server/src/services/heartbeat/run-completion.ts index 87f95c21daf..278570856b2 100644 --- a/server/src/services/heartbeat/run-completion.ts +++ b/server/src/services/heartbeat/run-completion.ts @@ -18,7 +18,7 @@ import { pendingCaseHandoffForRun } from "./case-handoff-lifecycle.js"; import { NON_RETRYABLE_PREFLIGHT_FAILURE_CODES, isHeartbeatRunTerminalStatus } from "./run-lifecycle.js"; import { ChatControlRecoveryUnresolvedError } from "./queue.js"; import { readTransientRecoveryContractFromRun, readHeartbeatRunErrorFamily, isTransientWorkspacePreparationCode } from "./retries.js"; -import { RemoteWorkspacePreparationTimeoutError, REMOTE_WORKSPACE_RESTORE_FAILED_CODE, findRemoteWorkspaceRestoreError } from "../remote-workspace-transport.js"; +import { RemoteWorkspacePreparationTimeoutError, REMOTE_WORKSPACE_RESTORE_FAILED_CODE, findRemoteWorkspaceCloneAccessFailure, findRemoteWorkspaceRestoreError } from "../remote-workspace-transport.js"; import { escalateRemoteWorkspaceRestoreFailure } from "../remote-workspace-restore-recovery.js"; import { findReusableSandboxResumeError } from "../reusable-sandbox-resume-error.js"; import { findPluginWorkerUnavailableError, PLUGIN_WORKER_UNAVAILABLE_CODE } from "../plugin-worker-unavailable-error.js"; @@ -1690,6 +1690,7 @@ export function createHeartbeatRunCompletion(db: Db, dependencies: HeartbeatRunC : null) ?? recordedResponsibleUserDenialCode ?? nonRetryablePreflightCode ?? + findRemoteWorkspaceCloneAccessFailure(outerErr) ?? "setup_failed"; const failureCause = GENERIC_RUN_FAILURE_CODES.has(setupFailureErrorCode) ? thrownFailureCause : null; // Bounded kind and reason only: a workspace provider's own text never crosses into Core. diff --git a/server/src/services/remote-workspace-transport.ts b/server/src/services/remote-workspace-transport.ts index 8e80375eecb..56dc74b21b8 100644 --- a/server/src/services/remote-workspace-transport.ts +++ b/server/src/services/remote-workspace-transport.ts @@ -153,6 +153,17 @@ export function findRemoteWorkspaceRestoreError(error: unknown): RemoteWorkspace return null; } +const CLONE_ACCESS_FAILURE = /; remote_workspace_(?:prepare|repository)_failed: stage=clone(?: [a-z_]+=[A-Za-z0-9_]+)*? git=(auth_failed|repository_not_found)(?: |$)/; + +export function findRemoteWorkspaceCloneAccessFailure(error: unknown): "github_auth_required" | "github_repo_not_accessible" | null { + for (let cause = error, depth = 0; cause && depth < 4; cause = (cause as { cause?: unknown }).cause, depth++) { + if (!(cause instanceof RemoteWorkspaceOperationError)) continue; + const git = CLONE_ACCESS_FAILURE.exec(remoteWorkspaceFailureCause(cause) ?? "")?.[1]; + if (git) return git === "auth_failed" ? "github_auth_required" : "github_repo_not_accessible"; + } + return null; +} + const TRANSPORT_FAILURE_LABELS: Array<[RegExp, string]> = [ [/daytona_sandbox_not_found/i, "daytona_sandbox_not_found"], [/sandbox lease \S+ is no longer active/i, "sandbox_lease_inactive"], diff --git a/server/src/services/task-interruption-presentation.test.ts b/server/src/services/task-interruption-presentation.test.ts index 4a8bd737803..3af6037253a 100644 --- a/server/src/services/task-interruption-presentation.test.ts +++ b/server/src/services/task-interruption-presentation.test.ts @@ -595,3 +595,20 @@ describe("hand-off of a run that failed before any provider work", () => { .toMatchObject({ state: "failed", canRetry: true }); }); }); + +describe("task GitHub access interruption", () => { + it.each(["github_auth_required", "github_repo_not_accessible"] as const)("asks the person to fix the GitHub connection for %s, keeping Retry", errorCode => { + const failed = { ...run, errorCode, resultJson: { executionRecovery: { kind: "bootstrap", providerWorkStarted: false } } }; + expect(projectTaskInterruption(issue, { run: failed, agent, paused: false, approval: false })).toMatchObject({ + state: "waiting_for_user", responsibility: "user", userAction: "connect_github", canRetry: true, githubAccess: errorCode, + }); + }); + + it("shows an accepted Retry as working and keeps a generic setup failure generic", () => { + const failed = { ...run, errorCode: "github_auth_required", resultJson: null }; + expect(projectTaskInterruption(issue, { run: failed, agent, paused: false, approval: false, + wait: { id: "request", requestedAt: new Date() } })).toMatchObject({ state: "working", canRetry: false }); + expect(projectTaskInterruption(issue, { run: { ...failed, errorCode: "setup_failed" }, agent, paused: false, approval: false })) + .toMatchObject({ state: "failed", responsibility: "system", userAction: null, canRetry: true }); + }); +}); diff --git a/server/src/services/task-interruption-presentation.ts b/server/src/services/task-interruption-presentation.ts index ca13eebd909..8da6e923f78 100644 --- a/server/src/services/task-interruption-presentation.ts +++ b/server/src/services/task-interruption-presentation.ts @@ -404,6 +404,9 @@ function projectTaskInterruptionState(issue: ProjectionIssue, input: ProjectionS return { ...base, state: "failed", canRetry: false, retryWait: { reason: "cleanup_quarantined", message: NATIVE_CLEANUP_SETTLING_MESSAGE } }; } + if (run.status === "failed" && (run.errorCode === "github_auth_required" || run.errorCode === "github_repo_not_accessible")) + return { ...base, responsibility: "user", state: "waiting_for_user", canRetry: true, userAction: "connect_github", + githubAccess: run.errorCode }; return { ...base, state: "failed", canRetry: true, ...(projectAccess ? { projectAccess } : {}) }; } diff --git a/ui/src/components/ExecutionBlockerNotice.test.tsx b/ui/src/components/ExecutionBlockerNotice.test.tsx index 2b1d388ca16..95e6e326a21 100644 --- a/ui/src/components/ExecutionBlockerNotice.test.tsx +++ b/ui/src/components/ExecutionBlockerNotice.test.tsx @@ -182,6 +182,25 @@ describe("ordinary task interruption", () => { await act(async () => container.querySelector("button")!.click()); expect(retry).toHaveBeenCalledOnce(); }); + it("names a missing GitHub connection with one Connect GitHub step and a secondary Retry", async () => { + await render({ ...failed, responsibility: "user", state: "waiting_for_user", userAction: "connect_github", githubAccess: "github_auth_required" }); + expect(container.textContent).toContain("Couldn’t get this project’s repository from GitHub. Connect your GitHub account, then retry. Your message is saved."); + expect(container.textContent).not.toContain("Couldn’t finish this attempt."); + const connect = container.querySelector('[data-testid="task-execution-connect-github"]'); + expect(connect?.textContent).toBe("Connect GitHub"); + expect(connect?.getAttribute("href")).toBe("/apps/connect?source=github"); + await act(async () => container.querySelector('[data-testid="task-execution-retry"]')!.click()); + expect(retry).toHaveBeenCalledOnce(); + await render({ ...failed, responsibility: "user", state: "waiting_for_user", userAction: "connect_github", githubAccess: "github_auth_required" }, { canRetry: false }); + expect(container.querySelector("button")).toBeNull(); + expect(container.querySelector('[data-testid="task-execution-connect-github"]')).not.toBeNull(); + }); + it("names a GitHub repository the connection cannot reach", async () => { + await render({ ...failed, responsibility: "user", state: "waiting_for_user", userAction: "connect_github", githubAccess: "github_repo_not_accessible" }); + expect(container.textContent).toContain("Your GitHub account can’t reach this repository. Check the repository and its access in the GitHub connection, then retry."); + expect(container.textContent).not.toContain("Couldn’t finish this attempt."); + expect(container.querySelector('[data-testid="task-execution-connect-github"]')?.getAttribute("href")).toBe("/apps/connect?source=github"); + }); it("shows why an accepted Retry is waiting and keeps another attempt available", async () => { const retryWait = { reason: "remote_cleanup", message: "Retry is waiting for the previous environment to stop. Your message is saved." }; await render({ ...failed, retryWait }); diff --git a/ui/src/components/ExecutionBlockerNotice.tsx b/ui/src/components/ExecutionBlockerNotice.tsx index 59ad7ec2372..4d8914cd42f 100644 --- a/ui/src/components/ExecutionBlockerNotice.tsx +++ b/ui/src/components/ExecutionBlockerNotice.tsx @@ -11,6 +11,7 @@ import { ProviderFailureNotice } from "./ProviderFailureNotice"; import { LockedIssueChip, isLockedIssueStub } from "./LockedIssueChip"; import { PreviousServerStopConfirmation } from "./WorkspaceExportRecovery"; import { issuesApi } from "../api/issues"; +import { appSourceConnectHref } from "../pages/apps/app-connect-policy"; const recoveryStepText: Record, string> = { checking_previous_run: "Checking that the previous attempt stopped", @@ -106,6 +107,19 @@ export function ExecutionBlockerNotice({ presentation, canRetry, onRetry, optimi placeholder: "For example: no codex or claude process for this task is running on the server host.", resuming: "Starting your Retry…", confirm: "Confirm it stopped" }} />; } + if (!optimistic && presentation?.state === "waiting_for_user" && presentation.userAction === "connect_github") return ( +
+
+
+
+ ); // Other person-owned decisions have their own card on the task (approval, // project access, ...). A budget hold has none, so name it here and keep the // failure visible. The saved attempt starts by itself once the budget allows. diff --git a/ui/src/pages/Inbox.tsx b/ui/src/pages/Inbox.tsx index afba4faf967..801baec0a98 100644 --- a/ui/src/pages/Inbox.tsx +++ b/ui/src/pages/Inbox.tsx @@ -415,6 +415,7 @@ export function FailedRunInboxRow({ approval: "Approval required", reconnect: "Reconnect account", assign_agent: "Assign an agent", choose_model: "Choose a supported model", resume: "Work is paused", budget: "Budget limit reached", project_access: "Agent needs project access", + connect_github: "Connect GitHub", confirm_owner_stop: "Confirm the previous server stopped", confirm_run_stopped: "Confirm the previous run stopped", }[interruption.userAction ?? "resume"]) : runFailureMessage(run);