<!-- task=m-iop-agent-cli-runtime/10+06_state_recovery plan=0 tag=API -->

# Durable Supervisor and State Recovery

## For the Implementing Agent

`06+05_config_registry/complete.log`가 필요하다. actual verification output만 `CODE_REVIEW-cloud-G10.md`에 기록한다.

## Background

manager는 CAS와 in-memory fixture lease를 이미 사용하지만 device singleton, persistent process/session/overlay locator, corrupt checkpoint reconciliation 및 failure budget은 없다.

## Roadmap Targets

- Milestone: `agent-roadmap/phase/automation-runtime-bridge/milestones/iop-agent-cli-runtime.md`
- Milestone link: [Milestone 문서](agent-roadmap/phase/automation-runtime-bridge/milestones/iop-agent-cli-runtime.md)
- Task ids:
  - `state-recovery`: singleton/workspace lease, checkpoint, restart reconciliation
- Completion mode: check-on-pass

## Analysis

### Files Read

- `packages/go/agenttask/intent.go`
- `packages/go/agenttask/manager.go`
- `packages/go/agenttask/reconcile.go`
- `packages/go/agenttask/state_machine.go`
- `packages/go/agenttask/manager_test.go`
- `packages/go/agenttask/integration_queue_test.go`
- `agent-contract/inner/agent-runtime.md`
- `agent-roadmap/sdd/automation-runtime-bridge/iop-agent-cli-runtime/SDD.md`

### SDD Criteria

S09/Evidence Map S09: duplicate daemon/workspace owner, restart/live child, corrupt checkpoint, partial archive and failure budget must never cause silent recovery or duplicate execution.

### Test Environment Rules

local rules were read. Baseline agenttask tests PASS. Tests use temp roots and deterministic clocks; no external process is required.

### Test Coverage Gaps

Current in-memory lease tests do not persist device identity, expiry, locator validation or corrupt state across process construction.

### Split Judgment

config registry provides local state root/revision. Durable manager state and recovery are one transaction invariant, so this packet remains indivisible.

### Scope Rationale

actual overlay creation/integration backend is excluded to `11`/`12`; this task stores and reconciles opaque locator/revision records only.

### Final Routing

`first-pass`; cloud G10. temporal-state, concurrent-consistency, boundary-contract risks; G10 state/recovery verification. official cloud G10 review.

## Implementation Checklist

- [ ] Add durable local StateStore format with schema/version/checksum and atomic CAS writes.
- [ ] Add device singleton and workspace lease ownership/expiry/reconciliation without relaxing manager CAS semantics.
- [ ] Persist process/session/overlay/change-set locators and failure budget as opaque, identity-checked records.
- [ ] Block corrupt, stale or ambiguous checkpoint state with zero provider invocation.
- [ ] Add restart, duplicate owner, cancel, corrupt checkpoint, partial archive and budget matrices.
- [ ] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

### [API-1] crash-safe state store와 reconciliation을 구현한다

**Problem:** `ManagerState` only has fixture backing; `reconcile.go` cannot distinguish live durable work from absent/corrupt state after process restart.

**Solution:** introduce a local state package with atomic revisioned snapshots and lock/lease records. Extend manager reconciliation to validate locator identity, retain blocker evidence and resume only known stages; malformed state has a typed terminal blocker.

**Test Strategy:** use a temp state root and fake clock for concurrent singleton claim, lease expiration, restart replay, corrupt/checksum failure, cancel release, partial archive and failure budget tests.

**Verification:** race-enabled agenttask/state tests pass and no corrupt state is overwritten.

## Modified Files Summary

| File | Item |
|---|---|
| `packages/go/agentstate/store.go` | API-1 |
| `packages/go/agentstate/store_test.go` | API-1 |
| `packages/go/agenttask/ports.go` | API-1 |
| `packages/go/agenttask/intent.go` | API-1 |
| `packages/go/agenttask/reconcile.go` | API-1 |
| `packages/go/agenttask/manager_test.go` | API-1 |

## Dependencies and Execution Order

`06+05_config_registry` PASS 후 시작한다.

## Final Verification

```bash
go test -count=1 -race ./packages/go/agentstate ./packages/go/agenttask
git diff --check
```

After completing all code changes, fill implementation-owned sections in `CODE_REVIEW-*-G??.md`.
