# Task to Merge Workflow

**Status:** Approved target-state baseline  
**First realization:** I1.

## Target State

```text
Task ready
  -> FactoryRun / AgentRun coding Attempt
  -> recoverable WIP
  -> ChangeSet candidate
  -> focused verification / required checks
  -> trusted publication
  -> independent Review
       approved? ── no -> correction AgentRun -> new ChangeSet revision -> focused reverify -> re-review
       yes
  -> MergeGate
  -> trusted merge
  -> read-back/fidelity verification
  -> Task completed
```

## Coding Boundary

Agent only edits isolated Workspace. It does not publish/merge. Attempt provenance is attached to candidate.

## Candidate Collection

AWP collects exact base/candidate tree/patch, changed paths/digest and checkpoint provenance before disposable workspace cleanup.

## Verification

I1 uses smallest meaningful focused checks plus actual repository-required GitHub checks. Results are persisted as thin VerificationEvidence. I5 later deepens planning/admission/invalidation without replacing identity.

## Publication

Trusted ForgeProvider verifies base/ref policy and candidate fidelity, creates branch/commit/PR as configured, reads back provider identity and records it.

## Review

Independent reviewer consumes candidate + existing evidence. It is read-only and has no merge authority. Changes requested create a new candidate revision; old approval does not automatically apply.

## MergeGate

Requires:

```text
current exact candidate/base
required focused evidence current/passing
repository-required provider checks satisfied
independent Review acceptable
no unresolved blocking finding/policy/Approval
ChangeSet publication/fidelity valid
```

I3/I5 can add generic policy/VerificationAuthority depth but I1 uses the final gate seam.

## Merge

Trusted control plane executes provider merge, verifies resulting commit/PR state and persists exact merge identity. Timeout reconciles before repeat.

## Failure / Recovery

- agent crash -> checkpoint/new Attempt;
- publication outage -> keep ChangeSet/retry publication only;
- review changes -> correction loop;
- stale base/conflict -> structured blocked/correction/rebase workflow;
- failed check -> focused correction/verification;
- merge timeout -> provider reconciliation.

## Increment Realization

I1 proves entire workflow against AWP repository. I5 enriches CI/verification; I3 policy/Approval; I6 downstream Release begins after merge.

## Acceptance

AWP can use AWP to make a real small change to AWP through the entire path without normal coding execution on the workstation.