Architecture
How PatchPatrol selects bounded source context in a customer-controlled runtime, uses a configured model endpoint, validates the response, and writes review artifacts.
PatchPatrol runs in a CI job or local process and calls the model endpoint configured for that run. You choose the runner and network environment.
On the GitLab artifact-first path, the configured GitLab runner prepares the repository and job environment. The operator selects the runner and configures its variables, permissions, and network access. PatchPatrol selects bounded source context, sends it to the configured model endpoint, validates the response, and writes Run Reports.
A customer-controlled model endpoint can stay inside infrastructure you manage, but the configured endpoint may still be remote. Configuring it does not make it PatchPatrol-operated.
Review flow and boundaries
| Boundary | Role in the review flow |
|---|---|
| GitLab | Makes repository, diff-ref, and merge-request context available to the configured runner. Optional feedback returns to GitLab only when that delivery path is enabled. |
| Customer-controlled runtime | Runs the PatchPatrol CLI or container with customer-selected configuration, network access, credentials, workspace, and output path. |
| PatchPatrol process | Resolves the diff plan, selects bounded source context, applies the pre-provider controls described below, and sends the selected review payload to the configured endpoint. |
| Configured model endpoint | Receives the selected payload and returns a model response. It can be Ollama or a self-hosted OpenAI-compatible endpoint inside customer-managed infrastructure, or a public or otherwise remote endpoint. |
| Response validation | PatchPatrol parses and validates the provider response, applies the documented fallback behavior when needed, and accepts only schema-valid report content. |
| Generated artifacts | PatchPatrol writes the validated result as ai-review.json, ai-review.md, and ai-review.html, with optional code-quality and GitLab feedback outputs when configured. |
Scope: the sections below document current behavior in the
ai-review runpipeline, including how failures are reported.
What happens when ai-review run starts
The command runs these stages:
- Read effective configuration from environment and command flags.
- Resolve a diff plan (
auto,mr,branch,staged,working-tree). - Build a bounded review scope:
- file include/exclude filtering,
- file-level and total-size guardrails,
- chunking and omission tracking.
- For GitLab MR runs, decide whether the provider can review an incremental delta since the prior PatchPatrol-reviewed head SHA.
- Run trust checks before any provider call.
- Run optional semantic precheck (only in
diff+semanticcontext mode). - Collect repository overview signals.
- Execute provider review and validate the structured output.
- Emit artifacts (
ai-review.json,ai-review.md,ai-review.html, optionalcode_qualityoutput). - Optionally run GitLab MR feedback, depending on
AI_REVIEW_FEEDBACK_MODEand environment.
Input and Output Boundaries
Inputs
- Working tree/diff data from the selected git context.
- Run configuration and runtime limits from flags/environment.
- Optional repository overview evidence (file structure + detected tooling signals).
- Optional local semantic diagnostics when
AI_REVIEW_CONTEXT_MODE=diff+semantic.
Processing boundaries
- Diff scope is bounded by fail-fast limits before provider execution.
- Review inputs are filtered into bounded chunks before provider review.
- If provider output is invalid for schema, PatchPatrol retries once and then emits an explicit fallback report.
Outputs
ai-review.jsonis the canonical machine-readable Run Report for one execution.ai-review.mdis the operator-readable Markdown Run Report.ai-review.htmlis the printable HTML Run Report.gl-code-quality-report.jsonis written when code-quality export is enabled in runtime config.- The optional persistent GitLab Review Summary and separate inline discussions are written only when delivery is configured.
Trust Gate
Before any provider call, PatchPatrol evaluates the configured Trust Gate controls. A failed gate stops provider review and records the failure state in the generated artifacts.
Use Security & Privacy for the exact data-handling stages and the Configuration reference for endpoint policy settings and defaults.
Review execution behavior
- The review phase builds prompts from bounded diff content and repository context.
- In GitLab MR incremental mode, the provider can receive only the new delta
since the prior PatchPatrol-reviewed head SHA. PatchPatrol still keeps full MR
diff refs for inline eligibility and records the decision in
meta.incremental_review. - Prompts may include bounded supporting context under
AI_REVIEW_MAX_SUPPORTING_CONTEXT_BYTES. When present, that context is packed in priority order: matched repo-local review rules, deterministic preflight review hints, chunk-local supporting code evidence, relevant semantic diagnostics, and repository overview. - Deterministic preflight hints can highlight duplicate added code-like text, dependency additions, risky import additions, and missing test-counterpart signals before provider review. They are prompt evidence only: the provider must verify the signal against diff/context evidence before reporting a finding, and hints do not become automatic findings or fail gates.
- Review prompts may annotate added and context lines with prompt-only
L<number>:labels to help providers anchor findings to new/right-side lines. Finalline_startandline_endartifact fields remain normal integer file line numbers; the prompt labels are not persisted. - The default review-call output mode remains JSON-object/JSON compatible.
- When
AI_REVIEW_STRUCTURED_OUTPUT_MODE=json_schemaorautois used with an OpenAI-compatible provider, PatchPatrol can request strict JSON-schema output for review calls and fall back to JSON-object mode if the endpoint rejects schema mode. - On invalid provider output, PatchPatrol attempts a fallback validation strategy.
- All report content is still validated against the shipped artifacts schema before writing.
- Usage and runtime metadata are attached to the JSON report for transparency.
- Structured-output mode decisions are recorded only as compact
meta.limits.structured_output_*metadata; raw prompts and provider request payloads are not persisted in artifacts. - Preflight hint metadata is also compact; raw prompt bodies, raw hint evidence, and provider chain-of-thought are not available in artifacts.
For exact command flags and environment variables, see:
Why these boundaries are explicit
The sequence records configured scope limits, the Trust Gate result, provider response validation, and the JSON, Markdown, and HTML Run Reports. Operators can inspect those control points before enabling optional GitLab feedback.
Evidence and next steps
- Use Security & Privacy for credential, redaction, provider-processing, and retention responsibilities across these boundaries.
- Use the Configuration reference for exact provider, endpoint, scope, and artifact settings.
- Review the trust and rollout settings in Policy controls.
- Follow the Admin Quickstart for the GitLab artifact-first setup.
- Inspect First review output to see how the generated Run Reports are used.
Visit the PatchPatrol product website
for the short product overview.
Discuss a private GitLab review pilot
to review these boundaries in your environment.