Skip to content

Event streaming (7/11): Suggest gh event listen to agents in gh pr and gh api - #15077

Merged
BagToad merged 3 commits into
babakks/event-sub-deletefrom
babakks/event-hints
Nov 17, 2026
Merged

BagToad merged 3 commits into
babakks/event-sub-deletefrom
babakks/event-hints

Conversation

@babakks

@babakks babakks commented Nov 17, 2026

Copy link
Copy Markdown
Member

Layer 7 of 11 in the stack tracked by #15070.

Description

Coding agents asked to wait for a pull request to be reviewed or merged reach for what they know: a loop over gh pr view or gh api repos/OWNER/REPO/pulls/N with sleep. They do not discover gh event listen on their own. This PR points them at it from the commands they already use.

When gh detects an agent caller (the existing InvokingAgent detection), these print a hint on stderr:

  • gh pr create, after creating a github.com pull request.
  • gh pr view, for a github.com pull request that is not merged or closed. When --json is used without state, the state is fetched anyway to make that decision, and only the requested fields are printed.
  • gh api, after a successful GET of repos/OWNER/REPO/pulls/NUMBER or any of its subpaths on github.com, given as a path or as an absolute https://api.github.com URL, such as an event's data.api_url.

The hint gives a copyable gh event listen command for that pull request with review and state change events, and short notes: it prints the first event and exits, --timeout bounds the wait with status 8, events carry no details, changes made before it starts are missed so the pull request should be read once it runs, and the feature is in preview. The gh pr and gh pr view help texts also point to gh event listen for everyone.

Human invocations, other hosts, stdout, JSON output, and exit statuses are unchanged.

How did you test this change?

I ran the agent evals from the next PR, which give a Copilot agent (gpt-5.6-luna) a task that requires waiting on a sandbox pull request while a second account reviews, merges, or closes it. Without the gh skill, agents only had gh's own help and these hints to go on. In one full run, they used gh event listen and passed all four graders in five of six scenarios; in a second run, four of six. Every failing trial polled. In both runs, the listen-at-limit agent polled instead of freeing a subscription slot and listening. In the second run, the notify-review agent looped gh pr view with sleep 30 and saw the hint on every read without acting on it.

Key points

  • The hint leaves out --follow. Agents offered it chose it even for one-off waits, ran it in the background, and were never resumed, because their harness waits for the command to exit. The default exit on the first event fits that model.
  • Agents only. Hints on stderr would be noise for people, and the help text already covers them. JSON output still gets the hint, on stderr, because agents often use --json.
  • gh api cannot tell the pull request's state, so its hint also appears for merged or closed pull requests. It only appears for GET requests, which is when an agent is reading state.

Notes for reviewers

Stack, bottom to top (this is 7 of 11, based on babakks/event-sub-delete): babakks/event-client, babakks/event-listen, babakks/event-sub-list, babakks/event-sub-create, babakks/event-sub-view, babakks/event-sub-delete, babakks/event-hints, babakks/event-evals, babakks/event-listen-flush, babakks/event-listen-deleted-sub, babakks/event-check-suite.

Start with pkg/cmd/event/shared/hint.go, the shared hint text. Then read where each command calls it: pkg/cmd/pr/view/hint.go, the end of createRun in pkg/cmd/pr/create/create.go, and pkg/cmd/api/hint.go, whose regular expression decides which endpoints qualify.

Authorship and follow-up

Who wrote this:

  • A human wrote it.
  • An agent wrote it under close human direction.
  • An agent wrote it independently, and no human has guided the implementation beyond the initial prompt.

Who answers review comments:

  • @babakks will read and reply directly. Name the account.
  • An agent will draft replies and @username will read them before they are posted.
  • Nobody has explicitly committed to replying.

babakks and others added 3 commits November 17, 2026 16:36
Co-authored-by: Copilot <[email protected]>
Copilot-Session: bbce5a7f-103c-4e67-99c9-2d6dc3f6a02b
… pr help

Co-authored-by: Copilot <[email protected]>
Copilot-Session: bbce5a7f-103c-4e67-99c9-2d6dc3f6a02b
…oints

Co-authored-by: Copilot <[email protected]>
Copilot-Session: bbce5a7f-103c-4e67-99c9-2d6dc3f6a02b
@babakks
babakks requested a review from a team as a code owner November 17, 2026 17:11
@babakks
babakks requested review from sergiou87 and a balanced review from Copilot and removed request for a team November 17, 2026 17:11
@babakks
babakks added this pull request to stack #15082 November 17, 2026 17:14
@babakks
babakks requested a review from BagToad November 17, 2026 17:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The API tests discard command errors, allowing no-hint cases to pass despite early failures and leaving exit-status preservation unverified.

1 open issue
What changed in this PR

This layer of the event-streaming stack makes gh event listen discoverable from commands agents already use to read or create pull requests, encouraging event-driven waiting instead of polling.

Changes:

  • Add agent-only stderr hints after pull request creation, eligible views, and successful pull request API reads.
  • Extend pull request help with listener guidance and document timeout, preview, and missed-event limitations.
  • Add tests for hint eligibility and preservation of requested JSON output.
File Description
pkg/​cmd/​pr/​view/​view.go Wire agent hints and fetch state when needed for JSON views.
pkg/​cmd/​pr/​view/​view_test.go Test hint eligibility and requested JSON fields.
pkg/​cmd/​pr/​view/​hint.go Select the pull request resource and suppress hints for closed or merged requests.
pkg/​cmd/​pr/​pr.go Add event-listening guidance to command help.
pkg/​cmd/​pr/​create/​create.go Print agent hints after pull request creation.
pkg/​cmd/​pr/​create/​create_test.go Test creation hints and unchanged stdout.
pkg/​cmd/​event/​shared/​hint.go Centralize hint text and supported-host filtering.
pkg/​cmd/​api/​hint.go Recognize eligible pull request REST paths and absolute API URLs.
pkg/​cmd/​api/​api.go Emit hints after successful response processing.
pkg/​cmd/​api/​api_test.go Test API hint eligibility across methods, hosts, paths, and responses.

Review effort: Balanced

Comment thread pkg/cmd/api/api_test.go Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants