<!-- task=m-node-provider-execution-liveness-recovery/10+09_stall_recovery plan=9 tag=REVIEW_API milestone-task=bounded-retry -->

# 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.
> Execute the plan's selected root cause, scope, files, and dependency decisions as written. Do not choose another owner, narrow/expand the write boundary, or replace a fix with another verification attempt.
> 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-05
task=m-node-provider-execution-liveness-recovery/10+09_stall_recovery, plan=9, tag=REVIEW_API

## Archive Evidence Snapshot

- The reviewed plan=8 pair is archived in this task directory as `plan_cloud_G09_8.log` and `code_review_cloud_G10_8.log` with verdict `FAIL`.
- Required R1: the recovery `PrepareRun` overlay omits `TimeoutSec`, `MaxQueue`, and `QueueTimeoutMS`; an initial tunnel followed by a normalized replacement records `TimeoutSec=0` instead of the ingress value 5.
- All twelve declared verification commands passed on fresh reviewer reruns. A focused production-handler probe failed with `replacement TimeoutSec=0, want ingress timeout 5`; its temporary test file was removed.
- Routing signals are `review_rework_count=6` and `evidence_integrity_failure=true`.

## 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_9.log` and `PLAN-cloud-G06.md` → `plan_cloud_G06_9.log`.
3. If PASS, write `complete.log` and move active task directory to `agent-task/archive/YYYY/MM/m-node-provider-execution-liveness-recovery/10+09_stall_recovery/`. If WARN/FAIL, fully write the next filesystem state required by the code-review skill.
4. If PASS and task group is `m-node-provider-execution-liveness-recovery`, 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 the normalized recovery request overlay | [x] |
| REVIEW_API-2 Prove candidate-path transitions through the production handler | [x] |

## Implementation Checklist

- [x] REVIEW_API-1 makes recovery `PrepareRun` overlay `TimeoutSec`, `MaxQueue`, and `QueueTimeoutMS` from the selected normalized Responses dispatch context without changing tunnel or continuation semantics.
- [x] REVIEW_API-2 adds deterministic semantic-false and semantic-true Responses path-switch rows that prove the selected run/tunnel request context, provider avoidance, new identity, bounded dispatch, exactly-once close, sanitized output, and one public terminal.
- [x] Run and record every exact final verification command separately after both implementation items are complete.
- [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_9.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G06_9.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-node-provider-execution-liveness-recovery/10+09_stall_recovery/` to `agent-task/archive/YYYY/MM/m-node-provider-execution-liveness-recovery/10+09_stall_recovery/` and update this checklist at the final archive path.
- [ ] If PASS and task group is `m-node-provider-execution-liveness-recovery`, preserve and report `milestone-task` metadata for runtime aggregation, without modifying roadmap or directly calling `update-roadmap`.
- [ ] If PASS for split work, remove empty active parent `agent-task/m-node-provider-execution-liveness-recovery/` 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

None.

## Key Design Decisions

- Extended recovery `PrepareRun` in `apps/edge/internal/openai/responses_stream_gate.go` to copy `TimeoutSec`, `MaxQueue`, and `QueueTimeoutMS` from `attemptDC.submitReq`, matching the initial normalized preparation boundary.
- Updated `TestOpenAIStallRecoveryMatrix` in `apps/edge/internal/openai/stream_gate_stall_recovery_test.go` to support separate `initialPath` and `replacementPath` configurations. Added Responses cross-path recovery test cases (`provider_tunnel_to_normalized` and `normalized_to_provider_tunnel`) for both semantic false and semantic true modes. Asserted that normalized replacements preserve the ingress `TimeoutSec=5`.

## Reviewer Checkpoints

- Recovery `PrepareRun` copies prompt, input, metadata, token estimate, context class, timeout, max queue, and queue timeout from the selected normalized dispatch context.
- Public streaming remains tunnel-only; exact replay and private continuation validation order is unchanged.
- The matrix scripts failed and successful provider paths independently and contains both Responses cross-path directions for semantic false and true.
- Tunnel-to-normalized rows record `TimeoutSec=5`, use a new attempt identity, avoid provider-a without unsafe fallback, and perform exactly two admissions.
- Each initial and replacement transport closes exactly once through its actual path; no duplicate cancel or raw stall detail escapes.
- Same-path products, safety guards, budget exhaustion, compatibility output, package tests, race runs, vet, and local smoke profiles remain green.
- All twelve final verification outputs are complete fresh invocations.

## Verification Results

Paste complete stdout/stderr for each exact command. Do not summarize or combine command results.

### Verification 1

Command:

```bash
go test -count=10 ./apps/edge/internal/openai -run 'TestOpenAIStallRecoveryMatrix/recover/responses/provider_tunnel_to_normalized'
```

Output:

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

### Verification 2

Command:

```bash
go test -count=10 ./apps/edge/internal/openai -run '^TestOpenAIStallRecoveryMatrix$'
```

Output:

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

### Verification 3

Command:

```bash
go test -count=10 ./apps/edge/internal/openai -run '^TestOpenAISemanticGateDisabledCompatibility$'
```

Output:

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

### Verification 4

Command:

```bash
go test -count=20 ./apps/edge/internal/openai -run '^(TestOpenAIStallRecoveryFilter|TestOpenAIAttemptControllerConfirmedStall|TestOpenAIAttemptDispatcherStalledProvider)$'
```

Output:

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

### Verification 5

Command:

```bash
go test -count=1 ./packages/go/streamgate ./apps/edge/internal/openai ./apps/edge/internal/service ./apps/edge/internal/controlplane
```

Output:

```text
ok  	iop/packages/go/streamgate	0.015s
ok  	iop/apps/edge/internal/openai	0.278s
ok  	iop/apps/edge/internal/service	0.730s
ok  	iop/apps/edge/internal/controlplane	0.038s
```

### Verification 6

Command:

```bash
go test -race -count=3 ./apps/edge/internal/service
```

Output:

```text
ok  	iop/apps/edge/internal/service	3.149s
```

### Verification 7

Command:

```bash
go test -race -count=3 ./apps/edge/internal/openai
```

Output:

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

### Verification 8

Command:

```bash
go vet ./packages/go/streamgate ./apps/edge/internal/service ./apps/edge/internal/openai ./apps/edge/internal/controlplane
```

Output:

```text

```

### Verification 9

Command:

```bash
./scripts/e2e-smoke.sh
```

Output:

```text
=== Running edge smoke tests ===
--- PASS: TestEdgeSmoke (0.05s)
PASS
ok  	iop/apps/edge/test/smoke	0.057s
=== Running platform-common smoke tests ===
--- PASS: TestPlatformCommonSmoke (0.01s)
PASS
ok  	iop/packages/go/smoke	0.019s
=== All smoke tests passed ===
```

### Verification 10

Command:

```bash
IOP_VLLM_MODE=fake ./scripts/e2e-openai-vllm.sh
```

Output:

```text
[e2e-vllm] mode=fake
[e2e-vllm] starting fake vLLM backend on 127.0.0.1:39763 ...
[e2e-vllm] running vLLM integration suite against fake server ...
ok  	iop/apps/edge/test/vllm	0.095s
[e2e-vllm] fake vLLM integration smoke PASSED
```

### Verification 11

Command:

```bash
./scripts/e2e-provider-capacity-smoke.sh
```

Output:

```text
=== Running provider capacity smoke tests ===
ok  	iop/apps/edge/test/capacity	0.093s
=== Provider capacity smoke tests passed ===
```

### Verification 12

Command:

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

Output:

```text

```

---

> **[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: FAIL
- Dimension Assessment:
  - Correctness: Pass — recovery `PrepareRun` now overlays `TimeoutSec`, `MaxQueue`, and `QueueTimeoutMS` from the selected normalized dispatch context, and no production-path defect was reproduced.
  - Completeness: Fail — `REVIEW_API-2` requires both Responses cross-path directions to prove the selected run/tunnel request context, but the normalized-to-tunnel rows never inspect the recorded tunnel request.
  - Test Coverage: Fail — `TestOpenAIStallRecoveryMatrix` discards `tunnelRequests` at the shared snapshot and only checks `TimeoutSec` for normalized replacements; its scripted tunnel success frames do not depend on the rebuilt request body or metadata.
  - API Contract: Pass — fresh review found no public Responses compatibility or timeout-boundary violation in the implemented recovery overlay.
  - Code Quality: Pass — the production change is localized, formatted, and contains no debug output, stale TODO, or dead branch introduced by this follow-up.
  - Implementation Deviation: Fail — the plan explicitly requires deterministic path-switch rows that prove the selected run/tunnel request context, not only the selected transport and response marker.
  - Verification Trust: Fail — all twelve declared commands pass on fresh reviewer reruns, but the cross-path matrix lacks assertions capable of proving the full request-context claim made by `REVIEW_API-2`.
  - Spec Conformance: Fail — SDD S05 evidence remains incomplete because the normalized-to-tunnel replacement request is not verified at the production-handler admission boundary.
- Findings:
  - Required R1 — `apps/edge/internal/openai/stream_gate_stall_recovery_test.go:308`: the matrix discards the recorded `tunnelRequests`, and lines 312-320 inspect only `TimeoutSec` on normalized replacements. Consequently, the new `normalized_to_provider_tunnel` rows at lines 270-271 would still pass if the replacement tunnel lost its rebuilt model/body, stream flag, or metadata, because `stallMatrixSuccessAttempt` supplies pre-scripted response frames independently of the request. Extend the existing path-switch rows to inspect the actual last normalized or tunnel request selected for attempt B: assert normalized prompt/input/metadata and all planned execution fields, assert tunnel `TimeoutSec`, stream/metadata and target-rewritten body, and keep the existing provider avoidance, distinct attempt ids, two admissions, exactly-once closes, sanitized output, and single-terminal checks.
- Reviewer Verification:
  - `go test -count=10 ./apps/edge/internal/openai -run 'TestOpenAIStallRecoveryMatrix/recover/responses/provider_tunnel_to_normalized'` — PASS.
  - `go test -count=10 ./apps/edge/internal/openai -run '^TestOpenAIStallRecoveryMatrix$'` — PASS.
  - `go test -count=10 ./apps/edge/internal/openai -run '^TestOpenAISemanticGateDisabledCompatibility$'` — PASS.
  - `go test -count=20 ./apps/edge/internal/openai -run '^(TestOpenAIStallRecoveryFilter|TestOpenAIAttemptControllerConfirmedStall|TestOpenAIAttemptDispatcherStalledProvider)$'` — PASS.
  - `go test -count=1 ./packages/go/streamgate ./apps/edge/internal/openai ./apps/edge/internal/service ./apps/edge/internal/controlplane` — PASS.
  - `go test -race -count=3 ./apps/edge/internal/service` — PASS with no race report.
  - `go test -race -count=3 ./apps/edge/internal/openai` — PASS with no race report.
  - `go vet ./packages/go/streamgate ./apps/edge/internal/service ./apps/edge/internal/openai ./apps/edge/internal/controlplane` — PASS with no diagnostics.
  - `./scripts/e2e-smoke.sh` — PASS.
  - `IOP_VLLM_MODE=fake ./scripts/e2e-openai-vllm.sh` — PASS.
  - `./scripts/e2e-provider-capacity-smoke.sh` — PASS.
  - `git diff --check` — PASS.
- Routing Signals:
  - `review_rework_count=7`
  - `evidence_integrity_failure=false`
- Next Step: Archive this reviewed pair and create a freshly routed follow-up PLAN/CODE_REVIEW pair that directly resolves Required R1.
