Skip to content

feat: pull request feedback (M4), starting with superagent's own GitHub account - #16

Merged
pakgin merged 16 commits into
mainfrom
feat/pr-feedback
Nov 8, 2026
Merged

pakgin merged 16 commits into
mainfrom
feat/pr-feedback

Conversation

@pakgin

@pakgin pakgin commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

What

M4, pull request feedback, starting with superagent's own GitHub account. Code complete and smoke-tested live.

#15 and #14 are merged, and main is merged in here.

  • Roadmap: the M4 spec, with the agent's own GitHub account as its first step. Open decision 2 is closed.

  • The agent's own account (@repo/core/github):

    • SUPERAGENT_GITHUB_TOKEN and SUPERAGENT_OWNER_GITHUB, with a startup check that the token isn't the owner's.
    • Workers act as the agent: GH_TOKEN, git pushes over https with that token, and commits authored with its noreply address.
    • The machine's own credential helpers can't answer (for example a keychain holding another login), and SSH remotes for GitHub are rewritten, so the machine's SSH key isn't used.
  • The pull request watcher, every minute:

    • readPullRequest fetches only what changed: reviews and comments when updated_at moved, check runs for a new head commit or while some are pending. A quiet PR costs one request a minute.
    • pullRequestFeedback is pure, and holds every rule:
      • only the owner's words and installed bots' count; the agent's own and other people's are dropped;
      • failed checks on the head commit count, once each;
      • bots get three rounds;
      • CI and bots never wake a failed or stopped task;
      • a PR off agent/<task id>, or from a fork, is foreign, and the owner is told once;
      • a merge or close posts once and closes the task.
    • The loop writes inputs (github:<kind>:<id>), notices, the close, and the kv read position in one transaction.
  • Ownership at report time: recordReport refuses a PR URL outside the task's repo.

  • closeTask: a merge or close drops unread inputs and moves the task to done from any state. stopTask shares dropUnreadInputs with it.

  • The guard now covers gh api. Merges (including GraphQL mergePullRequest and enablePullRequestAutoMerge), approvals, and closing issues are refused there too. Resolving threads and replying to comments still pass.

  • Review instructions:

    • a comment the worker agrees with: fix it and resolve its thread;
    • one it disagrees with: decline in one sentence on the comment;
    • a failed check: read its log and fix the cause;
    • then push and report ready again.
  • Answering on GitHub, where it was asked:

    • ack puts 👀 on a [github] comment as the agent, as it does in Slack. Greptile's and other bots' comments count.
    • When a turn that didn't fail ends, 👀 becomes ✅ in Slack and 👍 on GitHub, which has no check mark, as Greptile does. A message handed back is left for the router, and a failed turn keeps 👀.
    • The runner decides where a report goes, from the messages it answers: [github] ones get a pull request comment, Slack ones a Slack post, and a turn with both gets both. This replaces an answeredOnGitHub flag the worker had to remember, and live it didn't.
    • The worker doesn't comment on the pull request itself: its report is the answer there, and live, a reply of its own plus the report said everything twice. Instructions alone didn't stop it, so the guard refuses gh pr comment, gh pr review, and gh issue comment on the task's pull request, and gh api writes to its comments. Replies in review threads, reads, and other pull requests and issues pass.
    • An edited comment counts like a new one: a comment or review comment already read, and updated since, reaches the worker again as an edit with its new text, once per edit, with 👀 and 👍. Greptile rewrites its summary in place after each review, which the watcher used to miss. A bot's edit uses one of its rounds.
    • GitHub comments and reactions go through the outbox, so they are durable, ordered per pull request, and posted once. Migration 3 rebuilds the outbox table for reaction removals and GitHub entries, keeping its rows. A GitHub comment carries a hidden <!-- superagent:<key> --> marker that a retry looks for before posting again.
  • Docs: AGENTS.md has a "Pull requests" section and the layout. The core README, CONTRIBUTING, and .env.example are updated.

  • Greptile's review (8 findings), fixed in 551d80b:

    • a live worker can't reopen a task its pull request closed; the runner interrupts it;
    • comment edits are tracked per comment, so parallel or paged reads can't hide one;
    • an unchanged head's checks are read again every five minutes, for CI that starts late or is rerun;
    • every GitHub list is read to the end, and a list past the page cap fails loudly;
    • the outbox starts no GitHub comment once stopping;
    • the guard's comment rule names the task's repo, and gh api with an explicit GET is a read.

Checks

  • pnpm format, pnpm lint, pnpm typecheck, and pnpm test all pass: core 430, agent 20.
  • Mutation checks: removing each new guard makes a test fail:
    • the credential-helper reset and the SSH rewrite (tested against real git);
    • refusing the owner's token;
    • workers using the agent account;
    • requiring the owner's login;
    • every feedback rule;
    • the watcher's skips, closing, change-only reads, and per-PR error isolation;
    • the repo check;
    • the gh api guard;
    • no done reaction after a failed turn or on a handed-back message, and 👀 off before ✅ on;
    • routing a report to the pull request, and skipping Slack when only GitHub asked;
    • taking an edit, once per edit, without mistaking a comment written mid-poll for one, and without replaying old edits from a position saved before;
    • the guard's comment rule: the task's pull request by number, URL, or none, gh api writes but not reads, other pull requests passing, and the session and runner wiring;
    • the GitHub comment's duplicate check on retry, removing only the agent's own reaction, and a Slack reaction already gone counting as removed.

Verified live (2026-11-08, scratch repo with CI)

  • The agent account: PR feat(core): add the SQLite store and record Slack events in it #5 was opened by pakgin-agent. Every commit was authored and pushed as pakgin-agent with its noreply address. Startup resolved the token to pakgin-agent and accepted it, since it isn't the owner's.

  • A failing CI run fixed without Slack: CI failed on the first commit (the old add() bug on main). The watcher passed the failed check to the worker 22 seconds later. The worker fixed it, CI passed, and it reported ready again. The owner sent no Slack messages.

  • The owner's comments:

    • a plain PR comment ("rename negate to negative") was done and reported ready;
    • a review comment on a line ("add a one-line JSDoc…") was fixed, and its thread was resolved by pakgin-agent through gh api graphql.

    The review itself, which had no text of its own, was rightly skipped.

  • Merge: the owner merged PR feat(core): add the SQLite store and record Slack events in it #5. 39 seconds later the thread got one "Pull request feat(core): add the SQLite store and record Slack events in it #5 was merged, so this task is done." post, and the task became done. The watcher stopped polling it.

  • Not live: a stranger's comment being dropped, which needs a third GitHub account. Unit tests cover it.

🤖 Generated with Claude Code

pakgin and others added 13 commits November 7, 2026 23:22
M4 starts with a GitHub account for the agent. Workers push, open pull
requests, comment, and resolve threads as that account, so the owner
can review its work and M4 can tell the owner's comments from the
agent's. On GitHub only the owner's words and installed bots' count:
the owner gate's equivalent, so a stranger's comment on a public repo
can't steer a worker. A merge or close ends the task from any state.
Open decision 2 is closed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first step of M4. With SUPERAGENT_GITHUB_TOKEN set, startup asks
GitHub whose token it is and refuses one that belongs to
SUPERAGENT_OWNER_GITHUB, and workers act on GitHub as that account:

- gh through GH_TOKEN;
- pushes over https with the same token, through a credential helper
  that follows an empty credential.helper, so the machine's own
  helpers, like a keychain holding another login, don't answer;
- insteadOf rewrites, so an SSH remote for GitHub doesn't push with the
  machine's SSH key;
- commits authored as the agent, with GitHub's noreply address.

A new @repo/core/github module holds a small fetch-based client,
resolveAgentAccount, and agentAccountEnvironment. Without a token,
workers use the machine's own logins, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The middle of M4's pull request watcher, before the loop that runs it:

- readPullRequest fetches a pull request, and only the parts the caller
  says have changed: reviews and comments when its updated_at moved,
  check runs for a new head commit or while checks are pending. That
  keeps a poll to one or two requests.
- pullRequestFeedback is pure. It turns a snapshot into the inputs that
  wake the worker, the notices for the Slack thread, whether the task
  is over, and the new read position for kv:
  - a pull request off agent/<task id>, or from a fork, is foreign, and
    the owner is told once;
  - a merge or close posts once and closes the task;
  - only the owner's words and installed bots' count; the agent's own
    and other people's are dropped;
  - failed checks on the head commit count, once each;
  - bots get three rounds;
  - CI and bots never wake a failed or stopped task.
- TaskStore.withPullRequest, and done reachable from waiting, blocked,
  failed, and stopped, so a merge can close a task from any state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
createPullRequestWatcher polls each task's pull request every minute.
It skips closed and foreign ones, reads only what changed, and applies
pullRequestFeedback. Inputs, notices, the close, and the new read
position are written in one transaction. The outbox and the runner are
woken only when something new arrived, and one pull request's failure
is logged without stopping the rest. A merge or close goes through the
new closeTask: unread inputs dropped, the task done, and any live
session ending at its next turn. stopTask shares dropUnreadInputs with
it.

M4 tells workers to use gh api, so the guard now looks inside it,
refusing what gh pr merge, gh pr review --approve, and gh issue close
are refused for: merges, including GraphQL mergePullRequest and
enablePullRequestAutoMerge; approvals; and closing issues. Resolving
review threads and replying to comments still pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- main starts the watcher, with the agent's client and login, after
  recovery alongside the task runner and the router, and stops it first
  on shutdown. Without SUPERAGENT_GITHUB_TOKEN it stays off, and startup
  says so.
- recordReport refuses a pull request URL outside the task's repo, so
  the watcher only ever follows the task's own.
- The worker learns what [github] messages are and what to do with
  them: fix and resolve the thread, or decline in one sentence on the
  comment; read a failed check's log and fix it; push; report ready
  again.
- AGENTS.md gains a "Pull requests" section with M4's rules. The core
  README describes the watcher, and the roadmap marks M4 built,
  waiting on a live run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PR #5 in the scratch repo was opened and committed to as pakgin-agent.
Its failing CI run was fixed with no Slack message, the owner's review
comment was fixed and its thread resolved by the agent, and the merge
posted once and closed the task. Only a stranger's comment being
ignored is untested live, since that needs a third GitHub account.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From the owner's review of M4's live run: a comment on a pull request
got no acknowledgement, and its answer went to Slack. The owner
shouldn't have to switch places.

- ack puts 👀 on the GitHub comments the worker was given, as the
  agent, through the new acknowledgePullRequestInputs. It's once per
  comment per session, and GitHub keeps one reaction per account anyway.
  Reviews and check runs can't take a reaction. A failure is logged,
  not thrown. The runner gets the agent's client.
- report takes answeredOnGitHub: the state is recorded, nothing is
  posted in Slack.
- The worker answers [github] messages on GitHub: in the review
  comment's thread (resolving it once fixed), with gh pr comment for a
  pull request comment, a review, or a fixed check. It then reports
  with answeredOnGitHub.
- Automated reviewers such as Greptile: the worker judges each finding,
  fixing what's right and declining in its thread what isn't. A
  comment cut short says so, pointing at gh for the rest. The bot round
  limit keeps a reviewer that reviews every push from looping.
- GitHubClient gains post.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ages

A report answering a [github] message is now posted as a comment on the
pull request instead of in Slack. The runner works out where it goes from
the inputs the session was given since the last accepted report, less any
handed back, so the worker no longer has to set answeredOnGitHub, which it
forgot. A turn with Slack and GitHub messages posts in both places.

When a turn that didn't fail ends, 👀 comes off each message it read and
✅ goes on in Slack, or 👍 on GitHub, which has no check mark. A message
handed back is left for the router; a failed turn keeps 👀.

GitHub comments and reactions now go through the outbox, like Slack's:
migration 3 rebuilds the table for reaction removals and GitHub entries,
the sender delivers each kind to Slack or to the agent's GitHub account,
and a GitHub comment carries a hidden dedupe marker that a retry looks for
before posting again. The direct-call acknowledgePullRequestInputs is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Live, the worker replied to each of the owner's pull request comments with
gh pr comment and then reported, and the report was posted there too, so
every answer showed up twice. Its session had started under the earlier
instructions, which told it to use gh pr comment. The instructions now say
the report is the answer, and that the worker writes on GitHub itself only
in a review comment's thread.

AGENTS.md also records that an edited comment isn't read again: the
watcher follows comment IDs, and Greptile edits its summary in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Greptile rewrites its summary comment in place after each review, and the
watcher, which follows comment IDs, never saw it. A comment or review
comment already read, and updated since, now becomes an input saying it
was edited, with its new text, under its own ref
(github:<kind>:<id>:edited:<updated_at>), so each edit is passed on once
and gets 👀 and 👍 like a new comment. Who counts is unchanged, and a
bot's edit uses one of its rounds.

The edit mark is the newest updated_at among the comments read, kept in
the read position, not the pull request's updated_at, so a comment
written while a poll was reading isn't taken for an edit on the next one.
A position saved before this falls back to its updatedAt, so no old edit
is replayed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Telling the worker that its report is its answer on the pull request
wasn't enough: live, after an edited comment, it still ran gh pr comment
and then reported, so the answer was posted twice. The guard now refuses
gh pr comment, gh pr review, and gh issue comment on the task's pull
request (by number, URL, or none, meaning the current branch's), and gh
api writes to its /issues/<n>/comments, saying the report is posted
there. Review thread replies, reads, and other pull requests and issues
still pass.

The runner gives each session the task's pull request number, read when
the command runs, and the session passes it to the guard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pakgin
pakgin marked this pull request as ready for review November 8, 2026 09:32
@greptile-apps

greptile-apps Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The reviewed changes appear safe to merge; the remaining finding about live workers reopening closed tasks is fixed.

Summary

Adds GitHub pull request feedback through the agent’s own account.

  • Workers use the agent’s GitHub identity for pushes and pull requests.
  • Pull-request reviews, comments, and failed checks reach the task that opened the branch.
  • Workers answer GitHub feedback with reports and reactions on the pull request.
  • Merged or closed pull requests mark their tasks done.
  • The worker guard blocks risky GitHub actions and duplicate comments on its pull request.

The remaining numbered finding is fixed. No new actionable issues were found in the changes since the previous review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Pull request merged or closed] --> B[Drop unread inputs]
  B --> C[Mark task done and save closedAt]
  C --> D[Reject late worker reports]
  C --> E[Interrupt old session]
  E --> F[Old session ends]
  F --> G{New owner input?}
  G -->|Yes| H[Launch session and clear closedAt]
  G -->|No| I[Keep task closed]
Loading

Reviews (4) · Last reviewed commit: "fix(core): keep a closed task closed wit..." · Reviewed by Greptile

Comment thread packages/core/src/tasks/close-task.ts Resolved
Comment thread packages/core/src/outbox/sender.ts Resolved
Comment thread packages/core/src/tasks/worker-guard.ts Resolved
Comment thread packages/core/src/tasks/worker-guard.ts Resolved
- A live worker no longer reopens a task its pull request closed. The
  runner interrupts the session, as for a stop, and reopenReportedTask
  refuses a task that went done under a session that didn't report done,
  so a late report is turned down. The owner's next message resumes it.
- Comment edits are tracked per comment (commentVersions), not with one
  mark for all, so reading the two lists in parallel, or across pages,
  can't hide an edit.
- An unchanged head commit's checks are read again every five minutes,
  so CI that starts late or is rerun on the same commit still counts.
- getAllPages reads every GitHub list to the end, check runs and the
  outbox's comment and reaction lookups included, and throws past
  GITHUB_MAX_PAGES instead of passing a cut-off list for the whole.
- The outbox sender starts no GitHub comment once it is stopping.
- The guard's comment rule names the task's repo (gh api paths,
  {owner}/{repo}, --repo, and URLs), and gh api with an explicit GET is a
  read even with fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pakgin and others added 2 commits November 8, 2026 01:52
Greptile, re-reviewing: now that a list past the page cap throws, a
merged pull request with that many comments would fail every poll before
pullRequestFeedback saw the merge, so its task would never close. The
watcher now reads reviews, comments, and checks only for an open pull
request that is the task's, the only one feedback uses them for. A first
look at a foreign pull request is settled the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Greptile's re-review still flagged the closed-task case, and one remained:
the runner told a close apart by a done task its own session hadn't
reported done, so a task whose worker had reported done before its pull
request merged could still be reopened by a queued turn or a late report,
and the watcher would never close it again.

closeTask now marks the task closed (closed_at, migration 4), even when
it was already done, and reopenReportedTask refuses a closed task. Every
transition clears the mark, so the owner's next message, which resumes
the task through a launch, reopens it. The live session's flag is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pakgin
pakgin merged commit 53b65ca into main Nov 8, 2026
3 checks passed
@pakgin
pakgin deleted the feat/pr-feedback branch November 8, 2026 10:02
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.

1 participant