# Task store

A task is one list and a step is one todo, kept per conversation in `todos.json`. [Task blocks](https://fzkuji.github.io/OpenProgram/docs/reference/design/ui/chat/task-blocks.html) draw from it.

- **Task**: `T3`: title, purpose, open, done or displaced, outcome, whether it ever advanced, the Goal it was started under
- **Step**: A todo whose `plan` is the task's id: pending, in progress, completed or dropped, with a half-sentence `result`
- **Segment**: One per reply and task: the task and all its steps as that reply last left them

## Board

| Item | Rule |
| --- | --- |
| One board per branch | Tasks, steps and segments. A branch made by a retry, an edit or a fork starts from a copy of the board it left from, so two branches never overwrite each other. |
| One open task per agent | Starting a task closes the open one. A sub-agent's tasks are its own (`scope` `agent:<id>`). |
| Ids | A task is `T<n>`, counted per board. A step keeps its todo id; the model names steps by their place in the task, 1 for the first. |
| Dropped step | Not counted in progress and no Goal requirement. Still listed to the Goal's verifier. |
| Sub-agent without a task | Ticks a step of the conversation's open task; the parent's latest segment is updated |

## Segment

| Field | Holds |
| --- | --- |
| `anchor_id`, `plan_id` | The reply and the task. A later change in the same reply replaces the segment; a change in a later reply adds one, so earlier replies keep the task as they left it. |
| `state` | `running`, `done`, `carried` (open, continued in a later turn) or `displaced` (another task took its place). A stop or a failure is not stored: the reply's status tells. |
| `current` | The step in progress at the last change; kept after a stop |
| `earlier` | Steps already finished when the segment began: the "earlier steps done" row |
| `advanced` | Whether a step call ever moved the task on |
| `todos` | Every step: id, subject, status, result |
| `title`, `purpose`, `outcome`, `started_at`, `ended_at` | What the header shows |

500 segments are kept per branch; the oldest drop off.

## Sent to the interface

| Frame | Carries |
| --- | --- |
| `todos_update` | `changed`: the segments a call or the end of a turn changed. A client replaces its copy of each by reply and task. |
| `session_loaded` | `todo_plans`: every branch's segments |
| `goal_update` | `progress`: the Goal's latest task, the step in progress, steps done and counted, the reply holding its latest block |
| Blocks and text frames | `task` and `step` on each text, thinking and tool block |

## Stored before tasks

| Entry | Read as |
| --- | --- |
| Segment without `title` | A plain todo list, read as stored. The chat joins the entries of one agent under a reply into one list and draws it once, folded. |
| Todo in no task | Kept on the board; it still counts for the Goal it was created under |
| File with a single board | Belongs to the branch selected when it is first read |

## Why

| Decision | Reason |
| --- | --- |
| The todo store is kept under tasks | Goal acceptance, the Goal's checklist and a sub-agent ticking its parent's step already read todos. A task adds a name and a state on top; none of them changes. |
| A segment per reply | A reply read later shows the task as that reply left it, and a task spanning turns is drawn in each turn's own part |
| Only changed segments are sent | A long Goal holds hundreds; a reconnect reloads them all |
| Stop is not a stored state | The reply already says how it ended; a second copy could disagree |

**Code**

- `openprogram/programs/tools/planning/todo/shared.py` (`place_segment`, `close_at_turn_end`, `turn_owner`, `publish`)
- `openprogram/programs/tools/planning/todo/task_start/task_start.py`, `task_step/task_step.py`
- `openprogram/programs/tools/planning/goal/chat.py` (`progress`)
- `apps/web/lib/chat/transcript/task-blocks.ts` (`normalizeSegments`, `tasksByRow`, `oneListPerAgent`)

[Task blocks](https://fzkuji.github.io/OpenProgram/docs/reference/design/ui/chat/task-blocks.html)
