<!-- task=m-node-provider-execution-liveness-recovery/06+05_failure_wire_mapping plan=0 tag=API milestone-task=failure-handoff -->

# Code Review Reference - 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.
> 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/06+05_failure_wire_mapping, plan=0, tag=API

## 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_0.log` and `PLAN-local-G08.md` → `plan_local_G08_0.log`.
3. If PASS, write `complete.log` and move active task directory to `agent-task/archive/YYYY/MM/m-node-provider-execution-liveness-recovery/06+05_failure_wire_mapping/`. If WARN/FAIL, fully write the next filesystem state required by the code-review skill.
4. If PASS, preserve the first-line `milestone-task` metadata in `complete.log` and report it for runtime aggregation. 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 |
|------|---------|
| API-1: Preserve typed failures across both Node paths | [x] |

## Implementation Checklist

- [x] API-1 maps only allowlisted `response_stalled` failures on normalized and tunnel terminals while preserving legacy behavior for nil/other failures.
- [x] Add absent/present, two-path parity, defensive-clone, and raw-free round-trip tests; synchronize runtime/wire contracts and living spec.
- [x] Run focused, package, race, vet, provider-only/fake-provider full-cycle, and diff verification with fresh output.
- [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_G08_0.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_local_G08_0.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/06+05_failure_wire_mapping/` to `agent-task/archive/YYYY/MM/m-node-provider-execution-liveness-recovery/06+05_failure_wire_mapping/` and update this checklist at the final archive path.
- [x] If PASS, 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

- Created a single clone-safe helper function `executionFailureToProto` in package `node` (`apps/node/internal/node/runtime_bridge.go`) that maps `runtime.Failure` to protobuf `iop.ExecutionFailure` only when `failure.Code == runtime.FailureCodeResponseStalled`.
- Implemented `allowlistedLivenessMetadata` to filter metadata keys against the closed SDD allowlist (`failure_code`, `provider_health`, `liveness_classification`, `idle_duration_ms`, `run_id`, `attempt_id`, `attempt_fence`, `adapter`, `target`, `health_observation_seq`). Non-allowlisted keys (e.g. `recovery_eligible`, secrets, raw prompts) are stripped, and a fresh map clone is returned to prevent mutable aliasing.
- Preserved legacy error string behavior (`RunEvent.Error` / `ProviderTunnelFrame.Error`) for nil and non-stalled failures while leaving the wire `ExecutionFailure` field `nil`.

## Reviewer Checkpoints

- Confirm only stalled failures populate the typed field and legacy strings remain compatible.
- Confirm normalized/tunnel mappings use the same allowlist and never carry raw/arbitrary metadata or `recovery_eligible`.
- Confirm parser separation, cloning, race, and both repository-native full cycles pass.

## 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=1 ./apps/node/internal/node -run '^(TestRuntimeEventToProtoPreservesTypedFailure|TestStallMetadata.*)$' && go test -count=1 ./apps/edge/internal/transport -run '^(TestEdgeParserMap_.*)$'
```

Output:

```
ok  	iop/apps/node/internal/node	0.032s
ok  	iop/apps/edge/internal/transport	0.031s
```

### Verification 2

Command:

```bash
go test -count=1 ./packages/go/execution ./apps/node/... ./apps/edge/internal/transport ./apps/control-plane/...
```

Output:

```
ok  	iop/packages/go/execution	0.015s
ok  	iop/apps/node/cmd/node	0.314s
ok  	iop/apps/node/internal/adapters	0.238s
?   	iop/apps/node/internal/adapters/mock	[no test files]
ok  	iop/apps/node/internal/adapters/ollama	0.100s
ok  	iop/apps/node/internal/adapters/openai_compat	0.233s
ok  	iop/apps/node/internal/adapters/vllm	0.282s
ok  	iop/apps/node/internal/bootstrap	1.876s
ok  	iop/apps/node/internal/node	1.589s
ok  	iop/apps/node/internal/router	0.571s
ok  	iop/apps/node/internal/store	0.377s
ok  	iop/apps/node/internal/transport	5.856s
ok  	iop/apps/edge/internal/transport	5.135s
ok  	iop/apps/control-plane/cmd/control-plane	3.342s
ok  	iop/apps/control-plane/internal/credentiallease	0.113s
ok  	iop/apps/control-plane/internal/credentialops	0.231s
ok  	iop/apps/control-plane/internal/credentialseal	0.091s
ok  	iop/apps/control-plane/internal/credentialstore	0.277s
ok  	iop/apps/control-plane/internal/wire	2.008s
```

### Verification 3

Command:

```bash
go test -race -count=1 ./packages/go/execution ./apps/node/internal/node ./apps/edge/internal/transport
```

Output:

```
ok  	iop/packages/go/execution	1.066s
ok  	iop/apps/node/internal/node	2.397s
ok  	iop/apps/edge/internal/transport	10.925s
```

### Verification 4

Command:

```bash
go vet ./packages/go/execution ./apps/node/... ./apps/edge/internal/transport ./apps/control-plane/...
```

Output:

```
(clean - no diagnostics output, exit code 0)
```

### Verification 5

Command:

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

Output:

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

### Verification 6

Command:

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

Output:

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

### Verification 7

Command:

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

Output:

```
(clean - no output, exit code 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: PASS
- Dimension Assessment:
  - Correctness: Pass — the shared mapper emits typed wire failures only for `response_stalled`, and both normalized and tunnel stall terminals use it with matching retryability and safe metadata.
  - Completeness: Pass — all API-1 implementation and evidence items are complete for this split mapping contribution; Edge reception fencing and runtime health overlay remain owned by later sibling tasks.
  - Test Coverage: Pass — focused present/absent, parity, defensive-clone, raw-free, parser round-trip, package, race, vet, and repository-native smoke evidence all passed.
  - API Contract: Pass — protobuf presence semantics, legacy error strings, the closed metadata allowlist, generated bindings, runtime/wire contracts, and the living spec agree.
  - Code Quality: Pass — the mapper is centralized, transport-neutral runtime ownership is preserved, and reviewer-only `gofmt` cleanup left no formatting drift.
  - Implementation Deviation: Pass — no behavioral deviation or unrelated implementation was found; the predecessor-owned additive protobuf foundation is supported by its archived PASS evidence and fresh consumer compilation.
  - Verification Trust: Pass — all reported commands were re-run successfully, including verbose focused fixtures, package tests, race tests, vet, both repository-native smoke commands, and `git diff --check`.
  - Spec Conformance: Pass — the implementation satisfies the normalized/tunnel typed-failure mapping portion of SDD S04 without introducing Node-owned `recovery_eligible` or claiming completion of the remaining Edge overlay/release-once criteria.
- Findings: None.
- Routing Signals:
  - `review_rework_count=0`
  - `evidence_integrity_failure=false`
- Next Step: PASS — archive the active pair, write `complete.log`, move the task artifacts to the monthly archive, and report milestone contribution metadata for runtime aggregation.
