Skip to content

Wake a thread when its pull request needs it - #7894

Closed
lanjak wants to merge 1 commit into
get-bb:mainfrom
lanjak:feat-pr-watch
Closed

lanjak wants to merge 1 commit into
get-bb:mainfrom
lanjak:feat-pr-watch

Conversation

@lanjak

@lanjak lanjak commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

An agent that has to wait for CI or a review has no way to be told when the pull request changes. Agents poll gh in sleep loops or ask the user to come back. This costs tokens, and the wait stops when the turn ends. The github-pr-status plugin already polls each pull request that a client shows, but it only updates the UI. Issue #1543 asks for an exact-thread wake from that existing poller, with no second GitHub poller.

What changed

All changes are in plugins/github-pr-status. There are no server, daemon or wire changes outside the plugin, and no HOST_DAEMON_PROTOCOL_VERSION change.

  • bb pull-request watch|watching|unwatch [--thread] and the RPC methods watch, watching, unwatch. A watch belongs to one thread and is saved in a new watches table (append-only migration). A background service restores watches after a restart. The watch keeps the environment's row polling through the existing store, the same way an open client view does.
  • watch.ts compares each read with what the thread was last told. It sends one message (threads.send, queue-if-active) when a check run fails (keyed by name and start time, so a re-run that fails again is new), all checks pass, someone other than the machine's gh account comments or reviews, the review decision becomes approved or changes requested, the branch starts to conflict, or the pull request merges or closes. While the thread is busy, later news updates the queued message (queuedMessages.update) instead of queuing another message.
  • A watch ends on merge or close, unwatch, thread archive or delete, environment removal, a switch to a named branch with another pull request or none, 10 comment-only messages in a row, or 15 minutes of failed reads while the machine is online. A detached HEAD (for example during a rebase) does not end a watch. While the machine is offline, the watch waits.
  • bb pull-request logs|rerun <environment-id> [--check] and the RPC methods checkLogs, rerunChecks. They use the latest run of each check, and only jobs in the pull request's own repository. logs prints the lines up to the last ##[error] of each failing job (gh api .../actions/jobs/<id>/logs, with --allow-escape-sequences only when gh asks for it). rerun runs gh run rerun <run> --failed once per run, or --job for --check.
  • The GraphQL read adds the last 10 comments and the last 10 reviews (viewerDidAuthor) to find activity by other people. Failed check runs and outside activity stay in server memory. The public pullRequests row and its strict schema do not change, so older bb thread show clients still parse it.
  • The store now retries a failed PR lookup every 5 minutes while the environment is watched. Before this change, a failed lookup stopped all later reads.
  • GitHub text (check names, authors, titles) is put on one line and shortened before it goes into an agent message.
  • Docs: the plugin's skill, README and overview.

Differences from #1543:

  • The detector is the github-pr-status poller, not the github plugin's sync. github-pr-status already owns the per-environment pull request that the thread shows.
  • The message gives the pull request number, title, link and one line per change. It does not include the full before and after state.
  • If a send fails with an error other than 404, the watch restores its previous progress, so the next read reports the change again. The plugin calls threads.send inside the server, so an accepted send that reports a failure is unlikely.

How you verified

  • New tests: watch.test.ts (rules, merging, one-line GitHub text), host/checks.test.ts (log tail, Actions job links, latest run per name, other-repository jobs, escape-sequence retry, re-run grouping), server.test.ts (wake once per failed run, end on merge, restore after reload, end on thread delete, offline machine waits, 15-minute end, end on branch switch, detached HEAD keeps the watch, queued-message update, re-send after a failed send, CLI logs/rerun), store.test.ts (retry of a failed lookup), assemble.test.ts and git-host.test.ts (facts and outside activity). Each fix from review has a test that fails without it (checked by reverting the fix).
  • pnpm exec turbo run typecheck test lint lint:type-aware --filter=bb-plugin-bb--github-pr-status --filter=@bb/cli: plugin 217 tests, CLI 1407 tests, 0 lint findings. apps/server test/skills/: 105 passed. oxfmt --check is clean on all changed files.
  • Live, in the isolated QA instance (pnpm --filter @bb/qa standalone:start) against real GitHub pull request Route native browser close shortcuts to the renderer #7831 with a Claude Haiku thread:
    • watch started and listed the real failing check.
    • logs printed the real npm 404 error from the failing job.
    • After bb plugin reload, the watch was restored. With its saved baseline cleared, the next read sent the failure message to the thread, and the agent started to read the logs.
    • Switching the checkout to a branch without a pull request ended the watch with a message. This live run found a defect that the unit tests missed (the watch did not end after re-discovery), which is fixed in this change.
    • A detached HEAD and a return to the branch kept the watch and sent no messages.
  • A probe against real GitHub found that gh 2.104 refuses job logs that contain escape codes unless it gets --allow-escape-sequences. The retry handles this.
  • An Opus review found three medium and seven low defects, plus two nits. All are fixed.

Fixes #1543

AGENT GENERATED

Agents that wait for CI or reviews poll gh in sleep loops. That costs
tokens and stops when the turn ends. The github-pr-status plugin already
polls each pull request, so it now tells a watching thread what changed.

- `bb pull-request watch|watching|unwatch` store one watch per thread in
  the plugin database. A background service restores them after a
  restart. After each read, the server compares the pull request with
  what the thread was last told and sends one message when a check run
  fails, all checks pass, someone else comments or reviews, the review
  decision becomes approved or changes requested, the branch starts to
  conflict, or the pull request merges or closes. While the thread is
  busy, new news updates the queued message instead of queuing another.
- A watch ends on merge or close, unwatch, thread archive or delete, a
  switch to a named branch with another pull request or none, 10
  comment-only messages in a row, or 15 minutes of failed reads while
  the machine is online. A detached HEAD does not end it.
- `bb pull-request logs|rerun` read the latest failing GitHub Actions job
  logs and re-run failed jobs of the pull request's own repository.
- The GraphQL read adds the last 10 comments and reviews to find
  activity by other people. Watch-only data stays in server memory, so
  the public `pullRequests` row is unchanged.
- The store retries a failed discovery read every 5 minutes while the
  environment is watched.
@lanjak

lanjak commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Closing this for now. The feature needs maintainer sign-off on #1543 first. The branch stays on my fork as a prototype, linked on the issue.

@lanjak lanjak closed this Nov 21, 2026
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.

Wake an exact thread from native GitHub PR state changes

1 participant