Skip to content
Merged
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
72 changes: 72 additions & 0 deletions .github/workflows/cache-benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Trusted image cache benchmark
on:
workflow_dispatch:
workflow_call:
permissions:
contents: read
jobs:
benchmark:
runs-on: ubuntu-24.04
timeout-minutes: 10
env:
DOCKER_BUILD_RECORD_UPLOAD: 'false'
DOCKER_BUILD_SUMMARY: 'false'
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with: { persist-credentials: false }
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with: { node-version: '24.22.3', package-manager-cache: false }
- run: npm ci --ignore-scripts
- run: npm run build
- name: Measure ordinary build
shell: bash
run: |
cache_start=$(date +%s)
docker build --tag codexbot-benchmark:baseline .
echo "$(( $(date +%s) - cache_start ))" > "$RUNNER_TEMP/baseline-seconds"
docker image rm codexbot-benchmark:baseline
date +%s > "$RUNNER_TEMP/cold-start"
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
with:
name: codexbot-cache-cold
cleanup: false
version: v0.39.0
driver-opts: image=moby/buildkit@sha256:c5f8862f52499773af85bc07695b2379ef08e8002352b0df2c4864c91d78dabe
- uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
load: true
push: false
tags: codexbot-benchmark:cold
cache-to: type=gha,version=2,scope=codexbot-benchmark-${{ github.run_id }}-${{ github.run_attempt }},mode=min,timeout=90s
- name: Discard builder and loaded image before measuring a cache restore
shell: bash
run: |
echo "$(( $(date +%s) - $(cat "$RUNNER_TEMP/cold-start") ))" > "$RUNNER_TEMP/cold-seconds"
docker buildx rm codexbot-cache-cold
docker image rm codexbot-benchmark:cold
date +%s > "$RUNNER_TEMP/warm-start"
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
with:
name: codexbot-cache-warm
version: v0.39.0
driver-opts: image=moby/buildkit@sha256:c5f8862f52499773af85bc07695b2379ef08e8002352b0df2c4864c91d78dabe
- uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
load: true
push: false
tags: codexbot-benchmark:warm
cache-from: type=gha,version=2,scope=codexbot-benchmark-${{ github.run_id }}-${{ github.run_attempt }},timeout=90s
cache-to: type=gha,version=2,scope=codexbot-benchmark-${{ github.run_id }}-${{ github.run_attempt }},mode=min,timeout=90s
- name: Report measured timings
shell: bash
run: |
echo "$(( $(date +%s) - $(cat "$RUNNER_TEMP/warm-start") ))" > "$RUNNER_TEMP/warm-seconds"
node --input-type=module <<'JS'
import {readFileSync, appendFileSync} from 'node:fs';
const read = name => Number(readFileSync(`${process.env.RUNNER_TEMP}/${name}-seconds`, 'utf8'));
const baseline=read('baseline'), cold=read('cold'), warm=read('warm');
console.log(JSON.stringify({event:'cache_benchmark',baseline_seconds:baseline,cold_seconds:cold,warm_seconds:warm}));
appendFileSync(process.env.GITHUB_STEP_SUMMARY, `Baseline: ${baseline}s; cold cache: ${cold}s; restored cache: ${warm}s. Includes builder setup and load/export. Same-run builder-image reuse is optimistic; repeat on independent runners before enabling cache. No provider or credential access.\n`);
JS
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ name: CI
on:
push:
pull_request:
workflow_dispatch:
inputs:
cache_benchmark: { type: boolean, default: false }
permissions:
contents: read
jobs:
cache-benchmark:
if: ${{ github.event_name == 'workflow_dispatch' && inputs.cache_benchmark }}
uses: ./.github/workflows/cache-benchmark.yml
check:
runs-on: ubuntu-24.04
timeout-minutes: 10
Expand Down
77 changes: 73 additions & 4 deletions .github/workflows/review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ on:
credential_owner: { required: true, type: string }
installation_id: { required: true, type: string }
backend: { required: true, type: string }
credential_check_only: { required: false, type: boolean, default: false }
docker_cache: { required: false, type: boolean, default: false }
secrets:
CODEXBOT_VAULT_KEY: { required: false }
CODEXBOT_API_KEY: { required: false }
permissions: {}
jobs:
source:
Expand Down Expand Up @@ -43,6 +48,22 @@ jobs:
contents: read
id-token: write
steps:
- name: Verify Environment credential availability
shell: bash
run: |
node --input-type=module <<'JS'
const vault = Boolean(process.env.CODEXBOT_VAULT_KEY);
const api = Boolean(process.env.CODEXBOT_API_KEY);
if (vault === api) {
console.error(JSON.stringify({event: 'review_failed', stage: 'environment', code: vault ? 'ambiguous_environment_credentials' : 'missing_environment_credentials'}));
process.exitCode = 1;
} else {
console.log(JSON.stringify({event: 'credential_availability_verified', mode: vault ? 'chatgpt' : 'api-key'}));
}
JS
env:
CODEXBOT_VAULT_KEY: ${{ secrets.CODEXBOT_VAULT_KEY }}
CODEXBOT_API_KEY: ${{ secrets.CODEXBOT_API_KEY }}
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: ${{ needs.source.outputs.repository }}
Expand All @@ -51,23 +72,70 @@ jobs:
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '24.22.3'
package-manager-cache: false
- run: npm ci --ignore-scripts
- run: npm run build
- name: Build trusted review image
run: docker build --tag codexbot-review:local .
- name: Verify read-only OIDC and Environment diagnostic
if: ${{ inputs.credential_check_only }}
run: node dist/src/runner/main.js check
env:
CODEXBOT_BACKEND: ${{ inputs.backend }}
CODEXBOT_VAULT_KEY: ${{ secrets.CODEXBOT_VAULT_KEY }}
CODEXBOT_API_KEY: ${{ secrets.CODEXBOT_API_KEY }}
- name: Build trusted review image without cache overhead
if: ${{ !inputs.credential_check_only && !inputs.docker_cache }}
run: docker build --tag "codexbot-review:$TRUSTED_REV" .
env:
TRUSTED_REV: ${{ needs.source.outputs.ref }}
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
if: ${{ !inputs.credential_check_only && inputs.docker_cache }}
with:
version: v0.39.0
driver-opts: image=moby/buildkit@sha256:c5f8862f52499773af85bc07695b2379ef08e8002352b0df2c4864c91d78dabe
- name: Build trusted review image with scoped cache
if: ${{ !inputs.credential_check_only && inputs.docker_cache }}
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
file: Dockerfile
load: true
push: false
tags: codexbot-review:${{ needs.source.outputs.ref }}
cache-from: type=gha,version=2,scope=codexbot-${{ github.repository_id }}-${{ needs.source.outputs.ref }}-${{ hashFiles('Dockerfile', 'package.json', 'package-lock.json', '.dockerignore') }},timeout=10s
cache-to: type=gha,version=2,scope=codexbot-${{ github.repository_id }}-${{ needs.source.outputs.ref }}-${{ hashFiles('Dockerfile', 'package.json', 'package-lock.json', '.dockerignore') }},mode=min,timeout=10s,ignore-error=true
env:
DOCKER_BUILD_RECORD_UPLOAD: 'false'
DOCKER_BUILD_SUMMARY: 'false'
- id: image
name: Bind execution to the built image ID
if: ${{ !inputs.credential_check_only }}
shell: bash
run: |
node --input-type=module <<'JS'
import {execFileSync} from 'node:child_process';
import {appendFileSync} from 'node:fs';
const ref = process.env.TRUSTED_REV;
if (!/^[a-f0-9]{40}$/.test(ref)) throw new Error('Invalid trusted source revision');
const id = execFileSync('docker', ['image', 'inspect', `codexbot-review:${ref}`, '--format', '{{.Id}}'], {encoding:'utf8'}).trim();
if (!/^sha256:[a-f0-9]{64}$/.test(id)) throw new Error('Invalid built image identity');
appendFileSync(process.env.GITHUB_OUTPUT, `id=${id}\n`);
JS
env:
TRUSTED_REV: ${{ needs.source.outputs.ref }}
- name: Review exact commit in isolated container
if: ${{ !inputs.credential_check_only }}
run: node dist/src/runner/main.js review
env:
CODEXBOT_BACKEND: ${{ inputs.backend }}
CODEXBOT_REQUEST_ID: ${{ inputs.request_id }}
CODEXBOT_CREDENTIAL_OWNER: ${{ inputs.credential_owner }}
CODEXBOT_INSTALLATION_ID: ${{ inputs.installation_id }}
CODEXBOT_IMAGE: codexbot-review:local
CODEXBOT_IMAGE: ${{ steps.image.outputs.id }}
CODEXBOT_VAULT_KEY: ${{ secrets.CODEXBOT_VAULT_KEY }}
CODEXBOT_API_KEY: ${{ secrets.CODEXBOT_API_KEY }}
publish:
needs: [source, review]
if: ${{ needs.review.result == 'success' }}
if: ${{ always() && !inputs.credential_check_only && needs.source.result == 'success' && (needs.review.result == 'success' || needs.review.result == 'failure') }}
runs-on: ubuntu-24.04
timeout-minutes: 5
environment: codexbot-publish-${{ inputs.installation_id }}
Expand All @@ -90,3 +158,4 @@ jobs:
env:
CODEXBOT_BACKEND: ${{ inputs.backend }}
CODEXBOT_REQUEST_ID: ${{ inputs.request_id }}
CODEXBOT_REVIEW_JOB_SUCCEEDED: ${{ needs.review.result == 'success' }}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased — security remediation pass

- Explicitly forward only named Environment credential grants; add a credential-only availability diagnostic, safe runner/broker/OIDC failure codes and failed-job publication safeguards.
- Add migration 0003 with recoverable, App-owned progress comments, verified run status, failure metadata and bounded operator reconciliation. Existing sessions remain valid.
- Add opt-in source-scoped Buildx caching and a credential-free cache benchmark; execute review images by content ID. Keep cache off until measurements justify its cost.
- New setup triggers use @CBReview plus repository ID; document independent OpenAI connector settings without changing App identity or removing legacy parsing.

- Generate Cloudflare Env from the pinned Wrangler configuration before every build/typecheck. CI tests an independent source checkout without generated declarations.
- Resolve commit objects to tree SHAs; fetch essential changed files/instructions first. Separate complete diff, essential context and bounded supplementary coverage. Cache immutable trees/blobs only inside the authorized collection.
- Add migration 0002: durable webhook/outbox receipts, stable dispatch attempts, exact run-name reconciliation, quotas, publication leases/checkpoints and installation-bound sessions. Existing sessions require reconnect; pending legacy requests are invalidated. See docs/operations.md.
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
An Apache-2.0 GitHub App for Codex pull request reviews on repository-owned GitHub Actions runners. The Cloudflare Worker authenticates requests and publishes native reviews; it never runs Codex.

```text
@codexbot review --effort xhigh --merge
@CBReview review --effort xhigh --merge

Review authentication, authorization, migrations and compatibility.
```

Configure a trigger plus up to five aliases matching `@[A-Za-z0-9]{1,39}`. Matching ignores case. These are text commands and can notify unrelated GitHub users with the same name; choose distinctive aliases. Quoted examples and fenced commands do not trigger reviews. Model and reasoning effort are separate; omitted effort preserves Codex's default.

Set `bot.trigger: "@CBReview"` to use the example above. The legacy default `@codexbot` remains supported; new setup chooses `@CBReview<repository_id>`. Use a name without “codex” when another Codex integration is installed. CodexBot cannot control that independent connector; see [trigger isolation and rollout](docs/review-rollout.md).

## Status

**Pre-release implementation; no public hosted App has been deployed by this repository setup.** Unit/integration tests exercise signed webhooks, official OAuth contracts, OIDC, actual SQLite persistence, setup PR creation and GitHub publishing against mocked external APIs. The pinned official Codex binary is tested without credentials. A separate Docker check uses synthetic inference; it does not claim to have performed a real AI review. See [validation and live acceptance](docs/validation.md).
Expand Down Expand Up @@ -59,7 +61,9 @@ npm run cli -- connect-api-key --repository OWNER/REPO --backend https://YOUR-WO

The ChatGPT flow displays **Continue with ChatGPT** and opens an official authorization URL using a loopback callback. Manual `auth.json` export is unnecessary. API-key mode requires `credentials.mode: api-key` in trusted configuration. Do not keep both mode secrets in the Environment.

5. Review and merge the setup PR. Configure whitelist/merge policies and an optional custom handle in `.codexbot.yml`. Protect both the default branch and credential/publishing Environments. Comment using the handle from your setup PR. New setup chooses `@CodexBotReview<repository_id>` to reduce collisions; existing/manual `@codexbot` configurations remain supported.
5. Review and merge the setup PR. Configure whitelist/merge policies and an optional custom handle in `.codexbot.yml`. Protect both the default branch and credential/publishing Environments. Comment using the handle from your setup PR. New setup chooses `@CBReview<repository_id>` to reduce collisions; existing/manual `@codexbot` configurations remain supported.

Accepted requests receive one editable App-owned progress comment, separate from the native review. It shows verified commit/file counts, a request identifier, confirmed lifecycle/run status and the final native-review link. Temporary comment/API failures are reconciled without borrowing credentials or duplicating ambiguous POSTs. Image caching is opt-in pending measurement; [the rollout guide](docs/review-rollout.md) explains both controls.

### ChatGPT hosting restrictions

Expand Down
2 changes: 2 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Architecture

The [review reliability guide](review-rollout.md) documents migration 0003, named Environment grants, sanitized runner diagnostics, durable progress comments and optional Buildx caching. Progress writes are backend-only and validate App/request/PR ownership; the model receives no write capability. A failed upstream job permanently disables approval for its persisted result, including publication recovery.

The Cloudflare Worker ingests signed GitHub webhooks, verifies live authorization, maintains D1 metadata and publishes native reviews. Official Codex runs exclusively in the repository owner's ephemeral GitHub-hosted Linux Actions jobs. Independent installations choose their own App, Worker, D1 database and source release; no vendor backend or shared OpenAI credential exists.

```mermaid
Expand Down
2 changes: 2 additions & 0 deletions docs/authentication.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Authentication and credential ownership

Reusable callers must explicitly grant the two optional secret names with empty values; the called installation/actor Environment supplies the actual credential. No repository-key fallback or blanket inheritance is supported. [Credential diagnostics and rollout](review-rollout.md) include a no-inference availability check. Migration 0003 does not change encryption/session formats or require reconnecting.

## Official ChatGPT OAuth

CodexBot uses the documented OSS public-client flow, not a borrowed Codex client ID or an undocumented ChatGPT endpoint. [Registration/sign-in](https://developers.openai.com/siwc/token-sharing-open-source/sign-in), [sessions](https://developers.openai.com/siwc/token-sharing-open-source/profiles-and-sessions), [app-server](https://developers.openai.com/siwc/token-sharing-open-source/codex-app-server) and [deployment transfer](https://developers.openai.com/siwc/token-sharing-open-source/self-hosted-vms) define the contract.
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Patterns are full-string, case-insensitive RE2. `*` matches a sequence; `?` one

The first nonempty top-level line must begin with a configured trigger and `review`. Four-space/tab indents, quotations, inline examples and code fences do not invoke. Flags may occur in any order on that first line: `--merge`, `--effort LEVEL`, `--effort=LEVEL`, `--rerun`, and `--` for literal context. Duplicates, unknown flags and unclosed quotes are errors. Later lines are advisory context, never flags or authorization.

Aliases are textual commands, not guaranteed GitHub App mentions. A custom alias can notify an unrelated GitHub account with the same name. Existing @codexbot installations remain compatible. New automated setup uses @CodexBotReview followed by the numeric repository ID to reduce collisions; it remains editable. Prefer a distinctive repository-specific alias such as @CodexBotReview7319, confirm account collisions yourself, and document it for contributors. Changing a trigger never changes the App's publishing identity.
Aliases are textual commands, not guaranteed GitHub App mentions. A custom alias can notify an unrelated GitHub account with the same name. Existing @codexbot installations remain compatible. New automated setup uses @CBReview followed by the numeric repository ID to reduce collisions; it remains editable. Configure `bot: {trigger: "@CBReview", aliases: []}` for a short explicit alternative. Avoid adding the old name as an alias if the purpose is avoiding an independent connector. Changing a trigger never changes the App's publishing identity. See [trigger isolation](review-rollout.md).

Effort syntax recognizes none/minimal/low/medium/high/xhigh/max, but the selected model must actually advertise the requested value. Omission preserves Codex defaults. Catalog discovery does not prove account entitlement; completed inference is required. Never substitute an unsupported value or change billing modes.

Expand Down
2 changes: 2 additions & 0 deletions docs/deployment.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Deployment checklist

For existing deployments, follow [the coordinated immutable-pin upgrade](review-rollout.md) before deploying this revision. Apply additive migration 0003, update the caller's named Environment secret grants, and set its workflow pin and Worker TRUSTED_WORKFLOW to the same actual merged commit. Keep merge disabled. Report validation before the production change; a temporary mismatch fails closed.

This document is operator instructions, not evidence of an existing hosted deployment. Do not register, deploy, publish a release or use paid inference without your own authorization.

## GitHub App
Expand Down
2 changes: 2 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Development and local validation

For the current reliability changes, `node --import tsx --test tests/broker.test.ts tests/progress.test.ts tests/worker.test.ts tests/workflows.test.ts` runs the focused contracts. Full check also exercises them. [The rollout guide](review-rollout.md) describes provider-free credential and cache diagnostics; neither is a substitute for real inference acceptance.

Use Node 24. Dependency, Codex, Wrangler, Action and container versions are pinned. npm ci --ignore-scripts installs the packaged official native Codex binary without executing lifecycle scripts. The lockfile records integrity; the minimatch override avoids the audited transitive advisory and is checked by lint/tests.

```sh
Expand Down
Loading