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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Security and behavior changes

## Unreleased — binary/large-PR context hotfix

- Verify PNG evidence separately from textual patches and supply immutable base/head images through official Codex localImage inputs. Require image-capable models and actual image transport; independently verify publication evidence. Image findings appear in the summary without invented inline locations. Unsupported formats and incomplete visual coverage remain non-approving.
- Raise bounded context capacity to 768 calls, 16 MB text, 512 KB per text file and 6 MB diff; retain immutable caches, safe Git types, deadlines and precise non-approving budget diagnostics.
- Allow explicit `unlimited` rolling-day review quotas without disabling authorization, concurrency, cooldown or idempotency.
- Temporarily close the deployment merge gate for the coordinated runner upgrade.

## 0.1.0-beta.2

- Treat GitHub required reviews as qualifying App/user approvals rather than additional humans; retain explicit Human-in-the-Loop policy and native GitHub enforcement, including last-push/CODEOWNER rules.
Expand Down
16 changes: 14 additions & 2 deletions docs/adaptive-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The existing immutable collection and isolated Codex execution remain in place.

The collector writes `/workspace/file-index.json`: at most 12 nonrecursive directory walks and 5,000 regular-file paths. A partial supplementary index does not invalidate a small PR. It does not imply exhaustive semantic coverage. No full recursive tree or unrelated blob download is required.

A separate trusted host Unix socket at `/run/proxy/context.sock` accepts only POST `/file` JSON with `snapshot: base|head` and a relative `path`. Successful retrieval materializes a verified file under the existing read-only reviewer mount. Paths, immutable commit/tree/blob identity, object modes, UTF-8, size and Git blob SHA are validated by the same collector. It cannot request another repository/ref, fetch URLs, follow symlinks or execute commands. There are at most 24 lookups, sharing the existing 100-call/3-MB-source/200-KB-file limits and SHA cache. Missing explicitly requested evidence makes the result incomplete and fails the review job. Optional omissions that were never needed do not.
A separate trusted host Unix socket at `/run/proxy/context.sock` accepts only POST `/file` JSON with `snapshot: base|head` and a relative `path`. Successful retrieval materializes a verified file under the existing read-only reviewer mount. Paths, immutable commit/tree/blob identity, object modes, UTF-8, size and Git blob SHA are validated by the same collector. It cannot request another repository/ref, fetch URLs, follow symlinks or execute commands. There are at most 24 lookups, sharing the 768-call/16-MB-source/512-KB-file limits and SHA cache. Missing explicitly requested evidence makes the result incomplete and fails the review job. Optional omissions that were never needed do not.

The GitHub read token remains on the trusted host through bounded exploration, rather than being revoked before inference. It is never mounted into the reviewer or credential proxy. On completion/failure, the host aborts/drains outstanding lookups, closes the context service, revokes the token and removes temporary source. Token cleanup failure fails the review job; it does not authorize approval. The separate publisher still uses the job conclusion and exact commit to decide whether a safe COMMENT is appropriate.

Expand All @@ -14,7 +14,7 @@ Human-readable summaries distinguish clean completion, advisory findings, change

Validation: immutable lookup/path/type/budget tests, small PR in a 1,200-file repository, native Codex/Docker reads of exact diff/base/head/trusted instructions/unchanged caller/hostile-text hashes, denied writes/network/credentials and full severity/confidence/completeness summary checks. Scripted Responses exercise real tools and sandbox behavior, not real AI recognition or prompt-quality improvement. Live old/revised-prompt comparison on identical clean/buggy/security/cross-file fixtures requires separate owner authorization; no paid or ChatGPT inference is part of CI.

Runner changes require coordinated Worker/caller pins to the actual merged source revision. Never guess a merge SHA or use a branch/tag. Keep production merge disabled.
Runner changes require coordinated Worker/caller pins to the actual merged source revision. Never guess a merge SHA or use a branch/tag. Close the production merge gate for the coordinated upgrade, then restore it only after verifying matching Worker/caller pins.

## Prompt evaluation fixtures (opt-in live, no default inference)

Expand All @@ -23,3 +23,15 @@ Runner changes require coordinated Worker/caller pins to the actual merged sourc
The existing guarded provider acceptance supports `--case clean|buggy|security|multi-file`, `--label baseline|revised` and optional `--report-file` in an owner-protected local directory. It records only completeness, finding count, expected-line match, label/model/effort and the resolved immutable local image ID. It never stores raw model text or credentials. Failure still exits nonzero. Build the baseline and revised images from their reviewed source revisions; hold Codex version/model/effort/fixture constant and compare all four cases. Use the credential-file, deployment authorization, explicit `--allow-live-oauth` or `--allow-paid-api` and 1–3 request budget controls already documented in acceptance.md. API output remains capped. Browser-managed sessions must instead use the authorized repository workflow; do not export them to a credential file.

No live A/B run has been authorized or executed in this engineering pass. Keep quality/entitlement conclusions pending until owner-authorized acceptance; local fixture scores and scripted Docker responses are not model-quality evidence.

## Large PRs and binary coverage

The exact base-to-head aggregate diff covers all PR commits together. The collector does not promise per-intermediate-commit analysis. Up to 200 changed files, 6 MB of serialized diff, 16 MB of materialized text, 512 KB per text file, 768 GitHub calls and 120 seconds of initial collection are supported. Individual API calls time out after 15 seconds. Commit/tree/blob caches are local to this tenant and review; identical blobs are fetched once. Changed files and trusted AGENTS.md precede optional context. On-demand requests share the remaining byte/call budget. Precise failure codes and non-approving summaries explain exhausted budgets.

Missing patches are never assumed binary merely from extensions. Supported PNGs require exact immutable tree paths, regular non-executable blobs, verified Git blob SHA/size and PNG signature/chunk framing through IEND without trailing payload. Both base/head versions are verified as applicable to addition, modification, deletion and rename. Binary reads are bounded to 2 MB/file and 8 MB total unique content. The trusted collector never decompresses or renders images, and binary bytes are not installed as UTF-8 source. It materializes verified base/head PNGs separately under `/workspace/media`. The engine supplies official App Server `localImage` inputs with immutable path/side labels, deduplicated by blob SHA (at most 16 unique images). The selected model must advertise image input. The credential proxy requires the expected number of actual base64 image inputs on each inference request and denies remote image URLs, uploads, audio/video and generic file inputs. Missing or rejected images cannot produce an approval. Image text is untrusted data, never instructions. Unknown formats (including audio, executables, archives and extension spoofing), missing/truncated text and unverifiable essential files remain fail-closed.

The publisher independently verifies PNG evidence within 32 additional Git calls. A complete text-and-image analysis uses the ordinary confidence/verdict policy; unavailable visual evidence remains incomplete and cannot approve or merge. Image findings use `line: null` and appear in the overall review, since GitHub cannot anchor inline comments to image pixels. Text findings still require actual changed lines.

The pinned Codex 0.169.0 App Server supports `localImage`; its current adapter has no general local-file input. [Official SIWC limitations](https://developers.openai.com/siwc/token-sharing-open-source/preview-limitations) allow model-supported images/files on Responses, but exclude audio/video input, transcription and Files API uploads. This implementation supports verified PNG images, not every binary format. It does not execute, unpack, transcribe or silently skip EXE/archive/audio/PDF files. Those changes require a supported explicit inspection path before approval. No private ChatGPT endpoints or paid fallback are used.

The Docker acceptance uses the actual pinned Codex binary to prove PNG conversion, transport, tool inspection and isolation against scripted Responses. It is not proof of real-model visual understanding; no new real-provider inference is part of this hotfix validation.
4 changes: 2 additions & 2 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ sequenceDiagram

## Required-first immutable context

Each immutable commit is resolved through Git Commits to its tree SHA. Nonrecursive tree requests walk only needed directories; trees and verified Git blobs are cached by SHA within that authorized collection. There is no cross-tenant cache or full recursive repository download. Changed base/head content (including rename/delete locations) and applicable default-branch AGENTS.md files precede root manifests/README, nearby tests and up to 24 essential direct literal JS/TS local dependencies across base/head (including new imports). Nonrelative/dynamic resolver semantics are not exhaustively reconstructed; model completeness must reflect remaining uncertainty.
Each immutable commit is resolved through Git Commits to its tree SHA. Nonrecursive tree requests walk only needed directories; trees and verified Git blobs are cached by SHA within that authorized collection. There is no cross-tenant cache or full recursive repository download. Changed base/head content (including rename/delete locations) and applicable default-branch AGENTS.md files precede root manifests/README, nearby tests and up to 256 essential direct literal JS/TS local dependencies across base/head (including new imports). Nonrelative/dynamic resolver semantics are not exhaustively reconstructed; model completeness must reflect remaining uncertainty.

The manifest distinguishes `diffComplete`, `requiredContextComplete` and supplementary selected/omitted coverage. Approval needs both required signals and complete model analysis. Unrelated omitted files do not make a small PR incomplete. Missing/truncated/binary/special/oversized essential evidence does. Limits: 200 changed files, 200 KB per blob, 3 MB source plus a separate 3 MB diff budget and 100 collector API calls including a final exact-head/base recheck. UTF-8, paths, Git object types, blob sizes and Git blob hashes are verified. No checkout/hooks/project installation occurs. Tests in the reviewed repository are inspected, never executed.
The manifest distinguishes `diffComplete`, `requiredContextComplete` and supplementary selected/omitted coverage. Approval needs both required signals and complete model analysis. Unrelated omitted files do not make a small PR incomplete. Missing/truncated/special/oversized essential text or unsupported binaries do. Verified base/head PNGs are supplied as official localImage inputs to an image-capable model. The proxy verifies actual image inputs; incomplete visual analysis remains non-approving. Image findings use a null line and appear in the summary, while text findings still require actual changed lines. Unsupported binaries remain fail-closed. Limits: 200 changed files, 512 KB per text blob, 16 MB source, 6 MB diff, 768 collector API calls and 120-second initial collection, including a final exact-head/base recheck. UTF-8, paths, Git object types, blob sizes and Git blob hashes are verified. No checkout/hooks/project installation occurs. Tests in the reviewed repository are inspected, never executed.

## Isolated inference

Expand Down
12 changes: 12 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,15 @@ The incoming PR-event actor still needs review authorization under `authorizatio
The protected runner Environment, encryption AAD, session lease and all user quotas bind to the consenting owner, installation and repository. Contributions cannot spread usage across actor IDs or select another user's Environment. Owner credentials are never returned to contributors or placed in the model container. Manual commands always use the command author's own connection, even when unattended assignment is enabled.

Revoking/disconnecting consent, replacing the connection, changing the configured owner/mode or losing administrator authority stops new delegated execution and privileged publication. Refresh and publication lease SQL fence the exact consent generation, so reauthorizing the same owner cannot revive an old merge intent. Already started inference may have consumed usage; revocation does not undo it. Configure `automatic_reviewer: null` through a reviewed PR to stop assignment; disconnect the owner connection to revoke its stored grant. No CLI process is needed after provisioning.

## Unlimited review quotas

Each rolling-day quota (`quotas.user_per_day`, `repository_per_day`, `installation_per_day`, `reruns_per_day`) accepts a positive integer or the exact string `unlimited`. Defaults remain capped. Only protected default-branch policy can opt in; configuring one repository does not alter another repository’s policy. Counts remain scoped as documented and are not reset; installation/user counts include all their repositories. Concurrency, cooldown, authorization, explicit rerun/idempotency, execution budgets and provider allowance still apply. An unlimited review quota is not unlimited ChatGPT usage and never enables paid API fallback.

```yaml
quotas:
user_per_day: unlimited
repository_per_day: unlimited
installation_per_day: unlimited
reruns_per_day: unlimited
```
41 changes: 41 additions & 0 deletions src/core/binary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { posix } from 'node:path';
import { requireCondition } from './errors.js';
import type { ChangedFile } from './review.js';
import type { gitSource } from './git-source.js';

export interface BinaryChange { filename:string; status:string; format:string; inspection:'requires-model'; snapshots:{side:'base'|'head';path:string;sha:string;bytes:number}[] }
export const MAX_BINARY_BYTES=8_000_000, MAX_BINARY_FILE_BYTES=2_000_000;
/** Format framing only: no decompression, rendering, execution or visual-review claim. */
function imageFormat(bytes:Buffer):string|null {
if(bytes.subarray(0,8).equals(Buffer.from([137,80,78,71,13,10,26,10]))){
let offset=8,chunks=0,idat=false;
while(offset+12<=bytes.length&&++chunks<=4096){
const size=bytes.readUInt32BE(offset),kind=bytes.toString('ascii',offset+4,offset+8);if(size>bytes.length-offset-12)return null;
if(chunks===1&&(kind!=='IHDR'||size!==13||!bytes.readUInt32BE(offset+8)||!bytes.readUInt32BE(offset+12)||bytes.readUInt32BE(offset+8)*bytes.readUInt32BE(offset+12)>16_000_000))return null;
if(kind==='IDAT')idat=true;offset+=size+12;
if(kind==='IEND')return size===0&&offset===bytes.length&&idat?'png':null;
}return null;
}
return null;
}
export async function binaryChange(file:ChangedFile,base:string,head:string,source:ReturnType<typeof gitSource>,budget:{bytes:number;shas:Set<string>}):Promise<BinaryChange> {
requireCondition(!file.patch,'context_text_patch_truncated');
const sides:('base'|'head')[]=file.status==='added'?['head']:file.status==='removed'?['base']:['base','head'];
requireCondition(['added','removed','modified','renamed'].includes(file.status),'context_unsupported_binary');
const snapshots:BinaryChange['snapshots']=[];let format='';
for(const side of sides){
const path=side==='base'?(file.previous_filename??file.filename):file.filename;
const entry=await source.find(side==='base'?base:head,path);
requireCondition(entry?.type==='blob'&&entry.mode==='100644'&&entry.sha,'context_binary_unverifiable');
requireCondition(entry.size!==undefined&&entry.size<=MAX_BINARY_FILE_BYTES,'context_binary_size_limit');
const bytes=await source.read(entry,MAX_BINARY_FILE_BYTES);
if(!budget.shas.has(entry.sha)){budget.shas.add(entry.sha);budget.bytes+=bytes.length;}
requireCondition(budget.bytes<=MAX_BINARY_BYTES,'context_binary_size_limit');
const kind=imageFormat(bytes),extension=posix.extname(path).toLowerCase();
requireCondition(kind==='png'&&extension==='.png','context_unsupported_binary');
format=kind;snapshots.push({side,path,sha:entry.sha,bytes:bytes.length});
}
return {filename:file.filename,status:file.status,format,inspection:'requires-model',snapshots};
}

export function binaryLocations(files:BinaryChange[]):Set<string>{return new Set(files.flatMap(file=>file.snapshots.map(snapshot=>`${snapshot.side==='base'?'LEFT':'RIGHT'}:${file.filename}`)));}
5 changes: 3 additions & 2 deletions src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Effort } from './command.js';
import { requireCondition } from './errors.js';
import { validatePolicy } from './policy.js';

export type ReviewQuota = number | 'unlimited';
export interface Policy { whitelist: string; blacklist: string }
export interface Config {
version: 1;
Expand All @@ -13,7 +14,7 @@ export interface Config {
review: { enabled: boolean; auto_review: boolean; auto_approve: boolean; request_changes: boolean; model: string | null; effort: Effort | null; blocking_confidence: number; advisory_confidence: number };
merge: { enabled: boolean; auto_merge_on_approval: boolean; method: 'squash' | 'merge' | 'rebase'; authorization: Policy; minimum_human_approvals: number; guard_check: string };
credentials: { mode: 'chatgpt' | 'api-key'; automatic_reviewer: string | null };
quotas: { user_per_day: number; repository_per_day: number; installation_per_day: number; concurrent_repository: number; concurrent_installation: number; cooldown_seconds: number; reruns_per_day: number };
quotas: { user_per_day: ReviewQuota; repository_per_day: ReviewQuota; installation_per_day: ReviewQuota; concurrent_repository: number; concurrent_installation: number; cooldown_seconds: number; reruns_per_day: ReviewQuota };
}
export const DEFAULT_CONFIG: Config = {
version: 1, bot: { trigger: '@codexbot', aliases: [] }, authorization: { whitelist: '', blacklist: '*' },
Expand All @@ -38,7 +39,7 @@ const schema = { type: 'object', additionalProperties: false, properties: {
minimum_human_approvals: { type: 'integer', minimum: 0, maximum: 6 }, guard_check: { type: 'string', minLength: 1, maxLength: 80, pattern: '^[A-Za-z0-9 _.-]+$' }
} },
credentials: { type: 'object', additionalProperties: false, properties: { mode: { enum: ['chatgpt', 'api-key'] }, automatic_reviewer: {type:['string','null'],pattern:'^[A-Za-z0-9][A-Za-z0-9-]{0,38}$',maxLength:39} } },
quotas: { type: 'object', additionalProperties: false, properties: Object.fromEntries(Object.keys(DEFAULT_CONFIG.quotas).map(key => [key, { type: 'integer', minimum: key === 'cooldown_seconds' ? 0 : 1, maximum: key === 'cooldown_seconds' ? 86400 : key.startsWith('concurrent') ? 10 : 1000 }])) }
quotas: { type: 'object', additionalProperties: false, properties: Object.fromEntries(Object.keys(DEFAULT_CONFIG.quotas).map(key => [key, key.endsWith('_per_day') ? {anyOf:[{type:'integer',minimum:1,maximum:1000},{const:'unlimited'}]} : { type: 'integer', minimum: key === 'cooldown_seconds' ? 0 : 1, maximum: key === 'cooldown_seconds' ? 86400 : key.startsWith('concurrent') ? 10 : 1000 }])) }
} };
const validate = new Ajv({ strict: true, allowUnionTypes: true }).compile<Partial<Config>>(schema);

Expand Down
Loading