<!-- task=m-iop-hot-path-one-shot-execution/11+09,10_cleanup plan=2 tag=REVIEW_REVIEW_API milestone-task=cleanup -->

# Code Review Reference - REVIEW_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-08-03
task=m-iop-hot-path-one-shot-execution/11+09,10_cleanup, plan=2, tag=REVIEW_REVIEW_API

## Archive Evidence Snapshot

- Current review archive after finalization: `agent-task/m-iop-hot-path-one-shot-execution/11+09,10_cleanup/code_review_cloud_G10_1.log`.
- Earlier review archive: `agent-task/m-iop-hot-path-one-shot-execution/11+09,10_cleanup/code_review_cloud_G10_0.log`.
- Current verdict: FAIL; findings: Required 1, Suggested 0, Nit 0.
- Required gap: `hot_path_cleanup.go` can start a primary-error cleanup only from a resumed artifact frontier with an already stored selector response, while `hot_path_light.go` terminates non-cancelled local/review failures directly.
- Reviewer reproduction: an exact failed prepare receipt returned HTTP 400 `cleanup response identity is unavailable` on both OpenAI and Anthropic instead of a delete frontier.
- Trusted passing evidence: focused cleanup/TTL registration, focused race tests, common package race tests, full Edge tests with an executable temporary directory, vet, format, and diff checks all passed; those suites do not cover the reproduced prepare/local/review variants.
- Affected implementation area: `artifact_pair.go`, `hot_path_cleanup.go`, `hot_path_light.go`, `request_identity_ingress.go`, and focused cleanup tests.
- Roadmap carryover: milestone task `cleanup`, approved and unlocked SDD Acceptance Scenario/Evidence Map row S09 only.

## 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-G09.md` → `code_review_cloud_G09_2.log` and `PLAN-cloud-G09.md` → `plan_cloud_G09_2.log`.
3. If PASS, write `complete.log` and move active task directory to `agent-task/archive/YYYY/MM/m-iop-hot-path-one-shot-execution/11+09,10_cleanup/`. 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>`, preserve the first-line `milestone-task` metadata in `complete.log` and report it for the runtime aggregation event. Roadmap state evaluation belongs to `sync-milestone-workstate`.
5. Check applicable `Review-Only Checklist` items at the final `.log` location before reporting.

---

## Implementation Item Completion

| Item | Status |
|------|---------|
| REVIEW_REVIEW_API-1 — Persist cleanup response identity and select the exact cleanup source stage | [x] |
| REVIEW_REVIEW_API-2 — Route cleanup-capable local and review errors through primary cleanup | [x] |
| REVIEW_REVIEW_API-3 — Close focused and regression evidence | [x] |

## Implementation Checklist

- [x] Persist the exact selector response correlation for every caller-visible prepare or pair frontier before its receipt can resume the request.
- [x] Start primary-error cleanup from either the resumed artifact frontier or the exact active local/review stage without weakening ownership or receipt validation.
- [x] Route every cleanup-capable non-cancelled local/review failure through the delete frontier while retaining the original endpoint error if cleanup fails to start or acknowledge.
- [x] Add deterministic OpenAI and Anthropic regression coverage for prepare, local, and review primary-error variants plus cancellation and error-precedence assertions.
- [x] Run all focused and final verification commands with fresh output.
- [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_G09_2.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G09_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-hot-path-one-shot-execution/11+09,10_cleanup/` to `agent-task/archive/YYYY/MM/m-iop-hot-path-one-shot-execution/11+09,10_cleanup/` and update this checklist at the final archive path.
- [ ] If PASS and task group is `m-<milestone-slug>`, preserve and report `milestone-task` metadata for runtime aggregation, without modifying roadmap or directly calling `update-roadmap`.
- [ ] If PASS for split work, remove empty active parent `agent-task/m-iop-hot-path-one-shot-execution/` 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

No implementation or verification command deviated from the plan. The unchanged final verification block was repeated once, and its common-race and full-Edge subcommands were also rerun separately, because the combined execution bridge returned only the leading package lines even though the shell exited successfully. The supplemental reruns produced complete package-level output and did not change test semantics.

## Key Design Decisions

- Commit selector correlation immediately after any validated artifact frontier is issued. The one-call prepare response is therefore resumable for primary-error cleanup, and the later pair response replaces it with the exact correlation consumed by local/review prompts.
- Derive the cleanup source while holding the light-store lock. Only a resumed artifact phase uses an empty source; local and all review control phases must present their exact pinned stage IDs and matching committed correlations.
- Route post-artifact local/review failures through one primary-error writer. It clears only the owned in-flight dispatch, checks cancellation before cleanup, emits one caller-executed delete frontier, and preserves the original protocol status/type/message through cleanup acknowledgement failure.
- When cleanup setup cannot produce a frontier, detach the coordinator with `primary_error` ownership, keep light/artifact state for bounded TTL removal, and return the original endpoint error without exposing cleanup internals. A failed dispatch acquisition does not abort another caller's already-running stage.
- Keep artifact-continuation fallback symmetric across OpenAI and Anthropic. Cancellation remains detached as `cancelled`; non-cancelled cleanup-start failure returns the stored artifact primary error.
- Exercise exact public handlers for prepare/pair, local dispatch/tool-frontier, review dispatch/classification/tool-frontier, cleanup start/acknowledgement failure, and cancellation, with provider-call counts proving that no hidden model work occurs.

## Reviewer Checkpoints

- Confirm the one-call prepare and two-call pair frontiers both persist their exact selector response before a caller result can resume them, without changing public tool-call identity or receipt matching.
- Confirm primary-error cleanup selects only the exact resumed artifact state or active local/review stage and keeps the coordinator/light transition exactly once under duplicates, cancellation, and TTL races.
- Confirm every non-cancelled post-artifact local/review failure either issues one canonical delete frontier or returns its original endpoint error when cleanup setup fails; cleanup acknowledgement failure must never replace that error.
- Confirm OpenAI and Anthropic tests cover prepare, pair, local, review, setup failure, acknowledgement failure, and cancellation with exact provider-call counts and no hidden work.
- Confirm public API/Anthropic shapes, TTL/redaction semantics, and the existing success cleanup matrix remain unchanged.

## Verification Results

Paste actual stdout/stderr for every command below. Do not summarize or reconstruct output. If a command changes, record the replacement and reason in `Deviations from Plan` before pasting its output.

### REVIEW_REVIEW_API-1 — prepare and pair primary errors

```bash
go test -race -count=1 ./apps/edge/internal/openai -run '^TestHotPathCleanupPrimaryErrorPrecedence$'
```

_Actual stdout/stderr:_

```text
ok  	iop/apps/edge/internal/openai	1.311s
```

### REVIEW_REVIEW_API-2 — local/review and cleanup-start errors

```bash
go test -race -count=1 ./apps/edge/internal/openai -run '^TestHotPathCleanupPrimaryError(StageMatrix|StartFailure)$'
```

_Actual stdout/stderr:_

```text
ok  	iop/apps/edge/internal/openai	1.363s
```

### REVIEW_REVIEW_API-3 — registration and focused race evidence

```bash
go test ./apps/edge/internal/openai -list '^TestHotPathCleanupPrimaryError' | rg '^TestHotPathCleanupPrimaryError'
go test -race -count=1 ./apps/edge/internal/openai -run '^TestHotPathCleanupPrimaryError'
```

_Actual stdout/stderr:_

```text
TestHotPathCleanupPrimaryErrorPrecedence
TestHotPathCleanupPrimaryErrorStageMatrix
TestHotPathCleanupPrimaryErrorStartFailure
ok  	iop/apps/edge/internal/openai	1.489s
```

### Final — prerequisites, focused suites, common race suites, and full Edge

```bash
test -f agent-task/archive/2026/08/m-iop-hot-path-one-shot-execution/09+06,08_artifact_pair/complete.log
test -f agent-task/archive/2026/08/m-iop-hot-path-one-shot-execution/10+07,09_light_flow/complete.log
go test ./apps/edge/internal/openai -list '^TestHotPathCleanupPrimaryError' | rg '^TestHotPathCleanupPrimaryError'
go test -race -count=1 ./apps/edge/internal/openai -run '^TestHotPathCleanupPrimaryError'
go test -race -count=1 ./apps/edge/internal/openai -run '^Test(LogicalRequestTTL|HotPathCleanup)'
go test -race -count=1 ./packages/go/streamgate ./packages/go/config ./apps/edge/internal/openai ./apps/edge/internal/service
edge_test_tmpdir="$(mktemp -d /config/workspace/iop-edge-test.XXXXXX)"
chmod 700 "$edge_test_tmpdir"
TMPDIR="$edge_test_tmpdir" go test -count=1 ./apps/edge/...
edge_test_status=$?
rmdir "$edge_test_tmpdir"
exit "$edge_test_status"
```

_Actual stdout/stderr:_

```text
TestHotPathCleanupPrimaryErrorPrecedence
TestHotPathCleanupPrimaryErrorStageMatrix
TestHotPathCleanupPrimaryErrorStartFailure
ok  	iop/apps/edge/internal/openai	1.485s
ok  	iop/apps/edge/internal/openai	2.021s
ok  	iop/packages/go/streamgate	2.113s
ok  	iop/packages/go/config	1.880s
```

_Supplemental raw stdout from the separately repeated common-race and full-Edge subcommands described in `Deviations from Plan`:_

```text
ok  	iop/packages/go/streamgate	2.070s
ok  	iop/packages/go/config	1.658s
ok  	iop/apps/edge/internal/openai	10.464s
ok  	iop/apps/edge/internal/service	7.040s
ok  	iop/apps/edge/cmd/edge	0.796s
ok  	iop/apps/edge/internal/authprojection	0.092s
ok  	iop/apps/edge/internal/bootstrap	11.255s
ok  	iop/apps/edge/internal/configrefresh	0.618s
ok  	iop/apps/edge/internal/controlplane	6.723s
ok  	iop/apps/edge/internal/edgecmd	0.364s
ok  	iop/apps/edge/internal/edgevalidate	0.121s
ok  	iop/apps/edge/internal/events	0.090s
ok  	iop/apps/edge/internal/input	0.185s
ok  	iop/apps/edge/internal/input/a2a	0.141s
ok  	iop/apps/edge/internal/node	0.145s
ok  	iop/apps/edge/internal/openai	9.879s
ok  	iop/apps/edge/internal/opsconsole	0.103s
ok  	iop/apps/edge/internal/service	6.180s
ok  	iop/apps/edge/internal/transport	4.926s
```

### Final — static checks

Run this block in a new shell after the full Edge command.

```bash
go vet ./apps/edge/...
gofmt -d apps/edge/internal/openai/artifact_pair.go apps/edge/internal/openai/hot_path_cleanup.go apps/edge/internal/openai/hot_path_light.go apps/edge/internal/openai/request_identity_ingress.go apps/edge/internal/openai/hot_path_cleanup_test.go
git diff --check
```

_Actual stdout/stderr:_

```text
```

---

> **[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) |
| 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 |
| 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: Fail — an exact pair result that fails the configured receipt matcher without an explicit error field bypasses primary-error cleanup after another pair write may already have created an artifact.
  - Completeness: Fail — prepare/pair response identity and local/review primary errors are covered, but the artifact receipt failure classifier still admits only the narrower explicit-error subset.
  - Test Coverage: Fail — the primary-error suite uses explicit `error` fields for artifact failures and does not cover a correlation-valid matcher failure such as `{"written":false}` in a partially successful pair.
  - API Contract: Fail — SDD S09 requires artifact-bearing errors to attempt caller-executed cleanup while retaining the endpoint primary error.
  - Code Quality: Pass — the reviewed implementation is formatted, vet-clean, race-clean under the required suites, and contains no stale-symbol or debug residue in the current plan scope.
  - Implementation Deviation: Fail — the plan requires every exact failed prepare or pair receipt to enter the cleanup transaction, but `artifact_pair.go` restricts that transition to `workspaceResultExplicitlyFailed` results.
  - Verification Trust: Fail — all listed commands pass, but a focused public-handler reviewer reproducer contradicts the claimed complete artifact primary-error matrix on both protocols.
  - Spec Conformance: Fail — S09 error best-effort cleanup evidence remains incomplete for correlation-valid receipt-matcher failures.
- Findings:
  - Required — `apps/edge/internal/openai/artifact_pair.go:445`: after validating request lineage, pending call identity, and immutable issue correlation, a receipt mismatch enters `PrimaryError` only when `workspaceResultExplicitlyFailed` detects a status or `error` field. A focused OpenAI/Anthropic handler reproducer sent a successful Plan result plus an exact Review result `{"written":false}`; both endpoints returned HTTP 400 `result does not satisfy the configured result matcher` and issued no delete frontier. Treat every correlation-valid receipt mismatch that can follow a caller-executed artifact operation as the stored primary error, while retaining immediate rejection for malformed identity/lineage/correlation, and add deterministic partial-pair matcher-failure tests that assert one delete frontier, cleanup acknowledgement/error precedence, and no hidden provider work on both protocols.
- Routing Signals:
  - `review_rework_count=3`
  - `evidence_integrity_failure=true`
- Next Step: Invoke the plan skill for a FAIL follow-up using this raw reviewer evidence; do not create `USER_REVIEW.md`.
