<!-- task=m-iop-agent-cli-runtime/08+06,07_quota_failure plan=0 tag=API -->

# Quota and Typed Failure Policy

## For the Implementing Agent

`06+05`와 `07+06`의 completion evidence가 필요하다. implementation-owned review fields를 실제 stdout/stderr로 채운다.

## Background

quota snapshot과 `agentruntime.Failure`는 이미 일부 정규화하지만, policy-bound retry/failover와 immutable per-work-unit observation은 없다.

## 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:
  - `quota-failure`: typed quota/failure와 policy-only retry/failover
- Completion mode: check-on-pass

## Analysis

### Files Read

- `packages/go/agentruntime/failure.go`
- `packages/go/agentruntime/failure_test.go`
- `packages/go/agentruntime/status.go`
- `packages/go/agentprovider/cli/status/quota.go`
- `packages/go/agentprovider/cli/status/quota_test.go`
- `packages/go/agenttask/dispatch.go`
- `agent-roadmap/sdd/automation-runtime-bridge/iop-agent-cli-runtime/SDD.md`

### SDD Criteria

S07/Evidence Map S07 requires available/exhausted/unknown isolation, typed runtime observation, policy-declared retry/failover only, and unknown error as work-unit blocker.

### Test Environment Rules

local rules를 읽었고 quota/status, runtime failure와 manager tests의 fresh execution을 사용한다.

### Test Coverage Gaps

quota parser tests cover raw status normalization, but no decision-level failover or immutable observation isolation exists.

### Split Judgment

registry and target policy provide immutable policy input. This packet owns their quota/failure interaction, not config parsing or provider transport.

### Scope Rationale

provider raw output/redaction semantics and CLI status parsers remain intact; Edge provider-pool is excluded.

### Final Routing

`first-pass`; cloud G09. boundary-contract/temporal-state risk 2, multiple durable state and failure paths. review official cloud G09.

## Implementation Checklist

- [ ] quota evidence와 Failure를 work-attempt snapshot으로 normalize하고 secret-bearing diagnostics를 exclude한다.
- [ ] retry/failover eligibility를 ordered policy, unused candidate, failure budget으로 제한한다.
- [ ] unknown/stale/corrupt observation을 silent selection 없이 typed blocker로 만든다.
- [ ] exhaustion, unknown, retry budget, failover and isolation tests를 추가한다.
- [ ] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

### [API-1] failure-aware route continuation을 구현한다

**Problem:** quota snapshot은 selector-facing data일 뿐 `agenttask`가 policy-bounded failover로 연결하지 않는다.

**Solution:** `agentpolicy`에 immutable observation and continuation types를 추가하고 manager port를 이 decision으로 확장한다. known retryable codes만 same target retry하고, eligible unused alternate만 fail over하며 unknown은 retained blocker가 된다.

**Test Strategy:** normalizer, policy and manager integration matrices cover quota available/exhausted/unknown, typed failures, exhausted budget, alternate history and raw output exclusion.

**Verification:** relevant package tests PASS and no raw provider output appears in durable snapshot encoding.

## Modified Files Summary

| File | Item |
|---|---|
| `packages/go/agentpolicy/quota.go` | API-1 |
| `packages/go/agentpolicy/failure_policy.go` | API-1 |
| `packages/go/agentpolicy/failure_policy_test.go` | API-1 |
| `packages/go/agenttask/ports.go` | API-1 |
| `packages/go/agenttask/dispatch.go` | API-1 |

## Dependencies and Execution Order

`06+05_config_registry`와 `07+06_target_policy`의 PASS가 선행한다.

## Final Verification

```bash
go test -count=1 ./packages/go/agentruntime ./packages/go/agentprovider/cli/status ./packages/go/agentpolicy ./packages/go/agenttask
rg --sort path -n 'RawOutput' packages/go/agentpolicy packages/go/agenttask
git diff --check
```

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