# Wait on upstream

Hold a task until a command says the release it needs has landed, and free it the moment it has.

Your code has a workaround for a bug in an external library, and the fix lands in the next release. The task that drops the workaround looks ready. An agent picks it up, finds the old version still locked and wastes an hour proving it. Or the workaround stays for a year after the library maintainers fix the bug.

## Config

[`examples/api-service/.mindtape/config.toml`](https://github.com/mlavrinenko/mindtape/blob/main/examples/api-service/.mindtape/config.toml)

```toml
[[tasks.waits]]
name = "locked"
run = "scripts/locked {id}"
```

`scripts/locked` reads `Cargo.lock`. It exits 0 once the lockfile pins the version an id names or a later one, and 1 while it pins an older one.

## Behavior

The task records what it waits on in `waits-on`. In a fresh clone `mt` doesn’t run a checker. It blocks the task as unknown and asks you to allow the config’s commands. Once you do, `why` quotes the script while the lockfile pins 2.3.2, and `mt wip` won’t start the task. Merge the dependency bot’s branch, and the same listing lets it go:

```
$ grep waits-on: tasks/verify-webhooks-with-the-acme-pay-sdk.typ
  waits-on: ("locked:acme-pay@2.4.0",),
$ mt ls blocked --columns title,why
TITLE                                  WHY
Verify webhooks with the acme-pay SDK  waits on: locked:acme-pay@2.4.0 (unknown: not allowed)
Throttle failed logins per IP          waits on: add-redis-client (proposed)

2 of 14 tasks · your filter
warning: not running the commands your config declares until you allow them
hint: read them, then run mt allow
note: command: 'scripts/locked {id}'
note: command: 'scripts/test'
$ mt allow
allowed in this repository and its worktrees:
  waits    scripts/locked {id}
  on.flip  scripts/test
$ mt ls blocked --columns title,why
TITLE                                  WHY
Verify webhooks with the acme-pay SDK  waits on: locked:acme-pay@2.4.0 (acme-pay 2.3.2 is locked)
Throttle failed logins per IP          waits on: add-redis-client (proposed)

2 of 14 tasks · your filter
$ mt wip verify-webhooks-with-the-acme-pay-sdk
error: status requires an unblocked task: 'wip'
hint: finish what it waits on first, or pass --force to skip this check
note: waits on: locked:acme-pay@2.4.0 (acme-pay 2.3.2 is locked)
$ git merge -q renovate/acme-pay-2.x
$ mt ls blocked --columns title,why
TITLE                          WHY
Throttle failed logins per IP  waits on: add-redis-client (proposed)

1 of 14 tasks · your filter
```

## Readiness checks

Each `[[tasks.waits]]` entry names a checker command. A task lists `checker:id` entries in `waits-on`, and `mt` runs the checker’s `run` from the project root with `{id}` filled in. A `run` is a shell line or an array, as in a [flip hook](https://mlavrinenko.github.io/mindtape/hooks/index.md#trust-and-portability). Exit 0 means the wait is over. Exit 1 means the task still waits. Any other exit means `mt` can’t tell, and the task stays blocked. The first line the command prints becomes the `why` value. Add an entry with `mt set <task> waits-on+=locked:acme-pay@2.4.0`.

Every command that reads readiness runs checkers, `mt ls` included. A checker takes its answer from local state, and fast. `mt` runs each distinct command line once per call and skips closed tasks. Fetching news over the network is the tool’s own job, on its own schedule, such as a timer, a recipe or the bot that bumps your lockfile.

A checker can run `mt` too, say `mt ls ready` against the same project. That inner `mt` loads the project, so it would run the same checker, which starts another `mt`, and so on forever. It doesn’t. Every checker runs with `MINDTAPE_WAITS_CHECKER=1` set, and an `mt` that sees it doesn’t run a checker at all. Its waits read `unknown: asked inside a checker`, and the outer `mt` gets its answer in one hop.

In a string `run`, `mt` inserts `{id}` into a shell line as is. `mt check` refuses an id that a shell could read as more than a word. An id starts with a letter or digit and allows letters, digits and `._@/#:+-`. An array such as `run = ["scripts/locked", "{id}"]` fills `{id}` into each item on its own, and `mt` passes each item to the command directly. The same id rule applies there. An entry works under either form.

A checker runs with your full rights, like a `Justfile` recipe, and `mt ls` would run it the moment you clone. So `mt` runs none until [`mt allow`](https://mlavrinenko.github.io/mindtape/cli/allow/index.md) records the config’s commands for the repo. Until then each command warns once and lists them, every wait reads `unknown: not allowed`, and `mt wip --force` still starts a task. `mt` stores the approval outside the repo, and it covers each of its worktrees. Change a `run` and `mt` asks again.

[Task links](https://mlavrinenko.github.io/mindtape/links/index.md) covers `depends-on`, the blocker that waits on another task instead.
