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

## Archive Evidence Snapshot

- The reviewed plan=4 pair is archived in this task directory as `plan_cloud_G08_4.log` and `code_review_cloud_G08_4.log` with verdict `FAIL`.
- Required R1: supported Chat/Responses normalized and tunnel entry points still select the liveness runtime through `streamGateEnabled()`, so `openai.stream_evidence_gate.enabled=false` remains ownerless; introduce an always-on supported-path owner while keeping semantic filters and capability admission flag-controlled and preserving disabled-semantic wire behavior.
- Required R2: `TestOpenAIStallRecoveryMatrix` invokes the private filter directly and `TestOpenAISemanticGateDisabledCompatibility` only counts registrations; neither proves handler dispatch, provider selection, new identity, shared budget, old-transport close, unsafe/no-owner terminals, or exactly-once rendering.
- Fresh reviewer reruns passed all eleven exact commands, including separate service and OpenAI race runs. Evidence integrity is trusted; the blocking deficiency is implementation and coverage completeness.

## 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_5.log` and `PLAN-cloud-G08.md` → `plan_cloud_G08_5.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 Install the compatibility-capable supported-path owner | [ ] |
| REVIEW_API-2 Prove the S05 handler/runtime lifecycle matrix | [ ] |

## 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 alone controls configured semantic filters and candidate capability admission and disabled-semantic public behavior remains compatible.
- [ ] REVIEW_API-2 replaces registry/filter-only coverage with deterministic production handler/runtime lifecycle tests for the S05 endpoint/path/config, provider-selection, safety-terminal, identity, budget, close, cancellation, and exactly-once matrices.
- [ ] Synchronize the active execution/config/OpenAI contracts and matching specs with always-on supported-path liveness ownership and semantic-only flag behavior, then run every exact verification command.
- [ ] 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_G08_5.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G08_5.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

Implementation is blocked before the compatibility adapter and production
lifecycle fixtures can be completed. The supported-path ownership split was
applied, and configured semantic filter registrations now remain disabled when
`openai.stream_evidence_gate.enabled=false`. The current release sinks do not
preserve the legacy disabled-semantic contract: package tests show changed
cancel status, missing strict/tool validation retries, reasoning/finish
rendering changes, tunnel write ordering changes, and request-runtime setup
failures for existing direct stream fixtures.

No fallback to the legacy ownerless path was retained because it would negate
the required always-on liveness owner. No contract/spec completion claims were
made, and no review-only action was taken.

Resume condition: complete the explicit disabled-semantic compatibility adapter
in the Chat, Responses, normalized SSE, buffered SSE, tunnel, and release-sink
paths; then replace the current registry/filter-only matrix with handler/runtime
fixtures and rerun all eleven commands.

## Key Design Decisions

- `openAIResponseRuntimeOwned()` is independent of the semantic configuration
  switch so supported OpenAI response lifecycles have one private owner.
- `streamGateSemanticEnabled()` remains the provider-admission policy switch.
- `openAIOutputFilterRegistrations()` emits no configured semantic filters or
  capability requirements when the switch is disabled; private typed-stall
  registration remains request-local runtime mechanics.

## Reviewer Checkpoints

- Every supported Chat/Responses normalized/tunnel entry point reaches exactly one request runtime when semantic activation is false and true; unsupported/non-OpenAI paths do not gain an owner.
- Configured semantic registrations and candidate capability admission are inactive when the flag is false and unchanged when true; the private typed-stall registration remains present.
- Disabled-semantic JSON/SSE/tunnel success, cancel, error, strict/tool, reasoning, finish, usage, and write-failure behavior remains endpoint-compatible with one terminal.
- No new retry/counter/owner exists in StreamGate Core, Edge service, or Node; confirmed old transports close without duplicate `CancelRun`.
- The matrix drives Chat and Responses handlers over normalized/tunnel and semantic false/true rows rather than invoking the filter directly.
- Alternate and same-provider rows assert provider selection, one recovery dispatch, new identity, shared-budget consumption, failed-provider avoidance, old-transport close, and one public terminal.
- Unconfirmed, committed, 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 enablement, and all eleven verification outputs are complete.

## 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  \tiop/apps/edge/internal/openai\t0.034s
```

### Verification 2

Command:

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

Output:

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

### Verification 3

Command:

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

Output:

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

### 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
Not run: the prerequisite package check is failing after the always-on owner
transition. The focused command below identifies the blocking regressions.

    go test -count=1 ./apps/edge/internal/openai
    FAIL: TestChatCompletionContextCancelSendsCancelRun (status 200, expected cancellation response)
    FAIL: TestResponsesContextCancelSendsCancelRun (status 200, expected cancellation response)
    FAIL: TestChatCompletionsFailsMalformedToolCallAfterRetryLimit (run stream unavailable replaces tool_validation_error)
    FAIL: TestChatCompletionsStreamsSSE (finish/reasoning rendering differs from endpoint-native output)
    FAIL: TestChatCompletionsPassthroughWriteFailureSendsCancelRunOnce (tunnel emits additional bytes)
    FAIL: TestTunnelSchemaContextPreserved (semantic registration absent when disabled)
    FAIL: TestOpenAIStreamGatePolicyTargetMatrix (fixtures require Enabled=true under the new semantic-only switch)
    FAIL: TestOpenAIStreamGateObserveOnlyDoesNotGateAdmission (fixtures require Enabled=true under the new semantic-only switch)
```

### Verification 5

Command:

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

Output:

```text
_Paste complete stdout/stderr here._
```

### Verification 6

Command:

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

Output:

```text
_Paste complete stdout/stderr here._
```

### Verification 7

Command:

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

Output:

```text
_Paste complete stdout/stderr here._
```

### Verification 8

Command:

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

Output:

```text
_Paste complete stdout/stderr here._
```

### Verification 9

Command:

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

Output:

```text
_Paste complete stdout/stderr here._
```

### Verification 10

Command:

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

Output:

```text
_Paste complete stdout/stderr here._
```

### Verification 11

Command:

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

Output:

```text
_Paste complete stdout/stderr 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) |
| 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 — making `openAIResponseRuntimeOwned()` unconditional routes disabled-semantic requests through release paths that currently change cancellation, tool-validation, reasoning, finish, tunnel error, and write-failure behavior; the fresh package integration command fails across those variants.
  - Completeness: Fail — REVIEW_API-1 and REVIEW_API-2 remain unchecked, the compatibility adapter and production lifecycle fixtures are incomplete, and the required contract/spec synchronization was not performed.
  - Test Coverage: Fail — the two named matrix tests still inspect registry/private-filter behavior rather than Chat/Responses normalized/tunnel handler dispatch, replacement identity, shared budget, transport close, or exactly-once public terminals.
  - API Contract: Fail — active execution/config/OpenAI contracts and matching specs still describe typed-stall recovery as runtime-enabled and continue to make the semantic flag control response-runtime ownership.
  - Code Quality: Fail — the constant-true owner leaves legacy response branches unreachable while the replacement path is incomplete, so the partial transition retains dead compatibility paths without preserving their behavior.
  - Implementation Deviation: Fail — the implementation stopped before both direct fixes and seven required verification commands, which are explicit PLAN and SDD S05 completion conditions.
  - Verification Trust: Fail — fresh reviewer runs reproduce the package regressions, while Verification 5 through Verification 11 remain placeholders and Verification 4 records a different focused command instead of the required invocation.
  - Spec Conformance: Fail — SDD S05 requires supported-host bounded retry with the existing public contract and production lifecycle evidence; the current partial owner transition satisfies neither condition.
- Findings:
  - Required R1 — `apps/edge/internal/openai/stream_gate_runtime.go:801`, `apps/edge/internal/openai/cancellation_routes_test.go:65`, `apps/edge/internal/openai/chat_stream_reasoning_test.go:65`, and `apps/edge/internal/openai/provider_tunnel_test.go:546`: `openAIResponseRuntimeOwned()` is now always true, but no disabled-semantic compatibility mode was added to the release/event-source adapters. Fresh `go test -count=1 ./packages/go/streamgate ./apps/edge/internal/openai ./apps/edge/internal/service ./apps/edge/internal/controlplane` fails cancellation, strict/tool validation, reasoning/finish rendering, tunnel ordering/error, and write-failure compatibility. Complete the planned compatibility adapter across Chat, Responses, normalized SSE, buffered SSE, tunnel, and release sinks; keep only semantic filters/capability admission flag-controlled; remove the unreachable ownerless selection; then synchronize the active contracts/specs.
  - 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` still constructs a registry and calls the private filter directly, while `TestOpenAISemanticGateDisabledCompatibility` only checks the semantic flag and registration count. Replace them with deterministic production handler/runtime fixtures that prove Chat/Responses normalized/tunnel dispatch, alternate and allowed same-provider selection, new identity, one shared-budget debit, confirmed old-transport close, zero-dispatch safety terminals, cancellation, and exactly-once rendering, then run and record all eleven commands separately.
- Routing Signals:
  - `review_rework_count=3`
  - `evidence_integrity_failure=true`
- 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.
