iCode Workbench · Guide · Queue

Agent task states, retries, and schedules

A task is not a process. A process is either running or not; a task has a goal, a history, and a state. The state is what tells you whether the work needs you, whether it can wait, and whether it is actually done.

This guide is the model behind a useful queue: the states, how retries work, why “waiting” is not “failed,” and how schedules fit without becoming a second system.

This guide is currently available in English only.

Why states matter

With one agent, you can hold the state in your head: it is running, or it is done. With three, the head fails. A wall of green terminals does not tell you which task is blocked, which is waiting for an approval, and which finished but has not been reviewed.

A false green is worse than an honest unknown. If a task shows “running” when it is actually waiting for a person, you wait too. If it shows “completed” when it has not been reviewed, you may merge unreviewed work.

The state model

  • Queued. The task exists and is waiting for a slot. Nothing is running.
  • Dispatching. A slot opened and the task is being assigned. A short state, but it makes the transition visible.
  • Running. The agent is working. Running does not mean “will succeed,” and it does not mean “reviewed.”
  • Waiting. The agent needs a person: an approval, a decision, or an answer. Waiting is not failed and not running.
  • Completed. The process exited successfully. The task still needs a review decision before it is accepted.
  • Failed. The process exited with an error, or the verification command failed. A retry creates a new attempt.
  • Cancelled. A person stopped the task. It should not silently reappear.

The names matter less than the distinctions. The critical ones are waiting vs failed, and completed vs accepted.

Retries as new attempts

A retry is a new attempt, not an erased failure. The previous attempt should stay in the task history: what the agent tried, why it failed, and what changed. If the retry succeeds, you still review the final diff; if it fails again, the history shows the pattern.

A retry should never count as a review, and a successful retry should not auto-merge. The review decision is independent of how many attempts it took.

Keep the policy simple: retry a failed verification, do not retry a failed review without a change, and do not retry a task that is waiting on a person.

Waiting vs failed

Waiting means the agent is blocked on a human. Failed means the agent or the verification failed. The distinction changes what you do next:

  • Waiting: read the prompt, answer or approve, and let the same session continue.
  • Failed: read the failure, decide whether the task or the code needs to change, then retry.
  • Running slowly: check the last tool call or file before assuming it is stuck.

If these all look like “red” in your UI, you will interrupt waiting sessions and wait on failed ones. That is a state-model problem, not an agent problem.

Schedules

A schedule creates an ordinary queued task on a cadence: once, daily, weekdays, weekly, or every few hours. It is not a separate automation with its own failure modes; it is a task factory that uses the same queue, the same review gate, and the same state model.

The important decision is overlap. If the previous run is still running when the next is due, queue the new one or skip it — pick one explicitly. A nightly audit that silently stacks ten concurrent runs is worse than one that skips a night.

Status hooks

A status hook lets the harness report what it is actually doing. Without one, the queue has to guess from process output, and guesses become false greens. A good hook reports running, waiting, and completed distinctly; a harness without a hook should stay unknown rather than pretend to be running.

Do not infer “running” from a live PTY. A terminal can be open while the agent is waiting for an answer; the process is alive, but the task needs you. That is exactly the case a status hook exists to distinguish.

Unknown is a legitimate state. It tells you to look, which is better than a confident wrong answer.

A task through the states

09:00 — queued. The task exists; no slot is free.
09:05 — dispatching. A slot opened.
09:06 — running. The agent started.
09:40 — waiting. The agent needs an approval.
09:45 — running. You approved; the same session continues.
10:10 — completed. The process exited zero. The task is not accepted yet.
10:15 — review: revise. The diff skipped a test.
10:25 — running. A retry, as a new attempt, with the test restored.
10:40 — completed. The retry exited zero.
10:45 — accepted. You reviewed the diff and recorded the decision.
10:50 — merged.

The history is the point. The first failure was not erased, the waiting period was visible, and the retry was a new attempt. If the UI collapsed all of this into “running” and then “done,” you would not know which task needed you or which diff had been reviewed.

State transitions

FromToTrigger
QueuedDispatchingA slot opens
DispatchingRunningThe agent starts
RunningWaitingThe agent asks for approval or a decision
WaitingRunningA person answers or approves
RunningCompletedProcess exits zero and verification passes
RunningFailedProcess error or verification failure
CompletedAcceptedReview accepts the diff
CompletedReviseReview requests changes; a retry follows
FailedQueuedA new attempt is created
AnyCancelledA person stops the task

A state machine this small is enough to make a fleet legible. The value is in the transitions being visible, not in the number of states.

Measuring state accuracy

  • False green rate. Tasks marked running or completed that were actually waiting or failed. Any nonzero rate means the status hooks are guessing.
  • Waiting time. How long tasks sit in waiting before a person responds. This is the queue's attention latency.
  • Retry rate. Retries per task. A rising rate means the task statement or the tests are weak.
  • Review latency. Time from completed to accepted. This is the real throughput limit.

If the false green rate is above zero, fix the hooks before adding agents. A wrong state is worse than an unknown one.

Anti-patterns

  • Completed means done. Completed is a process exit, not an accepted task. Keep the review decision separate.
  • Retry until green. Retrying without changing the task or the code produces the same failure. Read the history first.
  • One state for everything. If waiting, failed, and running all look the same, the queue cannot route your attention.
  • Schedules outside the queue. A separate cron with its own state and review path becomes a second system to maintain.
  • Guessing status. A false green is worse than an honest unknown.

For the practical setup, read how to queue coding agent tasks. For the fleet view, read the parallel-agents pillar.