Wait for a human
Pause code until a person acknowledges. Deploy gates, agent approvals, break-glass access.
Some steps should not happen without a person. The pattern is always the same: create an alert, then wait for it to be acknowledged. treason.app does the hard part, reaching a human through push, text, call and Slack with escalation, and tells you the answer.
const result = await treason.page({
message: "Approve deploy of v42 to production?",
alias: "deploy:production:v42", // a re-run reuses the open request
priority: "P3",
wait: { timeoutMs: 10 * 60_000 },
});
result.acknowledged; // a person said yes
result.timedOut; // nobody answered in time
result.alert; // the final state of the alert (acknowledgedVia: "sms", "app", ...)page() is alerts.create() followed by alerts.waitFor(). Use them separately when you want to do something while you wait.
#How the wait works
waitFor polls GET /v1/alerts/{id} (every second, easing to five) until the alert is acknowledged or closed, or your timeout passes. It never throws on a timeout: check reached or timedOut. There is no long-lived connection to hold open and nothing to reconnect, so it behaves the same from a laptop, a CI runner and a serverless function.
From the shell, with no SDK at all:
id=$(curl -s -X POST $TREASON_API_URL/v1/alerts \
-H "Authorization: Bearer $TREASON_API_KEY" -H "Content-Type: application/json" \
-d '{"message":"Approve deploy?","alias":"deploy-42"}' | jq -r .alert.id)
until [ "$(curl -s -H "Authorization: Bearer $TREASON_API_KEY" $TREASON_API_URL/v1/alerts/$id | jq -r .alert.status)" != "open" ]; do sleep 2; done#Denied, approved, ignored
An acknowledgement is a "yes". There is no separate "no": a person who refuses closes the alert (or lets it time out). Treat the three outcomes explicitly:
| What happened | alert.status | acknowledgedAt | Your code should |
|---|---|---|---|
| Approved | acknowledged | set | go ahead |
| Refused | closed | not set | stop; they said no |
| Nobody answered | open or exhausted | not set | stop, then close the alert so nothing keeps ringing |
#Recipe: a deploy gate
import { Treason } from "@treason/sdk";
const treason = new Treason();
const { acknowledged, alert } = await treason.page({
message: `Approve deploy of ${version}?`,
alias: `deploy:production:${version}`,
wait: { timeoutMs: 10 * 60_000 },
});
if (!acknowledged) {
await treason.alerts.note(alert.id, "No approval. Deploy cancelled.");
await treason.alerts.close(alert.id);
process.exit(2);
}
await deploy();
await treason.alerts.note(alert.id, `Deployed ${version}.`);
await treason.alerts.close(alert.id);The notes become part of the alert's permanent event log, so the page doubles as an audit trail of who approved what, when, and from which channel.
The full, tested version is in examples/deploy-gate.
#Recipe: an AI agent that must ask first
Wrap the dangerous tool, not the whole agent:
const dropTable = withHumanApproval(treason, "drop_table", realDropTable, {
describe: ({ table }) => `DROP TABLE ${table} in production`,
timeoutMs: 120_000,
});
const result = await dropTable({ table: "scratch_tmp" });
// { ran: true, value: ... } or { ran: false, reason: "denied" | "timeout", message: "..." }Return the refusal to the model as a normal tool result and let it re-plan. See examples/agent-approval.
#Choosing priority and timeouts
P3for approvals during working hours: a push and a text.P1when the wait itself is an emergency: it keeps escalating to a call.- Set the timeout shorter than your escalation policy's total length if you want to give up before the page runs out of people.
- Use the alias so a retried job does not page a second time while the first is still open.
#Cost and etiquette
Each notification is metered. A gate that pages for every deploy to every environment is a noisy one: gate production, not staging, and use P3 so it does not call.