<!-- task=m-iop-hot-path-one-shot-execution/06+04,05_request_identity_ingress plan=1 tag=REVIEW_API milestone-task=request-identity -->

# 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-08-03
task=m-iop-hot-path-one-shot-execution/06+04,05_request_identity_ingress, plan=1, tag=REVIEW_API

## Archive Evidence Snapshot

- Current pair: `agent-task/m-iop-hot-path-one-shot-execution/06+04,05_request_identity_ingress/PLAN-local-G07.md` and `agent-task/m-iop-hot-path-one-shot-execution/06+04,05_request_identity_ingress/CODE_REVIEW-cloud-G07.md`.
- Predicted archives: `plan_local_G07_0.log` and `code_review_cloud_G07_0.log`; verdict `FAIL`, Required=3, Suggested=0, Nit=0.
- Required findings: add a trusted per-turn call id; prevent preset count-tokens from creating execution state; add cross-owner and tool-schema mutation zero-dispatch endpoint evidence.
- Fresh evidence: focused preset identity race, common race, vet, and diff checks passed; full `./apps/edge/...` passed with an executable `/config` TMPDIR after the host `/tmp` noexec failure was isolated.
- Roadmap carryover: preserve `milestone-task=request-identity`; approved SDD S05 and its request-identity Evidence Map remain the acceptance source.

## 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_1.log` and `PLAN-cloud-G08.md` → `plan_cloud_G08_1.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/06+04,05_request_identity_ingress/`. 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_API-1 Complete per-turn identity and rejection evidence | [x] |
| REVIEW_API-2 Isolate Anthropic count-tokens from execution state | [x] |

## Implementation Checklist

- [x] Attach trusted request/call/stage identity to preset Chat and Messages turns and prove cross-owner/tool-schema rejection dispatches nothing.
- [x] Keep preset Anthropic count-tokens outside the logical execution coordinator and prove operation isolation.
- [x] Run dependency, focused, race, full Edge, vet, and diff verification exactly as written.
- [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_1.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G08_1.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/06+04,05_request_identity_ingress/` to `agent-task/archive/YYYY/MM/m-iop-hot-path-one-shot-execution/06+04,05_request_identity_ingress/` and update this checklist at the final archive path.
- [x] 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`.
- [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

- None affecting scope, files, or verification commands. All four accepted ingress branches and the Anthropic operation gate were changed exactly as the plan `Before`/`After` blocks specify.
- Implementation detail within the plan's stated test strategy: the two new rejection cases (`cross-owner waiting record`, `tool-schema mutation`) were added as `t.Run` focused subtests inside `TestPresetRequestIdentityRejectionCases`, matching the plan's "Add focused subtests" wording. Per-turn identity is asserted by reading the fake pool dispatch metadata (`poolLastRunSnapshot().Metadata`); the turn tests additionally assert each HTTP turn receives a fresh stage id (stronger than, and consistent with, the required non-empty stage-id assertion). No verification command was changed.

## Key Design Decisions

- REVIEW_API-1: a fresh call id is allocated once per accepted preset ingress turn using the existing `logicalRequestCoordinator.newCallID` and attached as `iop_call_id` alongside `iop_logical_request_id` and `iop_stage_id` on all four accepted branches (Chat begin/continuation, Anthropic begin/continuation). Because these keys are written after `resolveCallerIdentity`/`joinPreset*Ingress`, any caller-supplied internal identity value is overwritten; the logical request id stays stable across a continuation while the call id differs per HTTP turn. Coordinator transition semantics were not touched.
- REVIEW_API-2: preset coordinator joining in `anthropicPoolRequest` is now gated by `dispatch.IsPreset && operation == config.OperationMessages`, so a native count-tokens fallback no longer allocates a logical request or active stage. Candidate selection, body rewrite, and header behavior for count-tokens are unchanged; the local `TokenCounter` fast path is untouched.
- Evidence is deterministic and provider-free: the seeded cross-owner case uses a foreign-owner waiting record whose frontier the current Edge cannot resume (owner mismatch); the tool-schema case resumes with a changed `tools` digest (lineage mismatch); the count-tokens case asserts zero coordinator records and absent request/call/stage metadata on the dispatched pool request. All rejection cases assert the provider submission count does not increase.

## Reviewer Checkpoints

- Every accepted preset Chat/Messages turn carries server-issued request, call, and stage ids; caller metadata cannot choose them.
- A logical request id is stable across its continuation while each inbound HTTP turn receives a distinct call id.
- Cross-owner and tool-schema mutation continuations return endpoint-standard errors before provider submission.
- Anthropic count-tokens never creates or resumes logical execution state and carries no request/call/stage identity.
- Legacy/provider-only routes keep their coordinator bypass.

## Verification Results

### REVIEW_API-1 focused verification

```bash
go test -count=1 ./apps/edge/internal/openai -run 'TestPresetRequestIdentity'
```

Actual stdout/stderr:

```
ok  	iop/apps/edge/internal/openai	0.307s
```

Verbose subtest run confirming the new cases execute:

```
=== RUN   TestPresetRequestIdentityAcrossChatTurns
--- PASS: TestPresetRequestIdentityAcrossChatTurns (0.02s)
=== RUN   TestPresetRequestIdentityAcrossAnthropicTurns
--- PASS: TestPresetRequestIdentityAcrossAnthropicTurns (0.01s)
=== RUN   TestPresetRequestIdentityRejectionCases
=== RUN   TestPresetRequestIdentityRejectionCases/cross-owner_waiting_record
=== RUN   TestPresetRequestIdentityRejectionCases/tool-schema_mutation
--- PASS: TestPresetRequestIdentityRejectionCases (0.00s)
=== RUN   TestPresetRequestIdentityAnthropicCountTokensBypassesCoordinator
--- PASS: TestPresetRequestIdentityAnthropicCountTokensBypassesCoordinator (0.00s)
PASS
ok  	iop/apps/edge/internal/openai	0.210s
```

### REVIEW_API-2 count-tokens isolation verification

```bash
go test -count=1 ./apps/edge/internal/openai -run 'TestPresetRequestIdentityAnthropicCountTokensBypassesCoordinator'
```

Actual stdout/stderr:

```
=== RUN   TestPresetRequestIdentityAnthropicCountTokensBypassesCoordinator
--- PASS: TestPresetRequestIdentityAnthropicCountTokensBypassesCoordinator (0.00s)
PASS
ok  	iop/apps/edge/internal/openai	0.089s
```

### Final verification

```bash
test -f agent-task/m-iop-hot-path-one-shot-execution/04+02,03_preset_model_authorization/complete.log || test -f agent-task/archive/2026/08/m-iop-hot-path-one-shot-execution/04+02,03_preset_model_authorization/complete.log
test -f agent-task/m-iop-hot-path-one-shot-execution/05+02,04_request_coordinator/complete.log || test -f agent-task/archive/2026/08/m-iop-hot-path-one-shot-execution/05+02,04_request_coordinator/complete.log
go test -count=1 ./apps/edge/internal/openai -run 'TestPresetRequestIdentity'
go test -race -count=1 ./apps/edge/internal/openai -run 'TestPresetRequestIdentity'
go test -race -count=1 ./packages/go/streamgate ./apps/edge/internal/openai ./apps/edge/internal/service
mkdir -p /config/.tmp-iop-request-identity
TMPDIR=/config/.tmp-iop-request-identity go test -count=1 ./apps/edge/...
rmdir /config/.tmp-iop-request-identity
go vet ./apps/edge/...
git diff --check
```

Actual stdout/stderr (environment: `/config/.local/bin/go`, `go version go1.26.2 linux/arm64`, `GOROOT=/config/opt/go`; host `/tmp` is noexec so the full Edge suite used an executable `TMPDIR` under `/config`):

```
dep04 exit=0
dep05 exit=0
ok  	iop/apps/edge/internal/openai	0.117s
focused exit=0
ok  	iop/apps/edge/internal/openai	1.108s
focused-race exit=0
ok  	iop/packages/go/streamgate	2.090s
ok  	iop/apps/edge/internal/openai	8.919s
ok  	iop/apps/edge/internal/service	7.000s
race-multi exit=0
ok  	iop/apps/edge/cmd/edge	1.162s
ok  	iop/apps/edge/internal/authprojection	0.093s
ok  	iop/apps/edge/internal/bootstrap	8.208s
ok  	iop/apps/edge/internal/configrefresh	0.928s
ok  	iop/apps/edge/internal/controlplane	6.755s
ok  	iop/apps/edge/internal/edgecmd	0.458s
ok  	iop/apps/edge/internal/edgevalidate	0.127s
ok  	iop/apps/edge/internal/events	0.084s
ok  	iop/apps/edge/internal/input	0.185s
ok  	iop/apps/edge/internal/input/a2a	0.137s
ok  	iop/apps/edge/internal/node	0.135s
ok  	iop/apps/edge/internal/openai	7.700s
ok  	iop/apps/edge/internal/opsconsole	0.170s
ok  	iop/apps/edge/internal/service	6.091s
ok  	iop/apps/edge/internal/transport	5.131s
fulledge exit=0
rmdir exit=0
vet exit=0
diffcheck exit=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) |
| 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 — all four accepted preset Chat/Messages branches attach trusted request, call, and stage identity, and count-tokens no longer enters the execution coordinator.
  - Completeness: Pass — all implementation and integrated verification items are complete, including the three inherited Required findings.
  - Test Coverage: Pass — focused handler evidence covers stable request identity, fresh per-turn call/stage identity, cross-owner and tool-schema zero-dispatch rejection, and count-tokens state isolation.
  - API Contract: Pass — Messages execution and count-tokens preserve their distinct Anthropic operation semantics and endpoint-standard rejection behavior.
  - Code Quality: Pass — the changes are localized, formatted, free of stale debug/TODO residue, and pass Edge vet.
  - Implementation Deviation: Pass — the implementation matches the follow-up plan; the focused subtest organization is consistent with its stated test strategy.
  - Verification Trust: Pass — fresh reviewer runs reproduced the focused, race, full Edge, vet, formatting, and diff results.
  - Spec Conformance: Pass — the implementation and aggregate predecessor evidence satisfy SDD S05 identity, owner/affinity, lineage/toolset, frontier, mapping, and race requirements for `request-identity`.
- **Findings:** None.
- **Routing Signals:**
  - `review_rework_count=1`
  - `evidence_integrity_failure=false`
- **Next Step:** PASS — write `complete.log`, archive this pair and task directory, and report milestone completion metadata for runtime aggregation.
