on this page

MonitorsHeartbeats

Heartbeats

A heartbeat is a send URL that expects to hear from you. Beat it when a job finishes; if a beat doesn't arrive in time, Mast pages the phone that owns the alert source. A failed backup, a dead cron daemon and a powered-off box are all one missing check-in and one page.

This page has the whole of it: a bare period or a crontab schedule, a start signal that catches the run which never finished, the beat history, the exit-code form of a beat, the web app screen that shows all of it, and a status badge you can paste into a README. The short forms of a beat (/start, /fail, the exit code, run ids and the failure threshold) have a page of their own under run signals.


Making one

In the app, New alert source, then Heartbeat instead of the ordinary kind; a new one starts at every hour with ten minutes of grace. In the web app, Heartbeats, then New heartbeat, which also hands you the crontab line. Over the API a heartbeat is an alert source with kind: "heartbeat" and a period:

curl -X POST https://api.tissue.systems/v1/mast/alert-sources \
  -H "Authorization: Bearer $TISSUE_TOKEN" -H "Content-Type: application/json" \
  -d '{"name": "nightly-backup", "kind": "heartbeat",
       "period_secs": 86400, "grace_secs": 3600, "heartbeat_priority": "loud"}'

Every route below takes either the phone's own credential or an account API token, and the token needs mast:read to read and mast:write to publish a badge. They work before a phone is linked, but nothing rings until one is.

period_secs is how often you promise to beat. grace_secs is how late that may be before anyone is woken. Silence past period_secs makes the heartbeat late and does nothing else; silence past period_secs + grace_secs makes it go down and sends a page at heartbeat_priority. The next beat closes that page. A new heartbeat starts as waiting (pending in the API): nothing is counted until its first beat, so one you make on Friday and wire up on Monday pages nobody over the weekend. After a period plus grace with no beat it gets one quiet card saying it's still waiting, and that's all it gets. A heartbeat is only swept while it watches something. Set period_secs, schedule and max_duration_secs all to 0 or "" and nothing sweeps it, so it never goes late. That's how you park one without deleting it. Clearing only period_secs on a heartbeat that also has a schedule leaves the schedule watching.

The app and the web app show five states for a heartbeat: Waiting until its first beat, Up, Late once a beat is overdue, Down once the grace has run out too, and Paused. The API calls them pending, alive, late, flatline and paused. When a heartbeat goes down, webhooks get heartbeat_down, and vital_flatline with the same payload for receivers that already read that name.

A heartbeat can watch three different things, and it needs at least one of them:

Field Watches Fails when
period_secs How long between beats Nothing heard for longer than the period allows
schedule That the beat lands on a crontab A fire came and went with no beat behind it
max_duration_secs How long one run may take A run opened and is still open past the limit

period_secs and schedule answer the same question two ways, so a heartbeat that sets both is judged on the schedule and the period is ignored. max_duration_secs is independent and stacks with either.

Each plan includes a number of heartbeats. Past it, a create answers 402 with plan_limit, says which plan and how many, and carries limit and used. Archive one or move up a plan; Limits has the numbers. Beats, history and badges are never rationed; the count is of live heartbeats on the account.


Beating it

The plain beat is a POST to the send URL with nothing in it, which is what lets a crontab line be one curl:

17 3 * * *  /usr/local/bin/backup.sh && curl -fsS -m 10 --retry 3 https://mast.tissue.dev/mk_8e2a… >/dev/null

-m 10 gives up on a request that hangs, and --retry 3 tries again after a timeout or a 5xx, waiting a little longer each time. mast.tissue.dev answers from more than one host, and curl already moves to the next address when it can't connect, so the retries cover the rest: a host that went away after DNS handed it out, or a reply that never came. A beat that arrives twice is still one beat.

With the exit status

&& only beats when the job succeeds, and says nothing at all when it fails. The heartbeat waits out its grace window before anyone hears about it. Put the exit status in the path instead and the failure is reported the moment it happens:

17 3 * * *  /usr/local/bin/backup.sh >/tmp/backup.log 2>&1; \
            curl -fsS -m 10 --data-binary @/tmp/backup.log \
              "https://mast.tissue.dev/mk_8e2a…/$?" >/dev/null

$? is the shell's exit status of the command before it, so the route sees 0 on success and the real status on failure:

Path What happens
POST /mk_…/0 A beat. The heartbeat stays up and nothing rings, whatever the body says
POST /mk_…/17 Down, right now. The card reads nightly-backup exited 17
POST /mk_…/fail Down the same way, with no status to name. The card reads nightly-backup failed

0 is a beat even when the body carries warnings. A job that prints to stderr on a good run shouldn't wake anybody, so on this route the exit status is the whole message and the text is only logged.

The code has to be an integer from 0 to 255. Anything else (abc, 256, -1, an empty segment) answers the same flat 404 an unknown key gets, because the caller holds a key and nothing else, and a more specific refusal would describe the alert source behind it.

Whatever you send as the body is kept as the job's output: up to 16 KiB on the wire, of which the history keeps the first 4096 characters. --data-binary @file is the usual way to hand it a log.

From a Cell

The beat belongs in the pulse handler, on the path that finished:

export default {
  async pulse(event, env) {
    const rows = await sweep(env);
    await fetch(`${env.HEARTBEAT_URL}/0`, { method: "POST", body: `swept ${rows} rows` });
  },
};

A throw before that fetch sends nothing, and the heartbeat goes down on its own once the grace window closes.

From GitHub Actions

A scheduled workflow is a common thing to put a heartbeat on. In a public repository, GitHub disables a workflow's schedule trigger after 60 days with no commit to the repository. Tags, issues, releases and merges from a fork do not count; only a push to a branch resets the clock. The Actions tab shows no error, and the disable also stops the workflow's other triggers (workflow_dispatch included) until somebody re-enables it. Private repositories are not affected.

From our side a workflow disabled this way looks exactly like a job that died: the beats stop and the heartbeat goes down. We cannot tell the two apart, and we do not try. If the repository is public and the page says the heartbeat went quiet a couple of months after the last commit, check the workflow's page on GitHub first; a yellow banner there means the fix is one click and the alert was benign.

The recipe below beats a heartbeat and keeps itself enabled without a commit. The re-enable call is the same endpoint the Actions tab's button uses, and calling it on a workflow that is still enabled resets the 60-day clock; the token the workflow already has can make the call once it is granted actions: write.

name: nightly
on:
  schedule:
    - cron: "17 3 * * *"
  workflow_dispatch:

permissions:
  contents: read
  actions: write   # the keepalive step

jobs:
  nightly:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: ./nightly.sh
      - name: Beat the heartbeat
        if: always()
        run: |
          curl -fsS -m 10 --retry 3 -X POST "${{ secrets.HEARTBEAT_URL }}/${{ job.status == 'success' && 0 || 1 }}" \
            --data-binary "run ${{ github.run_id }} ${{ job.status }}"
      - name: Keep the schedule enabled
        if: always()
        env:
          GH_TOKEN: ${{ github.token }}
        run: gh api --method PUT "repos/${{ github.repository }}/actions/workflows/nightly.yml/enable"

if: always() runs both steps whether or not nightly.sh failed, and the exit-code segment tells the heartbeat which it was. nightly.yml in the last line is the workflow's own file name. If you would rather not grant actions: write, gautamkrishnar/keepalive-workflow does the same thing with an empty commit instead, at the cost of one commit every so often in the history.

The heartbeat's URL is a write capability; keep it in a repository secret, never in the workflow file, because a public repository's history is public forever and a key seen in it has to be rotated.


On a schedule instead of a period

A period is a stopwatch: beat every 86400 seconds, whenever those seconds start. That's the wrong shape for a job that runs at 03:17, because a beat at 03:17 on Monday and one at 03:16 on Tuesday are 86340 seconds apart and the stopwatch has nothing to say about it. A schedule is the crontab itself:

curl -X PATCH https://api.tissue.systems/v1/mast/alert-sources/nightly-backup \
  -H "Authorization: Bearer $TISSUE_TOKEN" -H "Content-Type: application/json" \
  -d '{"schedule": "17 3 * * *", "schedule_tz": "America/Los_Angeles", "grace_secs": 1800}'

Five POSIX fields (minute, hour, day of month, month, day of week) with ranges, lists and steps: */15, 0,30, 1-5, 17 3 * * 1-5. Day of week is 0 to 6 with Sunday 0, and 7 is also Sunday, which is what a line lifted straight out of a real crontab means. Names work too: mon, fri, jan.

schedule_tz is an IANA zone name such as America/Los_Angeles or Europe/Berlin, a fixed offset like +02:00, or empty for UTC. Prefer the name. A backup written as 17 3 * * * at a fixed -08:00 runs an hour off for eight months of the year; the name follows the clocks.

The two rungs are the same, hung off the last fire instead of a stopwatch. Past the fire the heartbeat is late; past the fire plus grace_secs it goes down, and the card names what it was waiting for: No beat for 1200s; expected 03:17 America/Los_Angeles daily. A weekly heartbeat stays quiet for six days on purpose: it's the fire that's compared against the last beat, not the clock.

A schedule needs a grace_secs above zero, and a create or patch that would leave it at zero is refused. On a period, zero is honest: the period is itself the wait. On a schedule it means "page the second the minute ticks", which is before the job has started, let alone reported. Give it the time the job actually takes plus room.

A schedule that doesn't parse pages nobody. The API refuses the ones it can see at write time, and the sweep treats anything it can't read as owing nothing. The edit that broke it was made at a desk and the page it would cause arrives at 03:00.


A run that takes too long

Everything above notices a job that stopped. None of it notices a job that started and never finished, the one that's been holding a lock for six hours. Say the run began:

curl -fsS -m 10 --retry 3 -X POST https://mast.tissue.dev/mk_8e2a…/start
/usr/local/bin/backup.sh >/tmp/backup.log 2>&1
curl -fsS -m 10 --retry 3 --data-binary @/tmp/backup.log "https://mast.tissue.dev/mk_8e2a…/$?"

With max_duration_secs set, a run still open past that many seconds goes down immediately. There's no late rung under it, because that number is you writing down the longest this job may honestly take:

curl -X PATCH https://api.tissue.systems/v1/mast/alert-sources/nightly-backup \
  -H "Authorization: Bearer $TISSUE_TOKEN" -H "Content-Type: application/json" \
  -d '{"max_duration_secs": 5400}'

The card reads nightly-backup is still running rather than stopped reporting, because those are different incidents with different first moves. An overrun outranks a silence: while a run is in flight the last beat is by definition older than the run, so a long job trips the silence threshold as a side effect of doing what it was told.

A start is not a beat. It moves neither last_ping_at nor the heartbeat's state, and it pages nobody. A job that starts every hour and never finishes is exactly what a heartbeat is for, and counting the start as proof of life would hide it for as long as the job kept starting.

Answer Means
202 {"state": "started"} The run is open and the clock is running
202 {"state": "running"} A start was already open: the previous run never reported an end

running is not an error and doesn't reset the clock, so a retried curl can't rescue an overdue run by starting it again. It's also what a hung job looks like from the outside.

/start exists only on a heartbeat; on an ordinary alert source it answers the same flat 404 an unknown key gets. The body is the run's own label (a git sha, a dataset name), kept in the history and never turned into a card.

The beat that ends the run carries how long it took, which is where duration_ms comes from.


The beat history

last_ping_at is one column and answers "is it late". The history answers "when did it last actually run, and what did it say", which is the question you have after being paged:

curl -s "https://api.tissue.systems/v1/mast/alert-sources/nightly-backup/pings?limit=50" \
  -H "Authorization: Bearer $TISSUE_TOKEN"
{
  "pings": [
    {
      "id": "mpi_9c1e4b70d25a8f3691c04e7b2d5a8f13",
      "at": "2026-09-18T03:19:44.207Z",
      "kind": "beat",
      "source_ip": "203.0.113.19",
      "user_agent": "curl/8.7.1",
      "exit_code": 0,
      "duration_ms": null,
      "body": "backup: 41 tables, 1.9 GiB in 94s"
    },
    {
      "id": "mpi_4a7f0b3ce918d26504af71b8e3c92d06",
      "at": "2026-09-17T03:19:41.880Z",
      "kind": "fail",
      "source_ip": "203.0.113.19",
      "user_agent": "curl/8.7.1",
      "exit_code": 17,
      "duration_ms": null,
      "body": "backup: error: connection to server failed"
    }
  ],
  "next_before": null
}

Newest first. A heartbeat that went down from silence has no sender and writes no row, so the gap in the list is the outage.

exit_code is null when the sender reported none, which is not the same statement as 0. A bare beat and POST /fail both report none; the exit-code route always reports one.

kind is beat, fail or start. duration_ms is the run length on the beat that closed a run opened by /start, and null on every other row, including a beat from a heartbeat that never sends a start, which is most of them. It's measured on the server from the two stamps, so a job that reports from a machine with a wrong clock still gets an honest number.

Paging is by cursor. limit defaults to 50 and caps at 200; pass the next_before you got back as before and the next page starts where the last one ended. A plain time works too, and reads the beats strictly before it:

curl -s "https://api.tissue.systems/v1/mast/alert-sources/nightly-backup/pings?limit=200&before=2026-09-17T03:19:41.880Z" \
  -H "Authorization: Bearer $TISSUE_TOKEN"

next_before is null once the page came back short, so a loop that pages until the cursor clears terminates.

Every plan keeps the same amount: 200 beats per heartbeat, and 30 days whatever the count says. The per-heartbeat trim rides along with each write, and the age sweep is what reclaims a heartbeat that stopped beating and would otherwise hold its last 200 rows forever.


The web app

Heartbeats live in the Tissue Mast web app at dashboard.tissue.systems/mast/heartbeats, not in the platform dashboard: every heartbeat on the account, its state, how often it's meant to beat and when it last did. Clicking one opens its history, the badge controls and the key. You can create a heartbeat there too.


A status badge

A badge is a public read of one heartbeat's state. Mint the token:

curl -X POST https://api.tissue.systems/v1/mast/alert-sources/nightly-backup/badge \
  -H "Authorization: Bearer $TISSUE_TOKEN"
{
  "badge_token": "mb_3f9d1a4c7e0b25869d13c4a7f0e28b56",
  "badge_url": "https://mast.tissue.dev/badge/mb_3f9d1a4c7e0b25869d13c4a7f0e28b56.svg",
  "badge_json_url": "https://mast.tissue.dev/badge/mb_3f9d1a4c7e0b25869d13c4a7f0e28b56.json"
}
![nightly-backup](https://mast.tissue.dev/badge/mb_3f9d1a4c7e0b25869d13c4a7f0e28b56.svg)
State Badge reads Colour
alive up green
late late yellow
flatline down red
pending waiting grey
never swept, or not a heartbeat unknown grey

The image is drawn by Mast rather than fetched from anywhere, so a README on a network that can't reach a badge CDN still renders, and a badge outage can only ever be our outage. The label is the alert source's name, cut at 40 characters. Responses carry Cache-Control: public, max-age=60, which is about the resolution the sweep behind the state has anyway.

The .json form is Shields' endpoint schema, so https://img.shields.io/endpoint?url=… renders it in whatever style the rest of the README already uses:

{ "schemaVersion": 1, "label": "nightly-backup", "message": "up", "color": "brightgreen" }

A bare https://mast.tissue.dev/badge/mb_… with no extension is the image, which is what a paste into a README wants.

The token is a read capability and nothing else. It can't send, it doesn't name the alert source's key, and it's revoked on its own. What it does expose is the alert source's name and whether the thing behind it is up. That's what a badge is, and it's why one is minted on request instead of existing on every alert source from birth.

Minting twice gives back the same token, because a badge URL gets pasted into places you don't control and a second mint that silently retired the first would break every copy. Replacing one is a revoke and a mint, which is the same two steps said out loud:

curl -X DELETE https://api.tissue.systems/v1/mast/alert-sources/nightly-backup/badge \
  -H "Authorization: Bearer $TISSUE_TOKEN"

Every pasted copy 404s from then on, and a 404 renders as a broken image. An unknown token, a malformed one and a revoked one all answer the same way, so nobody reading a badge URL can learn whether it was ever real.


Not here yet

  • The phone's own create form offers a period. A schedule or a run limit is set in the web app or over the API; the phone reads both back and shows them.
  • The badge is the only unauthenticated read of one heartbeat. Several at once go on a status page.
  • A heartbeat's history is per alert source. There's no account-wide feed of beats.