<!-- task=m-iop-owned-single-request-agent-execution/20+19_review_stage plan=1 tag=API milestone-task=review-stage -->

# Code Review Reference - API

> **[IMPLEMENTING AGENT — READ FIRST] Filling in this file is the mandatory final step of implementation.**
> Complete the fixed checklists and evidence fields, leave both active files in place, and report ready for review. Only the official review agent may append a verdict, archive files, write `complete.log`, or classify the next state. If blocked, record the blocker, attempted commands/output, and resume condition here; do not change owner or scope.

## Overview

date=2026-08-07
task=m-iop-owned-single-request-agent-execution/20+19_review_stage, plan=1, tag=API

## For the Review Agent

Compare every item with source and freshly rerun recorded verification. Then append the official verdict and routing signals. On PASS, archive this file as `code_review_cloud_G09_1.log`, archive the plan as `plan_cloud_G09_1.log`, write `complete.log` preserving `milestone-task=review-stage`, and move the task directory to the dated archive. On WARN/FAIL, write only the next state prescribed by the code-review skill. The implementing agent must not perform these steps.

## Archive Evidence Snapshot

- Prior plan: `agent-task/m-iop-owned-single-request-agent-execution/20+19_review_stage/plan_cloud_G09_0.log`.
- Prior review stub: `agent-task/m-iop-owned-single-request-agent-execution/20+19_review_stage/code_review_cloud_G09_0.log`.
- The archived pair contains no implementation evidence and no official verdict. It was preserved because explicit self-review found material dependency and state-machine defects.
- Its active-only predecessor check could not survive task-19 archival. Its expected `repairing -> reviewing` edge is rejected by the existing service transition table and by the SDD, which requires re-review dispatch while the lifecycle remains `repairing`.
- It also omitted the direct reviewer inspection path `reviewing -> internal_tool(saved reviewing) -> reviewing`. This revision covers inspection and repair as separate deterministic fixtures.
- No production code, test, contract, spec, or roadmap completion is claimed by the archived pair.

## Implementation Item Completion

| Item | Status |
|------|---------|
| API-1 Implement strict Review, inspection, and persisted pass evidence | [ ] |
| API-2 Drive bounded repair and re-review without a false state edge | [ ] |
| API-3 Compose the three private stages | [ ] |
| API-4 Install and synchronize the active contract | [ ] |

## Implementation Checklist

- [ ] Implement Gemini high-reasoning Review with strict pass, direct non-mutating inspection, REVIEW persistence before finalization, and fail-closed bounded results.
- [ ] Implement one-tool-at-a-time repair with `repairing -> internal_tool(saved repairing) -> repairing`, re-review dispatch while state remains repairing, and no invalid `repairing -> reviewing` transition.
- [ ] Add a concurrent request-safe composite executor that drives Plan → Work → Review through one controller, reuses the predecessor continuation bridge, and returns only reviewer-approved output.
- [ ] Install the composite at Edge input startup and add S10, inspection, repair, full lifecycle, concurrent isolation, cancellation, cleanup, and installation fixtures without changing the public Anthropic schema.
- [ ] Update the current outer contract and implementation spec, then run dependency, focused race, installation, regression, vet, deterministic document/search, and diff checks while leaving S12 external evidence deferred.
- [ ] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

## Review-Only Checklist

> **[REVIEW AGENT ONLY]** Implementing agents must not modify this section.

- [ ] Append one `PASS`, `WARN`, or `FAIL` verdict with verified `review_rework_count` and `evidence_integrity_failure`.
- [ ] Verify verdict, dimension assessment, and Required/Suggested/Nit classifications agree.
- [ ] Archive this file to `code_review_cloud_G09_1.log` and the plan to `plan_cloud_G09_1.log`.
- [ ] Verify `.gitignore` unignores task Markdown/log files and ignores `agent-roadmap/current.md`.
- [ ] On PASS, write template-compliant `complete.log`, preserve/report `milestone-task=review-stage`, move the task directory to the dated archive, and remove the active parent only if empty.
- [ ] On WARN/FAIL, write the exact next filesystem state and do not write `complete.log`.

## Deviations from Plan

_Record deviations and rationale here._

## Key Design Decisions

_Record implementation decisions here._

## Reviewer Checkpoints

- Verify direct inspection records `reviewing -> internal_tool(saved reviewing) -> reviewing`; mutation records `reviewing -> repairing -> internal_tool(saved repairing) -> repairing`.
- Verify re-review provider dispatch occurs while state remains `repairing`; no implementation/test expects or enables `repairing -> reviewing`.
- Verify every Review/re-review request uses the frozen Gemini route and effective high reasoning, and every tool is admitted, correlated, bounded, and serialized one at a time.
- Verify REVIEW is durable before finalizing, only reviewer-approved bytes become terminal, shared state is request-isolated, and all waiters clean up.
- Verify production installation uses existing boundaries, public schemas remain unchanged, docs claim only local deterministic evidence, and S12 remains deferred.

## Verification Results

Paste actual stdout/stderr for every command. Any replacement requires a matching `Deviations from Plan` entry.

### 1. Dependency evidence

`bash -c 'set -euo pipefail; shopt -s nullglob; candidates=(agent-task/m-iop-owned-single-request-agent-execution/19_*/complete.log agent-task/m-iop-owned-single-request-agent-execution/19+*/complete.log agent-task/archive/*/*/m-iop-owned-single-request-agent-execution/19_*/complete.log agent-task/archive/*/*/m-iop-owned-single-request-agent-execution/19+*/complete.log); printf "%s\n" "${candidates[@]}"; ((${#candidates[@]} == 1))'`

Expected: exactly one path and exit zero before implementation or review.

```text
_Paste actual output here._
```

### 2. Focused Review/composite race tests

`go test -race ./apps/edge/internal/openai -run 'TestSingleRequest(ReviewStage|Executor)' -count=1`

```text
_Paste actual output here._
```

### 3. Service state and cleanup compatibility

`go test ./apps/edge/internal/service -run 'TestSingleRequest(InternalToolLoop|Cleanup|EnvelopeOrdering)' -count=1`

```text
_Paste actual output here._
```

### 4. Production installation

`go test ./apps/edge/internal/input -run 'TestManager.*SingleRequestExecutor' -count=1`

```text
_Paste actual output here._
```

### 5. Changed-path regression

`go test ./apps/edge/internal/service ./apps/edge/internal/openai ./apps/edge/internal/input -count=1`

```text
_Paste actual output here._
```

### 6. Vet and Edge regression

`go vet ./apps/edge/internal/service ./apps/edge/internal/openai ./apps/edge/internal/input && go test ./apps/edge/... -count=1`

```text
_Paste actual output here._
```

### 7. Installation and state-order evidence

`rg --sort path -n 'NewSingleRequestExecutor|SetSingleRequestExecutor|reasoning_effort|SingleRequestArtifactReview|finalizing|repairing' apps/edge/internal/openai apps/edge/internal/input --glob '*.go'`

Expected: installation and tests make high Review, legal repair, REVIEW persistence, and finalization ordering explicit; no `repairing -> reviewing` behavior is introduced.

```text
_Paste actual output here._
```

### 8. Canonical service transition table remains unchanged

`git diff --exit-code HEAD -- apps/edge/internal/service/single_request.go`

Expected: no task-20 worktree delta against the predecessor-completed transition table.

```text
_Paste actual output here._
```

### 9. Contract/spec synchronization

`rg --sort path -n 'Plan|Work|Review|repair|active|claude-smoke|S12|deferred' agent-contract/outer/anthropic-compatible-api.md agent-spec/runtime/edge-node-execution.md`

```text
_Paste actual output here._
```

### 10. Diff hygiene

`git diff --check`

```text
_Paste actual output here._
```

External qualification remains S12 `claude-smoke`.

---

> **[IMPLEMENTING AGENT — BEFORE SAVING] Have you filled in every implementation-owned section?**
> Leave review-agent-only sections unchanged.

## Section Ownership

| Section | Owner | Note |
|---------|-------|------|
| Header, Overview, Review Agent Instructions | Fixed at stub creation | Implementing agent must not change finalization metadata |
| Archive Evidence Snapshot | Fixed at stub creation | Read only cited prior evidence when needed |
| Implementation Item Completion and Checklist text/order | Fixed at stub creation | Implementing agent changes only `[ ]` to `[x]` |
| Review-Only Checklist | Review agent | Implementing agent must not modify it |
| Deviations, Key Design Decisions | Implementing agent | Replace placeholders with actual evidence |
| Reviewer Checkpoints and verification commands | Fixed at stub creation | Implementing agent fills output only; command changes require a deviation |
| Code Review Result | Review agent appends | Not present in this stub |
