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

## Unreleased — final context completion

- Add metadata-only optional existence probes without weakening mandatory file evidence, immutable verification or existing request/API budgets. Verified absent candidates no longer invalidate otherwise complete context; infrastructure/verification errors stay distinct.
- Report the exact trusted-host/model completion conditions when analysis cannot be accepted. Preserve findings and fail closed when on-demand essential evidence becomes unavailable.
- Record required on-demand failure reasons and close/drain lookups before the final result check, preventing late context mutation after submission. No inference, context-budget or approval-policy relaxation.

## Unreleased — inference diagnostics

- Preserve correlated per-request primary and cleanup errors, bounded HTTP/SSE metadata and allowlisted transport causes. A consumer closing after a completed SSE response is no longer mislabeled as a provider failure; successful retries clear stale failures.
Expand Down
8 changes: 7 additions & 1 deletion 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 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.
A separate trusted host Unix socket at `/run/proxy/context.sock` accepts POST `/file` for required contents or `/probe` for optional existence, with JSON containing `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 `/file` evidence makes the result incomplete and fails the review job. A `/probe` returns only `{exists: true|false}` from verified immutable tree metadata and never materializes source or satisfies content evidence. Verified absence is neutral; API/tree verification failures are errors and remain fail-closed, not false absence.

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 Down Expand Up @@ -35,3 +35,9 @@ The publisher independently verifies PNG evidence within 32 additional Git calls
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.


Final completion is checked again by the trusted host after the isolated engine returns and the context service is closed/drained. A missing file requested through `/file` remains essential missing evidence even if the model returns complete findings or has inspected every attached PNG. The host preserves validated findings in the non-approving submission, fails the review job and logs only completion booleans/result enum plus an approved context failure code. On-demand failures enter required coverage diagnostics rather than being labeled supplementary omissions. Paths, model text and credentials are not diagnostic fields. Neither a later successful lookup nor a complete model result clears a previous essential-evidence failure.


Optional discovery never uses a model-supplied required/optional flag. The existing `/file` endpoint stays mandatory and rejects extra fields such as `required: false`; the separate `/probe` operation supplies existence only, not readable or verified contents. A probe can report an object exists even when a later content read rejects its Git type, size or blob hash. A successful probe cannot waive initial changed-file/instruction/dependency requirements or clear a previous required failure. Both operations share the unchanged 24-request and GitHub API budgets. Exhausted optional probes fail without invalidating otherwise complete evidence; a denied required fetch remains fatal. There is no extra inference pass or model/budget change. Host checks do not claim to prove exhaustive model reasoning about every possible dependency.
2 changes: 1 addition & 1 deletion docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ See [operations](operations.md), [security](security.md) and [acceptance](accept

## Adaptive context and browser management

The collector also writes a supplementary regular-file index (12 directories / 5,000 paths, no recursive tree dump). Explicit Python relative imports and Rust sibling modules join JS/TS dependencies; nearby Python/Go/Java test names are considered. A separate host Unix socket accepts only bounded base/head path requests for this authorized immutable repository. It never forwards arbitrary URLs, executes project code or exposes credentials. At most 24 requests share the existing byte/blob/API limits and per-SHA cache. Requested files that cannot be obtained invalidate completeness. The reviewer mount stays read-only and network=none. The read token now lasts through bounded context exploration; shutdown cancels/drains lookups and revokes it before temporary source cleanup. Failed token cleanup fails the review job.
The collector also writes a supplementary regular-file index (12 directories / 5,000 paths, no recursive tree dump). Explicit Python relative imports and Rust sibling modules join JS/TS dependencies; nearby Python/Go/Java test names are considered. A separate host Unix socket accepts bounded base/head `/file` requests for required contents and `/probe` requests for optional existence for this authorized immutable repository. It never forwards arbitrary URLs, executes project code or exposes credentials. At most 24 requests share the existing byte/blob/API limits and per-SHA cache. Required files that cannot be obtained invalidate completeness. A metadata-only probe may establish absence without fetching source; it cannot waive required evidence. Probe API/tree failures remain fail-closed rather than being mislabeled as missing paths. The reviewer mount stays read-only and network=none. The read token now lasts through bounded context exploration; shutdown cancels/drains lookups and revokes it before temporary source cleanup. Failed token cleanup fails the review job.

The system prompt asks for introduced, evidence-backed bugs traced through unchanged callers and dependencies, with trusted default-branch guidance subordinate to execution/output safety. Additional comment context is advisory. The model/effort CLI precedence is unchanged; a generated pinned-native catalog powers dashboard validation and distinguishes catalog membership from account entitlement.

Expand Down
20 changes: 18 additions & 2 deletions src/core/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ExecutionError, executionFailure, proxyRequestDiagnostic, type ProxyReq
export const REVIEW_STAGES = ['environment','prepare','context','credentials','analyzing','result','publish','release'] as const;
export const FAILURE_CODES = new Set(['missing_environment_credentials','ambiguous_environment_credentials','credential_owner_mismatch','missing_read_token',
'api_key_missing_or_ambiguous_credentials','vault_key_missing_or_ambiguous_credentials','invalid_envelope','invalid_vault_key','invalid_saved_session',
'context_api_budget','context_collection_timeout','context_diff_size_limit','context_text_patch_truncated','context_unsupported_binary','context_binary_unverifiable','context_binary_size_limit','context_non_text_source','context_missing_dependency','context_file_size_limit','context_byte_budget','context_required_evidence_unavailable','required_file_missing_or_special','blob_integrity_failure','required_tree_unverifiable','review_incomplete','review_context_incomplete','review_output_invalid','read_token_cleanup_failed',
'context_path_missing','context_special_object','context_github_api_failed','context_lookup_rejected','context_api_budget','context_collection_timeout','context_diff_size_limit','context_text_patch_truncated','context_unsupported_binary','context_binary_unverifiable','context_binary_size_limit','context_non_text_source','context_missing_dependency','context_file_size_limit','context_byte_budget','context_required_evidence_unavailable','required_file_missing_or_special','blob_integrity_failure','required_tree_unverifiable','review_incomplete','review_context_incomplete','review_output_invalid','read_token_cleanup_failed',
'oauth_refresh_too_early','oauth_refresh_window_unavailable',
'session_too_short_reconnect_required','review_image_missing','isolated_review_failed','proxy_start_failed','docker_unavailable','docker_cleanup_failed_check_runner',
'oauth_grant_invalid_reconnect_required','chatgpt_plan_usage_permission_missing','oauth_token_endpoint_failed','oauth_token_exchange_uncertain_reconnect_required',
Expand All @@ -30,10 +30,26 @@ github_actions_oidc_unavailable invalid_oidc_endpoint github_oidc_request_failed
export class BrokerError extends AppError {
constructor(public readonly operation: string, status: number, public readonly remoteCode: string | null) { super(`broker_${operation}_failed`, status); }
}
export function diagnostic(error: unknown, stage: string): { event: string; stage: string; code: string; status?: number; broker_code?: string; execution?: ExecutionFailure; proxy_failure?: ExecutionFailure; proxy_cleanup?: ExecutionFailure; proxy_request?: Omit<ProxyRequestDiagnostic,'primary'|'cleanup'> } {
export interface ReviewCompletion {
context_complete: boolean; diff_complete: boolean; required_context_complete: boolean;
output_complete: boolean; output_result: 'clean' | 'findings' | 'inconclusive'; quarantined: boolean; output_truncated: boolean;
context_failure_code?: string;
}
/** Only fixed completion conditions leave the trusted runner, never paths or model text. */
export class ReviewCompletionError extends AppError {
readonly completion: ReviewCompletion;
constructor(value: ReviewCompletion) {
super('review_incomplete');
this.completion={context_complete:value.context_complete===true,diff_complete:value.diff_complete===true,required_context_complete:value.required_context_complete===true,
output_complete:value.output_complete===true,output_result:value.output_result==='clean'?'clean':value.output_result==='findings'?'findings':'inconclusive',quarantined:value.quarantined===true,output_truncated:value.output_truncated===true,
...(typeof value.context_failure_code==='string'&&FAILURE_CODES.has(value.context_failure_code)?{context_failure_code:value.context_failure_code}:{})};
}
}
export function diagnostic(error: unknown, stage: string): { event: string; stage: string; code: string; status?: number; broker_code?: string; execution?: ExecutionFailure; proxy_failure?: ExecutionFailure; proxy_cleanup?: ExecutionFailure; proxy_request?: Omit<ProxyRequestDiagnostic,'primary'|'cleanup'>; completion?: ReviewCompletion } {
const result: ReturnType<typeof diagnostic> = {
event: 'review_failed', stage: REVIEW_STAGES.includes(stage as typeof REVIEW_STAGES[number]) ? stage : 'environment', code: 'external_or_execution_failure'
};
if(error instanceof ReviewCompletionError){result.code=error.code;result.completion=error.completion;return result;}
if (error instanceof ExecutionError) {
result.code = error.code;
result.execution = executionFailure(error.detail)!;
Expand Down
7 changes: 4 additions & 3 deletions src/runner/context-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ export async function contextServer(socket: string, lookup: ContextLookup, abort
const pending = new Set<Promise<void>>();
const server = createServer((request, response) => { const task = (async () => {
try {
requireCondition(request.method === 'POST' && request.url === '/file', 'context_request_denied');
requireCondition(request.method === 'POST' && (request.url === '/file'||request.url === '/probe'), 'context_request_denied');
let body = '';
for await (const chunk of request) { body += String(chunk); requireCondition(Buffer.byteLength(body) <= 1024, 'context_request_too_large'); }
const input = record(JSON.parse(body) as unknown);
requireCondition(Object.keys(input).length === 2 && (input.snapshot === 'base' || input.snapshot === 'head') && typeof input.path === 'string', 'context_request_denied');
const available = await lookup(input.snapshot, input.path);
response.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' }); response.end(JSON.stringify({ available }));
const probe=request.url==='/probe';
const available = probe ? await lookup(input.snapshot,input.path,'probe') : await lookup(input.snapshot,input.path);
response.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' }); response.end(JSON.stringify(probe?{exists:available}:{available}));
} catch { response.writeHead(400, { 'Content-Type': 'application/json' }); response.end('{"error":"context_lookup_unavailable"}'); }
})().catch(() => { response.destroy(); }).finally(() => { pending.delete(task); }); pending.add(task); });
server.requestTimeout = 20_000; server.headersTimeout = 5000; server.maxConnections = 2;
Expand Down
Loading