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

## Archive Evidence Snapshot

- The reviewed plan=3 pair is archived in this task directory as `plan_cloud_G08_3.log` and `code_review_cloud_G08_3.log` with verdict `FAIL`.
- Required R1: supported OpenAI Chat/Responses normalized and tunnel requests bypass the private liveness owner when `stream_evidence_gate.enabled=false`; semantic filter enablement and liveness runtime ownership must be separated without changing normal disabled-semantic wire behavior.
- Required R2: `stream_gate_stall_recovery_test.go` contains only mapper/filter units, not the S05 lifecycle matrix, and the implementation artifact's combined race output recorded only the service package line.
- Fresh reviewer evidence passed the focused stall tests, relevant non-race packages, vet, `git diff --check`, and an independently rerun OpenAI race command; those passes validate the implemented subset but do not close R1 or R2.

## 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_4.log` and `PLAN-cloud-G08.md` → `plan_cloud_G08_4.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 Separate semantic activation from liveness runtime ownership | [ ] |
| REVIEW_API-2 Prove the S05 lifecycle matrix and restore evidence trust | [ ] |

## Implementation Checklist

- [ ] REVIEW_API-1 gives every supported OpenAI Chat/Responses normalized and tunnel request exactly one private typed-stall recovery owner independent of semantic gate enablement, while the flag and configured filters alone control semantic filter registration, evidence policy, and capability admission and disabled-semantic non-stall behavior remains wire-compatible.
- [ ] REVIEW_API-2 adds deterministic full-lifecycle tests for the S05 endpoint/path/config matrix, alternate and same-provider selection, every unsafe/no-owner terminal row, shared-budget/new-identity/exactly-once invariants, and disabled-semantic compatibility; all exact verification output is recorded completely.
- [ ] Synchronize the active execution/config/OpenAI contracts and matching specs so they state always-on supported-path liveness ownership and semantic-only flag behavior without claiming unsupported surfaces recover.
- [ ] Fill implementation-owned sections in `CODE_REVIEW-cloud-G08.md` with actual implementation notes, deviations, design decisions, and complete raw command 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_4.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G08_4.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

The always-on response-runtime conversion was not retained. With the semantic
flag disabled, routing every supported Chat/Responses path through the current
runtime regressed existing endpoint-native behavior (cancellation, strict/tool
rendering, reasoning/finish rendering, tunnel error ordering, and write-failure
handling). The direct conversion was reverted to preserve the current public
contract. Consequently REVIEW_API-1 and the full S05 handler lifecycle matrix
remain incomplete and require a compatibility-capable runtime/release-adapter
implementation before review can pass.

## Key Design Decisions

Added an explicit semantic-admission predicate name at provider-pool call sites
and added deterministic registration/filter matrix coverage for endpoint,
execution-path, semantic state, and `available|unavailable|unknown` typed-stall
classification. The private typed-stall registration remains independent of
configured semantic filter registrations in the test fixture; no new retry
counter or recovery owner was introduced.

## Reviewer Checkpoints

- Every supported Chat/Responses normalized/tunnel entry point reaches exactly one request runtime when semantic activation is both false and true; unsupported/non-OpenAI paths do not gain an owner.
- Candidate capability admission and configured semantic filters are inactive when the flag is false and unchanged when true.
- No new retry/counter/owner exists in StreamGate Core, Edge service, or Node; confirmed old transports still close without duplicate `CancelRun`.
- Disabled-semantic successful and terminal responses preserve endpoint-native public behavior and exactly-once usage/terminal ownership.
- The matrix contains both endpoints, both normalized/tunnel paths, and both semantic flag states; assertions prove runtime ownership rather than calling the filter directly.
- Alternate and same-provider rows assert provider selection, one recovery dispatch, a new identity, shared budget consumption, old transport close behavior, and one public terminal.
- Every unsafe/no-owner row asserts zero recovery dispatch and sanitized terminal behavior.
- Verification output includes separate complete service and OpenAI race results and all repository-native smoke results.

## Verification Results

### Verification 1

Command:

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

Output:

```text
ok  \tiop/apps/edge/internal/openai\t0.080s
```

### Verification 2

Command:

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

Output:

```text
ok  \tiop/apps/edge/internal/openai\t0.034s
```

### Verification 3

Command:

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

Output:

```text
ok  \tiop/apps/edge/internal/openai\t0.036s
```

### 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  \tiop/packages/go/streamgate\t1.003s
ok  \tiop/apps/edge/internal/openai\t7.370s
ok  \tiop/apps/edge/internal/service\t6.077s
ok  \tiop/apps/edge/internal/controlplane\t6.604s
```

### Verification 5

Command:

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

Output:

```text
ok  \tiop/apps/edge/internal/service\t19.376s
```

### Verification 6

Command:

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

Output:

```text
ok  \tiop/apps/edge/internal/openai\t24.939s
```

### Verification 7

Command:

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

Output:

```text
```

### Verification 8

Command:

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

Output:

```text
[e2e] verifying provider-only Node command and cancellation boundary
ok  \tiop/apps/node/internal/node\t0.089s
[e2e] verifying Edge dispatch, provider tunnel, queue, and reconnect fencing
ok  \tiop/apps/edge/internal/service\t4.541s
ok  \tiop/apps/edge/internal/transport\t0.250s
[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.jrLCj7
```

### Verification 11

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: Fail — supported Chat/Responses normalized and tunnel requests still bypass the private liveness recovery owner whenever `openai.stream_evidence_gate.enabled=false`.
  - Completeness: Fail — REVIEW_API-1 and REVIEW_API-2 remain unchecked, and the implementation explicitly records that always-on ownership and the S05 lifecycle matrix are incomplete.
  - Test Coverage: Fail — the two newly named matrix tests exercise registry construction and the private filter directly, not handler/runtime dispatch, provider selection, shared budget, attempt identity, transport close, or exactly-once public terminal behavior.
  - API Contract: Fail — the active contracts and specs continue to describe typed-stall recovery only for runtime-enabled requests instead of the SDD-required always-on supported OpenAI host.
  - Code Quality: Pass — the retained typed mapper and private registration remain bounded and raw-free, with no new retry counter or duplicate recovery owner in the reviewed subset.
  - Implementation Deviation: Fail — reverting always-on runtime ownership removes an explicit PLAN and SDD S05 acceptance condition rather than an optional implementation detail.
  - Verification Trust: Pass — all eleven exact commands were independently rerun successfully, including separate service and OpenAI race commands; the deficiency is what the tests cover, not whether their recorded output exists.
  - Spec Conformance: Fail — SDD S05 assigns bounded retry ownership to every supported OpenAI-compatible host path and reserves no-owner terminal behavior for unsupported surfaces.
- Findings:
  - Required R1 — `apps/edge/internal/openai/stream_gate_runtime.go:798`, `apps/edge/internal/openai/normalized_sse.go:41`, `apps/edge/internal/openai/responses_handler.go:151`, and `apps/edge/internal/openai/provider_tunnel.go:33`: `streamGateSemanticEnabled()` still delegates to `streamGateEnabled()`, which returns the semantic configuration flag, while every supported response entry point uses `streamGateEnabled()` to choose between the runtime and legacy paths. The default false configuration therefore remains ownerless. Implement a compatibility-capable always-on supported-path response runtime, keep semantic filter registration and capability admission controlled only by the semantic flag, and synchronize the active execution/config/OpenAI contracts and matching specs to that ownership split.
  - Required R2 — `apps/edge/internal/openai/stream_gate_stall_recovery_test.go:141` and `apps/edge/internal/openai/stream_gate_stall_recovery_test.go:195`: `TestOpenAIStallRecoveryMatrix` loops over endpoint/path/config labels but constructs a registry and invokes `stall.Filter().Evaluate` directly, while `TestOpenAISemanticGateDisabledCompatibility` only counts registrations. Neither test drives a Chat/Responses normalized/tunnel handler lifecycle or proves alternate/same-provider selection, new identity, shared-budget consumption, confirmed old-transport close, unsafe/no-owner terminal rows, or exactly-once dispatch/terminal behavior. Add the deterministic S05 lifecycle fixtures required by REVIEW_API-2 and retain the independently verified exact command evidence.
- Routing Signals:
  - `review_rework_count=2`
  - `evidence_integrity_failure=false`
- Next Step: Invoke the plan skill in `prepare-follow-up` mode with Required R1 and R2 as direct fixes, rerun isolated final routing, archive this pair, and materialize the routed follow-up PLAN/CODE_REVIEW pair.
