AGENT CONTINUATION · PRACTICAL FIELD GUIDE
How Coding Agents Wait for PR Review Without Polling
An event can wake the agent. Only current state, policy, and explicit authority can tell it what to do next.
On 18 November 2026, GitHub added gh event listen to GitHub CLI v2.105.0. A coding agent can now wait for pull request reviews, head changes, state changes, merge conflicts, and completed check suites instead of repeatedly asking GitHub whether anything changed.
1. Why this matters now
The new gh event commands are in preview. They work on GitHub.com for accounts with access to the Event Streams preview. A listener emits each event as a single line of CloudEvent JSON on stdout while status messages go to stderr. By default, it exits after the first event; --count, --follow, and --timeout support longer waits.
The events are intentionally thin. Their data.api_url points to the review, pull request, or check suite that changed. The event is a prompt to fetch the object and reconcile current state, not a complete decision record.
2. Replace the clock, not the state check
A polling agent often uses the same snapshot for two different jobs: deciding when to wake up and deciding what it may do next.
while true; do
gh pr view "$PR_URL" --json state,reviewDecision,headRefOid
sleep 60
done
The first job is wasteful. The second is necessary. Event Streams separate them:
gh event listen \
--resource "$PR_URL" \
--event com.github.pull_request.review.submitted.v1 \
--event com.github.pull_request.head.changed.v1 \
--event com.github.pull_request.state.changed.v1 \
--event com.github.pull_request.check_suite.status.changed.v1 \
--timeout 30m
The agent can sleep until something relevant happens. Once awake, it must read current state again.
3. Save a checkpoint after the listener attaches
Earlier events are not replayed. GitHub therefore recommends reading the current pull request after the listener attaches, even if the agent read it immediately beforehand. That ordering closes the gap in which a change could occur after the baseline read but before the stream is ready.
- Start the listener.
- Wait for its attachment status on stderr.
- Read the current head commit, PR state, review decision, draft status, merge status, and checks.
- Save that snapshot as a checkpoint.
- Block for the next event.
{
"pr_url": "https://github.com/acme/widgets/pull/42",
"observed_head": "aaaaaaaa",
"review_decision": "REVIEW_REQUIRED",
"state": "OPEN",
"is_draft": false,
"saved_at": "2026-11-19T09:30:00Z"
}
The checkpoint is evidence of what the agent knew when it went to sleep. It is not permission to act later.
4. Approval of commit A does not approve commit B
Suppose a reviewer approves commit A. The review event wakes the agent, but another actor pushes commit B before the agent processes the event.
The review object can identify commit A while the pull request now points to commit B. Repository rules may retain, dismiss, or otherwise reinterpret that approval. The agent should not try to reproduce branch-protection logic from memory. It should fetch the object named by the event and then read the current pull request state.
checkpoint head: A
review event: APPROVED on A
current PR head: B
result: wake up, reconcile, and stop short of any action
that assumed A is still current
A robust wake-up handler should parse the event, fetch the changed object, read the pull request and its checks again, compare that snapshot with the checkpoint, and only then evaluate repository policy and the agent’s authority.
| Observation | Safe interpretation | Next step |
|---|---|---|
| Approval is for A; head is A | The event and current revision agree. | Evaluate current checks, policy, and authority. |
| Approval is for A; head is B | The event describes an older revision. | Re-evaluate B and request fresh review if required. |
| Event ID was already handled | Delivery was duplicated. | Confirm current state, then no-op. |
| Listener reconnected or timed out | Events may have been missed. | Take a fresh baseline before waiting again. |
| One check suite says success | One suite completed successfully. | Read all current PR checks. |
5. Try the race without preview access
This small simulation writes a checkpoint for commit A, injects an approval event for A, and presents commit B as the current pull request head. It needs Bash and jq, but no Event Streams access.
#!/usr/bin/env bash
set -euo pipefail
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
printf '%s\n' \
'{"observed_head":"aaaaaaaa","review_decision":"REVIEW_REQUIRED"}' \
> "$workdir/checkpoint.json"
# A normalized stand-in for the event plus its fetched review object.
printf '%s\n' \
'{"id":"demo-review-1","review":{"state":"APPROVED","commit_id":"aaaaaaaa"}}' \
> "$workdir/event.json"
# A push landed before the agent processed the event.
printf '%s\n' \
'{"headRefOid":"bbbbbbbb","reviewDecision":"REVIEW_REQUIRED"}' \
> "$workdir/current-pr.json"
reviewed=$(jq -r '.review.commit_id' "$workdir/event.json")
current=$(jq -r '.headRefOid' "$workdir/current-pr.json")
event_id=$(jq -r '.id' "$workdir/event.json")
if [[ "$reviewed" != "$current" ]]; then
printf 'event %s woke the agent\n' "$event_id"
printf 'reviewed commit: %s\ncurrent commit: %s\n' "$reviewed" "$current"
printf 'decision: stop and evaluate the current revision\n'
exit 0
fi
printf 'same revision; evaluate current checks, policy, and authority\n'
The production adapter changes the source of the wake-up signal, not the reconciliation rule. Replace the injected event with gh event listen, fetch data.api_url, and obtain the current snapshot with gh pr view and gh pr checks.
6. Make duplicate events and dropped connections boring
Store processed CloudEvent IDs with the last reconciled head commit, and make the handler safe to run twice. If the same event arrives again and current state has not changed, the correct result is a no-op.
If the stream breaks, the CLI reconnects, but events that happened during the gap are not delivered. Reconnection is therefore a reason to take a fresh snapshot. The agent does not need to reconstruct every missed event; it needs to reconcile the state that exists now.
Attach→Snapshot→Wait→Wake→Snapshot→Decide
gh event listen removes the need for agents to keep asking whether anything changed. It does not make an event a command, an approval timeless, or a successful check suite equivalent to a merge decision. That makes Event Streams a natural follow-up to the field guide on when agents continue or stop, rather than another release recap.
Join the discussion
Share a question, correction, or something you learned. Sign in with GitHub to comment.
Comments powered by Giscus. You can also browse the discussions on GitHub.