<!-- task=m-multi-provider-protocol-profile-native-messages/02+01_messages_ingress plan=3 tag=REVIEW_API -->

# 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-01
task=m-multi-provider-protocol-profile-native-messages/02+01_messages_ingress, plan=3, tag=REVIEW_API

## Roadmap Targets

- Milestone: `agent-roadmap/phase/operational-observability-provider-management/milestones/multi-provider-protocol-profile-native-messages.md`
- Milestone link: [Milestone document](agent-roadmap/phase/operational-observability-provider-management/milestones/multi-provider-protocol-profile-native-messages.md)
- Task ids:
  - `messages-surface`: canonical/alias routes, principal auth, Anthropic model schema, and count-tokens
  - `messages-native`: native Messages raw tunnel preservation
  - `messages-chat-bridge`: Messages-to-Chat semantic and streaming bridge
- Completion mode: check-on-pass

## Archive Evidence Snapshot

- Direct predecessor PASS evidence: `agent-task/archive/2026/08/m-multi-provider-protocol-profile-native-messages/01_protocol_core/complete.log`.
- First plan/review logs: `agent-task/m-multi-provider-protocol-profile-native-messages/02+01_messages_ingress/plan_cloud_G09_01.log` and `agent-task/m-multi-provider-protocol-profile-native-messages/02+01_messages_ingress/code_review_cloud_G09_01.log`.
- Current plan/review archive targets: `agent-task/m-multi-provider-protocol-profile-native-messages/02+01_messages_ingress/plan_cloud_G09_02.log` and `agent-task/m-multi-provider-protocol-profile-native-messages/02+01_messages_ingress/code_review_cloud_G09_02.log`.
- Current verdict: `FAIL`; findings: Required=1, Suggested=0, Nit=0.
- Required finding: `apps/edge/internal/openai/anthropic_stream.go:67-83` continues consuming buffered SSE events after `[DONE]` or an error makes the stream terminal, allowing content after the terminal event.
- Verification evidence: focused surface/native/bridge tests, Edge vet/tests, Node tests, route inspection, diff hygiene, and the isolated fake Lemonade E2E pass; a focused reviewer reproducer fails by showing `message_stop` followed by a `late` content block.
- Roadmap carryover: `messages-surface`, `messages-native`, and `messages-chat-bridge` remain unchecked until this follow-up passes.

## 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-G06.md` → `code_review_cloud_G06_03.log` and `PLAN-cloud-G05.md` → `plan_cloud_G05_03.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/02+01_messages_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>`, 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 |
|------|---------|
| REVIEW_API-1 | [x] |

## Implementation Checklist

- [x] Stop `anthropicBridgeStream.Feed` immediately after the first successful terminal transition and discard buffered post-terminal SSE bytes.
- [x] Add integrated same-frame `[DONE]`/error terminal regressions that include later data and tunnel END, asserting the terminal event is final and emitted once.
- [x] Run the focused bridge, full Edge/Node, vet, fake Lemonade, and diff-hygiene verification commands.
- [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_G06_03.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G05_03.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-multi-provider-protocol-profile-native-messages/02+01_messages_ingress/` to `agent-task/archive/YYYY/MM/m-multi-provider-protocol-profile-native-messages/02+01_messages_ingress/` and update this checklist at the final archive path.
- [x] If PASS and task group is `m-<milestone-slug>`, report completion event metadata for runtime, without modifying roadmap or directly calling `update-roadmap`.
- [x] 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.
- [ ] If WARN/FAIL, write the next filesystem state matching code-review verdict and do not write `complete.log`.

## Deviations from Plan

None.

## Key Design Decisions

Checked `stream.stopped` after consuming each SSE event in `anthropicBridgeStream.Feed`. If true, cleared `pendingSSE` to discard remaining buffered bytes in the frame and returned `nil` early, ensuring no content deltas or blocks are emitted after `message_stop` or `error`.

## Reviewer Checkpoints

- Confirm `Feed` returns and clears pending bytes as soon as any consumed SSE event successfully transitions the stream to `stopped`.
- Confirm same-frame `[DONE]` and upstream-error cases ignore later data and remain idempotent when tunnel END follows.
- Confirm the regression asserts that the terminal is the final emitted event and occurs once, not only that the late text value is absent.
- Confirm the change does not alter native Messages relay, ordinary bridge event ordering, tool reconstruction, or non-stream responses.
- Reproduce the focused test and the complete verification set with fresh Go results.

## Verification Results

> **Implementation owner:** Run each command exactly as written and paste actual stdout/stderr plus exit status. If a command must change, record the replacement and reason in `Deviations from Plan` first.

### Verification 1

```bash
mkdir -p /config/.cache/iop-g09-followup/cache /config/workspace/iop-s0/.local/gotmp-g09-followup
```

```text
exit status: 0
stdout:

stderr:

```

### Verification 2

```bash
GOCACHE=/config/.cache/iop-g09-followup/cache GOTMPDIR=/config/workspace/iop-s0/.local/gotmp-g09-followup /config/.local/bin/go test -count=1 ./apps/edge/internal/openai -run 'TestAnthropicChatBridge(StreamFragmentationOrderAndTerminal|StreamStopsAtTerminalWithinFrame)$'
```

```text
exit status: 0
stdout:
ok  	iop/apps/edge/internal/openai	0.039s
stderr:

```

### Verification 3

```bash
GOCACHE=/config/.cache/iop-g09-followup/cache GOTMPDIR=/config/workspace/iop-s0/.local/gotmp-g09-followup /config/.local/bin/go test -count=1 ./apps/edge/internal/openai -run 'TestAnthropicChatBridge'
```

```text
exit status: 0
stdout:
ok  	iop/apps/edge/internal/openai	0.043s
stderr:

```

### Verification 4

```bash
GOCACHE=/config/.cache/iop-g09-followup/cache GOTMPDIR=/config/workspace/iop-s0/.local/gotmp-g09-followup /config/.local/bin/go vet ./apps/edge/...
```

```text
exit status: 0
stdout:

stderr:

```

### Verification 5

```bash
GOCACHE=/config/.cache/iop-g09-followup/cache GOTMPDIR=/config/workspace/iop-s0/.local/gotmp-g09-followup /config/.local/bin/go test -count=1 ./apps/edge/...
```

```text
exit status: 0
stdout:
ok  	iop/apps/edge/cmd/edge	1.079s
ok  	iop/apps/edge/internal/bootstrap	19.435s
ok  	iop/apps/edge/internal/configrefresh	0.827s
ok  	iop/apps/edge/internal/controlplane	4.578s
ok  	iop/apps/edge/internal/edgecmd	0.385s
ok  	iop/apps/edge/internal/edgevalidate	0.090s
ok  	iop/apps/edge/internal/events	0.061s
ok  	iop/apps/edge/internal/input	0.119s
ok  	iop/apps/edge/internal/input/a2a	0.094s
ok  	iop/apps/edge/internal/node	0.084s
ok  	iop/apps/edge/internal/openai	7.628s
ok  	iop/apps/edge/internal/opsconsole	0.100s
ok  	iop/apps/edge/internal/service	5.974s
ok  	iop/apps/edge/internal/transport	4.832s
stderr:

```

### Verification 6

```bash
GOCACHE=/config/.cache/iop-g09-followup/cache GOTMPDIR=/config/workspace/iop-s0/.local/gotmp-g09-followup /config/.local/bin/go test -count=1 ./apps/node/...
```

```text
exit status: 0
stdout:
ok  	iop/apps/node/cmd/node	0.192s
ok  	iop/apps/node/internal/adapters	0.148s
?   	iop/apps/node/internal/adapters/mock	[no test files]
ok  	iop/apps/node/internal/adapters/ollama	0.067s
ok  	iop/apps/node/internal/adapters/openai_compat	0.197s
ok  	iop/apps/node/internal/adapters/vllm	0.169s
ok  	iop/apps/node/internal/bootstrap	1.610s
ok  	iop/apps/node/internal/node	0.874s
ok  	iop/apps/node/internal/router	0.513s
ok  	iop/apps/node/internal/store	0.087s
ok  	iop/apps/node/internal/transport	5.579s
stderr:

```

### Verification 7

```bash
IOP_LEMONADE_MODE=fake ./scripts/e2e-openai-lemonade.sh
```

```text
exit status: 0
stdout:
[openai-lemonade] OpenAI-compatible Lemonade serving test PASSED (mode=fake).
stderr:

```

### Verification 8

```bash
git diff --check
```

```text
exit status: 0
stdout:

stderr:

```

---

> **[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: PASS
- Dimension Assessment:
  - Correctness: Pass — `anthropicBridgeStream.Feed` stops immediately after a successful terminal transition, clears buffered post-terminal bytes, and preserves the entry-time no-op for later frames.
  - Completeness: Pass — the scoped production fix, integrated `[DONE]` and upstream-error regressions, implementation evidence, and required verification are complete.
  - Test Coverage: Pass — the HTTP/tunnel-path regression asserts the full event sequence, no late content, final terminal identity, and exactly-once terminal behavior through a later tunnel END.
  - API Contract: Pass — translated streams now preserve the required Anthropic ordering and never emit a successor after `message_stop` or `error`.
  - Code Quality: Pass — the fix is request-local and minimal, and the scoped files contain no debug output, dead code, or unresolved TODOs.
  - Implementation Deviation: Pass — no deviation from the follow-up plan was recorded or observed.
  - Verification Trust: Pass — the focused bridge tests, Edge vet and tests, Node tests, fake Lemonade E2E, and diff-hygiene check were reproduced with exit status 0.
  - Spec Conformance: Pass — SDD scenario S07 and the `response/terminal` no-successor state are satisfied by the implementation and regression evidence.
- Findings: None.
- Routing Signals:
  - `review_rework_count=2`
  - `evidence_integrity_failure=false`
- Next Step: Write `complete.log`, archive the active plan/review pair and task directory, and report milestone completion event metadata to the runtime without modifying the roadmap.
