# See what the work cost, and where the money went

**Every agent run records what it spent and the tasks it worked on, so what a milestone cost is a query, and the spend that reached no task shows up beside it.**

Once several agents work at once, the limit stops being attention and becomes tokens, and a session that ends in a bill says nothing about where they went. So each run records itself: when it starts, the tasks it works on and the run that started it; before it stops, its status and what it spent. The cost is never written on a task. It is summed from the runs, which is why closed work still counts: a milestone's money is mostly spent on pieces already done. Grouped by agent or model, the same answer says which role spends the most. Two more questions find what the total would otherwise hide: spend that reached no task, and a run left open with no usage, which the total counts as unpriced rather than as free. What the answers change is the harness, the model each role runs on and what it is handed, and the next milestone is measured with the same query.

Driven by a person and an agent. Every step below is a step in
`packages/server/tests/e2e`, run against a listening server on every pull
request; the calls under each one are what that run executed.

The same flow is playable at https://flow.ttoss.dev/docs/examples/see-what-the-work-cost.

## 1. Ana points her agent at the repository she works in

- `POST /api/v1/projects` → `201`

## 2. The export ships when two pieces are done

- `POST /api/v1/tasks/batch` → `200`

## 3. A manager agent takes the export, and records its run as it starts

- `POST /api/v1/agent-runs` → `200`

## 4. It starts one child per piece, each naming the manager as its parent

- `POST /api/v1/agent-runs` → `200`
- `POST /api/v1/agent-runs` → `200`

## 5. Before stopping, each child records what it spent, and its piece closes

- `POST /api/v1/agent-runs` → `200`
- `PATCH /api/v1/tasks/task_8bmpc3xkbh` → `200`
- `POST /api/v1/agent-runs` → `200`
- `PATCH /api/v1/tasks/task_kpekkray37` → `200`

## 6. A reviewer works on both pieces and stops without recording its usage

- `POST /api/v1/agent-runs` → `200`

## 7. An exploration runs without naming any task

- `POST /api/v1/agent-runs` → `200`

## 8. The export ships, and the manager closes its own run with what it spent

- `PATCH /api/v1/tasks/task_jv9jgnjxsg` → `200`
- `POST /api/v1/agent-runs` → `200`

## 9. Ana asks what the export cost, and the answer counts the closed work

- `GET /api/v1/agent-runs?upstream_of=task_jv9jgnjxsg&group_by=agent` → `200`

## 10. The manager’s children are one query too

- `GET /api/v1/agent-runs?parent=arun_aby6pqr40s&group_by=model` → `200`

## 11. She asks what the total leaves out: spend that reached no task

- `GET /api/v1/agent-runs?project=proj_n331hpvdxa&linked=false` → `200`

## 12. And a run still open though everything it worked on is closed

- `GET /api/v1/agent-runs?project=proj_n331hpvdxa&lingering=true` → `200`

## 13. The reviewer’s agent closes the run it left open, and the total is whole

- `POST /api/v1/agent-runs` → `200`
- `GET /api/v1/agent-runs?upstream_of=task_jv9jgnjxsg&group_by=agent` → `200`
- `GET /api/v1/agent-runs?project=proj_n331hpvdxa&lingering=true` → `200`
