Long-Running Agents, Delegation, and Recovery

Give long agent jobs a clear boundary, saved checkpoints, a way to stop them, and a handoff note so you can pick up where the work left off.

Content date: October 15, 2026.

Plain English

A long-running task spans many steps and can outlast the agent's working memory (its context window). A checkpoint is a note saved outside the chat: the goal, work done, evidence, current state, and next step. Handing parts of a job to other agents (delegation) helps when the parts are independent, but adds the work of coordinating and combining results. Starting more agents is not evidence of progress.

Use this when

Use this for a big cleanup of your code, several separate investigations, or unattended work where a failure would cost real time or money.

If you are just starting

Use one agent, a task you can undo, a time or spending limit, and a checkpoint you can find. Practice stopping and resuming before you let an agent run unattended and change files. Give the agent a list of actions that always need your decision, such as deleting files, spending money, or sending email.

When your project grows

Record who owns the task, its permissions, the results it reported, and any process it started (a process ID is the number your computer uses to find a running program). On resume, check the real state instead of trusting an old summary. Give agents that edit at the same time separate working copies (git worktrees), and review the combined result. Make outside actions safe to repeat so a retry does not charge a card twice.

Worked example

Sam asks an agent to run the website's test suite, which takes twelve minutes. The chat times out. Instead of starting a second run, the agent finds the first one still going using the process recorded in its checkpoint. When it finishes, it records exit code 0 and the files it tested. A second agent updates the help page in its own copy, and Sam reviews the combined result before merging.

Practice

Interrupt and resume safely

  1. Create a disposable git branch or a copy of a small project, and pick a small task that sends nothing to outside services.
  2. Write down the commands the agent may run, a time limit, and one check that proves the task is done.
  3. Stop the agent after its first checkpoint. Look at the files and for any program left running, and compare with the checkpoint.
  4. Resume from that state. Later, ask the agent to cancel, and confirm yourself that the work stopped.
  5. Optional: give a writing task to a second agent in its own copy, and review the combined result before merging.

Deliverable: A checkpoint and recovery log showing one interruption, one resume, one cancellation you confirmed, and the finished, checked result.

Common mistakes to watch for

  • You restart a job that is still running, and two copies rebuild the same files.
  • Two agents edit the same page, and nobody owns the merge.
  • A summary says "tests passed" with no output and no note of which files were tested.
  • You close the chat, but a long command it started keeps running.

Prompting

A weak prompt

Keep running all night and use as many agents as you can.

A better prompt

Do this task within [time or spending limit] using only these actions: [allowed actions]. As you go, save a checkpoint listing files changed, evidence your checks passed, any program left running (with its process ID), and what remains. After an interruption, look at the real files and processes before resuming. Delegate only independent work with an owner and a separate copy. Stop and ask when you need a decision or hit the limit, and confirm outside work has stopped.

It lets you resume without redoing finished work, and it limits the damage when a session drops or a job is handed off.

Check before you move on

  • The task has a time or spending limit and a list of allowed actions.
  • The checkpoint includes evidence and lists any running programs.
  • On resume, the agent checked the real files and processes first.

You are done when

  • A brand-new session can continue from your checkpoint without repeating finished work.
  • You can tell from evidence which work finished, is running, failed, or was cancelled.

Questions to think about

The agent's wait on a long command times out. Did the command stop?

No. The agent only stopped waiting. Check the recorded process or the real files before starting anything again.

Two agents each report passing tests. Is the combined work verified?

No. Their changes can conflict in ways neither test covers. Merge them in a test copy, then review and check the result.

You rewind a session to before a mistake, but a build command had already deleted files. Are they back?

Not necessarily. Rewind restores what the agent's file-editing tools changed, not what commands did. Git history or a backup brings them back.

Official references