---
name: codemode-how-to-task
description: 'Track work as a task list with the tasks namespace, so the plan and its progress survive compaction, and hand tasks to background subagents. Use at the start of any request with three or more steps, when the person gives a list of things to do, or before delegating work.'
---

# Use Task

Po Task keeps a task graph on disk, outside the transcript. It survives compaction, holds dependencies, and can hand a task to a background subagent. In code mode it is the `tasks` namespace: call `discover({ namespace: 'tasks' })` for the types, then `exec`.

```ts
const { document } = await tasks.upsert([
  { ref: 'a', subject: 'Research the store' },
  { subject: 'Write the reducer', blockedBy: ['a'] },
]);
return document.tasks.filter((task) => task.status !== 'deleted');
```

`tasks.snapshot()` reads the graph. `upsert`, `delete`, `clear`, `assign` and `cancel` change it and return `{ message, document }`. Nothing is printed unless the script returns it, so return only what you need.

## Tracking work

- Batch the whole plan in one `upsert`. Report progress one call at a time: mark a task `in_progress` before you start it and `completed` the moment it lands, never batched at the end of a turn.
- Keep one task `in_progress` for your own work. Delegated tasks run in parallel and do not count.
- Status flow is `pending`, `in_progress`, `completed`. `failed` is recoverable. `deleted` is a tombstone. Pass `activeForm` (for example `'writing tests'`) when marking `in_progress`.
- Never mark a task `completed` while tests fail or the work is partial. Use `failed`, or keep it `in_progress` and add a task for the blocker in the same `upsert`.
- When every non-deleted task is `completed`, review the list once and call `tasks.clear()`.
- Subject stays short and imperative. `description` is the durable brief a subagent receives, so keep it separate from `instructions`.

## Reading failures

`upsert` applies each entry independently. Passing entries commit, and `applied` and `failed` tell you which. Nothing applied throws. Resend only the corrected entries, because resending an applied entry with no `id` creates a duplicate task. A graph holds 15 non-deleted tasks by default: updates still apply when full, but new tasks are refused until space is freed.

## Delegating

- Apply the session's delegation criteria first, then call `subagent({ action: 'agents' })` and use an exact discovered name. Prefer a general-purpose write-capable agent such as `delegate` or `worker` when no specialist fits. Use a focused `inlineAgent` only for read-only work.
- Assign through `tasks.assign([...])` even for one task. Put independent ready tasks in one batch. Do not start a direct subagent run for work already on the list.
- Successful entries keep running when another entry fails. Retry only the failures.
- Fill `relevantFiles` only with files you read or located, and `priorFindings` only with verified facts in a few lines, not directives. A guessed path costs more than an omitted one.
- When a delegated task completes and unblocks another, reconsider it promptly. If a child asks for a decision or an assignment fails to start, respond, rescope or retry instead of leaving it pending. The task itself records the delegated lifecycle and result.
- `tasks.cancel(id)` stops a running delegation. `delete` and `clear` refuse while one is running.
