Skip to content

Support reviewed repository workflows in Agents and Code - #1096

Merged
railgrid-prow[bot] merged 13 commits into
mainfrom
codex/factory-mvp-companion
Nov 15, 2026
Merged

railgrid-prow[bot] merged 13 commits into
mainfrom
codex/factory-mvp-companion

Conversation

@cwilhit

@cwilhit cwilhit commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Add reusable Agents support for reviewed repository runs, including structured results, isolated transcripts, and narrowly scoped run actions.
  • Add Code support for adopting and reviewing existing PRs, posting inline diff comments at the reviewed commit, and publishing repairs under an expected-head lease.
  • Receive GitHub issue-comment commands and verify the comment, author permissions, and PR head against GitHub before exposing them to consumers.
  • Improve runner cleanup and repository-run evidence used by these workflows.

Verification

  • Ran the Agents API and store tests, and exercised distinct repository-run transcript IDs on the existing Tilt cluster.
  • Built and deployed Code to Tilt. A real GitHub webhook drove review and repair on experimental-providers PR test: unit tests for controller reconcilers (#40, #41, #42, #43) #47. Inline comments landed on the reviewed commit, adoption preserved the PR title and description, and a concurrent push survived the repair attempt.
  • GitHub redelivery left the existing command and PR history intact.

The private Factory workflow that consumes these APIs is tracked in Providers PR #124.

cwilhit and others added 5 commits November 13, 2026 19:07
Code now reads, once per login, the repository permission (admin, write,
read or none) of each person who submits a CHANGES_REQUESTED review on the
pull request head, and reports it as PullRequestReview.authorPermission.
A coordinator such as Factory can act on a request for changes from
someone who could push the change, and ignore anyone else's. A 403 or 404
from the permission lookup records "none".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each ready Repository publishes a webhook path (status.commandsWebhookPath)
carrying an HMAC token over its workspace and name; a repository admin pastes
the URL into GitHub for Issue comments events. A delivery records only the
comment ID as a PullRequestCommand owned by the Repository. The
PullRequestCommand reconciler re-reads the comment and its pull request from
GitHub with the Repository's credential and records the verified command,
author, author permission and pull request head, or a rejection reason.

The repository detail page shows the setup steps and the URL behind a toggle.
The chart takes an optional commandsWebhook.keySecretRef (CODE_WEBHOOK_KEY)
to keep URLs stable across kubeconfig rotation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cwilhit
cwilhit requested a review from mjudeikis as a code owner November 14, 2026 18:50
@cwilhit

cwilhit commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator Author

@mjudeikis-bot review

@mjudeikis mjudeikis 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.

Scope: this PR is about 15k lines across 190 files and the diff API refuses to serve it (over 20000 lines). I read the Code provider's command intake, review actions, backend review path and publication lease in full. I did not review the Agents store/API/portal changes, the runner changes or the Code portal change. Treat those as uncovered.

Not anchored: Agents provider. No Agents code was traced, including the repository-run transcript isolation, run actions and the Postgres store changes. Someone should review them separately.

Checked

  • Read beyond the diff: commandhook/{commandhook,handler}.go, controller/pullrequestcommand/controller.go, actions/{server,pullrequest_actions,review_operation}.go, backend/github/review.go, backend/github/collaboration.go (new IssueComment, RepositoryPermission, ObservePullRequestBase), backend/github/snapshot.go advance (the --force-with-lease push), the publication-lease section of controller/pullrequest/controller.go, repository controller webhook-path wiring, chart values.yaml/deployment.yaml/README, provider-sdk/serve webhook class.
  • Correctness: the review/comment receipt state machines (Accepted/Complete/Release/ForgetMissing) are consistent. Release is fenced on updatedAt, and a payload mismatch is rejected before any mutation. Finding 2 is the one gap.
  • Concurrency: receipts are claimed with resourceVersion CAS via RetryOnConflict, so two replicas cannot both claim one key. The webhook create is idempotent through a deterministic object name.
  • Tenancy/kcp: the webhook cluster comes from the URL, which the HMAC binds to cluster+name, and the handler cross-checks the payload repository.id against status.repoID. The actions act through AsProvider and pin repository/connection UIDs. Nothing found, apart from finding 1.
  • Provider contract: new verbs submit-review, upsert-comment and ready are in pullRequestActions and in manifest.yaml. The catalog parity test was updated (18 actions, 3 resources). No bearer on the verbs and no /api/* route. The webhook is mounted as class (g) via Extra.
  • API/codegen: CRDs, kcp schemas and chart files/ were regenerated alongside the types, as far as I could see. I did not run make verify-codegen.
  • Security: the payload is treated as a doorbell and everything is re-read from GitHub. Command arguments are pattern-restricted. The review path rejects non-open and merged PRs, forks and a head mismatch. Review notes are validated against the PR's real diff. See finding 1 for the URL-as-credential concern.
  • Tests: the commandhook, receipt, review-action, catalog and subresource tests exist and pass. No test covers a status reader replaying a delivery or a full receipt history.
  • Commands run: cd providers/code && go build ./... && go vet ./... && go test -count=1 ./... passed for every package except the root provider-code package, which fails in the sandbox with assets.go: pattern all:portal/dist: no matching files found because the portal was not built. I did not build the portal.
  • Not run: make build, make lint, make verify-codegen, make verify-provider-contract, make verify-portalkit, make verify-boilerplate, the root go test ./pkg/..., the Agents module tests, and every e2e suite (too heavy for this run; the PR body reports a Tilt run).

Comment thread providers/code/commandhook/handler.go Outdated

func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
cluster, name := r.PathValue("cluster"), r.PathValue("name")
if !ValidToken(h.key, cluster, name, r.PathValue("token")) {

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.

Warning: Unverified: the webhook URL is the only credential and it is published in Repository.status
The token is the sole check here. It is also written to status.commandsWebhookPath (controller/repository/controller.go:150) and rendered in the portal. I traced the code but could not confirm which workspace roles can read Repository status. If a read-only member can, they can POST forged issue_comment payloads with any comment.id. Each one creates a PullRequestCommand and costs a GitHub GET comments/{id} on the repository's credential, and a 404 deletes the object, so a loop gives unbounded create/delete churn and rate-limit burn. They can also replay a real writer's comment ID within the one-hour window. If the consumer cleans up a Verified command, that re-creates a fresh Verified command and the command runs again. GitHub's X-Hub-Signature-256 is not checked, so the URL cannot be rotated apart from the provider-wide key.

// store a per-Repository secret outside status (provider-owned Secret) and
// verify GitHub's signature before recording anything:
if !validSignature(secret, r.Header.Get("X-Hub-Signature-256"), body) {
	http.NotFound(w, r)
	return
}

var evicted bool
ops, evicted = evictCompletedOperation(ops)
if !evicted {
return errors.New("review operation history is full")

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.

Note: Uncertain receipts are never evicted, so a PR can lock itself out of reviews
A transient error after the forge write was attempted leaves the key Accepted (classifyReviewWrite deliberately keeps it). The same happens if a replica dies mid-call. evictCompletedOperation only removes Complete entries, so after 64 such leftovers every new key on that PR fails with review operation history is full. The action layer reports this as review_operation_conflict (409), which looks like an idempotency clash rather than a full ledger. The comment ledger at line 132 has the same problem. Reconciling stale Accepted entries against the forge marker after a grace period, or at least returning a distinct error code, would avoid the dead end.

if !evicted {
	return errors.New("review operation history is full of unconfirmed operations; resolve or recreate the pull request")
}

}

func (r *Reconciler) verify(ctx context.Context, c client.Client, command *codev1alpha1.PullRequestCommand) (ctrl.Result, error) {
if !command.DeletionTimestamp.IsZero() || command.Status.Phase == codev1alpha1.PullRequestCommandVerified || command.Status.Phase == codev1alpha1.PullRequestCommandRejected {

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.

Note: Verified and Rejected commands are never reaped
Once a command reaches a terminal phase the reconciler returns early and nothing deletes it. The only cleanup is the owner reference to the Repository. Every /railgrid ... comment on a busy repository leaves a cluster-scoped object forever. That includes Rejected ones, which anyone who can comment can generate, such as a read-only user posting /railgrid x. A TTL (delete terminal commands some time after verifiedAt) would bound this.

if phase terminal && r.now().Sub(command.Status.VerifiedAt.Time) > retention {
	return ctrl.Result{}, client.IgnoreNotFound(c.Delete(ctx, command))
}

cwilhit and others added 8 commits November 14, 2026 20:37
Runner:
- Skip an unsafe, oversize or unreadable completion artifact with a
  path-free artifact event instead of failing a completed attempt and
  discarding its Git result.
- Treat an exhausted aggregate artifact budget as a zero limit, not as
  "no limit".
- Name the cleanup retry limit and probe retained process scopes at
  startup in parallel, each still bounded.

Agents:
- Keep the verified Git result when a structured result is invalid.
- Refuse an attended chat turn whose caller identity cannot be reviewed
  (retryable 503, nothing stored), so a session is never created without
  its owner; cache resolved subjects for a minute.
- Reuse runner cleanup observations on trace reads.
- Fetch the Agent only when a parked inbox item is restored, and do not
  re-sweep an Agent's parked runs for 30s after a clean sweep.
- Cap each session at its newest 500 notifications.
- Use the trimmed session ID in every notification handler; validate
  revoke input in Postgres.
- Answer a reuse found after an admission race like one found up front.

Code:
- Retry a rate-limited 403 on a permission lookup instead of recording
  "none".
- Let a command pin the head commit it means; reject it when the head has
  moved and record status.headPinned for consumers.
- Reject commands that cannot be verified within an hour.
- Cache the webhook's Repository and Secret lookup and answer every
  unauthenticated delivery with the same 404.
- Record a publication as Published when the moved branch still contains
  its candidate.
- Share the GitHub App JWT code and cache the App slug.
- Tell portal users the webhook Secret needs the railgrid.ai/owner: code
  label.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove the per-session notification feed and the session ownership that
existed only to grant access to it: the deliver, notifications and
session-access verbs, their request kinds and schemas, the notification
store and its Postgres tables, and the portal panel. Nothing outside
Factory posted to the feed, and Factory no longer does.

Chat turns no longer resolve the caller's kcp identity unless
attachments are involved, so an identity lookup failure no longer
refuses a turn.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cwilhit

cwilhit commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

/approve

@railgrid-prow

railgrid-prow Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cwilhit

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@railgrid-prow
railgrid-prow Bot merged commit 5120355 into main Nov 15, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants