<!-- task=m-iop-hot-path-one-shot-execution/13+12_outer_turn_integration plan=3 tag=REVIEW_REVIEW_API milestone-task=terminal-control -->

# 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/13+12_outer_turn_integration, plan=3, tag=REVIEW_REVIEW_API

## Archive Evidence Snapshot

- `code_review_cloud_G09_2.log` records the current FAIL verdict: one Required finding covering cap-at-tool-terminal continuation ownership and optimistic usage-less budgeting. Fresh targeted handler, package race, vet, and diff commands passed, but a focused real Chat/Messages handler reproducer returned a public `read_file` tool call and then observed `logical request count=0` for both protocols.
- `plan_cloud_G09_2.log` is the superseded cap/compatibility plan. This follow-up is limited to the unclosed Required finding; the `terminal-control` roadmap contribution scope remains unchanged.

## 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_3.log` and `PLAN-cloud-G09.md` → `plan_cloud_G09_3.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/13+12_outer_turn_integration/`. If WARN/FAIL, fully write the next filesystem state required by the code-review skill.
4. If PASS and task group is `m-iop-hot-path-one-shot-execution`, 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 Cap-terminal and frontier ownership | [x] |
| REVIEW_REVIEW_API-2 Protocol handler regression matrix | [x] |

## Implementation Checklist

- [x] [REVIEW_REVIEW_API-1] Preserve one live tool-result frontier when the current stage reaches the caller cap, and use conservative model-independent admission for usage-less stages across direct, artifact, light, and cleanup paths.
- [x] [REVIEW_REVIEW_API-2] Add Chat/Messages handler regressions for cap-at-tool-terminal continuity and usage-less multistage Unicode budgeting, then run the exact fresh race, vet, and diff gates.
- [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_3.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G09_3.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`.
- [x] If PASS, write `complete.log` based on `agent-ops/skills/common/code-review/templates/complete-log-template.md` and leave no active `.md` files.
- [x] If PASS, move active task directory `agent-task/m-iop-hot-path-one-shot-execution/13+12_outer_turn_integration/` to `agent-task/archive/YYYY/MM/m-iop-hot-path-one-shot-execution/13+12_outer_turn_integration/` and update this checklist at the final archive path.
- [x] If PASS and task group is `m-iop-hot-path-one-shot-execution`, preserve and report `milestone-task` metadata for runtime aggregation, without modifying roadmap or directly calling `update-roadmap`.
- [x] 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.
- [ ] If WARN/FAIL, write the next filesystem state matching code-review verdict and do not write `complete.log`.

## Deviations from Plan

The necessary `hot_path_review.go` call site was updated to pass the active request context into exact mapped-tool collection; no review classification or state-transition behavior changed. All four Final Verification commands ran unchanged.

## Key Design Decisions

- Separated next-provider-stage admission from current-terminal ownership. An exhausted turn with no visible tool commits `length`; a visible tool is projected, fingerprinted, registered, and rendered with the protocol-native tool terminal before any logical-request cleanup.
- Added a tokenizer-independent consumed-output upper bound based on UTF-8 bytes across visible content, reasoning, tool names, and serialized arguments. Provider-reported output usage is combined with this bound by taking the larger value, so reported usage can tighten but never loosen admission.
- Retained the existing four-runes-per-token public truncation ceiling for compatibility while keeping truncation UTF-8 safe. The stricter byte upper bound controls whether another provider stage may be submitted.
- Kept every outer turn request-local. A correlated tool continuation starts with its own caller cap, while the exhausted prior turn retains only the expected-result frontier required to accept that continuation once.
- Collected mapped light-stage tools, artifact tools, and cleanup tools in their exact caller-visible name/argument form before projection and registration. Artifact and cleanup pending hashes and counts are asserted against the coordinator frontier.

## Reviewer Checkpoints

- Confirm a tool emitted at caller-cap exhaustion is rendered with one stable public id and leaves exactly one live expected-result frontier for both Chat and Messages.
- Confirm the correlated continuation is accepted exactly once and cannot redispatch or reuse the terminal tool result.
- Confirm content/reasoning exhaustion without a tool continuation commits one endpoint-native `length` terminal and prevents all later provider acquisition/submission.
- Confirm usage-less Unicode across content, reasoning, tool name, and serialized arguments uses a model-independent conservative bound that never over-admits a later internal stage.
- Confirm direct, artifact, light, and cleanup paths fingerprint/register the same public tool output they render and never expose a dead tool id.
- Confirm exact provider submission counts, package race safety, vet, and diff checks remain clean.

## Verification Results

### Targeted cap-terminal handlers

Command: `go test -race -count=1 ./apps/edge/internal/openai -run 'TestHotPath(OuterTurnIntegration|OuterTurnCompatibility|OuterTurnCap|Direct|Light|Cleanup)'`

Exit status: 0

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

### Package race regression

Command: `go test -race -count=1 ./packages/go/streamgate ./packages/go/config ./apps/edge/internal/openai ./apps/edge/internal/service`

Exit status: 0

```text
ok  	iop/packages/go/streamgate	2.129s
ok  	iop/packages/go/config	1.741s
ok  	iop/apps/edge/internal/openai	11.634s
ok  	iop/apps/edge/internal/service	7.018s
```

### Edge vet

Command: `go vet ./apps/edge/...`

Exit status: 0

```text
(no output)
```

### Diff

Command: `git diff --check`

Exit status: 0

```text
(no output)
```

---

> **[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: PASS
- Dimension Assessment:
  - Correctness: Pass
  - Completeness: Pass
  - Test coverage: Pass
  - API contract: Pass
  - Code quality: Pass
  - Implementation deviation: Pass
  - Verification trust: Pass
  - Spec conformance: Pass
- Findings: None
- Routing Signals: `review_rework_count=2`, `evidence_integrity_failure=false`
- Next Step: Archive the active pair, write `complete.log`, and move the completed task artifacts to the monthly archive while preserving `milestone-task=terminal-control` for runtime aggregation.
