Failure Recovery Surface
Understand what completed and choose how to recover.
Your preview settings
{
"failure": "upload",
"retryFail": false,
"confirmRetry": false,
"rollback": true
}These are the exact settings driving this demo, including sample content and simulated states. For the installable component’s public API, see Usage and Props below.
Start the sample export. If a step fails, inspect the preserved work and retry or roll back.
A real browser viewport. Scroll within the preview when the sample needs more space. Configuration stays in sync between sizes.
01What it does
Presents a host-owned multi-step operation, its confirmed progress, preserved work and available recovery actions. Retry safety and rollback availability come from the host, which must prevent duplicate work and validate each result.
In this previewRun a fictional export. Change the failure and retry controls to inspect recovery without creating or uploading files.
Design decisions
A partial failure needs more context than a single error message. Step states and a plain-language summary show what is preserved and what remains unfinished.
The host determines whether retry or rollback is safe. This surface requests actions and displays confirmed results; it does not perform or deduplicate operations.
02Install
Registry install
Run this in a React project with components.json. The component and its stylesheet land in components/lab/failure-recovery/.
npx shadcn@latest add https://lab.tanishk.me/r/failure-recovery.jsonFiles included
2- components/lab/failure-recovery/failure-recovery.tsxcomponent
- components/lab/failure-recovery/failure-recovery.cssstyles
Manual install: copy each file into the same folder and preserve its relative imports. Open the source
03Usage
import { FailureRecoverySurface } from "@/components/lab/failure-recovery/failure-recovery";
<FailureRecoverySurface title="Export workspace" phase={phase} steps={steps} preserved={preserved} retrySafety="safe" rollbackAvailable={canRollback} onStart={start} onRetry={retryStep} onRollback={rollback} />04Props
| Prop | Type | Default | Notes |
|---|---|---|---|
phase / steps | RecoveryPhase / RecoveryStep[] | — | Host-confirmed operation phase and individual step states. |
preserved | string | — | Host-provided explanation of preserved work and whether a partial result is usable. |
retrySafety / rollbackAvailable | RetrySafety / boolean | — | Host-provided recovery policy. Confirmation is requested when retry safety is uncertain. |
onStart / onRetry / onRollback | callbacks | — | Requests operations; the host executes, deduplicates and confirms outcomes. |
05Accessibility
- Step states are written as words and do not rely on color alone.
- Status changes are announced politely, and keyboard focus stays on the recovery surface after an action.
- No animation is required to understand progress or recovery.
06Source
2 files, 52 lines. The combined copy is a reference; save each file separately for use.
components/lab/failure-recovery/failure-recovery.tsx— press enter to show or hide the source
"use client";
import { useRef, useState } from "react";
import "./failure-recovery.css";
export type RecoveryStepStatus = "pending" | "running" | "complete" | "failed" | "rolled-back";
export type RecoveryStep = { id: string; label: string; status: RecoveryStepStatus; detail?: string };
export type RecoveryPhase = "idle" | "running" | "failed" | "complete" | "rolled-back";
export type RetrySafety = "safe" | "confirm" | "unavailable";
export type FailureRecoveryProps = {
title: string;
phase: RecoveryPhase;
steps: RecoveryStep[];
/** Host-provided description of preserved work and whether it is usable. */
preserved: string;
retrySafety: RetrySafety;
rollbackAvailable: boolean;
onStart?: () => void;
onRetry?: (stepId: string) => void;
onRollback?: () => void;
};
const LABEL: Record<RecoveryStepStatus, string> = { pending: "Waiting", running: "In progress", complete: "Complete", failed: "Failed", "rolled-back": "Rolled back" };
const PHASE: Record<RecoveryPhase, string> = { idle: "Ready to export", running: "Export in progress", failed: "Export needs attention", complete: "Export complete", "rolled-back": "Rollback complete" };
/** Presents confirmed host state; the host executes and deduplicates operations. */
export function FailureRecoverySurface({ title, phase, steps, preserved, retrySafety, rollbackAvailable, onStart, onRetry, onRollback }: FailureRecoveryProps) {
const [confirmRetry, setConfirmRetry] = useState(false);
const root = useRef<HTMLElement>(null);
const failed = steps.find((step) => step.status === "failed");
const marker = `${phase}:${failed?.id ?? ""}:${retrySafety}`;
const [lastMarker, setLastMarker] = useState(marker);
if (marker !== lastMarker) { setLastMarker(marker); setConfirmRetry(false); }
const requestRetry = () => {
if (!failed || !onRetry || retrySafety === "unavailable") return;
if (retrySafety === "confirm" && !confirmRetry) { setConfirmRetry(true); return; }
setConfirmRetry(false);
root.current?.focus();
onRetry(failed.id);
};
return <section ref={root} tabIndex={-1} className="fr-root" aria-label={title}>
<header className="fr-head"><div><p className="fr-eyebrow">WORKSPACE EXPORT</p><h3>{title}</h3></div><span className="fr-phase" data-phase={phase}>{PHASE[phase]}</span></header>
<p className="fr-preserved" role="status" aria-live="polite">{preserved}</p>
<ol className="fr-steps">{steps.map((step, index) => <li key={step.id} data-status={step.status}><span className="fr-number" aria-hidden="true">{String(index + 1).padStart(2, "0")}</span><div><strong>{step.label}</strong>{step.detail ? <p>{step.detail}</p> : null}</div><span className="fr-step-status">{LABEL[step.status]}</span></li>)}</ol>
{phase === "idle" && onStart ? <div className="fr-actions"><button type="button" className="fr-primary" onClick={() => { root.current?.focus(); onStart(); }}>Start export</button></div> : null}
{phase === "failed" ? <div className="fr-recovery"><h4>Choose a next step</h4><p>{retrySafety === "safe" ? "The host reports that retrying the failed step is safe." : retrySafety === "confirm" ? "Retry requires confirmation because the host cannot guarantee it is safe." : "Retry is not available for this operation."}</p>{confirmRetry && retrySafety === "confirm" ? <p className="fr-warning">Retrying may repeat work. Confirm with the host before proceeding.</p> : null}<div className="fr-actions">{failed && onRetry && retrySafety !== "unavailable" ? <button type="button" className="fr-primary" onClick={requestRetry}>{confirmRetry ? "Confirm retry" : `Retry ${failed.label}`}</button> : null}{confirmRetry ? <button type="button" onClick={() => setConfirmRetry(false)}>Cancel</button> : null}{rollbackAvailable && onRollback ? <button type="button" onClick={() => { root.current?.focus(); onRollback(); }}>Roll back</button> : <span>Rollback unavailable</span>}</div></div> : null}
<p className="fr-foot">The host runs, deduplicates and confirms every operation.</p>
</section>;
}components/lab/failure-recovery/failure-recovery.css— press enter to show or hide the source
.fr-root{padding:20px;border:1px solid #dedee3;border-radius:14px;background:#fff;color:#17171b;font:inherit}.fr-head{display:flex;justify-content:space-between;align-items:start;gap:12px}.fr-eyebrow{margin:0;color:#5f5f68;font:600 10px/1.4 ui-monospace,monospace;letter-spacing:.1em}.fr-head h3{margin:4px 0 0;font-size:19px;line-height:1.2}.fr-phase{border-radius:999px;background:#f1eefc;color:#32119c;padding:5px 9px;font-size:11px;white-space:nowrap}.fr-phase[data-phase="failed"]{background:#fbefea;color:#8b3219}.fr-preserved{margin:14px 0;color:#4f4f58;font-size:13px;line-height:1.5}.fr-steps{list-style:none;margin:0;padding:0;border-top:1px solid #e9e9e6}.fr-steps li{display:grid;grid-template-columns:28px minmax(0,1fr) auto;gap:10px;align-items:start;padding:10px 0;border-bottom:1px solid #e9e9e6}.fr-number{color:#77717e;font:11px/1.5 ui-monospace,monospace}.fr-steps strong{font-size:13px}.fr-steps p{margin:2px 0 0;color:#5f5f68;font-size:12px;line-height:1.4}.fr-step-status{color:#5f5f68;font:11px/1.5 ui-monospace,monospace;text-align:right}.fr-steps li[data-status="failed"] .fr-step-status{color:#8b3219;font-weight:600}.fr-recovery{margin-top:16px;padding:14px;border-radius:9px;background:#f8f5f2}.fr-recovery h4{margin:0;font-size:14px}.fr-recovery p,.fr-foot{margin:7px 0 0;color:#5f5f68;font-size:12px;line-height:1.5}.fr-recovery .fr-warning{color:#7a341a}.fr-actions{display:flex;align-items:center;flex-wrap:wrap;gap:8px;margin-top:12px}.fr-root button{border:1px solid #d1d0d6;border-radius:8px;background:#fff;padding:8px 11px;color:#24242b;font:inherit;font-size:12px;font-weight:600;cursor:pointer}.fr-root .fr-primary{border-color:#4f27e0;background:#4f27e0;color:#fff}.fr-actions span{font-size:12px;color:#5f5f68}.fr-root :focus-visible{outline:2px solid #4f27e0;outline-offset:3px}.fr-foot{margin-top:16px;font-size:11px}@media(max-width:360px){.fr-root{padding:16px}.fr-head{flex-wrap:wrap}.fr-steps li{grid-template-columns:24px minmax(0,1fr)}.fr-step-status{grid-column:2;text-align:left}}