# Workflows and watchdogs

A workflow carries a repeatable job from one agent to the next: implement a change, review it, then prepare it for release. You describe the steps once, and OpenRig creates the next assigned task as each step closes. A watchdog brings an agent back when it needs to check something later.

## Start a workflow

A workflow spec names the steps, which agents do them and what follows each result. Start with a workflow spec you already have, or use `rig workflow specs` to list available specs and their source files. In the examples below, `workflows/search-page.workflow.md` stands for the file you choose and edit for your agents. Validate it without starting anything, then create a run with its objective and rig:

```
rig workflow validate workflows/search-page.workflow.md
rig workflow instantiate workflows/search-page.workflow.md --root-objective "Ship the search page" --created-by dev-impl@my-rig --rig my-rig
```

`instantiate` returns the run's ID and opens its first task. OpenRig keeps the run's own spec and objective, so you can inspect what that run was asked to do after a restart.

Use `--project`, `--mission` and `--slice` to put the run's tasks beside the work they belong to. `rig workflow run` starts the run and follows its progress until it finishes:

```
rig workflow run workflows/search-page.workflow.md --root-objective "Ship the search page" --created-by dev-impl@my-rig --rig my-rig --project my-project --mission search-experience --slice 01-search-page
```

## Finish a step and hand on the work

When you finish your step, use `rig workflow project` to close its task and create the next one together. The exit is `handoff`, `waiting`, `done` or `failed`.

```
rig workflow project --instance <run-id> --current-packet <task-id> --exit handoff --result-note "Search is ready for review"
```

The workflow records the handoff; the next agent still judges the work it receives. For a step waiting on another task, use `--exit waiting --blocked-on <task-id>`.

## Find what needs attention

```
rig workflow status
rig workflow list
rig workflow show <run-id>
```

`status` shows runs that are failed, stuck or waiting, with the next action. `list` shows the runs that exist. `show` gives one run's current work and who handles its exceptions. Use `rig workflow trace <run-id> --full` for its full step history, or `rig workflow watch <run-id>` to follow a run already in progress.

## Change a running plan

If a different agent should do a step, route that same step to them:

```
rig workflow route <run-id> --to dev-reviewer@my-rig --reason "reviewer is covering this step"
```

After fixing the cause of a failed step, `rig workflow resume <run-id>` opens a fresh task for that step, keeping completed steps and the history. `rig workflow abort <run-id>` cancels the run's live tasks and ends the run.

For workflows declared in project, mission and slice files, `rig workflow compile <mission-path>` shows the resulting plan. Editing those files does not change an existing run: inspect the proposed change with `rig workflow revise <run-id>`, then use the apply command it prints. Compatible changes preserve work already done or in progress. After a lost response, `rig workflow operation <key>` reads the recorded effect before you retry.

## Arrange a later check

For one task waiting on something, start with a timer:

```
rig queue block <task-id> --on external:build-result --wake-after 15m --continuation "Read the build result and finish the review"
```

Use a watchdog for a recurring reminder, a group of expected artifacts or a context-usage threshold. Its jobs survive daemon restarts.

For example, save this as `periodic-reminder.yaml`:

```yaml
policy: periodic-reminder
target:
  session: reviewer@my-rig
message: "Check the outstanding review and record what happens next."
```

Then register it:

```
rig watchdog register --spec periodic-reminder.yaml --policy periodic-reminder --target-session reviewer@my-rig --interval-seconds 600 --registered-by coordinator@my-rig
```

Keep the target in the file and command the same. `--message` is a shortcut for context-usage jobs, not periodic reminders.

To remind an agent before its context fills, a context threshold can be registered without a spec file:

```
rig watchdog register --policy context-usage-threshold --target-session dev-impl@my-rig --interval-seconds 300 --registered-by dev-impl@my-rig --threshold-mb 2 --message "Write a recap before continuing"
```

A byte threshold measures transcript size rather than the model's exact remaining context. Choose it with room to spare, or use a token or percentage threshold from the seat's own usage sample.

`rig watchdog list` shows the jobs; `rig watchdog status <job-id>` shows one job's recent evaluations. Use `rig watchdog update` to change an active job's message, interval or spec without replacing its ID. When its work ends, stop it with `rig watchdog stop <job-id>`.

## Where to go next

- [Coordination](/docs/coordination): assign work and set tasks aside until something they wait on happens.
- [The work tree](/docs/work-tree): the project, mission and slice files behind a lifecycle plan.
- [CLI reference](/docs/generated/cli-reference): every workflow and watchdog option.
