<!-- task=m-node-provider-execution-liveness-recovery/08+07_health_overlay plan=3 tag=REVIEW_REFACTOR milestone-task=failure-handoff -->

# Code Review Reference - REVIEW_REFACTOR

> **[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/08+07_health_overlay, plan=3, tag=REVIEW_REFACTOR

## Archive Evidence Snapshot

- The plan=2 pair is archived as `agent-task/m-node-provider-execution-liveness-recovery/08+07_health_overlay/plan_cloud_G07_2.log` and `agent-task/m-node-provider-execution-liveness-recovery/08+07_health_overlay/code_review_cloud_G08_2.log` with verdict `FAIL`, Required=1, Suggested=0, Nit=0.
- Required R2 affects `apps/edge/internal/service/model_queue_release.go` and `apps/edge/internal/service/provider_health_overlay_test.go`: probe recovery must retain the exact adapter/target binding that lowered the provider while advancing its per-provider observation high-water mark.
- Reviewer reproduction proved the failure: unavailable target B at sequence 1 was recovered by available target A at sequence 2 on the same multi-target provider.
- Fresh focused, package, race, vet, provider smoke, local-capacity smoke, and diff verification passed. The authorized live long-context provider and Edge status endpoints remain unreachable; do not repeat those unchanged external commands in this repository-fix packet.
- Roadmap carryover remains `milestone-task=failure-handoff`, SDD S04. Existing contracts/specs already require same-provider/adapter/target higher-sequence recovery and need no semantic rewrite for 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-G06.md` → `code_review_cloud_G06_3.log` and `PLAN-cloud-G06.md` → `plan_cloud_G06_3.log`.
3. If PASS, write `complete.log` and move active task directory to `agent-task/archive/YYYY/MM/m-node-provider-execution-liveness-recovery/08+07_health_overlay/`. 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>`, 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_REFACTOR-1: Preserve the lowered recovery binding | [x] |

## Implementation Checklist

- [x] REVIEW_REFACTOR-1 preserves the lowered adapter/target binding, advances a newer cross-target observation without recovery, and recovers only on a later exact-target available observation.
- [x] Add a deterministic multi-target regression while retaining catalog-ambiguity and available-before-terminal coverage.
- [x] Run focused, package, race, vet, provider smoke, local-capacity smoke, and diff verification with fresh output; do not retry the unchanged blocked live endpoints.
- [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_3.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G06_3.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-node-provider-execution-liveness-recovery/08+07_health_overlay/` to `agent-task/archive/YYYY/MM/m-node-provider-execution-liveness-recovery/08+07_health_overlay/` and update this checklist at the final archive path.
- [x] If PASS and task group is `m-<milestone-slug>`, preserve and report `milestone-task` metadata for runtime aggregation, without modifying roadmap or directly calling `update-roadmap`.
- [x] 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.
- [ ] 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

- In `applyProviderProbeEvidence` (`apps/edge/internal/service/model_queue_release.go`), probe recovery requires `overlay.unavailable && overlay.adapter == adapter && overlay.target == target`.
- When an available observation arrives for a different target on the same multi-target provider (cross-target evidence), `overlay.observationSeq` is updated to advance the per-provider sequence high-water mark, but the lowered adapter/target binding and unavailable state are preserved (`overlay.unavailable` remains `true`), returning `false` (no recovery).
- Only when an available observation matching the lowered binding (`adapter` and `target`) arrives with a higher sequence is the overlay cleared (`overlay.unavailable = false`), triggering queue pumping (`m.pumpAllLocked()`) and returning `true`.
- Added `TestProviderHealthOverlayCapabilitiesRecoveryRequiresLoweredBinding` in `apps/edge/internal/service/provider_health_overlay_test.go` to test multi-target cross-target available observation sequence advancement without recovery followed by exact-target recovery.

## Reviewer Checkpoints

- Confirm the current catalog still resolves adapter/target to exactly one provider before any sequence or health transition.
- Confirm a newer cross-target available observation advances the provider high-water mark but preserves the lowered binding and unavailable state.
- Confirm only a later exact adapter/target available observation clears the overlay, pumps once, and reports recovery.
- Confirm config health, Node wire evidence, command parsing, admission/snapshot consumers, and unrelated ingress recovery ownership remain unchanged.
- Confirm the exact focused/package/race/vet/provider commands have fresh trusted output and the archived external live blocker was not retried.

## Verification Results

> Implementing agent: run each command exactly as written and paste its actual stdout/stderr under `Output`. Record any replacement command and reason in `Deviations from Plan`.

### Verification 1

Command:

```bash
go test -count=50 ./apps/edge/internal/service -run '^(TestProviderHealthOverlayCapabilitiesRecoveryRequiresLoweredBinding|TestProviderHealthOverlayCapabilitiesRecoveryRejectsCatalogAmbiguity|TestProviderHealthOverlayCapabilitiesRecoveryPreservesAvailableHighWater|TestProviderHealthOverlayCapabilitiesRecoveryRejectsInconclusiveEvidence|TestProviderHealthOverlayCapabilitiesRecovery)$'
```

Output:

```
ok  	iop/apps/edge/internal/service	0.025s
```

### Verification 2

Command:

```bash
go test -count=20 ./apps/edge/internal/service -run '^(TestProviderHealthOverlay|TestReceived.*Failure|Test.*ReleaseOnce)' && go test -count=10 ./apps/node/internal/node ./apps/edge/internal/service -run '^(TestCapabilitiesHealthEvidence|TestProviderHealthOverlayCapabilitiesRecovery)'
```

Output:

```
ok  	iop/apps/edge/internal/service	0.031s
ok  	iop/apps/node/internal/node	0.061s
ok  	iop/apps/edge/internal/service	0.044s
```

### Verification 3

Command:

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

Output:

```
ok  	iop/packages/go/execution	0.012s
ok  	iop/apps/node/cmd/node	0.149s
ok  	iop/apps/node/internal/adapters	0.130s
?   	iop/apps/node/internal/adapters/mock	[no test files]
ok  	iop/apps/node/internal/adapters/ollama	0.089s
ok  	iop/apps/node/internal/adapters/openai_compat	0.212s
ok  	iop/apps/node/internal/adapters/vllm	0.195s
ok  	iop/apps/node/internal/bootstrap	1.491s
ok  	iop/apps/node/internal/node	0.998s
ok  	iop/apps/node/internal/router	0.516s
ok  	iop/apps/node/internal/store	0.038s
ok  	iop/apps/node/internal/transport	5.739s
ok  	iop/apps/edge/internal/node	0.083s
ok  	iop/apps/edge/internal/transport	4.785s
ok  	iop/apps/edge/internal/bootstrap	0.385s
ok  	iop/packages/go/streamgate	0.880s
ok  	iop/apps/edge/internal/openai	7.349s
ok  	iop/apps/edge/internal/service	5.855s
ok  	iop/apps/edge/internal/controlplane	6.576s
```

### Verification 4

Command:

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

Output:

```
ok  	iop/apps/node/internal/node	5.251s
ok  	iop/apps/edge/internal/node	1.066s
ok  	iop/apps/edge/internal/transport	15.496s
ok  	iop/apps/edge/internal/service	18.814s
```

### Verification 5

Command:

```bash
go vet ./packages/go/execution ./apps/node/... ./apps/edge/internal/node ./apps/edge/internal/transport ./apps/edge/internal/bootstrap ./packages/go/streamgate ./apps/edge/internal/openai ./apps/edge/internal/service ./apps/edge/internal/controlplane
```

Output:

```
(exit code 0, no output)
```

### Verification 6

Command:

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

Output:

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

### Verification 7

Command:

```bash
(cd scripts && sed -e 's|^SCRIPT_DIR=.*|SCRIPT_DIR="$(pwd)"|' -e 's|TMP_DIR="$(mktemp -d /tmp/iop-provider-capacity-smoke.XXXXXX)"|TMP_DIR="$(mktemp -d "$REPO_ROOT/.tmp/iop-provider-capacity-smoke.XXXXXX")"|' e2e-provider-capacity-smoke.sh | bash)
```

Output:

```
[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/workspace/iop-s1/.tmp/iop-provider-capacity-smoke.TdNhF3
```

### Verification 8

Command:

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

Output:

```
(exit code 0, no output)
```

---

> **[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

PASS

### Dimension Assessment

| Dimension | Result | Evidence |
|-----------|--------|----------|
| Correctness | PASS | Cross-target available evidence advances only the provider high-water mark while preserving the lowered binding; a later exact-target observation performs the recovery. |
| Completeness | PASS | The R2 transition and deterministic multi-target regression satisfy every implementation and verification item in the follow-up plan. |
| Test Coverage | PASS | The new regression covers lowering target B, cross-target target A no-recovery with sequence advancement, and later exact-target recovery, while the retained ambiguity and ordering suites pass repeatedly. |
| API Contract | PASS | Recovery now requires the same provider, adapter, and target binding required by the execution and Edge-Node wire contracts. |
| Code Quality | PASS | The transition remains localized under the queue lock with explicit high-water and recovery branches and no unrelated production changes. |
| Implementation Deviation | PASS | The implementation stayed within the planned source, test, and evidence boundary and preserved the recorded external-endpoint exclusion. |
| Verification Trust | PASS | Fresh focused, package, race, vet, provider smoke, capacity smoke, and whitespace commands all completed successfully and matched the implementation evidence. |
| Spec Conformance | PASS | The exact-binding recovery fence and monotonic observation behavior satisfy SDD Acceptance Scenario S04 and its Evidence Map. |

### Findings

None.

### Routing Signals

- `review_rework_count=2`
- `evidence_integrity_failure=false`

### Next Step

Finalize PASS by archiving the active pair, writing `complete.log`, and moving the split task artifacts to the monthly archive without directly modifying roadmap state.
