<!-- task=m-openai-compatible-output-validation-filters/03_repeat_guard_s07_remote_evidence plan=10 tag=REVIEW_OFR-S07-DURABLE-TERMINAL-10 -->

# Code Review Reference - REVIEW_OFR-S07-DURABLE-TERMINAL-10

> **[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-07-30
task=m-openai-compatible-output-validation-filters/03_repeat_guard_s07_remote_evidence, plan=10, tag=REVIEW_OFR-S07-DURABLE-TERMINAL-10

## Roadmap Targets

- Milestone: `agent-roadmap/phase/knowledge-tool-optimization-extension/milestones/openai-compatible-output-validation-filters.md`
- Milestone link: [Milestone document](agent-roadmap/phase/knowledge-tool-optimization-extension/milestones/openai-compatible-output-validation-filters.md)
- Task ids:
  - `repeat-guard`: rolling content/history/action repetition detection and safe continuation
- Completion mode: check-on-pass

## Archive Evidence Snapshot

- `plan_cloud_G08_9.log` / `code_review_cloud_G08_9.log`: FAIL with one Required finding and trusted local/remote audit evidence.
- The channel-aware content/reasoning parser, production alias precedence, deterministic fixtures, fresh local profiles, three-file overlay, unchanged deployed candidate, and zero restart result remain accepted.
- Preserved `plan-9/attempt-1` contains 15 raw SSE files and a structurally valid `reproduced` summary, but no durable terminal exit or `accepted-attempt`; it is not an accepted attempt and must not be modified or promoted.
- Reviewer preflight on 2026-07-30 confirmed clean base HEAD `750cb1d1cb88066a10d3c703c99f1326306d8e15`, overlay integrity, runtime hash `e0eff854e5c6841e6dd5cafcd7242254c91ece26b4ad328a2b937acca42122e5`, Edge PID `20646`, five listeners, four connected nodes, idle healthy `3+1` capacity, authenticated `/v1/models` HTTP 200, absent harness, absent accepted marker, and fresh attempt-2/attempt-3 paths.

## 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_10.log` and `PLAN-cloud-G08.md` → `plan_cloud_G08_10.log`.
3. If PASS, write `complete.log` and move active task directory to `agent-task/archive/YYYY/MM/m-openai-compatible-output-validation-filters/03_repeat_guard_s07_remote_evidence/`. 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>`, report completion event metadata. Roadmap state check and `update-roadmap` calls are runtime responsibilities.
5. Check applicable `Review-Only Checklist` items at the final `.log` location before reporting.

---

## Implementation Item Completion

| Item | Status |
|------|---------|
| REVIEW_OFR-S07-DURABLE-TERMINAL-10-1 | [x] |

## Implementation Checklist

- [x] [REVIEW_OFR-S07-DURABLE-TERMINAL-10-1] Preserve attempt 1; revalidate the immutable overlay, runtime, authentication, and idle capacity; run fresh foreground attempt 2 with atomic terminal capture and, only after one exact classified transient, fresh attempt 3; validate exactly one accepted summary and cleanup or preserve the terminal stop evidence.
- [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_10.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G08_10.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-openai-compatible-output-validation-filters/03_repeat_guard_s07_remote_evidence/` to `agent-task/archive/YYYY/MM/m-openai-compatible-output-validation-filters/03_repeat_guard_s07_remote_evidence/` and update this checklist at the final archive path.
- [ ] If PASS and task group is `m-<milestone-slug>`, report completion event metadata for runtime, without modifying roadmap or directly calling `update-roadmap`.
- [ ] If PASS for split work, remove empty active parent `agent-task/m-openai-compatible-output-validation-filters/` 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 authorized attempt-2 read-only gate and durable foreground block were executed verbatim from `PLAN-cloud-G08.md` (attempt=2). No edit was made to that command.
- Attempt 3 was intentionally **not** run. Authorization requires `terminal-attempt-2` to be `class=retryable-transient`; the durable record is `class=non-retryable`, so the sequence stopped exactly as the plan mandates ("Any other result stops").
- The plan's accepted-summary/cleanup validator block was **not** run. Its precondition is `test -f "$accepted_record"` (an existing `accepted-attempt`), and no accepted marker exists, so the block is not applicable this loop.
- Supplementary **read-only, non-mutating** SSH commands were run beyond the plan's literal blocks in order to satisfy the plan's "record the exact blocker, attempted commands/output, and resume condition" instruction without leaking raw content. They emit only normalized Go-toolchain / test-framework tokens, classifier booleans, counts, hashes, and provider-status scalars — never raw prompt, model output, SSE, Authorization header, or foreground-log body. These were: (a) a raw-free failure characterization of `attempt-2/foreground.log`; (b) a post-attempt integrity re-confirmation (checkout/overlay/runtime-hash/PID/listeners/harness/providers/attempt-1); (c) a `go.mod` + smoke-test-symbol location check to name the correct resume working directory.
- No product source, checkout, overlay, runtime binary/process/config, credential, provider, Control Plane, Node, roadmap, prior task log, or attempt-1 artifact was modified. The only tracked write is this active review file.

## Key Design Decisions

- **Stayed strictly inside the authorized attempt ordinals.** The plan authorizes one fresh attempt 2 and a transient-gated attempt 3 only. Attempt 2 is now consumed with an immutable durable terminal record and attempt 3 is disallowed by classification, so there is no in-scope path to synthesize an accepted attempt. I did **not** author a corrected wrapper or run additional attempts; the wrapper defect must be repaired in a follow-up plan. Per the implementing-agent contract I do not classify the next review state.
- **Recorded the blocker as a durable, atomic terminal-stop record, not an inferred success.** The wrapper wrote `terminal-attempt-2` (`state=stopped`, `class=non-retryable`) atomically; summary presence was never used to infer success, and no `accepted-attempt` was created. This is the explicit "preserve the terminal stop evidence" branch of the checklist item.
- **Kept all raw content on the remote ignored artifact path.** Only raw-free markers, booleans, counts, hashes, and provider scalars entered this review or chat output. The API key was decrypted only inside the remote shell and unset before any record was written.
- **Named the correct resume working directory from evidence.** The plan-9 overlay source root (`/tmp/iop-repeat-guard-live/repeat-guard-task-03-plan-9-source/iop`) contains `go.mod` and the overlay-modified `TestDevRepeatGuardOrnithSmoke`, and the deployed candidate was built from that overlay — so a corrected wrapper must `cd` there before `go test`.

## Reviewer Checkpoints

- Verify attempt 1 and every prior artifact remain byte-for-byte untouched and no marker is synthesized for attempt 1.
- Verify the overlay manifest, base HEAD, runtime hash, PID, listener set, checkout cleanliness, authentication, connected nodes, and two-sample idle `3+1` capacity gate before every consumed attempt.
- Verify only attempt 2 runs initially; attempt 3 runs only when the durable attempt-2 terminal record contains exactly `state=stopped` and `class=retryable-transient`.
- Verify each consumed attempt produces either the single atomic accepted record or one atomic stopped terminal record and never relies on summary presence alone.
- Verify the accepted record has `run_rc=0`, `state=accepted`, an attempt ordinal of 2 or 3, and a summary hash that matches the accepted immutable summary.
- Verify the accepted summary has 15 logical provider responses, globally disjoint bounded provider identity lists, 15 unique lifecycle correlations, three capacity rows with configured capacity 4, peak in-flight 4, queue pressure, and final idle state.
- Verify `reproduced` has a sanitized fingerprint/offset or the result is `not_reproduced`.
- Verify the harness is absent, providers are idle, the deployed candidate and checkout remain unchanged, attempt 1 remains preserved, invocation count is at most 3 cumulative, and Edge restart count remains zero.
- Verify tracked evidence contains no raw credential, Authorization header, prompt, model output, raw SSE, status payload, tool args/result, or foreground log content.
- Verify PASS reports only `repeat-guard`, not `ops-evidence`.

## Verification Results

### Remote identity gate and durable foreground terminal

Commands:

- Execute the exact read-only gate and durable foreground block in `PLAN-cloud-G08.md` for attempt 2.
- Execute the same block for attempt 3 only when `terminal-attempt-2` contains both exact permitted lines.

Implementation evidence:

**Outcome: BLOCKED — durable non-success terminal record captured; no accepted attempt.** Attempt 2 was consumed; attempt 3 was not authorized.

- Preflight gate PASSED for attempt 2 (it printed `remote_live_start`, which the wrapper reaches only after every read-only check succeeds): base HEAD `750cb1d1cb88066a10d3c703c99f1326306d8e15`, checkout clean, overlay `overlay.sha256` intact, runtime hash == plan-7 candidate, Edge PID `20646` single, five listeners exact (`*:18082,*:18083,*:18084,*:19101,127.0.0.1:19093`), harness absent, two idle `3+1` capacity samples, authenticated `/v1/models` HTTP `200`.
- Foreground markers (raw-free stdout):
  - `remote_live_start invocation_count=2 attempt=2 ownership=foreground artifact=plan-9/attempt-2 edge_restart_count=0`
  - `remote_live_finish=FAIL invocation_count=2 terminal_class=non-retryable durable_terminal=terminal-attempt-2 edge_restart_count=0`
- Durable atomic terminal artifact `terminal-attempt-2` (raw-free): `attempt=2`, `run_rc=1`, `state=stopped`, `class=non-retryable`. No `accepted-attempt` created; `attempt-2/summary.json` absent.
- **Blocker root cause (raw-free).** `attempt-2/foreground.log` is 94 bytes; its only content is the Go toolchain error `go: go.mod file not found in current directory or any parent directory`. The plan's foreground block invokes `go test ./apps/edge/internal/openai` (a relative package path) but never `cd`s into the Go module root; under `zsh -l` the working directory is `$HOME` (`/Users/toki`), which has no `go.mod`, so `go` aborts before the smoke test runs. No transient signature (`HTTP 429|502|503|504`, connection reset/EOF, request deadline) and no assertion/identity/correlation/capacity/grammar/duplicate/summary/checkout/runtime-hash/overlay/panic/data-race signature matched — the classifier correctly resolved `non-retryable`. The reviewer preflight verified environment identity but did not execute the `go test` invocation, so the missing `cd` was not caught earlier.
- Attempt 3 NOT run: the gate for attempt 3 requires `terminal-attempt-2` to contain `state=stopped` **and** `class=retryable-transient`; the record is `class=non-retryable`, so the sequence stopped.
- Invocation / mutation counts: 1 fresh foreground attempt consumed this loop (attempt 2); cumulative attempts = prior attempt-1 + attempt-2 = 2 (attempt-3 = 0), within the ≤ 3 cap. Edge restart count = 0. No product/runtime/config/credential/provider/roadmap mutation.
- Post-attempt integrity (read-only re-confirmation): base HEAD unchanged and checkout clean; overlay intact; runtime hash == plan-7 candidate (deployed candidate unchanged); Edge PID `20646` alive (zero restart); five listeners exact; harness absent; `nodes=4`, all connected; providers idle healthy `onexplayer-lemonade(cap=3,in_flight=0,queued=0)` + `rtx5090-lemonade(cap=1,in_flight=0,queued=0)`; `attempt-1` preserved (`summary.json` sha256 `399701df68103a59738f5683c6ef4e5ce193c2fb2105757d11c0661f1d453697`, 16 directory entries = 15 raw SSE files + summary).
- **Resume condition.** The attempt-2 ordinal and its `terminal-attempt-2` record are consumed and immutable. Producing an accepted S07 attempt requires a follow-up plan whose foreground wrapper `cd`s into the plan-9 overlay module root (`/tmp/iop-repeat-guard-live/repeat-guard-task-03-plan-9-source/iop`, which holds `go.mod` and the overlay-modified `TestDevRepeatGuardOrnithSmoke`) before `go test`, run under a fresh unused attempt ordinal (attempt 3+) against the unchanged deployed candidate, with attempt-1/attempt-2 artifacts preserved.

### Accepted summary and cleanup

Commands:

- Execute the exact raw-free accepted-summary and cleanup validator in `PLAN-cloud-G08.md` only after `accepted-attempt` exists.

Implementation evidence:

**Not applicable this loop — validator not run.** The accepted-summary/cleanup validator's first assertion is `test -f "$accepted_record"` (an existing `accepted-attempt`). No `accepted-attempt` exists because attempt 2 ended as a durable non-success terminal record and attempt 3 was not authorized (see the section above), so running the validator would only fail its precondition. No accepted summary hash, result/fingerprint/offset classification, or cleanup line was produced. Provider cleanup, harness absence, candidate/checkout identity, and attempt-1 preservation are instead evidenced by the read-only post-attempt integrity re-confirmation recorded above (providers idle `3+1`, harness absent, candidate unchanged, checkout clean, attempt-1 preserved, Edge restart count 0).

### Workspace hygiene

Commands:

```bash
git diff --check
git status --short
git grep -lE 'sk-[A-Za-z0-9_-]{16,}|Authorization: Bearer [^$]' -- . \
  ':(exclude)agent-task/archive/**' \
  ':(exclude)agent-task/m-openai-compatible-output-validation-filters/03_repeat_guard_s07_remote_evidence/*.log'
```

Implementation evidence:

- `git diff --check` → exit `0` (no whitespace/conflict errors).
- `git status --short` (paths only) preserves unrelated pre-existing changes and shows the active pair as untracked:
  - ` M --check`
  - ` M apps/edge/internal/openai/stream_gate_release_sink.go`
  - ` M apps/edge/internal/openai/stream_gate_tunnel_codec.go`
  - ` M apps/edge/internal/openai/stream_gate_vertical_slice_test.go`
  - `?? agent-task/archive/2026/07/m-openai-compatible-output-validation-filters/`
  - `?? agent-task/m-openai-compatible-output-validation-filters/`
  - The three ` M` `stream_gate_*` files and ` M --check` are pre-existing unrelated working-tree changes (present before this loop, not touched by this packet). This packet's only write is `agent-task/m-openai-compatible-output-validation-filters/03_repeat_guard_s07_remote_evidence/CODE_REVIEW-cloud-G08.md`, which lives inside the untracked `?? agent-task/m-openai-compatible-output-validation-filters/` entry.
- Path-only secret-like scan → exit `0`. Matches are all pre-existing unrelated files (contract docs `agent-contract/outer/a2a-json-rpc-api.md` and `openai-compatible-api.md`, `agent-ops/.../dispatch.py`, several `agent-roadmap/**` and `agent-roadmap/archive/**` docs/SDD/user_review logs, `apps/edge/internal/openai/log_safety_test.go` and `usage_metrics_test.go`, `packages/go/agentprovider/catalog/{lifecycle_conformance_test,redact_test}.go`, `docs/edge-local-dev-guide.md`, and an unrelated `tmp/iop-review-followup.MreBOU/*` review dir). The scan does **not** name the active review (`03_repeat_guard_s07_remote_evidence/CODE_REVIEW-cloud-G08.md` / `PLAN-cloud-G08.md`) or the scoped overlay source (`stream_gate_*`). No matching content was printed.

---

> **[IMPLEMENTING AGENT — BEFORE SAVING] Have you filled in every implementation-owned section?**
> If anything is blank, go back and fill it in.
> 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) |
| Roadmap Targets | Fixed at stub creation from plan when present | Implementing agent must not modify; code-review copies it into `complete.log` as `Roadmap Completion` only on PASS |
| 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 — the authorized foreground wrapper invokes a relative Go package from the login-shell working directory instead of the verified overlay module root, so it cannot start the required smoke.
  - Completeness: Fail — no accepted immutable attempt exists and the accepted-summary validator remains inapplicable.
  - Test Coverage: Fail — deterministic local profiles pass, but the required integrated S07 smoke did not execute.
  - API Contract: Pass — no API or runtime contract was changed in this loop.
  - Code Quality: Pass — no product source was changed in this loop, and the terminal classifier preserved the failed attempt without synthesizing success.
  - Implementation Deviation: Pass — the implementer executed the authorized attempt-2 command exactly and correctly stopped after its non-retryable terminal classification.
  - Verification Trust: Fail — reviewer evidence confirms the recorded exit and root cause, but the required live production path remains unexecuted.
  - Spec Conformance: Fail — SDD S07 requires an accepted capacity+1 smoke summary, which is still absent.
- Findings:
  - Required — `agent-task/m-openai-compatible-output-validation-filters/03_repeat_guard_s07_remote_evidence/PLAN-cloud-G08.md:272`: the foreground command uses `./apps/edge/internal/openai` without first changing to `source_root`; fresh remote evidence confirms the login shell ran outside the Go module and produced the exact one-line `go.mod file not found` failure. Preserve attempts 1 and 2, add an explicit `cd "$source_root"` before the remaining fresh attempt, and require one atomic accepted record plus the existing S07 summary and cleanup validators before completion.
- Routing Signals:
  - `review_rework_count=11`
  - `evidence_integrity_failure=true`
- Next Step: Prepare the smallest fresh follow-up plan that runs the remaining unused attempt from the verified overlay module root and accepts completion only through the atomic accepted record; do not write `complete.log`.
- Finalization Status: Completed. The verdict pair was archived as suffix `10`; the prepared plan-11 candidate passed `dispatch.py --validate-plan` before archive and again after byte-for-byte materialization; the routed `cloud-G08` follow-up pair is active; no `complete.log` or `USER_REVIEW.md` was written.
- Resume Condition: Execute the active plan-11 attempt-3 command from the verified overlay module root, fill its implementation-owned review evidence, and return it for official review.
