<!-- task=m-openai-compatible-output-validation-filters/02+01_repeat_guard plan=9 tag=REVIEW_OFR-REPEAT-8 -->

# Code Review Reference - REVIEW_OFR-REPEAT-8

> **[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-29
task=m-openai-compatible-output-validation-filters/02+01_repeat_guard, plan=9, tag=REVIEW_OFR-REPEAT-8

## 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

- Predecessor dependency: `agent-task/archive/2026/07/m-openai-compatible-output-validation-filters/01_resume_notice_builder/complete.log` records PASS and satisfies subtask `+01`.
- Prior review loops: `plan_cloud_G10_0.log` through `plan_cloud_G10_7.log` and their matching review logs remain the bounded same-task history; `code_review_cloud_G10_7.log` records the immediately preceding FAIL.
- Current failed pair: `plan_cloud_G10_8.log` and `code_review_cloud_G10_8.log`; its Required finding is the missing SDD S07 live evidence.
- Fresh reviewer evidence: focused Core and Edge race-enabled tests pass. The live command is `NOT RUN`; selected healthy capacity is 3, RTX5090 SSH times out, the deployed gate is absent, and filter observation count is zero.
- Required follow-up: restore the exact same-ref RTX5090 runtime, enable and observe the repeat-guard gate on Edge, prove aggregate capacity 4, and then record 15 unique SSE-derived correlations plus three accepted `4/4/>=1/0/0` capacity rows.

## 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-G10.md` → `code_review_cloud_G10_9.log` and `PLAN-cloud-G10.md` → `plan_cloud_G10_9.log`.
3. If PASS, write `complete.log` and move active task directory to `agent-task/archive/YYYY/MM/m-openai-compatible-output-validation-filters/02+01_repeat_guard/`. 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-REPEAT-8-1 — Restore the exact same-ref RTX5090 runtime and enabled Edge repeat-guard gate, then produce the clean `ornith:35b` 5-concurrent × 3 lifecycle and capacity evidence. | [ ] |

## Implementation Checklist

- [ ] [REVIEW_OFR-REPEAT-8-1] Restore the exact same-ref RTX5090 runtime and the enabled Edge repeat-guard gate, then produce the clean `ornith:35b` 5-concurrent × 3 lifecycle and capacity 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_G10_9.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G10_9.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/02+01_repeat_guard/` to `agent-task/archive/YYYY/MM/m-openai-compatible-output-validation-filters/02+01_repeat_guard/` 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 first remote shell entry for the live command exited `127` before `go test` started because non-login zsh did not include Homebrew Go in `PATH`. No HTTP request or live harness process started. The actual harness was then invoked once after adding `/opt/homebrew/bin` to `PATH`.
- The actual one-shot live harness timed out at Go's default 10-minute test deadline during run 1. The worker-owned prompt requested 24 sections with three substantial Korean paragraphs per section; two requests completed, while the three OneXPlayer streams remained active when the test process timed out. The command did not emit the required 15-correlation or three-capacity-row summary.
- The live harness was not retried because this plan requires exactly one invocation. A new authorized follow-up must explicitly permit another live attempt and choose either a bounded long-Korean prompt that completes within the existing deadline or a reviewed longer `go test -timeout` value.

## Key Design Decisions

- Restored the powered-off RTX5090 with Wake-on-LAN from the same LAN. No Startup shortcut, Run entry, scheduled task, or Windows service was created or restored.
- Replaced only the stale RTX5090 `iop-node.exe` with the runner's exact-ref Windows artifact after SHA-256 verification. The prior binary remains recoverable as `iop-node.exe.pre-d1e32b6-20260729T103220Z.bak`.
- The RTX operator toggle started its node with SSH-session-owned `Start-Process`, so the node exited when the SSH session closed. The final exact-ref node process was started with `Win32_Process.Create` through the existing `run-iop-node.cmd`, matching the deployment rule and remaining alive after session exit.
- Backed up the private Edge config, validated a YAML candidate with `edge config check`, then enabled the request-local gate and a base-disabled, `ornith:35b`-selected blocking `repeat_guard`. Both selected providers advertise `output.repeat_guard`.
- Routed the existing raw-free zap observation sink to `/tmp/iop-repeat-guard-live/edge-observations.jsonl`. The private bearer token was injected only into process memory through `IOP_OPENAI_API_KEY`; it was not printed or written into task evidence.

## Reviewer Checkpoints

- Confirm that the runner, Edge, `onexplayer-lemonade`, and `rtx5090-lemonade` use the exact reviewed ref `d1e32b6e06f7153a4db5a5a08b7026d6dd49fcfb`, with matching source, binary, process, listener, and provider identity evidence.
- Confirm that both selected providers are healthy and selected aggregate capacity is 4 before the live command.
- Confirm that the private deployed Edge configuration enables the blocking repeat-guard stream-evidence gate for the intended dev route/model and that the sanitized observation sink is active before the live command.
- Confirm that the live command is invoked exactly once only after every precondition passes.
- Confirm exactly 15 unique SSE-derived correlations and exactly three capacity rows with `configured=4`, `peak_in_flight=4`, `peak_queued>=1`, `final_in_flight=0`, and `final_queued=0`.
- Confirm that raw prompts, SSE, outputs, credentials, and tokens remain outside the workspace and that no production, test, contract, spec, or tracked config file changes.
- If a precondition remains unavailable, confirm that the command remains unrun and the exact blocker, attempted preflight, and resume condition are recorded without a live PASS claim.

## Verification Results

### Local Deterministic Verification

```bash
go version && go env GOMOD
git diff --check
go test -race -count=1 ./packages/go/streamgate -run '^TestRequestRuntimeTerminalFailureFidelity/fatal_filter_overrides_success_terminal$'
go test -race -count=1 ./apps/edge/internal/openai -run 'Test(DevRepeatGuardObservationCorrelation|DevRepeatGuardCapacityEvidence)'
```

Expected: all commands exit 0; focused evidence is fresh and uncached.

Implementation evidence:

```text
$ go version && go env GOMOD
go version go1.26.2 linux/arm64
/config/workspace/iop-s1/go.mod
SETUP_EXIT=0

$ git diff --check
DIFF_CHECK_EXIT=0

$ go test -race -count=1 ./packages/go/streamgate -run '^TestRequestRuntimeTerminalFailureFidelity/fatal_filter_overrides_success_terminal$'
ok  	iop/packages/go/streamgate	1.009s
CORE_RACE_EXIT=0

$ go test -race -count=1 ./apps/edge/internal/openai -run 'Test(DevRepeatGuardObservationCorrelation|DevRepeatGuardCapacityEvidence)'
ok  	iop/apps/edge/internal/openai	1.339s
EDGE_RACE_EXIT=0
```

All four commands exited 0. The focused Go tests used `-count=1` and race instrumentation.

### Exact Same-Ref Runtime and Gate Preflight

Before invoking the live command, record sanitized evidence for:

- clean runner source at `d1e32b6e06f7153a4db5a5a08b7026d6dd49fcfb`;
- exact-ref Edge and participating Node binary checksums/versions, process start times, and listeners;
- healthy `onexplayer-lemonade` capacity 3 and `rtx5090-lemonade` capacity 1, with selected aggregate capacity 4;
- an enabled blocking repeat-guard gate for the intended dev route/model and an active sanitized observation sink;
- non-empty worker-owned prompt and writable artifact paths under `/tmp/iop-repeat-guard-live/`.

Implementation evidence:

- Runner source:
  - checkout: `/Users/toki/agent-work/iop-dev`;
  - `HEAD=d1e32b6e06f7153a4db5a5a08b7026d6dd49fcfb`;
  - `git status --porcelain` was empty;
  - Edge artifact SHA-256: `c1dc3b13780ce2421867c2a56575b489136418b24acbae67d86dae6eba48d3cd`;
  - Windows node artifact SHA-256: `fc269bf238880845c8b0f419b0857b36d34e5953a69514b59f3fbeffbef10f5a`.
- Edge runtime:
  - PID `11006`, started `Wed Jul 29 19:35:36 2026`;
  - argv `./bin/edge --config edge.yaml serve`;
  - listeners `*:18083`, `*:18084`, and `127.0.0.1:19093`;
  - private config backup: `edge.yaml.pre-repeat-guard-20260729T103456Z.bak`;
  - candidate validation: `OK edge.repeat-guard.candidate.yaml`.
- Gate policy:
  - `enabled=true`, `environment=dev`;
  - filter `repeat_guard`, base `enabled=false`, `enforcement=blocking`;
  - capability `output.repeat_guard`, `hold_evidence_runes=500`, `timeout_ms=5000`;
  - selector `model_group=ornith:35b`, `enabled=true`, `enforcement=blocking`;
  - observation path `/tmp/iop-repeat-guard-live/edge-observations.jsonl`.
- OneXPlayer:
  - node binary version `0.1.0`, SHA-256 `fc269bf238880845c8b0f419b0857b36d34e5953a69514b59f3fbeffbef10f5a`;
  - node PID `15172`, started `2026-07-29T09:58:46.5143780Z`;
  - Lemonade PID `25352`, started `2026-07-26T04:14:05.0555770Z`;
  - llama PID `35560`, started `2026-07-26T04:14:06.1843090Z`;
  - listeners `0.0.0.0:13305` and `127.0.0.1:8001`.
- RTX5090:
  - Wake-on-LAN restored SSH connectivity;
  - node binary version `0.1.0`, SHA-256 `fc269bf238880845c8b0f419b0857b36d34e5953a69514b59f3fbeffbef10f5a`;
  - node PID `44152`, started `2026-07-29T10:40:19.0537930Z` with `Win32_Process.Create`;
  - Lemonade PID `3820`, started `2026-07-29T10:32:41.3051260Z`;
  - llama PID `19344`, started `2026-07-29T10:32:42.1607200Z`;
  - listeners `0.0.0.0:13305` and `127.0.0.1:8001`;
  - exact Ornith profile reported `ready=true`, `health=ok`, `model_loaded=true`, `profile_valid=true`, `listener_public=true`, and `edge_connected=true`.
- Selected provider snapshot immediately before the live invocation:

```text
onexplayer-lemonade connected=true health=healthy status=available capacity=3 in_flight=0 queued=0 capabilities=[list_models output.repeat_guard]
rtx5090-lemonade connected=true health=healthy status=available capacity=1 in_flight=0 queued=0 capabilities=[list_models output.repeat_guard]
selected_capacity=4
```

- Worker-owned inputs:
  - `/tmp/iop-repeat-guard-live/repeat-prompt.txt` was non-empty (`407` bytes);
  - `/tmp/iop-repeat-guard-live/repeat-guard/` was writable;
  - the observation path was a regular file.
- A single preflight request returned HTTP 200 and wrote `22` raw-free observations for one sanitized correlation. Observed filters were `noop`, `openai.repeat_guard`, and `openai.repeat_guard.action`; lifecycle kinds included staged, evaluation-started, evaluated, arbitration, release, and terminal. The raw response remained in `/tmp`.

### Clean Same-Ref Live Lifecycle and Capacity Evidence

After every preflight condition passes:

```bash
IOP_OPENAI_BASE_URL=http://127.0.0.1:18083 \
IOP_OPENAI_MODEL=ornith:35b \
IOP_OPENAI_SMOKE_CONCURRENCY=5 \
IOP_OPENAI_SMOKE_RUNS=3 \
IOP_OPENAI_SMOKE_PROMPT_FILE=/tmp/iop-repeat-guard-live/repeat-prompt.txt \
IOP_OPENAI_SMOKE_ARTIFACT_DIR=/tmp/iop-repeat-guard-live/repeat-guard \
IOP_OPENAI_SMOKE_OBSERVATION_FILE=/tmp/iop-repeat-guard-live/edge-observations.jsonl \
IOP_OPENAI_SMOKE_STATUS_URL=http://127.0.0.1:18001/edges/edge-toki-labs-dev/status \
IOP_OPENAI_SMOKE_PROVIDER_IDS=onexplayer-lemonade,rtx5090-lemonade \
go test -count=1 -v ./apps/edge/internal/openai -run '^TestDevRepeatGuardOrnithSmoke$'
```

Expected: exit 0; exactly 15 unique sanitized request correlations and three accepted capacity rows satisfying `4/4/>=1/0/0`, with no raw prompt, output, credential, or token in tracked files or stdout.

Implementation evidence:

Status: FAILED.

The first remote shell entry failed before the harness started:

```text
zsh:1: command not found: go
REMOTE_EXIT=127
```

No live HTTP request was issued by that shell. After provisioning the Homebrew Go path, the harness was invoked once:

```text
=== RUN   TestDevRepeatGuardOrnithSmoke
panic: test timed out after 10m0s
	running tests:
		TestDevRepeatGuardOrnithSmoke (10m0s)
...
FAIL	iop/apps/edge/internal/openai	600.564s
FAIL
REMOTE_EXIT=1
```

The timeout occurred in run 1 while three request goroutines were still reading SSE from OneXPlayer. Two raw SSE artifacts completed under the worker-owned `/tmp/iop-repeat-guard-live/repeat-guard/` directory. Because the test terminated before run 1 completed:

- no accepted capacity row was emitted;
- the required three `4/4/>=1/0/0` rows were not produced;
- the required summary of exactly 15 unique SSE-derived correlations was not produced;
- no live PASS claim is made.

Post-timeout cleanup evidence:

```text
onexplayer-lemonade connected=true health=healthy capacity=3 in_flight=0 queued=0
rtx5090-lemonade connected=true health=healthy capacity=1 in_flight=0 queued=0
selected_capacity=4
raw_artifact_count=2
cleanup=idle
```

Resume condition: a new explicitly authorized follow-up must permit a second live invocation, re-run the same exact-ref and capacity preflight, and use either a bounded long-Korean prompt that completes within Go's default 10-minute timeout or a reviewed command with a longer `go test -timeout`. The current plan's exactly-once live allowance has been consumed.

---

> **[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) |
| 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: Pass
  - Completeness: Fail
  - Test coverage: Fail
  - API contract: Pass
  - Code quality: Pass
  - Implementation deviation: Pass
  - Verification trust: Pass
  - Spec conformance: Fail
- Findings:
  - Required — `agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/CODE_REVIEW-cloud-G10.md:54`, `agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/CODE_REVIEW-cloud-G10.md:215`, and `agent-roadmap/sdd/knowledge-tool-optimization-extension/openai-compatible-output-validation-filters/SDD.md:158`: `REVIEW_OFR-REPEAT-8-1` remains incomplete because the one authorized live invocation exited 1 at Go's default 10-minute test timeout during run 1. It produced only two raw SSE artifacts, no accepted capacity row, no 15-correlation summary, and therefore does not satisfy the Milestone capacity+1 smoke or SDD S07. The same-ref runtime, enabled blocking gate, aggregate capacity 4, sanitized preflight observation, cleanup, and fresh focused race tests are all evidenced, so the next follow-up should preserve those preconditions, explicitly authorize one replacement live invocation, use a bounded long-Korean prompt and an outer `go test -timeout` compatible with the harness's own request/observer deadlines, then require exit 0, exactly 15 unique SSE-derived correlations, and three accepted `configured=4`, `peak_in_flight=4`, `peak_queued>=1`, `final_in_flight=0`, `final_queued=0` rows.
- Routing Signals: `review_rework_count=9`, `evidence_integrity_failure=false`
- Next Step: Archive this failed pair and create the routed follow-up PLAN/CODE_REVIEW pair for the same task path.
