# Repair proposals

> List and accept or reject the pose and jaw repairs checks propose on handheld takes

A check that finds a pose or jaw fault on a handheld (UMI) take proposes the
repair that fixes it: an interpolation over the bad frames, or a step that
corrects a tracking slip from one frame to the end of the take. Nothing is
repaired until a person or an API key accepts it. `client.repair_proposals`
reads and decides them on an upload or on a merged dataset that holds it.

Every method takes a dataset id or its full name
(`accounts/{account}/datasets/{dataset}`). A mixture, and an upload merged
into a dataset (use the merged dataset), are refused with
`FAILED_PRECONDITION`. `client.repair_proposals` is new after qualia-sdk
0.8.0rc19, which raises `AttributeError`.

## List the proposals

```python
page = client.repair_proposals.list(dataset_id)  # limit=, cursor= page through
for proposal in page.items:
    repair = proposal.repair
    print(proposal.name, proposal.state, proposal.applied)
    print(" ", repair.hand, repair.target, repair.kind, repair.start_frame, repair.end_frame)
    print(" ", proposal.check, proposal.reason)
```

The list holds the open and the rejected proposals, oldest first. Each has:

- `repair`: a ready `RepairPoses` add. Its episode, hand, target, kind
  (`INTERPOLATE` or `STEP`), frames `[start_frame, end_frame)` of the take as
  recorded, the `take_identity` the check read and, for a step, its `shift`
  (metres) or `turn` (radians) and `repair_identity`.
- `check` and `reason`: which check proposed it, and why.
- `state`: the decision, `PROPOSED` (nobody rejected it) or `REJECTED`.
- `applied`: the upload's published repairs hold it, accepted and landed or
  made by hand.

`applied` comes first. A proposal can be applied and read `REJECTED`, after a
reject that raced its accept or when the same repair was made by hand: it is
applied all the same.

## Accept or reject

```python
review(dataset, decision, proposals=None, *, episodes=None, all=False)
```

```python
client.repair_proposals.review(dataset_id, "accept", [proposal.name])
client.repair_proposals.review(dataset_id, "accept", episodes=[take])
client.repair_proposals.review(dataset_id, "reject", all=True)
```

`decision` is `"accept"` or `"reject"`, in any case. Pass exactly one of
`proposals` (ids or names, open or rejected), `episodes` (every open proposal
of each take) and `all=True` (every open proposal of the dataset); anything
else raises `ValueError` before a request.

**Accept** is one `RepairPoses` call adding every selected repair. The reply's
`reviewed` holds the proposals as they stand now (one is `applied` once its
publication lands) and `repair` holds what `RepairPoses` answered: its
`operation_id`, or `no_op` when the repairs were published already. On a
merged dataset each member upload publishes on its own: `repair.members` has
one answer per member, `CURRENT`, `RUNNING`, `BUSY` or `REFUSED` with its
`reason`. Accept the proposals of a busy or refused member again later.

`RepairPoses` refuses the whole batch when any proposal has a problem, and the
error names each one: its take was re-ingested since the check ran, its take's
pose trails the video (an open `handheld_pose_late` finding), or its frames
overlap another repair. Nothing is accepted then. Accept the others by take or
by id. A rejected proposal can be accepted.

An applied proposal is left out of the call: when only applied ones are
selected, nothing is sent and `repair` is unset. One call adds at most 200
repairs, so an accept of more is refused before any is added; accept them by
take or by id.

**Reject** closes the open proposals and repairs nothing. A rejected proposal
stays rejected when its check proposes the same repair on the same data again;
a re-ingest that changes the take lets it be proposed anew. A reject by take or
of all leaves applied proposals open. A person or an API key rejects.

Undoing an accepted repair is the episode page's Undo (a `RepairPoses`
remove).

## In the CLI

[`qualia dataset repairs`](https://docs.qualia.dev/cli/commands.md#qualia-dataset-repairs) lists the
proposals (short for `repairs list`), and `repairs accept|reject` decides them
by id, by take (`--episode`) or all (`--all`).

```bash
qualia dataset repairs <DATASET_UUID>
qualia dataset repairs accept <DATASET_UUID> <PROPOSAL_UUID>
qualia dataset repairs reject <DATASET_UUID> --episode <EPISODE_UUID>
```
