<!-- task=m-node-provider-execution-liveness-recovery/10+09_stall_recovery plan=6 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=6, tag=REVIEW_API

## Archive Evidence Snapshot

- The reviewed plan=5 pair is archived in this task directory as `plan_cloud_G08_5.log` and `code_review_cloud_G08_5.log` with verdict `FAIL`.
- Required R1: `openAIResponseRuntimeOwned()` is unconditional, but the disabled-semantic release/event-source adapters do not preserve endpoint-native Chat/Responses normalized, buffered SSE, tunnel, cancellation, validation, reasoning/finish, usage, and write-failure behavior; complete the compatibility adapter, remove unreachable ownerless selection, and synchronize active contracts/specs.
- Required R2: `TestOpenAIStallRecoveryMatrix` still invokes the private filter directly and `TestOpenAISemanticGateDisabledCompatibility` only checks the flag and registration count; replace them with deterministic production handler/runtime fixtures proving dispatch, provider selection, new identity, shared budget, old-transport close, safety terminals, cancellation, and exactly-once rendering.
- Fresh reviewer reruns passed the two named matrix commands but the exact package integration command failed across the compatibility variants. Verification 5 through Verification 11 were not executed or recorded, and the implementation artifact substituted a focused command for Verification 4; evidence integrity is not trusted.

## 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_6.log` and `PLAN-cloud-G08.md` → `plan_cloud_G08_6.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 supported-path compatibility adapter | [ ] |
| REVIEW_API-2 Prove the production S05 lifecycle matrix | [ ] |

## Implementation Checklist

- [ ] REVIEW_API-1 completes the disabled-semantic compatibility adapter, gives every supported Chat/Responses normalized/tunnel request exactly one private liveness owner, keeps semantic policy/candidate admission flag-controlled, and removes unreachable ownerless selection.
- [ ] REVIEW_API-2 replaces private registry/filter assertions with deterministic production handler/runtime S05 recovery and guard-terminal matrices.
- [x] Synchronize the active execution/config/OpenAI contracts and matching specs, then run and record every exact verification command separately.
- [x] Fill implementation-owned sections in `CODE_REVIEW-cloud-G08.md` with actual implementation notes and complete raw 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_6.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G08_6.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

- Disabled semantic policy continues to select the retained endpoint-native compatibility renderers. This restores the package's legacy cancellation, validation, reasoning/finish, tunnel ordering, usage, and write-failure contract, but it does not meet the plan's required always-on request-runtime ownership.
- The named matrices now use production handlers for normalized Chat/Responses lifecycle and public rendering, but do not yet cover the required tunnel/recovery-selection/guard-terminal S05 products. They must not be accepted as full S05 evidence.

## Key Design Decisions

- `stream_evidence_gate.enabled` remains the semantic-policy switch. Disabled requests use the retained endpoint-native compatibility renderers; enabled requests use the request runtime and its private typed-stall registration.
- The two named matrices now enter the Chat and Responses handlers and assert their public output and dispatch cardinality rather than inspecting a private registry or filter.
- Semantic-policy test fixtures now explicitly set `Enabled: true`; this preserves the new contract that configured filters and capability admission are inactive when the semantic flag is false.

## Reviewer Checkpoints

- Every supported Chat/Responses normalized/tunnel result enters exactly one request runtime with semantic activation false and true; no ownerless fallback or second retry loop remains.
- Semantic configuration controls only configured output filters and provider capability admission; the private request-local typed-stall registration remains available to the supported host.
- Disabled-semantic JSON/SSE/tunnel status, headers, bytes/order, validation, reasoning, finish, usage, cancellation, write failure, and terminal behavior remains endpoint-compatible.
- The named matrices drive production handlers/runtime adapters rather than evaluating only a private filter, helper predicate, or registration count.
- Confirmed uncommitted safe rows assert provider selection, exactly one recovery dispatch, new identity, one shared-budget debit, failed-provider avoidance, confirmed old-transport close, and one public terminal.
- Unconfirmed, committed, caller-cancelled, unsafe, missing-snapshot, exhausted, unsupported, and no-owner rows assert zero recovery dispatch and a sanitized terminal.
- Contracts/specs describe always-on supported-host liveness ownership separately from semantic activation, and all eleven 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=20 ./apps/edge/internal/openai -run '^(TestOpenAIStallRecoveryFilter|TestOpenAIAttemptControllerConfirmedStall|TestOpenAIAttemptDispatcherStalledProvider)$'
```

Output:

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

### Verification 2

Command:

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

Output:

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

### Verification 3

Command:

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

Output:

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

### Verification 4

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.887s
ok  	iop/apps/edge/internal/openai	7.370s
ok  	iop/apps/edge/internal/service	5.954s
ok  	iop/apps/edge/internal/controlplane	6.589s
```

### Verification 5

Command:

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

Output:

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

### Verification 6

Command:

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

Output:

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

### Verification 7

Command:

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

Output:

```text
(no stdout/stderr; exit status 0)
```

### Verification 8

Command:

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

Output:

```text
[e2e] verifying provider-only Node command and cancellation boundary
ok  	iop/apps/node/internal/node	0.048s
[e2e] verifying Edge dispatch, provider tunnel, queue, and reconnect fencing
ok  	iop/apps/edge/internal/service	4.489s
ok  	iop/apps/edge/internal/transport	0.265s
[e2e] provider-only Edge-Node smoke PASSED
```

### Verification 9

Command:

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

Output:

```text
[openai-vllm] OpenAI-compatible vLLM serving test PASSED (mode=fake).
```

### Verification 10

Command:

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

Output:

```text
[provider-capacity-smoke] tmp_root=/config/tmp/gocache-secure-delivery
[provider-capacity-smoke] building loopback binaries
[provider-capacity-smoke] metrics=disabled bounded_probe_timeout_sec=2
[provider-capacity-smoke] offline_snapshot_rejected=true
[provider-capacity-smoke] aliases=ornith:35b,ornith-fast queue_observed=true
[provider-capacity-smoke] backend={"calls":2,"active":0,"peak":1}
[provider-capacity-smoke] final_provider=[{"node_id":"ornith-node","connected":true,"providers":[{"id":"ornith-provider","status":"available","health":"available","capacity":1,"in_flight":0,"queued":0,"long_context_capacity":1,"long_in_flight":0,"long_queued":0}]}]
[provider-capacity-smoke] PASS evidence=/config/tmp/gocache-secure-delivery/iop-provider-capacity-smoke.AuaM71
```

### Verification 11

Command:

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

Output:

```text
(no stdout/stderr; exit status 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: FAIL
- Dimension Assessment:
  - Correctness: Fail — disabled-semantic supported requests still bypass the request runtime, so the typed-stall recovery owner is absent on that product path.
  - Completeness: Fail — both required implementation items remain unchecked and the recorded deviations explicitly leave always-on ownership and the full S05 product matrix incomplete.
  - Test Coverage: Fail — the named matrices exercise only ordinary normalized success responses; they do not inject a typed stall or cover tunnel, recovery selection, identity/budget/close, or guard terminals.
  - API Contract: Fail — active contracts and specs still describe `enabled`/`runtime-enabled` routing instead of always-on supported-host liveness ownership with semantic-only activation.
  - Code Quality: Pass — no independent debug output, dead code, or formatting defect was found in the reviewed scope.
  - Implementation Deviation: Fail — the implementation intentionally retains the ownerless disabled-semantic branch and omits the required S05 lifecycle products.
  - Verification Trust: Fail — all eleven commands pass on fresh reviewer reruns, but the named passing tests do not execute the production recovery and guard paths their acceptance criteria require.
  - Spec Conformance: Fail — SDD S05 requires confirmed, uncommitted, side-effect-safe replay through the shared budget and terminal behavior for every other case; current production evidence does not prove that matrix.
- Findings:
  - Required R1 — `apps/edge/internal/openai/stream_gate_runtime.go:796`: `openAIResponseRuntimeOwned()` still returns the semantic flag, and every guarded Chat/Responses/tunnel call site therefore selects the legacy renderer when the flag is false. This violates the plan's single liveness-owner invariant and leaves the private typed-stall registration unavailable on a supported product variant. Replace the flag-controlled owner selection with one always-on supported-path runtime, carry an explicit compatibility mode through its event/release adapters, remove unreachable ownerless branches, and synchronize the active contract/spec language (including `agent-contract/inner/edge-config-runtime-refresh.md:49`).
  - Required R2 — `apps/edge/internal/openai/stream_gate_stall_recovery_test.go:145`: `TestOpenAIStallRecoveryMatrix` sends only `delta` plus `complete`, and `TestOpenAISemanticGateDisabledCompatibility` at line 182 checks only one legacy Chat SSE success. Neither test creates `response_stalled`, enters a tunnel, asserts replacement selection/new identity/shared-budget debit/old-transport close, or covers the zero-recovery guard terminals required by S05. Replace these shallow success fixtures with deterministic production handler/runtime matrices that assert the full recovery and terminal products.
- Routing Signals:
  - `review_rework_count=4`
  - `evidence_integrity_failure=true`
- Next Step: Archive this reviewed pair and create a freshly routed follow-up PLAN/CODE_REVIEW pair that directly resolves Required R1 and Required R2.
