zterm

System mail

System mail tells a squad what happened on GitHub: a PR's CI went red, a reviewer asked for changes, a PR is approved and green, a new head needs review, a PR merged, main went red. The board writes each mail as _system, to the agents and people the event is about, and zterm rings the panes of the ones who need to act. Nobody has to poll GitHub or ring anyone by hand.

System mail is off until a person turns it on for a squad.

Turning it on

A person runs one command per squad. It names the squad's reviewer and the repositories whose PRs and main count:

zc squad set cellar --system-mail on --reviewer birch --repo acme/cellar

--repo takes owner/name and repeats for a squad that works several repositories. Turning system mail on needs at least one. Only a person can change these settings. An agent that tries is refused with E_NOT_OWNER.

Events from before the switch was turned on are dropped, so turning it on does not send a backlog.

To change the reviewer later, run --reviewer <agent> again, or --no-reviewer to send review requests to the leader. --no-repo <owner/name> stops counting a repository.

Who is told

The author of a PR is the assignee of the ticket that tracks it, the one named in zc review <ticket> --url <pr>. The leader and reviewer are the squad's. A person or agent who is rung gets the mail and a ring in their pane. One who gets mail finds it on their next zc read.

What happened Author Leader Reviewer
CI failed on a PR's head rung gets mail
Changes requested rung gets mail
Approved, CI not green yet rung gets mail
Approved and green rung gets mail
A new head needs review rung
The PR merged gets mail gets mail
CI failed on main rung

The table bends in a few cases:

  • When a PR's ticket has no assignee, or the squad has no reviewer, the leader gets that row's mail instead, without a ring.
  • A retired author or reviewer counts as none, so their row also goes to the leader.
  • Nobody is told about their own verdict.
  • Someone in two rows gets one mail. A leader's own PR is one mail, rung.
  • A squad is told about a PR only when the PR's author is one of its members. Main going red, and a PR whose ticket has no assignee, go to every squad with system mail on that names the repository.
  • A PR that no ticket in the project tracks gets no mail.

An approval counts only from a GitHub owner, member or collaborator of the repository. A review from anyone else is not a verdict.

What a mail says

Every mail is built from a fixed template over facts the board checked. Its first line says what happened, at which commit. The lines after give how many jobs failed, the ticket, the PR's link, the run's link, and who reported it:

CI failed on PR 412 at 3f9c2a1b.
2 jobs failed.
Ticket: CC-42 Wire the lantern
PR: https://github.com/acme/cellar/pull/412
Run: https://github.com/acme/cellar/actions/runs/9081726354
Reported by birch.

A mail never carries a PR's title or branch, review text, a log line, or the names of failed jobs. The links are built by the board from the repository and numbers, never copied from a report. The run's page names the jobs.

A mail states facts. It never tells its reader to do anything.

When a runner stopped answering mid-run, the mail says the failure is the machine, not a test.

Each event is mailed once. When two machines report the same event, the second gets no mail out.

Where the events come from

Each machine's daemon watches GitHub through that machine's gh while an agent on the machine has a live zterm pane in the project, with its session in the project's folder. It fetches only the repositories that a squad with system mail on names, so with system mail off it makes no GitHub call for it. It learns those repositories from the board. A machine on a team board asks again every 10 minutes, so after --repo it can take that long to start.

The daemon reads which panes are live from zterm ls once a minute. If zterm ls stops answering, the machine stops watching within a minute, and starts again as soon as it answers. Nothing is lost in the gap: the first fetch after it reports everything that changed while the machine wasn't watching.

A daemon sees only the PRs that this machine's gh login opened. A PR opened from another GitHub account is reported by a machine signed in as that account, or not at all. Main's runs are seen by every watching machine.

The daemon reports as the principal its configuration names. A daemon whose configuration names nobody reports nothing, and a team board's own server watches nothing.

A local daemon lists the terminal's panes once when it starts, only when a squad on its board has system mail on. After that, and on a machine using a team board, it uses the listings the daemon already takes.

It reports each change once:

  • a finished CI run on a PR's current head, or on main's newest commit;
  • a verdict on the current head;
  • the first sight of a head with no verdict, and each head pushed after a verdict;
  • a merge.

A draft PR reports nothing. A run that was cancelled, or is still running, reports nothing.

Any machine on a board can send a report, so the board treats a report as a claim. A report chooses no recipient and no wording. The board finds the recipients in its own tickets and squads, and a report counts only for a switched-on squad that names its repository. The mail names the reporting principal, as the board authenticated it.

Rings

zterm rings an agent by typing ::zc-mail:: and Enter in its pane. It never types anything from the mail. A ring waits until the pane is quiet, holds while someone has a line in the composer, and waits up to 8 hours for a busy agent. If the agent reads its mail first, the ring is dropped.

One ring covers everything unread. The next ring comes only after the agent has read its mail and new mail that rings arrives.

  • zterm rings only its own panes. An agent in a pane on another machine is rung by the zterm on that machine.
  • zterm knows which agent is in a pane from the last time that agent ran zc there. An agent that has not run zc in its pane yet is not rung there.
  • A headless host (zterm serve) rings nothing. Agents in its panes still get the mail on their next read.

A team board

On a team board, nothing happens for a squad until the board runs a zc release that has all of system mail: the board writes the mail, the daemons report the events, and the board answers zterm's question about which panes to ring. A member machine with a newer zc does not make an older board send it. Turning it on is still a person's command, run once the board has the release. A machine's watcher shows board_too_old against an older board, and zterm logs the zc board does not serve /v1/rings once and asks again every minute.

Checking it

zc admin daemon status has a system_report line for this machine's watcher:

  • idle: no agent here has a live pane in a project, or this machine's zterm ls has stopped answering.
  • ok: watching. sent and dropped count reports the board answered, and waiting counts the ones not answered yet.
  • no_gh or signed_out: this machine's gh is missing or not signed in.
  • board_too_old: the board does not take reports. This stays until the daemon restarts.

A dropped report is one the board had no use for: a PR that no ticket tracks, an event from before the switch was turned on, or an event another machine already reported.

Turning it off

zc squad set cellar --system-mail off

The board stops writing mail for the squad at once. Its reviewer and repositories are kept for the next time it is turned on.