# Take work, so nobody else starts it

**Two people — or two agents — never both build the same thing: an agent takes a task in the run it records, a person by taking it on, and the second one to try is told who has it.**

A task names who has taken it on: a person in the project, or one of its teams when nobody in particular has yet. The ready set offers what nobody has taken and what is yours or your team’s, and nothing else. A team hands its work to one of its own members by assigning it, and that is the ordinary path. One person’s agents all act as that person, so a holder cannot tell two of them apart: an agent takes a task by naming it in the run it records, in the same write, and a second run naming it is told which run has it and leaves it. Taking work somebody else holds is not refused — Flow refuses only a status that contradicts itself — but it is never silent either: the answer names who has it, so the one conversation that has to happen does.

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/take-work-so-nobody-duplicates-it.

## 1. Ana shares a project with Bruno and Carla

- `POST /api/v1/projects` → `201`
- `POST /api/v1/projects/proj_www4jv2362/members` → `200`
- `POST /api/v1/projects/proj_www4jv2362/members` → `200`
- `POST /api/v1/invitations/proj_www4jv2362/accept` → `200`
- `POST /api/v1/invitations/proj_www4jv2362/accept` → `200`
- `GET /api/v1/projects/proj_www4jv2362` → `200`

## 2. She makes an Engenharia team with Bruno in it

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

## 3. She routes one task to the team and leaves two free

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

## 4. Bruno is offered all three; Carla only the free ones

- `GET /api/v1/next?limit=10` → `200`
- `GET /api/v1/next?limit=10` → `200`

## 5. Bruno takes the team’s task, with no flag

- `PATCH /api/v1/tasks/task_62gc5r9vst` → `200`
- `GET /api/v1/tasks/task_62gc5r9vst` → `200`

## 6. Carla takes Bruno’s task: it lands, flagged, naming him

- `PATCH /api/v1/tasks/task_62gc5r9vst` → `200`

## 7. One of Ana’s agents takes the flaky test by naming it in the run it records

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

## 8. A second agent of hers names it too, and is told which run has it

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

## 9. It leaves that one and takes the other free task instead

- `POST /api/v1/agent-runs` → `200`
- `GET /api/v1/agent-runs?task=task_cm4vy6y4zq&status=running` → `200`
