paperclip/ui/src/components/IssueScheduledRetryCard.tsx

195 lines
7.4 KiB
TypeScript
Raw Normal View History

Add issue controls and retry-now recovery (#5426) ## Thinking Path > - Paperclip orchestrates AI agents for zero-human companies > - Issue operators need clear controls for execution settings, model overrides, and recovery retries > - Existing issue properties hid useful adapter override state and did not expose a board-triggered retry for scheduled heartbeat recovery > - Scheduled retries also need to respect the same safety gates as normal execution instead of bypassing budget, review, pause, dependency, or terminal-state checks > - This pull request adds the issue property controls and retry-now surfaces together because they share the issue details/properties UI > - The benefit is that operators can inspect and adjust issue execution settings and safely trigger pending scheduled recovery without hidden control-plane behavior ## What Changed - Adds editable issue assignee model override controls in `IssueProperties`, with focused coverage. - Removes the stale workspace tasks link from issue properties. - Adds a scheduled retry `retry-now` backend path and shared response types. - Adds main-pane and properties-pane scheduled retry UI, backed by a shared `useRetryNowMutation` hook. - Adds suppression coverage for budget hard stops, review participant changes, subtree pause holds, unresolved blockers, terminal issues, and company scoping. - Updates the `IssueProperties` test harness with toast actions required by the retry-now hook. ## Verification - `pnpm exec vitest run ui/src/components/IssueProperties.test.tsx ui/src/components/IssueScheduledRetryCard.test.tsx` — 31 passed. - `pnpm exec vitest run server/src/__tests__/issue-scheduled-retry-routes.test.ts` — exited 0, but this host skipped the embedded Postgres route tests with: `Postgres init script exited with code null. Please check the logs for extra info. The data directory might already exist.` - Pairwise merge check against the assigned-backlog PR branch completed without conflicts via `git merge --no-commit --no-ff` in a temporary worktree. ### Visual verification screenshots Storybook story: `Product/Issue Scheduled retry surfaces / ScheduledRetrySurfaces`. ![Scheduled retry card and issue properties rows - desktop](https://raw.githubusercontent.com/paperclipai/paperclip/62fb566f357312b43b9162af02252d0175530a8f/docs/assets/pr-5426/scheduled-retry-story-desktop.png) ![Scheduled retry card and issue properties rows - mobile](https://raw.githubusercontent.com/paperclipai/paperclip/62fb566f357312b43b9162af02252d0175530a8f/docs/assets/pr-5426/scheduled-retry-story-mobile.png) ## Risks - Medium: this touches issue execution/retry behavior, so CI should run the embedded Postgres route tests on a host that can initialize Postgres. - Low-to-medium UI risk around duplicated retry-now entry points; both surfaces share one mutation hook to keep behavior consistent. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used - OpenAI Codex coding agent, GPT-5 model family (`gpt-5`), tool-enabled Paperclip heartbeat environment. Context window and internal reasoning mode are not exposed by the runtime. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, I have included before/after screenshots - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-05-07 12:23:13 -05:00
import { Clock, RotateCcw, AlertCircle, Loader2, CheckCircle2 } from "lucide-react";
import { Link } from "@/lib/router";
import { Button } from "@/components/ui/button";
import { cn, formatDateTime } from "@/lib/utils";
import { formatMonitorOffset } from "@/lib/issue-monitor";
import { formatRetryReason } from "@/lib/runRetryState";
import type { IssueScheduledRetry } from "@paperclipai/shared";
import { useRetryNowMutation, type RetryNowError } from "../hooks/useRetryNowMutation";
const MAX_TURN_CONTINUATION = "max_turns_continuation";
function isContinuationReason(reason: string | null | undefined) {
return reason === MAX_TURN_CONTINUATION;
}
function shortRunId(runId: string | null | undefined) {
return typeof runId === "string" && runId.length >= 8 ? runId.slice(0, 8) : runId ?? "";
}
interface IssueScheduledRetryCardProps {
issueId: string | null | undefined;
scheduledRetry: IssueScheduledRetry | null | undefined;
}
export function IssueScheduledRetryCard({
issueId,
scheduledRetry,
}: IssueScheduledRetryCardProps) {
const retryNow = useRetryNowMutation(issueId);
if (!scheduledRetry || !issueId) return null;
if (scheduledRetry.status !== "scheduled_retry") return null;
const continuation = isContinuationReason(scheduledRetry.scheduledRetryReason);
const dueAtIso = scheduledRetry.scheduledRetryAt
? new Date(scheduledRetry.scheduledRetryAt).toISOString()
: null;
const relative = dueAtIso ? formatMonitorOffset(dueAtIso) : null;
const absolute = scheduledRetry.scheduledRetryAt
? formatDateTime(scheduledRetry.scheduledRetryAt)
: null;
const reason = formatRetryReason(scheduledRetry.scheduledRetryReason);
const attempt =
typeof scheduledRetry.scheduledRetryAttempt === "number"
&& Number.isFinite(scheduledRetry.scheduledRetryAttempt)
&& scheduledRetry.scheduledRetryAttempt > 0
? scheduledRetry.scheduledRetryAttempt
: null;
const badgeLabel = continuation ? "Continuation scheduled" : "Retry scheduled";
const titleAction = continuation ? "Automatic continuation" : "Automatic retry";
let titleSuffix: string;
if (relative === "now") {
titleSuffix = "due now";
} else if (relative) {
titleSuffix = relative;
} else {
titleSuffix = "pending schedule";
}
const title = `${titleAction} ${titleSuffix}`;
const helperIdle = continuation
? "Pulls continuation forward immediately"
: "Pulls retry forward immediately";
const isError = retryNow.isError || retryNow.lastError !== null;
const isSuccessTransient = retryNow.isSuccess
&& (retryNow.data?.outcome === "promoted" || retryNow.data?.outcome === "already_promoted");
return (
<div
data-testid="issue-scheduled-retry-card"
className="mb-3 rounded-lg border border-cyan-500/30 bg-cyan-500/5 px-3 py-3"
>
<div className="flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between">
<div className="min-w-0 flex-1">
<div className="flex flex-wrap items-center gap-2 text-xs">
<span className="inline-flex items-center gap-1 rounded-full border border-cyan-500/30 bg-cyan-500/10 px-2 py-0.5 font-medium text-cyan-700 dark:text-cyan-300">
<Clock className="h-3 w-3" aria-hidden="true" />
{badgeLabel}
</span>
{attempt !== null ? (
<span className="text-muted-foreground">Attempt {attempt}</span>
) : null}
{reason ? (
<span className="text-muted-foreground">{reason}</span>
) : null}
</div>
<div className="mt-1 text-sm font-medium text-foreground">{title}</div>
{(absolute || scheduledRetry.retryOfRunId) ? (
<div className="mt-0.5 text-xs text-muted-foreground">
{absolute ? <span>{absolute}</span> : null}
{absolute && scheduledRetry.retryOfRunId ? <span>{" · "}</span> : null}
{scheduledRetry.retryOfRunId ? (
<span>
Replaces run{" "}
<Link
to={`/agents/${scheduledRetry.agentId}/runs/${scheduledRetry.retryOfRunId}`}
className="font-mono text-foreground hover:underline"
>
{shortRunId(scheduledRetry.retryOfRunId)}
</Link>
</span>
) : null}
</div>
) : null}
{scheduledRetry.error ? (
<div className="mt-1 text-xs text-muted-foreground">
Last attempt failed: {scheduledRetry.error}. Paperclip will retry automatically.
</div>
) : null}
{isError ? (
<RetryErrorBand
error={retryNow.lastError}
onRetry={() => {
retryNow.reset();
retryNow.mutate();
}}
/>
) : null}
</div>
<div className="flex flex-col items-stretch gap-1 sm:items-end">
<Button
type="button"
variant="outline"
size="sm"
className="shrink-0 shadow-none"
onClick={() => retryNow.mutate()}
disabled={retryNow.isPending || isSuccessTransient}
data-testid="issue-scheduled-retry-card-retry-now"
>
{retryNow.isPending ? (
<span className="inline-flex items-center gap-1.5">
<Loader2 className="h-3.5 w-3.5 animate-spin" aria-hidden="true" />
Retrying
</span>
) : isSuccessTransient ? (
<span className="inline-flex items-center gap-1.5">
<CheckCircle2 className="h-3.5 w-3.5" aria-hidden="true" />
{retryNow.data?.outcome === "already_promoted" ? "Already promoted" : "Promoted"}
</span>
) : (
<span className="inline-flex items-center gap-1.5">
<RotateCcw className="h-3.5 w-3.5" aria-hidden="true" />
Retry now
</span>
)}
</Button>
<span className="text-right text-xs text-muted-foreground sm:max-w-[12rem]">
{retryNow.isPending
? "Promoting scheduled retry"
: isSuccessTransient
? retryNow.data?.outcome === "already_promoted"
? "Already promoted — run starting"
: "Promoted — run starting"
: helperIdle}
</span>
</div>
</div>
</div>
);
}
interface RetryErrorBandProps {
error: RetryNowError | null;
onRetry: () => void;
className?: string;
}
export function RetryErrorBand({ error, onRetry, className }: RetryErrorBandProps) {
if (!error) return null;
return (
<div
className={cn(
"mt-2 flex items-start gap-2 rounded-md border border-rose-500/30 bg-rose-500/5 px-2 py-1.5 text-xs text-rose-700 dark:text-rose-300",
className,
)}
role="alert"
data-testid="issue-scheduled-retry-error-band"
>
<AlertCircle className="mt-0.5 h-3.5 w-3.5 shrink-0" aria-hidden="true" />
<div className="min-w-0 flex-1">
<div className="font-medium">Couldn't retry now</div>
<div className="mt-0.5 text-muted-foreground">{error.message}</div>
</div>
<button
type="button"
onClick={onRetry}
className="shrink-0 font-medium text-rose-700 hover:underline dark:text-rose-300"
>
Try again
</button>
</div>
);
}