Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 50 additions & 20 deletions docs/monitoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Since 0139's switch (2026-11-25 13:43 UTC) most checks are Prometheus rules on t
| `protocol-changed` | `protocol` | 2026-11-09 12:19 UTC | 2026-11-09, fake points for both networks ([Drills](#drills)): ALARM 13:55:22, OK 13:59:22 UTC |
| `protocol-upgrade-coming` | `protocol` | 2026-11-09 12:19 UTC | 2026-11-09, fake points for both networks ([Drills](#drills)): ALARM 13:55:15–13:55:52, OK 13:59:15–13:59:52 UTC |
| `upstream-changed` | `upstream` | 2026-11-27 09:08 UTC | 2026-11-27, `make fire-test` ([Drills](#2026-11-27-the-upstream-alarms)): ALARM 09:14:57, OK 09:16:10 UTC, both seen in Slack |
| `upstream-silent` | `upstream` | 2026-11-27 09:08 UTC | 2026-11-27, `make fire-test` ([Drills](#2026-11-27-the-upstream-alarms)): ALARM 09:18:02, OK 09:39:03 UTC, both seen in Slack |
| `upstream-library-behind` | `upstream` | Not yet: 0026 | Not yet: 0026 fires it after the Alarms deploy |
| `audit-disk` | `host` | 2026-11-09 12:19 UTC | 2026-11-09, fake points in the stop window ([Drills](#drills)): ALARM 13:39:32, OK 13:49:32 UTC |
| `telemetry-silent` | `host` | 2026-11-09 12:19 UTC | 2026-11-09, the stop window ([Drills](#drills)): ALARM 13:40:23, OK 13:48:23 UTC |
| `credentials-stale` | `host` | 2026-11-09 12:19 UTC | 2026-11-09, fake points in the stop window ([Drills](#drills)): ALARM 13:31:13, OK 13:46:13 UTC |
Expand Down Expand Up @@ -246,7 +246,7 @@ down.
## The off-server check

The Watch stack's Lambda, `x402-production-watch`, runs every 5 minutes in AWS, so it works while
the server is down (ADR 0013). It has three sections, run at once:
the server is down (ADR 0013). It has four sections, run at once:

- **balance:** each served network's fee account through RPC with `checkFacilitatorBalance`,
published as `spendable_stroops`;
Expand All @@ -255,11 +255,17 @@ the server is down (ADR 0013). It has three sections, run at once:
- **upstream:** once a day, the run at 08:00 UTC: the conformance gate's pin from this repo's
`develop`, and four upstream x402 files at that pin and on upstream `main` (the x402 spec, the
Stellar `exact` scheme, the suite's Stellar routes and the discovery spec, task 0029),
published as `upstream_files_changed`, the count that differ.
published as `upstream_files_changed`, the count that differ;
- **library:** in the same 08:00 UTC run: the commit production's `/health` names, the
`@x402/stellar` range in `apps/facilitator/package.json` at that commit, and npm's `latest`
(task 0147), published as `upstream_library_behind`, 1 when they differ.

A network a section can't read publishes nothing, so its alarms keep their state and
`watch-errors` fires instead; the other sections still publish. The upstream section fails at most
once a day, which `watch-errors` can't count on its own: `upstream-silent` covers it.
`watch-errors` fires instead; the other sections still publish. The upstream and library sections
fail at most once a day, which `watch-errors` can't count on its own: their alarms read a day with
no point as a breach. Both read whole UTC days, so a day's result reaches the channel after
00:00 UTC: a sliding 24 hours would lose yesterday's point before today's lands and fire every
morning.

Its log, and a run by hand:

Expand All @@ -270,11 +276,12 @@ aws lambda invoke --function-name x402-production-watch --payload '{}' \
```

A run by hand with `--payload '{"scheduledTime":"<today>T08:00:00Z"}'`, after 08:00 UTC, runs the
upstream section too. Use today's date: every point is stamped with that time, and CloudWatch
refuses a point more than 2 hours ahead, so a later date fails all three sections.
upstream and library sections too. Use today's date: every point is stamped with that time, and CloudWatch
refuses a point more than 2 hours ahead, so a later date fails every section.

Each run logs `watch_balance` with the spendable balance in stroops and `watch_protocol` with
both versions, the 08:00 run `watch_upstream` with the pin and the files that differ, or
both versions, the 08:00 run `watch_upstream` with the pin and the files that differ and
`watch_library` with the commit and both versions, or
`watch_section_failed` with the section, the network and the error.

### balance-low
Expand Down Expand Up @@ -328,10 +335,11 @@ The check hasn't run for 15 minutes, so the balance and protocol alarms see noth
### upstream-changed

Upstream x402 `main` changed, since the gate's pin, a file the gate's suite rests on or the
discovery spec. Nothing breaks for us: the gate still runs the pinned suite. It means a seller or
buyer on the newest x402 libraries may no longer match what we tested.
discovery spec; or the day's read failed. Nothing breaks for us: the gate still runs the pinned
suite. It means a seller or buyer on the newest x402 libraries may no longer match what we tested.

1. Read the 08:00 run's `watch_upstream` line: `changed` lists the files.
1. Read the 08:00 run's `watch_upstream` line: `changed` lists the files. No such line: read
`watch_section_failed` with `section: upstream`, below.
2. Read the change upstream: `https://github.com/x402-foundation/x402/commits/main/<file>`.
3. If it changes what a payment or a listing looks like, bump `UPSTREAM_COMMIT` in
`conformance/src/upstream.ts` and rerun the gate (`conformance/README.md`); the next 08:00 run
Expand All @@ -340,16 +348,37 @@ buyer on the newest x402 libraries may no longer match what we tested.
While it stays in ALARM, a later upstream change sends no new message: read the daily
`watch_upstream` line until the pin moves.

### upstream-silent
If the day's read failed, `watch_section_failed` with `section: upstream` names the file:

The upstream section published nothing for two days, so `upstream-changed` sees nothing.
- `answered 404`: upstream moved or deleted a file, a change to read like the one above; update
`FILES` in `infra/src/watch/upstream.ts` and deploy the Watch stack.
- `answered 429` or `5xx`, or a timeout: GitHub refused or was slow; it usually passes by itself.
- `expected one commit`: `conformance/src/upstream.ts` no longer holds exactly one commit hash.

1. Read the 08:00 runs for `watch_section_failed` with `section: upstream`: the error names the
file.
2. `answered 404`: upstream moved or deleted a file, a change to read like `upstream-changed`;
update `FILES` in `infra/src/watch/upstream.ts` and deploy the Watch stack.
3. `answered 429` or `5xx`, or a timeout: GitHub refused or was slow; it usually passes by itself.
4. `expected one commit`: `conformance/src/upstream.ts` no longer holds exactly one commit hash.
### upstream-library-behind

Production's facilitator asks for another `@x402/stellar` than the one npm calls `latest`; or the
day's read failed. Nothing breaks at once: the facilitator keeps verifying and settling. It means
fixes upstream has released don't run in production yet, or a raise merged on `develop` is not
deployed. A protocol upgrade the SDK can't read has its own, earlier alarm,
[protocol-upgrade-coming](#protocol-upgrade-coming).

1. Read the 08:00 run's `watch_library` line: `production` and `latest`, and the `commit`
production runs.
2. `develop` already on `latest`: deploy (`docs/runbook.md`); the next 08:00 run publishes 0.
3. Otherwise read upstream's changes since our version, raise every `@x402` package together (AD-14
in `docs/architecture/m1-spine.md`), and deploy; or say in the channel why the version stays.

While it stays in ALARM, a later release sends no new message: read the daily `watch_library`
line. If the day's read failed, `watch_section_failed` with `section: library` names it:

- `names no commit`: `/health` gave no `commit`, so the image was built without `GIT_COMMIT`
(`.github/workflows/deploy-production.yml` sets it); redeploy through the workflow.
- `not ~X.Y.Z`: the range in `apps/facilitator/package.json` has another shape; AD-14 asks for
`~X.Y.Z`. Change it back, or the read in `infra/src/watch/library.ts`.
- `answered 404`, `429` or `5xx`, or a timeout: GitHub, npm or `/health` refused or was slow.
- `answered no JSON`: the named URL sent a page in place of JSON, such as a Cloudflare challenge in
front of `/health`.

## The facilitator

Expand Down Expand Up @@ -1072,7 +1101,8 @@ CloudWatch from the host probe's EMF lines, and `x402-watch` and `AWS/*` are Clo
| `spendable_stroops` | `x402-watch` | gauge, None | `network` | [balance-critical](#balance-critical), [balance-low](#balance-low) |
| `protocol_version` | `x402-watch` | gauge, None | `network` | [protocol-changed](#protocol-changed) |
| `protocol_supported_version` | `x402-watch` | gauge, None | `network` | [protocol-upgrade-coming](#protocol-upgrade-coming) |
| `upstream_files_changed` | `x402-watch` | gauge, Count | none | [upstream-changed](#upstream-changed), [upstream-silent](#upstream-silent) |
| `upstream_files_changed` | `x402-watch` | gauge, Count | none | [upstream-changed](#upstream-changed) |
| `upstream_library_behind` | `x402-watch` | gauge, Count | none | [upstream-library-behind](#upstream-library-behind) |
| `account_state_mismatches` | `x402-watch` | gauge, Count | `network` | `account-state` (off) |
| `account_effects_unexpected` | `x402-watch` | counter, Count | `network` | `account-effects` (off) |
| `backup_secret_reads` | `x402-watch` | counter, Count | none | `backup-secret-read` (off) |
Expand Down
2 changes: 1 addition & 1 deletion infra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ exists with its actions off (decision 26).
| `watch` | `balance-low`, `balance-critical`, `watch-errors`, `watch-no-invocations` | The Watch stack's Lambda publishes `spendable_stroops` (#115) |
| `watchSecurity` | `account-state`, `account-effects`, `backup-secret-read` | The check's theft and secret-read sections publish: task 0127 (decisions 68, 71) |
| `protocol` | `protocol-changed`, `protocol-upgrade-coming` | The check's protocol section publishes both versions for each network in `watch.protocol` (decision 70) |
| `upstream` | `upstream-changed`, `upstream-silent` | The check's 08:00 UTC run publishes `upstream_files_changed` (task 0029) |
| `upstream` | `upstream-changed`, `upstream-library-behind` | The check's 08:00 UTC run publishes `upstream_files_changed` (task 0029) |
| `heartbeat` | `monitoring-heartbeat`, in the Heartbeat stack: deploy it with `make deploy-production-heartbeat` | The topic's `NumberOfMessagesPublished` shows Alertmanager's `Watchdog` every minute (docs/monitoring.md, monitoring-heartbeat, step 1; 0139) |

`heartbeat` is the exception to what follows: check-series builds only the Alarms stack, so it
Expand Down
11 changes: 10 additions & 1 deletion infra/src/lib/alarms/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ export interface LevelSpec extends Common {
readonly threshold: number;
/** Default `ignore` (decision 19); `uptime` breaches on a missing point. */
readonly missing?: "ignore" | "breaching" | "notBreaching";
/**
* Whole UTC days, not CloudWatch's default sliding window: a sliding 24 hours loses yesterday's
* 08:00 point before today's lands and would fire and clear every morning (AWS, "Alarm
* evaluation window"). A day's point is read once the day ends, at 00:00 UTC.
*/
readonly wholeDays?: boolean;
}

export interface SilenceSpec extends Common {
Expand Down Expand Up @@ -196,14 +202,17 @@ export class AlarmFactory implements Alarms {

/** The Level shape: past the threshold in M of M periods; keeps its state without data. */
level(base: string, spec: LevelSpec): cloudwatch.Alarm | undefined {
return this.make(base, "level", spec, {
const alarm = this.make(base, "level", spec, {
metric: this.metric(spec.signal, spec.statistic, spec.periodMinutes),
comparisonOperator: COMPARISON[spec.comparison],
threshold: spec.threshold,
evaluationPeriods: spec.periods,
datapointsToAlarm: spec.datapoints ?? spec.periods,
treatMissingData: MISSING[spec.missing ?? "ignore"],
});
if (alarm && spec.wholeDays)
(alarm.node.defaultChild as cloudwatch.CfnAlarm).evaluationWindow = { wallClockWindow: {} };
return alarm;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion infra/src/lib/alarms/money.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function addMoneyAlarms(f: Alarms, c: EnvironmentConfig): void {
comparison: ">=",
threshold: 1,
description: {
what: "The off-server check failed in 2 of its last 3 runs: a section was not published, the balance (its RPC) or the protocol (Horizon). A failed daily upstream read can't fill 2 of 3 runs: upstream-silent covers it. The theft and secret-read sections come later (decision 68).",
what: "The off-server check failed in 2 of its last 3 runs: a section was not published, the balance (its RPC) or the protocol (Horizon). A failed daily upstream or library read can't fill 2 of 3 runs: upstream-changed and upstream-library-behind read its missing day as a breach. The theft and secret-read sections come later (decision 68).",
next: `Read the ${n.watchFunction} log for watch_section_failed: it names the section and the network; the other section still published.`,
noData: "Keeps its state; watch-no-invocations covers runs that don't happen.",
},
Expand Down
42 changes: 24 additions & 18 deletions infra/src/lib/alarms/upstream.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
// G-alarm-list, "Upstream": the off-server check's upstream section (task 0029), once a day at
// 08:00 UTC. `upstream-changed` fires while a file the conformance gate rests on, or the discovery
// spec, differs from the gate's pin, and clears once the pin moves to an upstream that has the
// change. `upstream-silent` fires when the section published nothing for two days: `watch-errors`
// counts 2 of 3 five-minute runs, so a once-a-day failure never reaches it.
// G-alarm-list, "Upstream": the off-server check's upstream and library sections (tasks 0029 and
// 0147), once a day at 08:00 UTC. `upstream-changed` fires while a file the conformance gate rests
// on, or the discovery spec, differs from the gate's pin, and clears once the pin moves to an
// upstream that has the change. `upstream-library-behind` fires while production asks for another
// `@x402/stellar` than npm's latest, and clears once a deploy brings it there. Each reads a day
// with no point as a breach: a read that broke can't pass as all clear, and `watch-errors` counts
// 2 of 3 five-minute runs, so a once-a-day failure never reaches it.
import type { Alarms } from "./factory.js";

export function addUpstreamAlarms(f: Alarms): void {
// FILL(m, 1) turns a day with no point into a breach; `breaching` covers a series that was never
// written, which metric math alone can't see (the factory's Silence shape, the Prices API's 0222).
f.level("upstream-changed", {
group: "upstream",
signal: { catalog: "upstream_files_changed" },
signal: { expression: "FILL(m, 1)", using: { m: { catalog: "upstream_files_changed" } } },
statistic: "Maximum",
periodMinutes: 24 * 60,
periods: 1,
comparison: ">=",
threshold: 1,
missing: "breaching",
wholeDays: true,
description: {
what: "Upstream x402 main changed, since the conformance gate's pin, a file its suite rests on (the x402 spec, the Stellar exact scheme, the suite's Stellar routes) or the discovery spec (bazaar.md).",
next: "Read the check's watch_upstream log line for the files, then the change upstream. Bump the pin in conformance/src/upstream.ts and rerun the gate (conformance/README.md), or say in the channel why not.",
noData: "Keeps its state; upstream-silent covers a section that stops publishing.",
what: "Upstream x402 main changed, since the conformance gate's pin, a file its suite rests on (the x402 spec, the Stellar exact scheme, the suite's Stellar routes) or the discovery spec (bazaar.md); or the day's read failed.",
next: "Read the check's 08:00 UTC log: watch_upstream lists the files that differ, watch_section_failed with section upstream names the read that failed. Bump the pin in conformance/src/upstream.ts and rerun the gate (conformance/README.md), or say in the channel why not.",
noData: "Breaching: a day with no point is a read that failed.",
},
});

// A day with no point breaches. 2 of 2: one failed day pages no one, as the next day's run retries.
f.level("upstream-silent", {
f.level("upstream-library-behind", {
group: "upstream",
signal: { catalog: "upstream_files_changed" },
statistic: "SampleCount",
signal: { expression: "FILL(m, 1)", using: { m: { catalog: "upstream_library_behind" } } },
statistic: "Maximum",
periodMinutes: 24 * 60,
periods: 2,
comparison: "<",
periods: 1,
comparison: ">=",
threshold: 1,
missing: "breaching",
wholeDays: true,
description: {
what: "The off-server check's daily upstream read published nothing for two days, so upstream-changed sees nothing: GitHub refused or timed out, a file moved upstream, or the pin file changed shape.",
next: "Read the check's log at 08:00 UTC for watch_section_failed with section upstream: it names the file that failed, or the publish.",
noData: "Breaching: no point is what this alarm is for.",
what: "Production's facilitator asks for another @x402/stellar than the one npm calls latest; or the day's read failed (/health, GitHub or npm).",
next: "Read the check's 08:00 UTC log: watch_library names both versions, watch_section_failed with section library names the read that failed. Raise the @x402 packages (AD-14 in docs/architecture/m1-spine.md) and deploy, or say in the channel why not.",
noData: "Breaching: a day with no point is a read that failed.",
},
});
}
Loading
Loading