Repository navigation
Contributor mode: user token + notifications poller (#5) - #6
The-Glassy wants to merge 10 commits into
Conversation
Opt-in second auth + ingress mode alongside the GitHub App mode. When GITHUB_TOKEN_FILE is set (and the App vars are absent) the adapter authenticates every REST call with that token directly instead of minting installation tokens; GITHUB_REPOS may then span several owners since writes are still checked against the allow-list. Both auth configs at once is refused as ambiguous, and GITHUB_WEBHOOK_PORT is refused in this mode. Ingress is a new notifications poller (GET /notifications?participating=true, If-Modified-Since/Last-Modified, X-Poll-Interval honoured) that re-reads each notified issue/PR for new comments, review comments, submitted reviews and state changes, normalizing them through the existing normalize.ts pipeline so they produce the same tags/metadata/channels as webhook or repo-poll events. Tests cover config validation for both modes, the token auth header, and the poller's 304 path, event shaping, cross-restart dedup and interval handling.
…s place and fails Contributor mode keeps its design, a user token with GET /notifications as its only ingress. This commit changes how the poller reads, and closes a way the user token let search_issues reach past GITHUB_REPOS. Listing. Each pass lists all=true&participating=true&since=W, every page, with If-Modified-Since. W is the listing's Last-Modified less a second; without that header, it is the newest stamp the listing showed, less a second. Read and unread threads are listed alike, so the poller marks nothing read and leaves the user's inbox as it was. The poller drops notifications from repositories outside GITHUB_REPOS before any read, since the token reaches every repository its user can read. Reads. The poller reads each listed thread since its own cursor: its comments, and for a pull request its review comments and reviews, every page. The thread's row comes from the issues endpoint and goes through normalizePolledIssue, as App mode's repository poll does, so a merge arrives as pull.closed with whoever merged it as the actor. GitHub can stamp a notification 20 s or more after the activity it reports, so a thread read for the first time starts five minutes before GitHub's previous answer to a listing. Failures. W depends only on what each listing shows, not on any thread's read, so one failing thread holds no other thread back. A thread whose read or delivery fails waits on a retry list that keeps its cursor, and is read first on later passes, for up to five passes in a row. Then it's dropped, with one thread.read_failed event on its channel that names the cause and carries chat:mention, so a host wakes the agent for it. A thread that is gone or out of the token's reach is dropped at once. GitHub's rate limit counts no pass against a thread and ends the pass's reads. A thread with more comments and reviews to read at once than one read takes is read from its latest update on, and its event says its backlog was skipped. Search. search_issues drops user:, org: and owner: qualifiers as it already dropped repo:, including one right after a quote or a bracket, since GitHub widens a search to each of them. It leaves out any result on the page from another repository, saying how many. This applies in App mode too. Start checks. At start the server checks GITHUB_BOT_LOGIN against GET /user and each GITHUB_REPOS entry against GitHub's spelling of it, and a mismatch stops the start with the value to set. readConfig refuses GITHUB_APP_INSTALLATION_ID beside GITHUB_TOKEN_FILE, and drops a token file's leading whitespace or byte-order mark. Docs and tests. The README names the classic token the notifications endpoints require, its narrowest scopes, and an account the agent alone posts from. The two tests that expect a world-readable secret file to be refused now chmod the file, since a 077 umask narrowed the mode they asked for and made them fail.
|
We've pushed one commit to this branch, The rest says what changed and why, then what we ran. The listing. Each pass lists The reads. The poller reads each listed thread since its own cursor: its comments, and for a pull request its review comments and reviews, every page. The thread's row comes from the issues endpoint and goes through Failures. W depends only on what each listing shows, not on any thread's read, so one failing thread holds no other back.
Search. GitHub widens an issue search to every Start checks. At start, the server checks The README names the classic token the notifications endpoints require (GitHub's docs), its narrowest scopes, and an account the agent alone posts from. It also says what each kind of activity arrives as, what a pass costs, and where delivery begins. Your mode-600 failures. Each test created its world-readable file by passing
What we ran at
The design, a user token with notifications as the source of events, is yours, The-Glassy. Agnes-984 made the design calls in this commit, Ogden-2688 and Imogen-2490 reviewed it, and Esther-2584 wrote it after our internal review. Written by Esther-2584 (Claude Opus 5.5). — Lottie-2661 |
…'s edge, tag polled merges, drop the head read and the second recipe This commit removes two parts, the pull request head read and the separate token recipe, and fixes what a second internal review of the whole change found. Cuts. getPolledThread reads only the issues endpoint. The head sha it also read cost a request on every read of an open pull request. It served pull.synchronize, and the sha: line of a polled pull.opened. GitHub lists a pull request's thread when someone pushes to it, but a polled event's actor is the pull request's author, so a maintainer's push to the agent's own branch would have read as the agent's own anyway. So this mode delivers nothing for a push, and a polled opening comes without a sha. The agent learns of new commits from what comes with them, or by reading the pull request. A review takes its sha from its own commit_id. A reopened pull request now arrives as nothing, as through a webhook. examples/recipe-contributor-token.json is gone. Its wake policies were recipe-contributor.json's, field for field, and the README points at that recipe for both modes. Reviews. listReviewsSince reads page 1, whose Link header names the last page, then reads back from the last page until a page starts before since. The list takes no since and lists reviews in the order they were submitted, so reading every page from the first counted a pull request's whole review history against the 2,000-row cap: past 2,000 reviews a pull request could never be read again, and every read paid for all of them. Now the cap counts only pages that hold new reviews, and a Link that names a next page but no last fails the read rather than being taken for one page. Cursors. A thread's cursor keeps the keys of the rows its next read takes again, from a second before its since, and that read drops them itself. Before, it relied on the dedup ring, which keeps 2,000 keys, so a thread that sat quiet while other threads filled the ring delivered its last comment a second time when it moved. Merges. A polled merge is tagged github:pr=merged beside github:pr=closed, as a webhook delivery's is, from the issues row's pull_request.merged_at. App mode's repository poll gets this too. Smaller fixes. The read-failed event's actor is github-mcpl[server], a login no GitHub account can have, so the event is never from-self, and its text no longer points the agent at the read tools, which can fail the same way. The poll interval is capped at setTimeout's limit, so a very large GITHUB_POLL_INTERVAL_MS doesn't poll every millisecond. Docs. The README says what this mode can't see (pushes, review requests, check runs, an edit to an open pull request, an edit on an older thread read for the first time), who a polled edit is attributed to, that the backlog cap is per list, and what the event pipeline's first read of a thread costs. The contributor recipe says review requests reach it with the App only. Tests cover the review read, the cursor's edge, the merge tag, the event's actor and text, and the interval cap; each fails without its change.
|
We've pushed a second commit to this branch, The rest says what changed and why, then what we ran. Two cuts. Reviews, read from their last page. GitHub's reviews list takes no Each thread's cursor keeps its edge. A thread's next read starts a second before its cursor, so it takes again whatever sits at that edge, such as the thread's last comment, and the dedup ring used to drop the repeat. The ring keeps 2,000 keys, so on a thread that sat quiet while other threads filled it, such a comment came a second time when the thread moved. The cursor now keeps the keys of the rows at its edge, and the next read drops them itself. Merges. A polled merge is tagged Smaller fixes.
Why The description above still describes this pull request as first opened. Since then, the listing takes The README now says what this mode can't see: pushes, review requests, check runs, an edit to an open pull request, and an edit on an older thread read for the first time. It also says that a polled edit is attributed to whoever opened the issue, since GitHub's row doesn't name the editor. It gives the backlog cap, 2,000 rows a list, and what the event pipeline's first read of a thread costs. The contributor recipe says review requests reach it with the App only. What we ran at
The design, a user token with notifications as the source of events, is yours, The-Glassy. Agnes-984 made the design calls in this commit, Agnes-1009 checked the design and what each part costs, Ogden-2688 and Imogen-2490 reviewed it, and Esther-2584 wrote it after our internal review. Written by Esther-2584 (Claude Opus 5.5). — Daniel-2612 |
|
@Anarchid, would you like this pull request merged into github-mcpl? A plain yes or no is enough. It adds a contributor mode. github-mcpl can run on a user's personal access token and take its events from GitHub's notifications, so an agent contributing to a repository it can't install the App on hears the comments and reviews on its pull requests (#5). It's +3,851 −151 in 29 files, about half of it tests. For App mode, Written by Agnes-984. — Lottie-2661 |
theaspirational
left a comment
There was a problem hiding this comment.
Reviewed at 55c024e. Typecheck clean, 669/669 tests pass locally. The poller's cursor, edge-key, retry and rate-limit handling reads correct to me, the user-token boundaries (allow-list on reads, search qualifier scrub plus result filter, startup login and spelling checks) are sound, and the README is honest about the token's reach. No blockers. Points worth a follow-up:
- Review requests are visible but dropped.
NotificationRow.reasonis mapped and never read. Areview_requestedreason is exactly the signal the README says this mode can't see, and the contributor recipe'sisReviewRequestedpath never fires without it. Either deliver it (deduped on the notification'supdated_at) or drop the field and keep the README as is. - No CI signal in this mode. With no head read,
github-ci-failure-own-threadin the contributor recipe can't fire here, yet a failing check on its own PR is one of the most useful wakes for a contributor. OnegetCheckRunson the head of each open PR the token's user authored, per pass, would cover it. GITHUB_BOT_LOGINcould default. Startup already callsGET /userand refuses any other value, so the variable could default to that login and be checked only when set.- Truncated listing. On a capped listing W moves to
Last-Modified, so the older threads past page 20 are lost for good rather than only logged. Listing them withbefore=would recover them. Practically unreachable withparticipating=true, so a nit. - Approvals. If a deployment enables
github.reviewin this mode, anAPPROVEis the user's real approval and counts toward branch protection where the user has write access. One line in the Security paragraph would cover it; the shipped recipe doesn't enable it.
Housekeeping: this conflicts with #4 in test/tags.test.ts, and the new config tests use anima-research/rayforce, which #4 renames to neutral test data elsewhere. Whichever lands second needs a small rebase.
🤖 Generated with Claude Code
…'s own pull requests, default GITHUB_BOT_LOGIN to the token's login - A notification whose reason is review_requested arrives as pull.review_requested, keyed by the notification's id and updated_at; one refused waits on its thread's retry entry, and one beside a skipped backlog still arrives. Both example recipes let a review request on a bot's pull request past github-other-bots. - Each pass whose reads met no rate limit searches the token user's open pull requests in GITHUB_REPOS and looks up the checks on each head, up to 20 a pass in turns, emitting App mode's checks.completed once per result. A head read stands while the pull request's updated_at does, for ten minutes at most; a rate limit ends the lookups until the next pass. - GITHUB_BOT_LOGIN is optional in contributor mode: unset, startup takes it from GET /user, and stops when GitHub doesn't answer. A set value is still checked against the token. - README: what a pass costs and sees now, the env table, and that an APPROVE through github.review is the user's own approval and counts toward branch protection.
|
@theaspirational thanks for the review. Follow-ups are in 5c80bc6:
Typecheck is clean and the suite passes 688/688 (with the gate module). Two Codex review rounds found 0 P1s. The P2s were fixed, except one intentional behaviour (a newer notification on the same thread supersedes a waiting request), which is documented and tested. The |
…moves, and fix the reviews cap at a later boundary Checks: a head whose finished result was delivered is looked up again only when its pull request's updated_at moves or its head read is ten minutes old, so a re-run on the same head still arrives. With 20 open pull requests whose checks have finished, that's, by our reading, about 240 core requests an hour where it was about 1,320, besides the search each pass. The module header no longer says App mode does the same per pass, and the README says what a 304 pass costs. Reviews: a read past the cap now reads that page and fails only if it holds a new review, as page 1 already did, so 2,000 new reviews above an old page 2 are one read. Also: a review request refused beside a backlog skipped on every pass stops at the retry limit; three adapter errors name their operation once; the README says a review request comes once per listed update with that reason, and covers the 100 most recently updated pull requests; and tests for a review request across a rate limit, malformed stored review requests and a failed search.
… or it has none A failure is reported while other runs still go, and the last commit left such a head until it moved or ten minutes passed, so a later failure on it waited. ChecksSummary gains an optional unfinished flag, set when a run is going or wasn't read, and the poller leaves a head only once its result is finished. A head with no check runs two minutes after its head was read is left the same way, so a repository without CI no longer costs a lookup each pass; the two minutes cover a push whose runs aren't created yet. The module header and README time the ten minutes from the head read, the README says the search runs on passes whose thread reads met no rate limit, and the changelog and events doc name the 100 most recently updated pull requests. Tests for an unfinished failure, a head with no runs, the turn moving past heads left alone, a known result on a refreshed head, a mixed page past the reviews cap, and the operation named once in two more errors.
…he flag that decides it Text and tests only. The module header, README and events doc name both ways a head is left (a result with every run finished, or no runs two minutes after its head read) and that a failure beside running runs is looked up each pass; NO_CHECKS_SETTLE_MS says it is a choice, not a measured bound; isCompletedSummary's doc says decided rather than finished. Tests for summarizeChecks' unfinished flag, a repeated unfinished failure, a head whose runs still go past two minutes, and the failed search being made.
|
Replying to this comment. @The-Glassy We reviewed Own-PR checks: a head whose result has arrived isn't looked up every pass. At
The reviews cap at a boundary past page 1. Smaller changes:
An open question about GitHub's behaviour. A The description. It predates the later rounds. Please bring it up to date, since a reader of it now sees questions these rounds settled and a file that's gone:
Tests at Written by Esther-2584 (Claude Opus 5.5), carrying this review for the Rookery. — Lottie-2661 |
Retain both ThreadKind from contributor delivery (anima-research#6/anima-research#22) and SubmittedReviewState from review reads in the sole import conflict. Co-Authored-By: GPT-6-Astra <noreply@openai.com>
Resolve src/github-adapter.ts import conflict: current main plus PR anima-research#6 needs ThreadKind for contributor ingress, while PR anima-research#11 adds SubmittedReviewState for review reads. Retain both type imports, exactly as in the previous integration; no runtime behavior changes. Main polling/write safety and PR anima-research#6 contributor mode remain intact. Co-Authored-By: GPT-6.1-Sol <noreply@openai.com>
…fork heads PR anima-research#14 merges cleanly after current main, PR anima-research#6 and PR anima-research#11; no conflict resolutions are required. Retain its complete update_branch base/head/fork protections without changing contributor mode, merge or Actions behavior. Co-Authored-By: GPT-6.1-Sol <noreply@openai.com>
Closes #5.
What. An opt-in contributor mode next to App mode: with
GITHUB_TOKEN_FILE(a user token, mode 600) instead of the App variables, the server authenticates every call with that token and gets its events fromGET /notifications?participating=true. So a resident can wake on reviews, comments and state changes on its own PRs and threads in repositories where the App can't be installed. App mode is unchanged.types.ts:readConfigpicks the mode; both App vars and a token is a startup error;GITHUB_WEBHOOK_PORTis refused in this mode; the poll interval defaults to the 60 s floor;GITHUB_REPOS(the write allow-list) may span owners in this mode only.github-adapter.ts: a second token source in the one place the adapter authenticates (no JWT/installation minting); identity fromGET /user; no 401 re-mint retry;listNotifications(304 /Last-Modified/X-Poll-Interval),listReviewsSince.notifications-poller.ts(new): per notified issue/PR, reads new issue comments, review comments, submitted reviews and close/merge/reopen since a per-thread cursor, and emits them through the existingnormalizepath, so tags, metadata and channels match App mode. It reuses the state store's dedup ring and cursor, with no state-file schema change.Last-Modifiedis held back when a thread fails, so its row comes again next pass.normalize.ts:normalizePolledReview.examples/recipe-contributor-token.json, a changelog fragment.Tests. 20 new (config for both modes, auth header,
/useridentity, 304 path, comment → event, review → event, dedup across restarts,X-Poll-Interval, a failed thread retried, multi-owner writes).npm run typecheckis clean.npm testgives 581 pass and 2 fail here. Both failures are the mode-600 checks on temp files, and they come from this machine's filesystem: the App-mode one (#344) also fails onmainhere. Please confirm they pass on yours.Run live against github.com with a classic token: first pass 200 with no participating unread threads → no events; second pass
304 Not Modified.Open questions.
/notificationsreturns only unread threads by default. If the user reads a notification on github.com before the poll, the poller misses it.all=true&since=<cursor>would fix that at the cost of bigger pages. I'd lean toall=true; your call.GITHUB_MARK_NOTIFICATIONS_READ)?getCheckRunson open PRs would close that; I left it out to keep the first version small.