# Factory Domain

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

## Target State

The Factory turns a selected Plan/Task graph into observable, durable coding/review work while AWP owns identities, lifecycle and progression.

```text
PlanRevision / Task graph
  -> FactoryRun
       -> provider workflow/graph (Fabro)
       -> AgentRun(s)
           -> Attempt(s) / Workspace(s)
       -> checkpoints / outputs
  -> ChangeSet / Review
  -> next Task until Plan completion
```

Fabro owns factory execution mechanics. AWP owns `FactoryRun`, Task relationships, AgentRun identities, policy, authoritative status, events/audit and downstream delivery.

## FactoryRun Identity

FactoryRun is one orchestration instance over a selected Plan/Task subset/graph. It records:

- Project/PlanRevision;
- selected tasks/work graph revision;
- FactoryProvider/reference;
- resolved ExecutionPolicy;
- start/stop/status/reason;
- AgentRun relationships;
- checkpoints/artifacts/change outputs;
- current node/task and progress;
- correlation/events.

## Invariants From Day 1

- provider-native Fabro run ID is a mapping, not FactoryRun identity;
- Task state is not inferred only from provider node status;
- FactoryRun survives provider/control-plane restart through durable orchestration/reconciliation;
- agents never receive lifecycle/publish/merge authority simply because they run inside Factory;
- WIP persists before compute cleanup;
- retries/fallback create explicit Attempt provenance;
- graph/dependency execution respects Plan execution policy and configured concurrency;
- unrelated work can continue when one task/run waits if dependencies/policy allow.

## Lifecycle

```text
planned -> queued -> starting -> running
 -> waiting/blocked
 -> cancelling -> cancelled
 -> failed/retryable/resolving
 -> completed
```

Reason codes identify dependency wait, agent/provider capacity, human approval, connection requirement, verification/review correction, infrastructure failure and policy block.

## Factory Provider Contract

`FactoryProvider` supports graph materialization/dispatch/observation/cancel/reconcile and maps provider nodes/outputs to AWP Task/AgentRun identities. Provider graph DSL is not the AWP Plan model.

## Progress

Progress is structural and evidence-based, not fake percentage. UI may show task/wave/phase counts, active/blocked nodes, completed outcomes and current critical path where available.

## Increment Realization

| Increment | Factory realization |
|---|---|
| I1 | small Task graph, durable FactoryRun, live AgentRuns, retry/WIP/ChangeSet/Review. |
| I2 | Planning-generated execution policies/graphs. |
| I4 | full graph/live agent/tool/files/diff/checkpoint/cost UX. |
| I5 | CI evidence/progression integration. |
| I8 | resolver workflow integration. |

## Current Implementation State

Target spec; Fabro is primary provider but final adapter implementation begins with I1.

## Deferred Realization

Advanced portfolio scheduling, cross-project factory optimization and deep provider-specific graph editing are not I1 requirements.

## Temporary Dogfood Behavior

I1 may use one Task and a simple two-Task dependency fixture. FactoryRun identity/lifecycle still supports the full graph model.

## Failure / Recovery

Provider unavailable, model/account exhausted, workspace failure, checkpoint failure and policy/human wait are distinct. A provider failure does not mark Task completed/failed until AWP lifecycle rules resolve it.

## UI Implications

FactoryRun page shows current graph/task/agent relationships, status reasons, retry/preserved-work state and direct navigation to Agent/ChangeSet/Review. Rich observability deepens I4 on the same event model.

## Decisions / ADRs

Replacing Fabro changes adapter/provider mechanics, not FactoryRun domain identity.