<!-- task=m-multi-provider-protocol-profile-native-messages/03+02_responses_profile plan=2 tag=API -->

# Code Review Reference - 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-01
task=m-multi-provider-protocol-profile-native-messages/03+02_responses_profile, plan=2, tag=API

## Archive Evidence Snapshot

- Current loop archives after review finalization: `agent-task/m-multi-provider-protocol-profile-native-messages/03+02_responses_profile/plan_local_G04_02.log` and `agent-task/m-multi-provider-protocol-profile-native-messages/03+02_responses_profile/code_review_cloud_G04_02.log`.
- Verdict: FAIL. Required: 2; Suggested: 0; Nit: 0.
- Required finding 1: `apps/edge/internal/openai/responses_protocol_profile_test.go` asserted a preparer-only 502 because `providerFakeRunService` skipped `providerOperationCandidatePredicate`; production rejected earlier with `ErrProviderPoolCandidateRejected` and the unrelated output-validation 400 message.
- Required finding 2: the recorded default `go test -count=1` commands were not reproducible because the configured `GOCACHE` was inaccessible. Reviewer-owned executable `GOTMPDIR` and writable `GOCACHE` overrides passed the focused Responses suite, service operation tests, Node profile tests, full Edge tests, Edge vet, and `git diff --check`.
- Affected production/test files: `apps/edge/internal/service/provider_pool.go`, `apps/edge/internal/service/protocol_profile_test.go`, `apps/edge/internal/openai/responses_handler.go`, `apps/edge/internal/openai/provider_test_support_test.go`, and `apps/edge/internal/openai/responses_protocol_profile_test.go`.
- The Messages predecessor is satisfied by archived PASS evidence at `agent-task/archive/2026/08/m-multi-provider-protocol-profile-native-messages/02+01_messages_ingress/complete.log`.
- Roadmap carryover: this split child supplies only the Responses profile/runtime portion of S08; the Pi and contract/spec sibling tasks remain responsible for the rest of `responses-regression`, so this plan intentionally has no `Roadmap Targets` section.

## 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-G07.md` → `code_review_cloud_G07_02.log` and `PLAN-cloud-G07.md` → `plan_cloud_G07_02.log`.
3. If PASS, write `complete.log` and move active task directory to `agent-task/archive/YYYY/MM/m-multi-provider-protocol-profile-native-messages/03+02_responses_profile/`. 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 |
|------|---------|
| API-1 | [ ] |
| API-2 | [ ] |
| API-3 | [ ] |

## Implementation Checklist

- [ ] Separate unsupported operation admission from request-local predicate rejection and preserve terminal queue behavior across initial and live re-resolution.
- [ ] Map the typed Responses operation rejection to a sanitized 400 response and make the handler test double mirror production operation admission ordering.
- [ ] Run deterministic fresh focused, broad, full Edge/Node, vet, smoke, and diff verification with explicit executable cache/temp roots.
- [ ] 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_G07_02.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G07_02.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-multi-provider-protocol-profile-native-messages/03+02_responses_profile/` to `agent-task/archive/YYYY/MM/m-multi-provider-protocol-profile-native-messages/03+02_responses_profile/` 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-multi-provider-protocol-profile-native-messages/` 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

_Record any deviations from the plan and the rationale here. The explicit `GOCACHE` and `GOTMPDIR` values are required plan commands, not a deviation; any further command change must be recorded._

## Key Design Decisions

_Record the typed-error shape, ordered operation/request filtering, generic-sentinel compatibility, public error mapping, and test-double ordering actually implemented._

## Reviewer Checkpoints

- Confirm initial all-unsupported and live re-resolution paths return `ProviderPoolOperationUnsupportedError` with operation `responses`, still satisfy `errors.Is(..., ErrProviderPoolCandidateRejected)`, terminate admission, and send no Node request.
- Confirm request-local/output-validation rejection remains distinguishable and retains its existing generic public message.
- Confirm `/v1/responses` maps only the typed operation rejection to HTTP 400, OpenAI `invalid_request_error`, and `no provider profile supports the requested Responses operation`.
- Confirm `providerFakeRunService` applies concrete-profile operation admission before candidate policy, tunnel preparation, request recording, or normalized dispatch, while nil-profile legacy behavior remains admitted.
- Confirm supported explicit-profile, legacy fallback, body/status/stream, provider-auth, and Node operation-over-Path behavior remain unchanged.
- Confirm every recorded Go command includes the deterministic `GOCACHE`/`GOTMPDIR` values, uses `-count=1` for tests, and contains actual stdout/stderr matching a fresh reviewer rerun.
- Confirm no contract/spec, Pi, roadmap, or central `agent-ops` file changed under this follow-up plan.

## Verification Results

### Verification 1 — Archived dependency

~~~bash
test -f agent-task/archive/2026/08/m-multi-provider-protocol-profile-native-messages/02+01_messages_ingress/complete.log
~~~

~~~text
_Paste actual stdout/stderr and exit status here._
~~~

### Verification 2 — Go toolchain

~~~bash
command -v go && go version && go env GOROOT
~~~

~~~text
_Paste actual stdout/stderr and exit status here._
~~~

### Verification 3 — Deterministic cache/temp roots

~~~bash
mkdir -p /config/.cache/iop-responses-profile-g07 /config/workspace/iop-s0/.local/gotmp-responses-profile-g07
~~~

~~~text
_Paste actual stdout/stderr and exit status here._
~~~

### Verification 4 — Service operation admission

~~~bash
env GOCACHE=/config/.cache/iop-responses-profile-g07 GOTMPDIR=/config/workspace/iop-s0/.local/gotmp-responses-profile-g07 go test -count=1 ./apps/edge/internal/service -run 'TestProtocolProfileOperationAdmission'
~~~

~~~text
_Paste actual stdout/stderr and exit status here._
~~~

### Verification 5 — Focused Responses profile suite

~~~bash
env GOCACHE=/config/.cache/iop-responses-profile-g07 GOTMPDIR=/config/workspace/iop-s0/.local/gotmp-responses-profile-g07 go test -count=1 ./apps/edge/internal/openai -run 'TestResponses(ProtocolProfile|LegacyProfileFallback)'
~~~

~~~text
_Paste actual stdout/stderr and exit status here._
~~~

### Verification 6 — Broad Responses and provider-auth suite

~~~bash
env GOCACHE=/config/.cache/iop-responses-profile-g07 GOTMPDIR=/config/workspace/iop-s0/.local/gotmp-responses-profile-g07 go test -count=1 ./apps/edge/internal/openai -run 'TestResponses|Test.*ProviderAuth'
~~~

~~~text
_Paste actual stdout/stderr and exit status here._
~~~

### Verification 7 — Node profile/Responses compatibility

~~~bash
env GOCACHE=/config/.cache/iop-responses-profile-g07 GOTMPDIR=/config/workspace/iop-s0/.local/gotmp-responses-profile-g07 go test -count=1 ./apps/node/internal/adapters/openai_compat -run 'TestProtocolProfile|TestLegacyEndpointPathFallback|TestOpenAICompatTunnelProvider_ResponsesPath'
~~~

~~~text
_Paste actual stdout/stderr and exit status here._
~~~

### Verification 8 — Full Edge suite

~~~bash
env GOCACHE=/config/.cache/iop-responses-profile-g07 GOTMPDIR=/config/workspace/iop-s0/.local/gotmp-responses-profile-g07 go test -count=1 ./apps/edge/...
~~~

~~~text
_Paste actual stdout/stderr and exit status here._
~~~

### Verification 9 — Edge vet

~~~bash
env GOCACHE=/config/.cache/iop-responses-profile-g07 GOTMPDIR=/config/workspace/iop-s0/.local/gotmp-responses-profile-g07 go vet ./apps/edge/...
~~~

~~~text
_Paste actual stdout/stderr and exit status here._
~~~

### Verification 10 — Credential-free Edge/Node/provider smoke

~~~bash
IOP_LEMONADE_MODE=fake IOP_LEMONADE_GOCACHE=/config/.cache/iop-responses-profile-g07 ./scripts/e2e-openai-lemonade.sh
~~~

~~~text
_Paste actual stdout/stderr and exit status here._
~~~

### Verification 11 — Diff validation

~~~bash
git diff --check
~~~

~~~text
_Paste actual stdout/stderr and exit status here._
~~~

---

> **[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 |
| 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 — operation admission still collapses protocol-operation rejection into the generic request-local candidate sentinel, so the required typed rejection and terminal classification are absent.
  - Completeness: Fail — none of API-1, API-2, or API-3 is marked complete, the planned typed error and public mapping are absent, and every implementation-owned evidence section remains unfilled.
  - Test Coverage: Fail — the service suite lacks initial all-unsupported typed-error coverage, live re-resolution asserts only the generic sentinel, and the Responses regression still expects the preparer-only 502 path.
  - API Contract: Fail — `/v1/responses` still maps operation incompatibility to the unrelated output-validation message instead of the required operation-specific 400 contract.
  - Code Quality: Pass — no new code-quality defect was needed to establish this verdict; the blocking issues are missing implementation and evidence.
  - Implementation Deviation: Fail — the active pair contains no implementation notes and the scoped source remains at the pre-follow-up behavior.
  - Verification Trust: Fail — all eleven verification result blocks still contain placeholders, so no current-loop command or output can be trusted or reproduced from the review artifact.
- Findings:
  - Required — `apps/edge/internal/service/provider_pool.go:105`: `SubmitProviderPool` still composes the operation and request-local predicates and returns only `ErrProviderPoolCandidateRejected` at both initial and live re-resolution boundaries. Implement `ProviderPoolOperationUnsupportedError`, apply operation filtering before request-local filtering in both paths, preserve `errors.Is(..., ErrProviderPoolCandidateRejected)`, and add the planned initial/live typed-error and zero-dispatch assertions.
  - Required — `apps/edge/internal/openai/responses_handler.go:466`: the handler still maps every candidate rejection to `openAIStreamGateCandidateRejectedMessage`; `provider_test_support_test.go:202` applies only `AcceptCandidate`, and `responses_protocol_profile_test.go:222` still expects HTTP 502. Apply concrete-profile operation admission first in the fake, map only the typed error to the sanitized operation-specific HTTP 400 response, and update both dedicated and table regressions with exact type/message and zero dispatch assertions.
  - Required — `agent-task/m-multi-provider-protocol-profile-native-messages/03+02_responses_profile/CODE_REVIEW-cloud-G07.md:48`: every implementation item/checklist remains unchecked and every verification output remains `_Paste actual stdout/stderr and exit status here._`. Complete the scoped implementation and record fresh deterministic cache/temp-root commands with actual output for every planned verification.
- Routing Signals:
  - review_rework_count=2
  - evidence_integrity_failure=false
- Next Step: Invoke the plan skill in `prepare-follow-up` mode with these raw findings and current repository evidence, rerun isolated final routing, then materialize the next active PLAN/CODE_REVIEW pair after archiving this pair.
