Architecture
A practical walkthrough of the public PatchPatrol review runtime, boundaries, and artifact output.
Architecture
This page documents the shipped public PatchPatrol runtime model for the GitLab artifact-first path.
Public path scope: this document describes current runtime behavior in the
ai-review runpipeline, plus how failures are surfaced.
What happens when ai-review run starts
The pipeline is shaped like a set of explicit 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.
- 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, 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 machine-readable structured payload.ai-review.mdis the operator-readable summary artifact.gl-code-quality-report.jsonis written when code-quality export is enabled in runtime config.- Optional GitLab summary note and inline discussions are written only when delivery is configured.
Trust Gate and Redaction
Before any provider call, PatchPatrol evaluates:
- Provider endpoint allowlist enforcement.
- Secret-like pattern redaction on review chunk content.
If trust checks fail, the run exits with trust-fail artifacts and does not continue provider review.
For non-mock providers, an empty AI_REVIEW_PROVIDER_ALLOWLIST_BASE_URLS is considered a hard failure.
That means provider review stops early (exit 11) unless an allowlist is explicitly configured.
See the Configuration reference for details and required defaults.
Review execution behavior
- The review phase builds prompts from bounded diff content and repository context.
- 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.
For exact command flags and environment variables, see:
Why the architecture is constrained this way
The default sequence is optimized for predictable, auditable review signal in CI:
- strict scope controls before remote calls,
- explicit boundary checks before provider interactions,
- artifact-first output for human verification,
- deterministic schema-validated payloads for downstream tooling.
This keeps the first deployment path lightweight while still making it clear where control points are.