---
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 that is not standing work is `completed`, review the list once and call `tasks.clear()`. Standing tasks survive it.
- Subject stays short and imperative. `description` is the durable brief a subagent receives, so keep it separate from `instructions`.

## Timeboxes

A `timebox` puts a time limit on a task. Pass a shorthand string or `{ window, shift?, target? }`.

- `window` is a duration (`30m`, `2h`, `1d`, `1w`; 15m to 12w) or a cutoff: an ISO datetime with an offset (`2026-05-01T17:00:00+10:00`), a local date (`2026-05-01`, the end of that day in the person's zone) or a local time (`17:00`, the next one). A datetime without an offset is refused, and so is a cutoff that has already passed.
- When a window ends it rolls forward by `shift` and the counter goes up: timebox #2, #3 and so on. The default shift is the duration itself, `1d` for a date or local time, and `2h` for an ISO cutoff.
- Changing the window restarts the counter. `timebox: null` clears a one-off timebox. A one-off event at a fixed time still belongs on the Calendar; a timebox only says how long the work may take.

## Standing work

Standing work comes from your playbook, such as checking the inbox or prospecting. Create it once with a `target` in its timebox, such as `timebox: { window: '1d', target: 3 }` for an inbox checked three times a day. It never finishes, so it stays on the list.

- Run it like any task: mark it `in_progress`, do the work, mark it `completed`. That records one run in the current window and returns it to `pending` in the same write. Completing it from any other status is refused, so a retried call never counts twice.
- When a delegated standing task succeeds, the run is recorded for you. Do not complete it yourself while its delegation runs.
- While a standing task is under its target in the current window, a bot that sits idle for 15 minutes is woken to run it. Runs past the target still count. Standing windows of a day or a week start at local midnight; the minimum window is 1h.
- Pick what to run next from standing and ordinary tasks by judgement and the playbook. There is no priority field. `runs.count` is the runs in window `runs.window`, so a task already at its target can wait.
- At a check-in, add any playbook standing task missing from the list, and delete ones the playbook no longer lists. Do not put them on the Calendar.
- `target` is set at creation, and a standing task keeps its timebox. To stop it, delete it. Standing work cannot be in another task's `blockedBy`.

## Reminders

Po adds a hidden task reminder when a timebox is ending soon or a one-off timebox rolls past its end, or a task sits `in_progress` untouched for hours. It repeats at most once per window and stops once you touch the task. Act on the task (update it, complete it, mark it `failed`, or change its timebox) instead of replying to the reminder.

## 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 ordinary tasks and, separately, 15 standing tasks by default: updates still apply when full, but new tasks of that kind 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.
