import { describeError } from "../api/errors"; import type { IssueRelationIssueSummary, TaskInterruptionPresentation } from "@paperclipai/shared"; import { AlertCircle } from "lucide-react"; import { Link } from "@/lib/router"; import { createIssueDetailPath } from "../lib/issueDetailBreadcrumb"; import { Button } from "./ui/button"; import { cn } from "../lib/utils"; import { useSecondTick } from "../hooks/useSecondTick"; import { TaskProjectAccessNotice } from "./TaskProjectAccessNotice"; import { ProviderFailureNotice } from "./ProviderFailureNotice"; import { LockedIssueChip, isLockedIssueStub } from "./LockedIssueChip"; import { PreviousServerStopConfirmation } from "./WorkspaceExportRecovery"; import { issuesApi } from "../api/issues"; const recoveryStepText: Record, string> = { checking_previous_run: "Checking that the previous attempt stopped", saving_previous_files: "Saving files from the previous attempt", finishing_recovery: "Finishing recovery of saved work", }; /** A budget hard stop holds saved work. Only a task that already ran has an * attempt to report; a task refused before its first run just waits. */ function budgetWaitText(presentation: TaskInterruptionPresentation) { const wait = "It is waiting for the budget to allow new work. Raise the budget in Costs."; return presentation.observedRunId || presentation.sourceRunIds.length ? `Couldn’t finish this attempt. Your message is saved. ${wait}` : `This task has not started. ${wait}`; } const isBudgetWait = (presentation: TaskInterruptionPresentation | null | undefined) => presentation?.state === "waiting_for_user" && presentation.userAction === "budget"; const blockerAction: Record = { blocked: "Blocked: open it to Retry", cancelled: "Cancelled: remove or replace it", done: "Saving its files", }; /** One ordinary interruption surface. Technical records remain in diagnostics. */ export function ExecutionBlockerNotice({ presentation, canRetry, onRetry, optimistic, takingLonger, error, className, issueId, companyId, agentName, projectName, blockers }: { presentation: TaskInterruptionPresentation | null | undefined; companyId?: string; blockers?: IssueRelationIssueSummary[]; canRetry: boolean; onRetry: () => void; optimistic?: boolean; takingLonger?: boolean; error?: Error | null; className?: string; issueId?: string; agentName?: string; projectName?: string; }) { useSecondTick(presentation?.state === "retry_scheduled"); if (presentation?.projectAccess && !optimistic && !takingLonger) return ; if (error && !optimistic && !takingLonger) return
{describeError(error).body}{canRetry && }
; if (takingLonger) return
Taking longer than usual…{canRetry && }
; const step = !optimistic && presentation?.responsibility === "system" && presentation.recoveryStep && ["working", "retry_scheduled"].includes(presentation.state) ? recoveryStepText[presentation.recoveryStep] : null; const seconds = Math.max(0, Math.ceil((Date.parse(presentation?.nextRetryAt ?? "") - Date.now()) / 1000)); const retryIn = `Trying again in ${seconds > 60 ? `${Math.ceil(seconds / 60)}m` : `${seconds}s`}…`; if (!optimistic && !presentation?.retryWait && presentation?.providerFailure && ["failed", "retry_scheduled", "waiting_for_user"].includes(presentation.state)) { // Saved-work recovery is what the task waits for, so name it over the // generic automatic-retry line while keeping the provider explanation. return Retry : undefined}> {presentation.state === "retry_scheduled" &&

{step ? `${step}. ${retryIn}` : "Paperclip will retry automatically."}

} {isBudgetWait(presentation) &&

It is waiting for the budget to allow new work. Raise the budget in Costs.

}
; } if (step && presentation?.state === "working") return
{`${step}…`}
; // A task that has not started yet names the admission hold it waits for. if (!optimistic && presentation?.state === "working" && presentation.retryWait) { const dependencies = presentation.retryWait.reason === "dependency_blocked" ? blockers ?? [] : []; const unfinished = dependencies.filter(blocker => isLockedIssueStub(blocker) || blocker.status !== "done"); const waitingOn = unfinished.length ? unfinished : dependencies; return

{presentation.retryWait.message}

{waitingOn.length ?
    {waitingOn.map(blocker => isLockedIssueStub(blocker) ?
  • :
  • {blocker.identifier ?? "Task"} {blocker.title} {blockerAction[blocker.status] ?? blocker.status.replace(/_/g, " ")}
  • )}
: null}
; } if (!optimistic && presentation?.userAction === "confirm_run_stopped" && presentation.observedRunId && issueId && companyId) { const runId = presentation.observedRunId; return issuesApi.confirmRunStopped(issueId, { runId, stopEvidence })} copy={{ waiting: presentation.retryWait?.message ?? "Paperclip can't confirm that the previous run stopped. Your message is saved.", question: "How did you confirm that no agent is still working on this task?", 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" }} />; } // 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. if (!optimistic && presentation && isBudgetWait(presentation)) return (
); if (optimistic || !presentation || presentation.responsibility !== "system" || !["failed", "retry_scheduled"].includes(presentation.state)) return null; return (
{presentation.state === "failed" &&
); }