# Runbook: alerting on a halt A halt that nobody hears about is a sleeve that has quietly stopped trading. `tapebook` raises a halt when the book and the broker disagree or when a cycle cannot be assembled; a runner can also lose its lease. This runbook is how those sentences reach a person. The seam is one outbound POST. There is no queue, no escalation policy and no pager integration beyond whatever your webhook receiver does. ## Set the webhook ```bash export TAPEBOOK_ALERT_WEBHOOK='https://hooks.example.test/tapebook' export TAPEBOOK_DESK='india-desk' # optional, defaults to "tapebook" ``` The runner reads these when it constructs its notifier. Set them in the same environment as `tape runner`, then restart the process. `tape serve` reads `TAPEBOOK_DESK` only, for the `/health` body. With `TAPEBOOK_ALERT_WEBHOOK` unset the notifier is a no-op: alerting is opt-in, and an unset variable never refuses startup. `--once` runs (a cron timer) deliberately do **not** send `runner_started`/`runner_stopped`; those would be one alert a minute. They do send halts, lost leases and cycle failures. ## The payload One JSON object, one POST, no batching: ```json { "event": "lease_expired", "sleeve": "momentum", "reason": "lease 'momentum' expired while held by 'runner-a'; another runner may now drive this sleeve", "at": "2026-12-01T10:00:00+00:00", "desk": "india-desk" } ``` `reason` is the desk's own sentence, kept verbatim. `sleeve` is `null` for runner-level events. `at` is UTC ISO-8601. This exact object is asserted in `tests/app/test_alerts.py`. `event` is one of: | event | when it fires | sleeve | |---|---|---| | `halted` | a halt is newly set by a cycle, or an active halt is seen for the first time by this process | yes | | `halt_cleared` | the halt store has no active halt, and the last recorded cycle was halted | yes | | `lease_expired` | a runner renewed its lease and the lease had already lapsed | yes | | `cycle_failed` | a cycle raised: assembly (unknown strategy, no bars) or the cycle itself | yes | | `runner_started` | the long-running loop starts (not `--once`) | no | | `runner_stopped` | the long-running loop stops, cleanly or with its stop reason | no | ## What to do when it fires - **`halted`** — read `reason`. It names the discrepancy the desk found. Do not clear the halt until the book and the broker agree; a halt is cleared by a named operator (`tape halts --clear --by `), never by a cycle. `GET /api/sleeves` and the sleeve page show the same reason. - **`halt_cleared`** — informational: the sleeve will trade again on its next due cycle. Confirm the operator who cleared it is the one you expect. - **`lease_expired`** — two runners may have been driving one sleeve, or the holder outlived its TTL. Check `tape leases` and the runner logs for the owner named in `reason` before assuming the next cycle is safe. - **`cycle_failed`** — the reason is the exception. The runner keeps its claim behaviour: the failure will repeat until fixed, but you get one alert per distinct error, not one per retry. - **`runner_started` / `runner_stopped`** — a stop without a planned restart is the incident. This repository ships no supervisor; bring the process back with your unit, then read `runner_stopped`'s `reason` if it was not a clean stop. ## `/health` shows the same state without paging `GET /health` stays `200` with `"status": "ok"` while the desk is healthy, so the container healthcheck and existing readers keep working. It returns `"status": "degraded"` in the body when a sleeve is halted, a lease has expired, or a sleeve has not recorded a cycle within twice its cadence. It is deliberately still HTTP 200: restarting the API does not clear a halt, and a failing healthcheck would only add a second incident to the first. ```json { "status": "degraded", "version": "0.0.0", "desk": "india-desk", "database": {"reachable": true}, "sleeves": [ { "sleeve": "momentum", "enabled": true, "cadence_seconds": 3600, "halted": true, "halt_reason": "book and broker disagree on INFY", "last_cycle_at": "2026-12-01T10:00:00+00:00", "stale": false } ], "newest_cycle_at": "2026-12-01T10:00:00+00:00", "halted_sleeves": 1, "expired_leases": 0, "reasons": ["sleeve 'momentum' is halted"] } ``` `last_cycle_at` is the last recorded snapshot, not the last claim: a cycle that raised before it could write a valuation does not count as successful. `stale` uses `2 × cadence_seconds`. ## Local test Point the variable at a listener you control and run one cycle with a strategy that cannot be assembled: ```bash TAPEBOOK_ALERT_WEBHOOK=http://127.0.0.1:8099/hook \ TAPEBOOK_DESK=test-desk \ uv run tape runner examples/india-runner.yaml --once ``` A POST body should arrive within the cycle. The webhook is attempted twice (one retry) with a five-second timeout. ## The honest limits - **Dedupe is transitions only, in one process.** A halt is announced once per halt record per process, a cleared halt once per halted snapshot, a cycle failure once per distinct error until the next success. A restart loses that memory: a standing halt is announced once more (one message per process, not per cycle), so a crash loop repeats it. There is no cross-process dedupe. - **No delivery guarantee.** A non-2xx or a connection error is logged at `warning` and dropped. There is no queue, no retry beyond the single attempt, and no at-least-once semantics. If the receiver is down when the desk halts, the ledger and `/health` still have the truth; the message is lost. - **No escalation policy.** One POST, one receiver. Routing, acknowledgement, paging and repeat reminders belong to whatever is on the other end. - **No authentication of the receiver response** beyond HTTP status: any 2xx is treated as delivered. - **Clearing a halt via the CLI is detected by the runner on its next cycle** for any halt this process saw, or for a halt whose last recorded cycle was halted. The notification carries the runner's wording that the store has no active halt, not the operator's name. A CLI halt raised *and* cleared while the runner was down leaves no evidence the runner can read, so no `halt_cleared` is sent. - **Start and stop are the long-running loop's events.** A configuration failure before the loop starts reaches the runner log and its non-zero exit code, not the webhook; a supervisor that only watches the webhook will not see it.