Skip to content
Goal: Deep understanding✓ Sources verified 2026-11-25State machineError designError copyHuman-in-the-loopLong-running tasks

Designing States, Errors and Failure Flows ​

A UI for long-running AI tasks has to answer four questions: how far has it got (progress), what is happening now (state), why did it go wrong (errors), and when does it need me (intervention). This article covers how to translate system state into the UI completely and accurately.

Core concepts ​

ConceptMeaningHow it shows up in the UI
State machine (finite state machine)At any moment an object is in exactly one of a finite set of states and can only move between them on defined eventsStatus label, available actions and layout all follow from the current state
Layered stateModel task, step, executor (agent) and connection state separatelyThe summary shows task state, the timeline shows step state, a corner shows connection state
State × UI matrixRows are states, columns are UI elements (summary, primary action, timeline, notification); each cell says exactly what to showDesign, code and tests line up against one table
"Impossible states"Contradictory combinations that appear when you model with several booleans, e.g. isLoading && isErrorA spinner and an error message on screen at the same time
Partial successSome sub-tasks in a batch succeed and some fail"7/10 done, 3 failed" + actions for the failed items
Intervention point (human-in-the-loop)The system needs a person to confirm, provide information or authorize before it can continueA clear alert + one click to where action is needed + automatic resume afterwards

Typical states of a long-running agent task ​

Task: queued → running ⇄ waiting_human
                 │  ↘ retrying ↗
                 ↓
      succeeded | partially_succeeded | failed | cancelled

Step: pending / running / retrying(n/N) / blocked / needs_human / succeeded / skipped / failed
Connection: live / reconnecting / offline

How it works ​

1. Why a state machine instead of a pile of booleans ​

Four booleans (isLoading, isError, isPaused, needsHuman) give 16 combinations; most are meaningless, yet any of them can occur. A state machine lists the legal states, each state maps to exactly one UI, and transitions only happen on events. Benefits:

  • In design you can enumerate every state and not miss a screen
  • In code a TypeScript discriminated union makes the compiler check every branch
  • In tests you write one case per state
ts
type TaskState =
  | { status: 'queued'; position: number }
  | { status: 'running'; step: string; progress?: number }
  | { status: 'retrying'; step: string; attempt: number; maxAttempts: number; reason: string }
  | { status: 'waiting_human'; request: HumanRequest; since: string }
  | { status: 'partially_succeeded'; done: number; failed: FailedItem[] }
  | { status: 'failed'; error: TaskError }
  | { status: 'succeeded'; resultUrl: string }
  | { status: 'cancelled'; by: string }

2. Classify failures and give each class different actions ​

ClassExampleHow to show itUser action
System can recover on its ownTimeout or rate limit, retryingYellow, "Retrying automatically 2/3"None needed; can expand to see why
Needs information from the userMissing parameter, needs authorization, needs a choiceProminent banner + waiting timeFill in / authorize / choose
Needs a user decisionPartial failure: continue or rerun?List of failed itemsSkip and continue / retry failed items
UnrecoverableInvalid input, permission deniedRed failure cardEdit and rerun / contact support

3. Three-part error copy ​

NN/g's error-message guidelines ask that errors be visible, explain the problem in plain language, and offer constructive advice on how to fix it. For AI tasks this can be fixed into three parts:

  1. What happened: which step, what problem (not just an error code)
  2. What the system already did: how many retries, what fallback it tried
  3. What you can do: 1–3 buttons, ordered by recommendation

Example: "The paper search service timed out. We retried automatically 3 times and all failed. You can: retry this step later / switch to the backup search source / skip search and use the papers you uploaded."

4. Elements of an intervention point ​

ElementHow
SeenIn-page banner, unread count in the page title, optional browser notification (needs the user's permission)
ReachableA "Handle it" button opens the right form and focuses its first field
In contextExplain why the system needs you and what it has already tried
Time-boundShow how long it has been waiting; state the timeout policy ("this step will be skipped after 30 minutes without a response")
ResumableConfirm immediately after submit ("Got it, the task is continuing") and record it on the timeline

In practice ​

State × UI matrix template ​

StateSummary copyColor / iconPrimary actionSecondary actionNotify?Screen reader announcement
runningStep 3/5: reading papersBlue / spinnerPauseCancelNoNo
retryingRetrying automatically 2/3: search timed outYellow / circular arrows—View reasonNoNo
waiting_humanNeeds you: add search keywordsOrange / handHandle itSkipYesYes (polite)
partially_succeeded7/10 papers read, 3 couldn't be fetchedOrange / half circleUpload PDFSkip and continueYesYes
failedSearch failed: service unavailableRed / crossRetry from this stepEdit and rerunYesYes
succeededReport is readyGreen / checkView reportExportYesYes

"While you were away" summary ​

Users leave long tasks running. Record when the user last looked; when they come back, the first screen shows which steps finished, which errors occurred, and what is waiting for them.

Honest progress ​

  • When the number of steps is known use "step n/N"; when it isn't, just say what it is doing now. Don't fake a percentage
  • If the time-remaining estimate is unreliable, hide it, or show "about" and say what it's based on
  • If no new events arrive for a while, show "last updated 12:03" so it doesn't look frozen

Common pitfalls ​

  1. Designs only for the happy path: error, empty and partial-success states turn out to have no design once coding starts. Check every cell of the matrix.
  2. Every error says "Something went wrong, please retry": users can't tell whether to wait, change something or give up.
  3. Showing retrying as a red failure: red while the system is recovering on its own invites the wrong action.
  4. State shown by color alone: users with color-vision deficiencies can't tell them apart; add icons and text (WCAG 1.4.1).
  5. Intervention requests buried in the timeline: anything that needs a person should also be collected in an "inbox".
  6. Optimistically showing "done": the front end assumes success while the back end actually failed. State must follow server events.

Common interview questions ​

  1. For an agent task that runs for 30 minutes, which states does the UI need?
  2. Why model UI state as a state machine? How do you express it in TypeScript?
  3. What classes of failure are there, and what actions does each give the user?
  4. How do you design for partial success?
  5. When the system needs a human, how do you make sure the user sees it and can act quickly?
  6. What makes a good error message?

Sources ​

Vin Amory · AI development × content creation · Technical notes cite official docs in each page’s sources section