Skip to main content

Module patchset

Module patchset 

Source
Expand description

AI PatchSet Definition

A PatchSet represents a proposed set of code changes (diffs) generated by an agent during a Run. It is the atomic unit of code modification in the AI workflow — every change the agent wants to make to the repository is packaged as a PatchSet.

§Relationships

Run ──patchsets──▶ [PatchSet₀, PatchSet₁, ...]
                       │
                       └──run──▶ Run  (back-reference)
  • Run (bidirectional): Run.patchsets holds the forward reference (chronological generation history), PatchSet.run is the back-reference.

§Lifecycle

  ┌──────────┐   agent produces diff   ┌──────────┐
  │ (created)│ ───────────────────────▶ │ Proposed │
  └──────────┘                          └────┬─────┘
                                             │
                         ┌───────────────────┼───────────────────┐
                         │ validation/review  │                   │
                         ▼ passes             ▼ fails             │
                    ┌─────────┐          ┌──────────┐            │
                    │ Applied │          │ Rejected │            │
                    └─────────┘          └────┬─────┘            │
                                              │                  │
                                              ▼                  │
                                 agent generates new PatchSet     │
                                 appended to Run.patchsets        │
  1. Creation: The orchestrator calls PatchSet::new(), which sets apply_status to Proposed. At this point artifact is None and touched is empty.
  2. Diff generation: The agent produces a diff against commit (the baseline Git commit). It sets artifact to point to the stored diff content, populates touched with a file-level summary, writes a rationale, and records the format.
  3. Review / validation: The orchestrator or a human reviewer inspects the PatchSet. Automated checks (tests, linting) may run.
  4. Applied: If the diff passes, the orchestrator commits it to the repository and transitions apply_status to Applied.
  5. Rejected: If the diff fails validation or is rejected by a reviewer, apply_status becomes Rejected. The agent may then generate a new PatchSet appended to Run.patchsets.

§Ordering

PatchSet ordering is determined by position in Run.patchsets. If a PatchSet is rejected, the agent generates a new PatchSet and appends it to the Vec. The last entry is always the most recent attempt.

§Content

The actual diff content is stored as an ArtifactRef (via the artifact field), while TouchedFile (via the touched field) provides a lightweight file-level summary for UI and indexing. The format field indicates how to parse the artifact content (unified diff or git diff). The rationale field carries the agent’s explanation of what was changed and why.

Structs§

PatchSet
PatchSet object containing a candidate diff.
TouchedFile
Touched file summary in a patchset.

Enums§

ApplyStatus
Patch application status.
ChangeType
Type of change for a file.
DiffFormat
Diff format for patch content.