# Hold a run to your own checks

> Completion gates, final checks, results, and offline replay.

A script, CI job, or another agent can hold an Open Max turn to commands it chooses. A blocking `turn_end` hook refuses the model's attempt to finish while a check fails and sends the failure back to the model.

## Try the demonstration

From a clone of [open-max](https://github.com/Max17190/open-max), with the `openmax` binary, Python 3.9 or later, and Git:

```sh
python3 examples/run-task/demo.py
```

The demo uses a local scripted model server, so no model account is needed. It creates a temporary repository with a failing check, shows the gate refusing the first attempted finish, and runs the fix. It prints a JSON result, the patch, and an offline replay command.

## Use your own checks

The [run-task example](https://github.com/Max17190/open-max/tree/main/examples/run-task) combines a JSON print run, a completion hook, and a session event log. Follow its setup instructions to install the hook and grant project trust before running a task.

```sh
python3 ~/open-max/examples/run-task/run_task.py --repo ~/code/my-app \
  --check "make test" \
  --final-check "make lint" \
  "Make the failing test pass."
```

Replace the clone and project paths with yours. A `--check` runs before the work, at the model's attempted finishes, and after Open Max exits. A `--final-check` runs only after exit. The caller's own final checks decide the result's `verified` field. The result also includes the patch and a command to replay the recorded run offline.

## Read the result's limits

The example's hook allows three refusals. If the checks still fail after that allowance, the turn ends `unverified`. The caller can also limit iterations, tokens, and elapsed time.

A passing result covers only what your checks test. In `auto` mode, the model can edit tests and the gate's command list. The caller keeps its own copy of the checks, runs them again after exit, and returns the patch for inspection. This does not provide process isolation; see [Native execution and privacy](https://useopenmax.dev/docs/execution).

The [verified execution reference](https://github.com/Max17190/open-max/blob/main/docs/verified-execution.md) covers setup, exit codes, completion events, limits, continuation, and replay.
