Description
Filed by Xum (an AI coding agent) on behalf of @ibetitsmike. Part of #311. Line numbers are at 607a95b.
Summary
A pull request watch re-reads the pull request from GitHub once a minute, per wake-up, on the wake-up worker's delivery goroutine. Each read is up to 7 unconditional API requests on the chat owner's token, including one to /user whose answer never changes. Two chats that watch the same pull request read it twice.
Webhooks are not an option for this deployment (the daily server is reachable on loopback only), so polling stays. It should be one poller, off the delivery path, that uses conditional requests.
Evidence
fork_pull_request_events.go:29-31:pullRequestPollInterval = time.Minute.fork_wait_for_events.go:425-452: the read runs insidedeliverEventsWakeup, "at most one read per tick", bounded bypullRequestReadTimeout= 30 s (fork_pull_request_events.go:40-42).fork_github_activity.go:107-114: every poll starts withGET /user.FetchPullRequestActivityin the same file then reads the pull request, reviews, issue comments, review comments, and, when checks are watched, check runs and the combined status, each paged up to 10 pages of 100.- No request sends
If-None-Match, so every poll counts against the owner's rate limit: about 420 requests per hour per watched pull request. - Upstream already polls pull request state per chat for the diff status (
worker.go:24-25), so a chat that watches its own pull request is polled by two independent loops.
Proposed design
New file coderd/x/chatd/fork_pull_request_poller.go: one poller goroutine per replica.
- Work list from the database. Each tick (30 s), one query lists the distinct
(pull_request_url, owner)pairs of openpull_requestwatches (indexchat_wakeup_watches_open_pr_idx, chatd: store wake-up watches as rows instead of an events JSON and run keys #293) whosespec->>'next_poll_at'is due. A lease per URL is not needed: a duplicate read by two replicas is harmless because step 4 is idempotent. - One read per pull request, not per wake-up. All watches of the same URL and owner share the result.
- Conditional requests. Store the
ETagof each endpoint in the watchspecand sendIf-None-Match. GitHub answers304without charging the rate limit. Cache the viewer login for the life of the watch; drop the per-pollGET /user. - Write a fact, then poke. When the comparison with the baseline finds new activity, set
fired_atandfired_payload(the summary text built today bypullRequestWakeupText) on the watch rows, andforkWaker.Poke(chat_id). The poller never sends a chat message. - Backoff in the row. Rate limit and error handling keep today's rules (
fork_pull_request_events.go:227-252) but writenext_poll_atto the watchspecinstead of rescheduling the wake-up. - Bounded concurrency. At most 4 reads in flight per replica, each with the 30 s deadline.
Removed from the delivery path: pullRequestWakeupText as a blocking call, pullRequestReadFailed rescheduling of the wake-up, the half-lease guard for pull request reads.
Acceptance criteria
- A test with a fake GitHub server asserts that a poll with unchanged state sends
If-None-Matchon every endpoint and that/useris requested once per watch, not once per poll. - Two chats watching one pull request with the same owner cause one set of requests per poll.
- A fake server that hangs for 30 s does not delay delivery of an interval wake-up of another chat.
- New activity produces exactly one message per watching chat.
Not in scope
Reusing upstream's chat_diff_statuses refresh as the event source. It does not carry reviews, comments or checks, and changing it means editing upstream code.
Activity
ibetitsmike commentedon Nov 16, 2026
Started: workstream chat 4ace9527 (Opus 5.5, high) on branch
mike/issue-296-pr-poller. It reports back to the lead for verification and merge.ibetitsmike commentedon Nov 16, 2026
PR #363 merged as 3a63653 at 09:36:20Z. The pull request poller now reads each pull request once per replica, off the wake-up path, and shares one read across the watches of the same owner. Gate evidence: #363 (comment)