Skip to content

git-workflow — watch-and-wake

Detail page of the git-workflow recipe card.

A landing that depends on a verdict, a merge or another session’s work is a WAIT, and a wait you poll by hand is the R3 band-aid. Arm ONE watcher instead: it exits the moment the event you care about fires, and the harness wakes you when a background command finishes — so exiting IS the notification.

There is ONE watcher, used by every harness: the umbrella’s scripts/gh/ toolset (opencharly/opencharly#1140).

Harness How it runs the watcher How the wake reaches the session
Claude Code, Codex, DeepSeek Harness node scripts/gh/cli.ts watch … as a MANAGED background command the harness’s background-completion notice
pi .pi/extensions/watch.ts spawns the CLI from .pi/watch.items and re-arms it a user turn (sendUserMessage)
OpenCode pr-watch.ts, tracker.ts and coord_watch import scripts/gh/lib/watch.ts in-process ctx.session.synthetic

THE HARNESS CONSTRAINT — design to it, do not fight it. An agent is woken ONLY when a background command COMPLETES. A watcher that never exits gives no wake, and a one-shot watcher that exits leaves nothing watching until it is re-armed. So: each wake is one finite watcher run, and the agent re-arms after acting on it. Never start the watcher with &, nohup or disown — a detached process wakes no one.

The loop is:

  1. Arm the ONE watch that covers the wait (the table below), as a managed background command.
  2. Wake on its single output line.
  3. Act — read the verdict in full, answer the comment, take over, or proceed.
  4. Re-arm in the same turn if the wait continues. Arming the same watch again TAKES OVER the old one (the lock), so a re-arm replaces and never adds. A binding that re-arms automatically passes --no-arm-wake after its first arm, so a verdict it already reported is not reported again — and drops every item whose STATE event fired, deciding which events those are by importing the engine’s STATE_EVENTS (scripts/gh/lib/watch.ts), never by listing them (the current set is in “Delta vs STATE events” below). --no-arm-wake does not suppress a state event: re-arming an item still in that state re-fires it at once, in a loop.

Pick the ONE row that matches what you are waiting for. It is always the same command; the --events set is what changes.

You are waiting for … Arm It wakes on
your own PR’s verdict and landing: after the first push, after a fix push, after gh pr update-branch, after a REST re-run node scripts/gh/cli.ts watch <owner>/<repo>#<pr> (the default events: verdict,merged,closed,conflict) VERDICT … PASS|BLOCK|INCONCLUSIVE, MERGED, CLOSED, CONFLICT; an ARM … verdict=BLOCK at once when the head already carries a BLOCK
several of your own PRs (a producer → consumer chain) the same command, listing every PR in ONE watch the first event on any of them
another session’s PR or issue that blocks you … watch --events merged,closed,stall <item> MERGED (the unblock; fires at once if already merged), CLOSED (find the successor), STALL (a takeover candidate)
a reply on a thread (a question you asked, a WAITING you posted) … watch --events comment <item> the first new comment
a bed or a long local command the command itself as a managed background command, its status captured (cmd > <log> 2>&1; echo rc=$? >> <log>) its exit

For a one-shot read without waiting: node scripts/gh/cli.ts status <item>… prints each PR’s state, its verdict class on the current head, and the newest verdict check run.

What a verdict is. The validator’s verdict is the newest validate / validate check run of the charly/pr-validator suite on the PR’s HEAD, and its class:

  • PASS — the check run succeeded;
  • INCONCLUSIVE — it failed, and the validator’s comment for that head says INCONCLUSIVE (an engine or provider condition to escalate, never a code finding);
  • BLOCK — any other failing conclusion;
  • PENDING — still queued or in progress, or the suite is re-running.

VERDICT fires only when a verdict is FINAL and NEW: the newest check run has completed, and it is a different check run than at arm, or it was not yet completed at arm. A REST re-run (gh api -X POST …/actions/runs/<id>/rerun) creates a new check run, so its verdict fires — the defect of the retired shell watcher, which keyed on the run id and never saw a re-run (opencharly/marketplace#628). A run that is merely in flight never wakes anyone.

A conflict means no verdict will ever come. A PR that conflicts with its base gets no test merge from GitHub, so no pull_request workflow runs on it — the validator included — and a watch that waited only for VERDICT would wait forever (measured on opencharly/opencharly#1145, where two pin waves advanced the same gitlink). conflict is in the default set: it fires while the open PR is CONFLICTING, at arm or later. Act on it by merging the base into your branch, resolving, and pushing a new commit (never a rebase or force-push after the first push), then re-arm.

The wake lines — one line on stdout, then exit:

MERGED <item> (unblocked) <url>
CLOSED <item> closed without merging — find its successor <url>
CONFLICT <item> conflicts with its base — the validator cannot run until the base is merged in <url>
COMMENT <item> new comment (<n> -> <m>) <url>
VERDICT <item> PASS|BLOCK|INCONCLUSIVE validate / validate <conclusion> at <head> <url>
STALL <item> no progress for <m>m (open, unmerged) — takeover candidate <url>
ARM <item> state=<s> verdict=BLOCK|INCONCLUSIVE [mergeable=<m>] <url>
TIMEOUT no event within <n>s

The ARM baseline of every item goes to stderr when the watch arms. Exit codes: 0 an event · 4 timeout · 5 usage or API error · 6 a peer watching the same items would not yield · 7 a rate limit (FATAL, never retried) · 8 the initial poll failed · 143 taken over or terminated.

One watcher, one poll per five minutes, and the API budget

Section titled “One watcher, one poll per five minutes, and the API budget”
  • ONE watcher per session. Put every item you wait on into ONE watch. The lock keys on the watched items and events, so arming the same watch twice takes over the first; a different item list is a different watch, so stop the old one before arming the new one, and confirm in the process table that exactly one runs: pgrep -fa '^node .*scripts/gh/cli\.ts watch'. Anchor the pattern on the node process: an unanchored pgrep -f also matches the harness’s wrapper shell and the probe’s own shell, whose command lines carry the same text (measured: one watcher, an unanchored count of 3).
  • A 300-second poll FLOOR. Every watcher polls at 300 s and REFUSES a shorter interval (exit 5). ALLOW_FAST_POLL=1 exists for tests only. Expect up to one interval of lag: when you need the state NOW, read it once with status. One read answers a question; a loop of reads is the hand-poll this replaces.
  • ONE request per poll for N items. The watcher observes every item in a single batched GraphQL query. The remaining quota is read from that response’s own header; below 200 the watcher backs off (×2, capped at 600 s) and says so on stderr. Any rate-limit signal (HTTP 429, a 403 with no quota left, a GraphQL RATE_LIMITED error) is FATAL: exit 7, never retried.
  • Prefer outcome events for other people’s items. Waking on every comment of an actively working owner is noise; merged,closed,stall is the blocker watch.

comment and verdict are DELTA events: the watch seeds the current state at arm, so a comment or verdict that already existed never fires — except that a BLOCK or INCONCLUSIVE already on the head wakes at arm, once, because a verdict that landed before you armed must not be missed. merged, closed, conflict and stall are STATE events: they fire while the item IS in that state, including at arm, and an item whose state event fired is done (a re-arm would re-fire it). stall requires an open, unmerged item with no update for --stallmin minutes (default 60, the B2b.1 takeover-window floor).

  1. Silence is an alarm. A blocked item emits no events, so a blocker watch carries stall: it fires when nothing has moved for the window while the item is open and unmerged.
  2. Liveness is not progress. Progress is an artifact — a pushed commit, a completed validator run, a merge — never a session heartbeat. The stall alarm keys on the item’s updatedAt, so its silence is measured against artifacts.
  3. Read the full result after the wake. The wake line names the event; the verdict is in the PR’s ## Review comment, read in full (“Before every update push”).

What each wake drives (the takeover protocol)

Section titled “What each wake drives (the takeover protocol)”
  • MERGED → the unblock. Proceed; comment the merge on the waiting issue.
  • CONFLICT → merge the base into your branch, resolve, gate the new head, push one new commit, re-arm.
  • VERDICT / ARM → read that PR’s full ## Review comment and every new comment; fix, rebut or escalate (INCONCLUSIVE), then re-arm.
  • STALL → a takeover candidate: run the B2b.1 window-based takeover in full — comment FIRST, wait the 60-minute floor window, then TAKING OVER — authority: window-expired BEFORE any push.
  • COMMENT → a peer or the owner replied; read it in full and answer on the thread.

A wake that starts a new turn can interrupt in-flight work, so an alert is an ADDITION to the todo ledger, never a reset (/charly-internals:agents, “Todo ledger & interruption safety”).

Watch the scopes actually in flight. The set changes as work moves, and a stale watch list produces false stalls. Re-derive the list from the currently open PRs each time you re-arm, never from a memorized one.