Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/pr-gate-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ concurrency:
group: pr-gate-test-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
Expand All @@ -20,4 +23,4 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: '22'
- run: node --test pr-gate/decide.test.mjs
- run: node --test pr-gate/*.test.mjs
78 changes: 71 additions & 7 deletions .github/workflows/pr-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,115 @@ on:
required: true
type: string
merge:
description: Squash-merge when every condition passes. False = report only.
description: Reserved for compatibility. True is refused; this gate is report-only.
required: false
type: boolean
default: false
gate-ref:
description: Commit of Starlight-Intelligence/.github to load the gate from. Pin it to the same SHA as the uses line.
required: false
type: string
default: main
default: ''
required-checks:
description: Comma-separated check run names that must pass on the head commit, e.g. "test, build".
required: true
type: string
wait-minutes:
description: How long to wait for running CI when it is the only thing outstanding.
description: Deprecated compatibility input. Reports are immediate and never poll.
required: false
type: number
default: 8

jobs:
resolve-pr:
runs-on: ubuntu-latest
timeout-minutes: 2
permissions:
contents: read
pull-requests: read
actions: read
outputs:
pr-number: ${{ steps.resolve.outputs.pr-number }}
steps:
- name: Require the same immutable resolver and reusable source
env:
GATE_REF: ${{ inputs.gate-ref }}
JOB_WORKFLOW_SHA: ${{ job.workflow_sha }}
JOB_WORKFLOW_REPOSITORY: ${{ job.workflow_repository }}
run: |
node <<'NODE'
// source-ref-validator:start
const e = process.env;
if (!/^[a-f0-9]{40}$/.test(e.GATE_REF || '') || e.GATE_REF !== e.JOB_WORKFLOW_SHA || (e.JOB_WORKFLOW_REPOSITORY || '').toLowerCase() !== 'starlight-intelligence/.github') process.exit(1);
// source-ref-validator:end
NODE
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
repository: Starlight-Intelligence/.github
ref: ${{ inputs.gate-ref }}
path: .pr-gate
persist-credentials: false
- name: Resolve only an API-authenticated current PR
id: resolve
env:
GITHUB_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ inputs.pr-number }}
run: |
node --input-type=module <<'NODE'
import { appendFileSync } from 'node:fs';
import { createClient, resolvePrNumber } from './.pr-gate/pr-gate/run.mjs';
const number = await resolvePrNumber(process.env, createClient(process.env.GITHUB_TOKEN));
appendFileSync(process.env.GITHUB_OUTPUT, `pr-number=${number ?? ''}\n`);
NODE

decide:
needs: resolve-pr
if: needs.resolve-pr.outputs.pr-number != ''
# Only eligible, resolved reports join this group. An unrelated comment
# cannot cancel a run, and all event types for the same PR serialize here.
concurrency:
group: starlight-pr-gate-${{ github.repository }}-${{ needs.resolve-pr.outputs.pr-number }}
cancel-in-progress: false
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: write
contents: read
pull-requests: write
issues: write
checks: read
actions: read
steps:
- name: Require an immutable gate source
env:
GATE_REF: ${{ inputs.gate-ref }}
JOB_WORKFLOW_SHA: ${{ job.workflow_sha }}
JOB_WORKFLOW_REPOSITORY: ${{ job.workflow_repository }}
run: |
node <<'NODE'
// source-ref-validator:start
const e = process.env;
if (!/^[a-f0-9]{40}$/.test(e.GATE_REF || '') || e.GATE_REF !== e.JOB_WORKFLOW_SHA || (e.JOB_WORKFLOW_REPOSITORY || '').toLowerCase() !== 'starlight-intelligence/.github') process.exit(1);
// source-ref-validator:end
NODE
- name: Load the gate
uses: actions/checkout@v4
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
repository: Starlight-Intelligence/.github
ref: ${{ inputs.gate-ref }}
path: .pr-gate
persist-credentials: false

- uses: actions/setup-node@v4
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: '22'

- name: Decide
env:
GITHUB_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ inputs.pr-number }}
PR_NUMBER: ${{ needs.resolve-pr.outputs.pr-number }}
# Resolve once before the per-PR lock; do not resolve a second time
# under a workflow_run event and accidentally select another PR.
PR_GATE_EVENT_RESOLVED: 'true'
PR_GATE_MERGE: ${{ inputs.merge }}
PR_GATE_WAIT_MINUTES: ${{ inputs.wait-minutes }}
PR_GATE_REQUIRED_CHECKS: ${{ inputs.required-checks }}
Expand Down
66 changes: 29 additions & 37 deletions pr-gate/README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
# pr-gate

The estate merge gate, running on GitHub instead of a laptop. On the PR's current head commit it passes only when:

- A review from a GitHub bot identity of a different harness than the author exists for that commit: `chatgpt-codex-connector[bot]` (Codex) or `claude[bot]` (Claude). The author is read from the branch prefix, because every harness pushes as the same GitHub account.
- That review is an approval, or a review whose body says it found no major issues. Dismissed and pending reviews are ignored. A bot review mentioning P0 or P1 blocks, and so does a bot comment that names a P0 or P1 against the head. Bot comments never sign off, because they carry no commit id.
- A renamed file is judged on both its old and new path.
- Every check named in the repo's `required-checks` has a latest attempt that succeeded, no other check failed, and nothing is still running. Commit statuses never count: anything holding a token can post one, which is how 20 PRs merged on 2026-10-19 with no check having run.
- All review threads are resolved (every page read; an unreadable answer blocks) and the full list of changed files was read.
- It is not a draft, carries no `hold` / `do-not-merge` / `blocked` / `wip` label, and its body links the intent it serves (an issue, board item or ruling).
- It touches none of Frank's paths: workflows, env files, dependencies, money, auth and middleware, `vercel.json`, or a new or deleted public page. No label overrides this. Labels prove nothing about who applied them on a shared account, so Frank merges those himself.

In merge mode it decides again from fresh facts just before merging and merges with a head-SHA guard.

## What does not count

Typed lines (`starlight-signoff: ...` from the estate `tools/pr-gate.mjs`, `Checker: claude-cloud · head <sha> · verdict PASS`) are shown as advisory but never pass the gate: the author can type them. The estate `pr-gate.mjs` still honours them for a merge a human runs.

So today, Claude-authored PRs pass once Codex reviews them. Codex- and Gemini-authored PRs pass only after a review from the Claude GitHub bot, or a human-run merge.

Branch prefixes: `agent/claude/`, `claude/`, `ccr-` and `factory/` (Foreman, whose implementer is an Anthropic model) are Claude; `codex/`, `agent/codex/`, `agent/gpt*` are Codex; `agent/antigravity/`, `agent/gemini/`, Jules and `sentinel-` branches are Gemini.

## Install in a repo

1. Copy `caller.yml` to `.github/workflows/pr-gate.yml` and `poke.yml` to `.github/workflows/pr-gate-poke.yml`. Replace both `GATE_SHA` with a commit of this repo, list the repo's CI workflow names under `workflow_run`, and its check names in `required-checks`.
2. Turn on Codex code review and automatic reviews for the repo in Codex settings.
3. Add the section in `CODE-REVIEW-RULES.md` to the repo's `AGENTS.md`.
4. Start with `merge: false` (report only). Flip to `merge: true` where autonomous landing is ruled.

Every trigger runs the caller from the default branch. Review events go through `pr-gate-poke`, which holds no permissions, and come back as `workflow_run`.

## Known limits

- Without branch protection nothing stops someone merging around the gate; the private repos on the free plan cannot have it. The gate is the merge path agents are told to use, not a lock.
- Between the final decision and the merge call a few milliseconds remain in which a review could be dismissed. Only a required status check under branch protection closes that.
- A same-repo PR's own workflows run with the repo token. The gate refuses to merge any PR that edits workflows, but cannot stop such a PR from posting a same-named check on itself.
- A squash merge made with the workflow token does not trigger push workflows on the base branch. Vercel's git integration still deploys.

Tests: `node --test pr-gate/decide.test.mjs`.
Report-only PR diagnostics. This implementation cannot authorize a merge or
certify provider independence. `merge: true` is refused before any API request.

The runner reads PR files, reviews, comments, threads and checks through GitHub's
API without executing PR source. It binds observations to a full head SHA,
checks current-attempt job membership, and rejects missing or ambiguous CI.
Typed receipts and clean prose never supply approval. A review bot identifies
the reviewer account; the maker's actual provider remains unverified because
all harnesses can push under the same human GitHub account and choose branch names.

Call the reusable workflow at an immutable commit with `gate-ref` set to that
same commit. Required contexts use JSON, for example:

```yaml
required-checks: >-
[{"name":"Starlight CI / release aggregate","appId":15368,"workflowPath":".github/workflows/ci.yml"}]
merge: false
```

Legacy comma-separated context names are diagnostic only and fail provenance
validation. Existing pinned consumers retain their old behavior until separately
reviewed. Do not change every consumer or enable required enforcement in a batch.

Permissions: contents/checks/actions read; issues/pull-requests write for reports.
No contents write, secrets, id-token write or production credentials are needed.
The zero-permission review relay triggers a fresh API read and supplies no verdict.

Tests: `node --test pr-gate/*.test.mjs`.
Threat model: `Review-threat-model-Codex-2026-11-03-v1.md`.
49 changes: 49 additions & 0 deletions pr-gate/Review-threat-model-Codex-2026-11-03-v1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# pr-gate threat model, Codex, 3 November 2026, revision 1

Author: Codex. Source base: e3faf85affc49cc8b97a87bebdf20bd97833d6b4.
Review state: candidate, independent-provider review pending. Existing consumers remain pinned.

Protect source, production, review evidence and write permissions. PR source,
branch names, comments, event titles, diffs and artifacts are untrusted. API
identities prove GitHub actors, not the model used by a human-account maker.
No trusted maker attestation exists, so different bot/harness names cannot
certify provider independence.

Ten new regression tests failed against the old source. They cover abbreviated
SHAs, free-form clean prose, unauthenticated maker identity, ignored same-provider
P1s, absent app/workflow/head provenance, retry ordering, duplicate names and
missing thread data. Origin cases exercise the missing provenance contract;
they do not claim every existing configuration exposed an identical exploit.

Repairs: full SHA equality; native APPROVED review state; blocking findings count
regardless of branch hint; app/workflow/repository/head/suite/current-attempt job
binding; failed newer attempts beat old success; incomplete data fails closed;
15-second API deadlines, at most three GET attempts, no retry of uncertain writes;
no private error-body printing; head re-read before report; only Actions Bot's
own sticky marker is updated; immutable gate checkout; no contents-write or
automatic merge; immediate reports replace billed idle polling.

Provider independence remains unverified. Every candidate stays WAITING or
BLOCKED, and merge=true is refused. This is a diagnostic limit, not production
authorization. Human review can evaluate declared authorship separately; typed
comments do not become authenticated remote attestations.

`pull_request_target` and `workflow_run` must load trusted default-branch callers.
Only pinned gate code is checked out; no PR executable, artifact or fork source
runs with reporting permissions. Relay numbers cause fresh API reads. Workflow
edits remain sensitive changes requiring security review and human authorization.

The head or reviews can still change after the final API read. Reports identify
their exact head and confer no merge authority. Actions app identity alone cannot
prove immutable workflow logic. Current protection and independent review must
cover workflow changes; no stronger enforcement is claimed by this candidate.

44 local tests pass: 17 reconciled existing tests, ten regression tests and 17
runner/API tests covering spoofed comments, races, missing data, pagination,
partial GraphQL results, retry/denial behavior and malicious URLs. Fixtures do
not establish live GitHub integration or independent security review.

Sources read 3 November 2026: GitHub required-status-check troubleshooting,
secure pull_request_target docs, REST check-runs/workflow-runs/jobs docs, and
the exact pinned source consumed by Starlight main. No existing app permission,
billing, default-branch rule, production deployment or PR finding is changed.
51 changes: 51 additions & 0 deletions pr-gate/Review-threat-model-Codex-2026-11-03-v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# pr-gate review reconciliation, Codex, 3 November 2026, revision 2

Author: Codex. Actual reviewer: Claude via the existing agentic-ops GitHub workflow.
Original candidate: 68cac61112403f68af7a9a6836d70899157a36e7. State: refined candidate;
the new head still requires exact-revision follow-up. Revision 1 is preserved.

Review evidence: https://github.com/frankxai/agentic-ops/pull/439#issuecomment-6606894236
The reviewer read all 13 supplied files in the combined source packet. It did not
recompute the hashes, fetch upstream source or review either complete product.
Its 2m16s workflow completion is supported by an actual substantive review comment,
not inferred from exit status. No specific model version or cash charge is asserted.

Reconciliation:

- Medium, self-attested aggregate code: protect .github/scripts and the aggregate
test path alongside workflows. This adds a human-gate reason in diagnostics;
report-only logic is still not server-side CODEOWNERS or required-workflow enforcement.
- Low-medium, fork relay/title: discard event titles and attached PR arrays. Read
the triggering workflow run and resolve its current PR from repository/head/fork
identity through the commits/pulls API. Reject unknown workflows or ambiguity.
Concurrency uses head SHA instead of title. Fork relay, stale and adversarial
title tests exercise this path directly.
- Low, source pin mismatch: use GitHub's documented job.workflow_sha and
job.workflow_repository (not github.job_workflow_sha) to compare the loaded gate
ref with the actual reusable job source before checkout. Missing context fails
closed. The actual inline validator is exercised in separate Node processes.
The privileged reusable workflow's existing checkout/setup-node v4 refs are now
pinned to their observed tag commits without changing major versions.
- Low, unused wait input/dead branch: mark the compatibility input deprecated
and remove the unreachable branch. Conservative free-text severity blocking
remains a diagnostic false-positive risk; it does not permit a merge. A trusted
structured finding protocol is required before this can become enforcement.
- Conditional medium, self-hosted fork code in the Starlight build: current
repository variable inventory returned no variables, including CI_RUNNER.
No self-hosted admission is observed. This remains a future configuration risk;
a later runner change must qualify untrusted-PR isolation and explicit approval.
- Low-medium, tested merge SHA/base: current Starlight logic relies on GitHub's
same-run needs and checkout semantics. It does not independently inspect merge
parents or enforce a current base. Do not claim those properties. Strict branch
protection or a qualified merge queue remains a separate release decision.

57 focused tests pass after these repairs, including the 44 initial cases and
13 additional protected-path, event-routing and actual workflow-validator cases.
No consumer pin, live protection, billing, app grant, sensitive merge or deployment
has changed. New runtime contexts need actual integration proof before adoption.

Primary sources checked 3 November 2026:
- https://docs.github.com/en/actions/reference/workflows-and-actions/contexts
- https://docs.github.com/en/rest/actions/workflow-runs
- Live Starlight pr-gate run 41656793060 referenced_workflows corroborates its
actual old reusable source pin; it does not qualify this new candidate.
33 changes: 33 additions & 0 deletions pr-gate/Review-threat-model-Codex-2026-11-03-v3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# pr-gate concurrency reconciliation, Codex, 3 November 2026, revision 3

Author: Codex. Reviewer: actual Claude GitHub workflow, follow-up comment
https://github.com/frankxai/agentic-ops/pull/439#issuecomment-6607435620.
State: refined source candidate; new exact-head follow-up and live reusable-source
qualification remain required. Earlier revisions and review limits are preserved.

Claude read all seven v2 packet files and confirmed earlier protected-path,
title-routing and source-pin repairs in the report-only scope. It identified a
medium availability defect: workflow-level cancellation happened before the
comment authorization condition, so an ineligible comment could cancel a report.
Different event groups could also overwrite same-head diagnostics out of order.

The caller now has no workflow concurrency. A read-only resolver in the pinned
reusable source obtains the actual PR before the report job. Only eligible,
resolved report jobs join one repository/PR group, with cancel-in-progress=false.
Every event type for that PR uses the same group. Main push completion is a no-op.
The report reloads current facts after it acquires its job slot; resolved identity
uses PR_GATE_EVENT_RESOLVED rather than attempting to override GITHUB_* variables.
Reports disclose observation time and run identity. This prevents overlapping
workflow reports; manual invocations outside that scheduler remain a limitation.

Repository identity comparison follows GitHub's case-insensitive semantics. New
tests exercise the actual resolver, actual inline source validator, resolved
identity handoff, pinned checkout refs and the workflow's concurrency contract.
They do not simulate GitHub's scheduler or prove a live reusable workflow context.
62 focused tests pass. Same-head facts can change immediately after collection;
diagnostic comments are snapshots and never authorize merge or production.

Remaining limits: app/workflow path does not prove immutable PR workflow content;
workflow changes still require the human gate. Conservative free-text severity
matching may block a clean bot comment. No authenticated maker-provider protocol
exists, so every report remains WAITING or BLOCKED. The gate stays report-only.
Loading
Loading