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

# Code Review Reference - REVIEW_API

> **[IMPLEMENTING AGENT — READ FIRST] Filling in this file is the mandatory final step of implementation.**
> The task is NOT complete until every implementation-owned section below is filled in.
> Complete the `Implementation Checklist`; the final checklist item is mandatory before saving.
> Fill implementation-owned sections, then stop with active files in place and report ready for review.
> If implementation is blocked, record the exact blocker, attempted commands/output, and resume condition only in implementation-owned evidence fields.
> Do not ask the user directly, present choices, call user-input tools, create control-plane stop files, or classify the next state.
> Finalization (`Code Review Result`, log rename, `complete.log`, archive moves, `Review-Only Checklist`) is review-agent-only, even after compaction/resume.
> Follow the ownership table at the bottom of this file for which sections you own.

## Overview

date=2026-07-29
task=m-iop-agent-cli-runtime/08+06,07_quota_failure, plan=2, tag=REVIEW_API

## Roadmap Targets

- Milestone: `agent-roadmap/phase/automation-runtime-bridge/milestones/iop-agent-cli-runtime.md`
- Milestone link: [Milestone document](agent-roadmap/phase/automation-runtime-bridge/milestones/iop-agent-cli-runtime.md)
- Task ids:
  - `quota-failure`: typed quota/failure and policy-only retry/failover
- Completion mode: check-on-pass

## Archive Evidence Snapshot

- Prior plan: `agent-task/m-iop-agent-cli-runtime/08+06,07_quota_failure/plan_cloud_G09_1.log`
- Prior review: `agent-task/m-iop-agent-cli-runtime/08+06,07_quota_failure/code_review_cloud_G09_1.log`
- Verdict: `FAIL`
- Findings: 1 Required, 0 Suggested, 0 Nit.
- Required summary:
  - Bind every manager-visible quota projection field to validated snapshot evidence so post-projection state, validity/time, reason, or target mutation becomes canonical corrupt evidence.
- Affected files: `packages/go/agentpolicy/quota.go`, its policy tests, manager continuation tests, durable store tests, and the two runtime contracts.
- Reviewer verification:
  - The raw snapshot tamper/not-applicable tests, manager continuation tests, race suites, vet, full shared-package suite, deterministic searches, formatting, and `git diff --check` passed on fresh reruns.
  - A focused reviewer reproducer changed a projected quota state from `exhausted` to `available` without changing `snapshot_id`; `SanitizeQuotaObservation` retained `Validity: valid` and the reproducer failed.
  - One affected-package run observed the unrelated timing-sensitive `TestSchedulerProviderCapacityAndParallelRelease` at concurrency 1 instead of 2. Twenty focused repetitions, an isolated `agenttask` rerun, the race suite, and the later full shared-package run passed. This remains outside the S07 repair scope.
- Routing signals: `review_rework_count=2`, `evidence_integrity_failure=true`.
- Roadmap carryover: S07 / `quota-failure` remains incomplete; the Milestone was not modified.

## For the Review Agent

> **[REVIEW AGENT ONLY]** The finalization steps below are review-agent only. Implementing agents must not execute this section.

Compare implementation of each item against source files and verify that output in `Verification Results` matches code.
Review completion means the following steps are finished:

1. Append verdict and `review_rework_count` / `evidence_integrity_failure` routing signals.
2. Archive `CODE_REVIEW-cloud-G08.md` → `code_review_cloud_G08_2.log` and `PLAN-cloud-G08.md` → `plan_cloud_G08_2.log`.
3. If PASS, write `complete.log` and move active task directory to `agent-task/archive/YYYY/MM/m-iop-agent-cli-runtime/08+06,07_quota_failure/`. If WARN/FAIL, fully write the next filesystem state required by the code-review skill.
4. If PASS and task group is `m-<milestone-slug>`, report completion event metadata. Roadmap state check and `update-roadmap` calls are runtime responsibilities.
5. Check applicable `Review-Only Checklist` items at the final `.log` location before reporting.

---

## Implementation Item Completion

| Item | Status |
|------|---------|
| REVIEW_API-1 Seal the durable quota projection | [x] |
| REVIEW_API-2 Prove manager and disk fail closed | [x] |
| REVIEW_API-3 Synchronize contract and completion evidence | [x] |

## Implementation Checklist

- [x] Seal every valid/stale `QuotaObservation` projection and make sanitizer, validation, cloning, and strict JSON round trips reject field/seal drift as canonical corrupt evidence.
- [x] Add policy and durable-store regressions for post-projection state, validity/time, reason/identity mutation and seal-preserving disk round trips.
- [x] Add manager regression coverage proving mutated projected evidence persists only as a typed corrupt blocker and never authorizes another invocation.
- [x] Synchronize the shared and standalone runtime contracts and run focused, affected, race, vet, full shared-package, search, formatting, and diff verification.
- [x] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

## Review-Only Checklist

> **[REVIEW AGENT ONLY]** This checklist is used only by the review agent.
> Implementing agents must not modify or check this section.

- [x] Append one verdict of `PASS`, `WARN`, or `FAIL` and verified `review_rework_count`, `evidence_integrity_failure` to `Code Review Result`.
- [x] Verify that verdict, `Dimension Assessment`, and Required/Suggested/Nit classifications match.
- [x] Archive active `CODE_REVIEW-*-G??.md` to `code_review_cloud_G08_2.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G08_2.log`.
- [x] Verify that the Agent-Ops managed block in `.gitignore` unignores `agent-task/**/*.md` and `agent-task/**/*.log` and ignores `agent-roadmap/current.md`.
- [ ] If PASS, write `complete.log` based on `agent-ops/skills/common/code-review/templates/complete-log-template.md` and leave no active `.md` files.
- [ ] If PASS, move active task directory `agent-task/m-iop-agent-cli-runtime/08+06,07_quota_failure/` to `agent-task/archive/YYYY/MM/m-iop-agent-cli-runtime/08+06,07_quota_failure/` and update this checklist at the final archive path.
- [ ] If PASS and task group is `m-<milestone-slug>`, report completion event metadata for runtime, without modifying roadmap or directly calling `update-roadmap`.
- [ ] If PASS for split work, remove empty active parent `agent-task/m-iop-agent-cli-runtime/` or verify it was kept due to remaining siblings/files.
- [x] If WARN/FAIL, write the next filesystem state matching code-review verdict and do not write `complete.log`.

## Deviations from Plan

None. The implementation uses the existing `digestParts`, constant-time comparison, and strict JSON decoder helpers in `agentpolicy`, so it does not introduce a second integrity or JSON-validation mechanism.

## Key Design Decisions

- The projection seal is private in Go and covers snapshot ID, adapter, target, state, UTC-normalized checked time, validity, and ordered reason codes.
- `QuotaObservation` implements strict JSON marshaling and unmarshaling. Valid/stale projections persist their seal; canonical corrupt evidence has no seal or source fields.
- State-store decoding fails before use when an otherwise checksum-valid durable state contains projection-seal drift.

## Reviewer Checkpoints

- A valid/stale quota projection must remain bound to the exact validated snapshot ID, adapter, target, state, checked time, validity, and ordered reasons.
- State, validity/time, reason, or identity mutation after normalization must become canonical corrupt evidence before `DecideContinuation`.
- The projection seal must survive `ManagerState` JSON/CAS persistence, while checksum-valid serialized seal drift must fail closed.
- Manager mutation regressions must produce `BlockerFailureObservationCorrupt`, persist no caller diagnostics, and invoke the provider only once.
- Shared and standalone contracts must match code, and every implementation-owned evidence field must contain actual output.

## Verification Results

For every command below, paste actual stdout/stderr and record its exit status. Do not replace output with a summary.

### `go test -count=1 -run 'Test(SanitizeQuotaObservationRejectsProjectionTampering|QuotaObservationJSONRoundTripRejectsTampering)$' ./packages/go/agentpolicy`

```text
ok  	iop/packages/go/agentpolicy	0.004s
```

Exit status: 0

### `go test -count=1 -run 'Test(FailureContinuationProjectionTamperBecomesTypedBlocker|StorePersistsSealedQuotaObservation)$' ./packages/go/agenttask ./packages/go/agentstate`

```text
ok  	iop/packages/go/agenttask	0.071s
ok  	iop/packages/go/agentstate	0.010s
```

Exit status: 0

### `rg --sort path -n 'projection integrity|SanitizeQuotaObservation|AttemptObservationRecord|corrupt quota' packages/go/agentpolicy packages/go/agenttask packages/go/agentstate agent-contract/inner/agent-runtime.md agent-contract/inner/iop-agent-cli-runtime.md`

```text
packages/go/agentpolicy/failure_policy_test.go:114:	copied := SanitizeQuotaObservation(immutable)
packages/go/agentpolicy/failure_policy_test.go:121:func TestSanitizeQuotaObservationRejectsProjectionTampering(t *testing.T) {
packages/go/agentpolicy/failure_policy_test.go:169:			if got := SanitizeQuotaObservation(observation); !reflect.DeepEqual(got, CorruptQuotaObservation()) {
packages/go/agentpolicy/failure_policy_test.go:170:				t.Fatalf("SanitizeQuotaObservation() = %#v, want canonical corrupt evidence", got)
packages/go/agentpolicy/quota.go:179:// SanitizeQuotaObservation returns a defensive copy of valid durable evidence
packages/go/agentpolicy/quota.go:182:func SanitizeQuotaObservation(observation QuotaObservation) QuotaObservation {
packages/go/agentpolicy/quota.go:209:	quota := SanitizeQuotaObservation(observation.Quota)
packages/go/agenttask/dispatch.go:551:		quota := agentpolicy.SanitizeQuotaObservation(candidate.Quota)
packages/go/agenttask/dispatch.go:679:		record := AttemptObservationRecord{
packages/go/agenttask/state_machine.go:273:		out.AttemptObservations = make([]AttemptObservationRecord, len(work.AttemptObservations))
packages/go/agenttask/types.go:294:// AttemptObservationRecord preserves the safe immutable evidence for one
packages/go/agenttask/types.go:297:type AttemptObservationRecord struct {
packages/go/agenttask/types.go:341:	AttemptObservations []AttemptObservationRecord
packages/go/agentstate/store_test.go:205:						AttemptObservations: []agenttask.AttemptObservationRecord{{
agent-contract/inner/agent-runtime.md:110:- Every valid or stale `QuotaObservation` carries a private projection integrity seal over its snapshot ID, adapter, target, state, normalized checked time, validity, and ordered reason codes. Any post-projection field or seal drift is canonical corrupt evidence before continuation policy evaluation.
agent-contract/inner/agent-runtime.md:111:- Durable quota-observation JSON is strict: it serializes the private seal without exposing a caller-settable Go field, preserves it through `AttemptObservationRecord` persistence, and rejects unknown fields or projection-seal drift before the enclosing manager state is used.
agent-contract/inner/agent-runtime.md:112:- A `FailureContinuationPolicySource` returns only the declared `FailurePolicy` and ordered `FailureContinuationCandidate` inputs. It cannot return a final action or target. The manager supplies the exact current target, normalized failed-attempt observation, authoritative pending dispatch failure budget, and target identities derived from durable prior `AttemptObservationRecord` history to `agentpolicy.DecideContinuation`.
agent-contract/inner/agent-runtime.md:115:- Every failed invocation persists one immutable `AttemptObservationRecord` before retry, failover, or block state is committed. The dispatch failure budget is persisted by the manager and becomes the non-retryable `failure_budget_exhausted` blocker at its configured limit.
agent-contract/inner/iop-agent-cli-runtime.md:68:- S07 host records persist only the safe shared-runtime `AttemptObservationRecord`, exact attempted target identity, and manager-owned failure budget. Valid/stale quota projections retain the shared runtime's private integrity seal over every policy-visible field; strict durable decoding rejects seal drift before state use. Quota normalization, `not_applicable` semantics, policy ordering, used-target exclusion, and the final `DecideContinuation` result remain owned by `iop.agent-runtime`; the standalone host does not duplicate or override them.
```

Exit status: 0

### `command -v go && go version && go env GOROOT`

```text
/config/.local/bin/go
go version go1.26.2 linux/arm64
/config/opt/go
```

Exit status: 0

### `gofmt -d packages/go/agentpolicy/quota.go packages/go/agentpolicy/failure_policy_test.go packages/go/agenttask/failure_continuation_test.go packages/go/agentstate/store_test.go`

```text
(no stdout or stderr; formatting check passed)
```

Exit status: 0

### `go test -count=1 -run 'Test(ValidateQuotaSnapshotRejectsTampering|NormalizeQuotaObservationSanitizesCorruptEvidence|SanitizeQuotaObservationRejectsProjectionTampering|QuotaObservationJSONRoundTripRejectsTampering)$' ./packages/go/agentprovider/cli/status ./packages/go/agentpolicy`

```text
ok  	iop/packages/go/agentprovider/cli/status	0.004s
ok  	iop/packages/go/agentpolicy	0.004s
```

Exit status: 0

### `go test -count=1 ./packages/go/agentpolicy ./packages/go/agenttask ./packages/go/agentstate`

```text
ok  	iop/packages/go/agentpolicy	0.010s
ok  	iop/packages/go/agenttask	1.541s
ok  	iop/packages/go/agentstate	0.080s
```

Exit status: 0

### `go test -count=1 -race ./packages/go/agentpolicy ./packages/go/agenttask ./packages/go/agentstate`

```text
ok  	iop/packages/go/agentpolicy	1.145s
ok  	iop/packages/go/agenttask	3.432s
ok  	iop/packages/go/agentstate	1.123s
```

Exit status: 0

### `go vet ./packages/go/...`

```text
(no stdout or stderr; `go vet ./packages/go/...` passed)
```

Exit status: 0

### `go test -count=1 ./packages/go/...`

```text
ok  	iop/packages/go/agentconfig	0.041s
ok  	iop/packages/go/agentguard	0.019s
ok  	iop/packages/go/agentpolicy	0.011s
ok  	iop/packages/go/agentprovider/catalog	0.095s
```

Exit status: 0

### `if rg --sort path -n 'RawOutput' packages/go/agentpolicy packages/go/agenttask; then exit 1; else test $? -eq 1; fi`

```text
(no output; no `RawOutput` references were found)
```

Exit status: 0

### `git diff --check`

```text
(no stdout or stderr; whitespace check passed)
```

Exit status: 0

---

> **[IMPLEMENTING AGENT — BEFORE SAVING] Have you filled in every implementation-owned section?**
> If anything is blank, go back and fill it in before saving this file.
> Leave review-agent-only sections unchanged.

## Section Ownership

| Section | Owner | Note |
|---------|-------|------|
| Header comment, Overview, Review Agent Instructions | Fixed at stub creation | Implementing agent must not modify or execute these (archive, complete.log, and task-directory archive move are review-agent only) |
| Roadmap Targets | Fixed at stub creation from plan when present | Implementing agent must not modify; code-review copies it into `complete.log` as `Roadmap Completion` only on PASS |
| Archive Evidence Snapshot | Fixed at stub creation from plan when present | Implementing agent uses it as default prior-loop context; read only the specific archive files cited there when more detail is required |
| Agent UI Completion | Mixed | Present only for plan-required agent-ui code work; implementing agent fills actual evidence, review agent applies `구현됨` status/evidence update on PASS and copies the section into `complete.log` |
| Implementation Item Completion (item names) | Fixed at stub creation | Implementing agent checks `[ ]` → `[x]` only |
| Implementation Checklist (item text/order) | Fixed at stub creation from plan | Implementing agent checks `[ ]` → `[x]` only |
| Review-Only Checklist | Review agent only | Implementing agent must not modify or check this section |
| Deviations from Plan, Key Design Decisions | Implementing agent | Replace placeholder text with actual content |
| Reviewer Checkpoints | Fixed at stub creation | Pre-filled from plan |
| Verification Results (section headings + commands) | Fixed at stub creation | Implementing agent fills in command output only; command changes require a `Deviations from Plan` entry |
| Code Review Result | Review agent appends | Not included in stub |

## Code Review Result

- Overall Verdict: FAIL
- Dimension Assessment:
  - Correctness: Pass
  - Completeness: Fail
  - Test coverage: Fail
  - API contract: Pass
  - Code quality: Pass
  - Implementation deviation: Fail
  - Verification trust: Pass
  - Spec conformance: Fail
- Findings:
  - Required — `packages/go/agentpolicy/failure_policy_test.go:121`: the required projection-integrity matrix does not mutate `SnapshotID` or `Adapter`, and `TestQuotaObservationJSONRoundTripRejectsTampering` at line 176 omits both serialized identity mutations and the plan-required `not_applicable` round trip. The manager matrix in `packages/go/agenttask/failure_continuation_test.go:138` repeats the same `SnapshotID`/`Adapter` omission. The implementation seals these fields, and all fresh reviewer commands passed, but REVIEW_API-1/2 and S07 require independent evidence for every manager-visible projection field plus valid, stale, not-applicable, and corrupt persistence cases. Extend the policy sanitizer/JSON tables with snapshot-ID and adapter drift, add `not_applicable` to the round-trip set, extend the manager table with snapshot-ID and adapter drift, and assert every manager case persists the full canonical corrupt projection with exactly one invocation.
- Routing Signals:
  - review_rework_count=3
  - evidence_integrity_failure=false
- Next Step: Archive this reviewed pair and create the freshly routed WARN/FAIL follow-up PLAN/CODE_REVIEW pair through the plan skill.
