Loadbudget

README

What does the watch print about a pull request, and what ends the watch?

Binds: architecture, code

The script pull-request-watch-for-agents runs watch.main.

Who it is for

The watch is for a coding agent that opened a pull request. The agent misses feedback, a failed check, a conflict and the merge unless something reports each one. The watch prints one line for each finding, and the agent answers each line as it arrives.

One line is one finding

A coding agent runs the watch under a tool that reports each line of output. So each line names one finding that asks the agent for work. No other line prints.

These findings print a line:

A new finding prints at once. A comment that somebody edits is a new finding, because the edit is new feedback.

An open finding prints again

While a finding stays open, its line prints again each REPEAT_SECONDS. The repeated line starts with REPEATED, which reads Still open:. The rest of the line is the same as the first line. A tool that holds output back then still gives the agent a turn.

Each kind of finding stays open while its condition holds:

Some feedback prints once, and never again. A comment or a review from the author of the pull request is the reply, so it asks for no work. A review with the state APPROVED asks for no work either.

A finding that closes and opens again prints as a new finding.

The watch reads REST and polls

The watch reads the REST API of GitHub through gh api. It reads no GraphQL. cli_tool_runtime_for_git_repos.github.pull_requests states why.

A local session has no address that GitHub can reach, so the watch polls. The default poll is DEFAULT_POLL_SECONDS apart.

The watch reads comments from the committer date of the head commit. A head commit handles each older comment, so that bound skips no open finding.

When a poll fails, one line names the reason, and the watch continues. Three events fail a poll: gh exits with an error, gh runs past its timeout, or GitHub answers something that is not the JSON that the watch expects. A second failure with the same reason prints nothing. So silence means no open finding, and never a broken poll.

The watch runs until the pull request ends

The watch has no timeout. The merge, the close or a kill from a tool ends it. A tool that kills the watch tells the agent. The agent then starts the same command again.

Each start reads the current state of the pull request. So a new watch prints each open finding as a new finding. No open finding falls between two watches.

A reply of the author prints once, and an earlier watch printed it. So a start prints nothing for a reply of the author that it finds already there. A session on a laptop runs on the token of the operator. So a comment that the operator typed while no watch ran reads as such a reply, and it prints nothing.

A repository that wraps the watch passes its own command to main as command. The help and the errors then name that command. The default is COMMAND.

The pull request comes from the caller or the branch

A caller names the pull request by number. With no number, the watch takes the one open pull request of the current branch. When the branch carries no open pull request, or more than one, the watch exits with code 2. A git or gh call that fails or runs past its timeout there also exits with code 2, and the error names the failure.