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

# Code Review Reference - REVIEW_OFR-REPEAT-9

> **[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=10, tag=REVIEW_OFR-REPEAT-9

## 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_8.log` and their matching review logs remain the bounded same-task history.
- Current failed pair after archival: `plan_cloud_G10_9.log` and `code_review_cloud_G10_9.log`; the Required finding is the missing SDD S07 live result after the first authorized harness invocation hit Go's default 10-minute timeout.
- Fresh reviewer evidence: `git diff --check`, the focused Core terminal-fidelity race test, and the focused Edge correlation/capacity race tests exit 0. The same-ref preconditions and post-timeout idle cleanup are trustworthy; no 15-correlation summary or accepted capacity row was produced.
- Required follow-up: revalidate the unchanged same-ref runtime and gate preconditions, provision a bounded long-Korean prompt, and complete exactly one replacement 5-concurrent × 3 live harness invocation with an explicit 90-minute outer test timeout.

## 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-G09.md` → `code_review_cloud_G09_10.log` and `PLAN-cloud-G09.md` → `plan_cloud_G09_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/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-9-1 — Revalidate the exact same-ref gate and capacity preconditions, provision a bounded long-Korean prompt, and complete one replacement `ornith:35b` 5-concurrent × 3 live run with an explicit 90-minute outer timeout and the required sanitized evidence. | [ ] |

## Implementation Checklist

- [ ] [REVIEW_OFR-REPEAT-9-1] Revalidate the exact same-ref gate and capacity preconditions, provision a bounded long-Korean prompt, and complete one replacement `ornith:35b` 5-concurrent × 3 live run with an explicit 90-minute outer timeout and the required sanitized 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_G09_10.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G09_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/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 exact one authorized replacement invocation failed during run 1 after five requests completed. The harness found six complete `ornith:35b` observation groups where the batch required exactly five, so runs 2 and 3 were not started and no live PASS is claimed.
- No retry was attempted because the plan authorizes exactly one replacement invocation. The incomplete live item remains unchecked.
- No production, test, contract, spec, tracked configuration, or tracked raw-evidence file was changed. The prompt and five raw SSE artifacts remain in the ignored worker-owned `/tmp/iop-repeat-guard-live/` paths.

## Key Design Decisions

- Kept the reviewed source ref and deployed runtime unchanged and limited preparation to the worker-owned prompt and recoverably rotated raw artifact directory.
- Required the strict same-ref, runtime identity, gate, selected-capacity, observation-sink, and prompt preflight to pass before consuming the single invocation allowance.
- Used the prescribed `go test -timeout 90m` lifecycle command once, then stopped on its first failure without changing the harness or filtering evidence after the fact.
- Diagnosed the failure only from sanitized correlation IDs, timestamps, provider IDs, lifecycle metadata, and raw-artifact file metadata; raw prompt/output content and credentials were not copied into the workspace or tracked evidence.

## Reviewer Checkpoints

- Confirm that the runner, Edge, `onexplayer-lemonade`, and `rtx5090-lemonade` remain on exact reviewed ref `d1e32b6e06f7153a4db5a5a08b7026d6dd49fcfb`, with matching source, binary, process, listener, and provider identity evidence immediately before the replacement invocation.
- Confirm that both selected providers are healthy and selected aggregate capacity is 4 immediately before the replacement invocation.
- Confirm that the private deployed Edge configuration still enables the blocking repeat-guard stream-evidence gate for `ornith:35b` and that the sanitized observation sink is active.
- Confirm that the worker-owned prompt is non-empty, 256-2048 bytes, and requests six substantive Korean paragraphs of five to seven sentences each without exposing its raw contents in tracked evidence.
- Confirm that exactly one replacement live command is invoked only after every precondition passes and that it uses `go test -timeout 90m`.
- Confirm exactly 15 unique SSE-derived correlations and exactly three accepted capacity rows with `configured=4`, `peak_in_flight=4`, `peak_queued>=1`, `final_in_flight=0`, and `final_queued=0`.
- Confirm post-run idle cleanup and that raw prompts, SSE, outputs, credentials, and tokens remain outside the workspace.
- Confirm that no production, test, contract, spec, tracked config, or tracked raw-evidence file changes were made.
- If a precondition or the one replacement invocation fails, confirm that no retry occurred and that the exact blocker/failure 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:

All commands ran from `/config/workspace/iop-s1` at
`d1e32b6e06f7153a4db5a5a08b7026d6dd49fcfb`.

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

$ git 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.011s
exit=0

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

### Exact Same-Ref, Gate, Capacity, and Prompt Preflight

Immediately before the replacement invocation, 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;
- the enabled blocking repeat-guard gate for `ornith:35b` and an active writable sanitized observation sink;
- a non-empty 256-2048-byte worker-owned prompt with the bounded six-paragraph shape, without recording its raw contents;
- a writable or freshly rotated exact worker-owned raw artifact target under `/tmp/iop-repeat-guard-live/`.

Implementation evidence:

Strict preflight passed immediately before the replacement invocation:

- Runner: branch `feature/openai-compatible-output-validation-filters`, HEAD
  `d1e32b6e06f7153a4db5a5a08b7026d6dd49fcfb`, clean status, upstream
  delta `0/0`, Go `go1.26.3 darwin/arm64`, and module
  `/Users/toki/agent-work/iop-dev/go.mod`.
- Edge: version `0.1.0`, SHA-256
  `c1dc3b13780ce2421867c2a56575b489136418b24acbae67d86dae6eba48d3cd`,
  PID `11006`, start time `Wed Jul 29 19:35:36 2026`, argv
  `./bin/edge --config edge.yaml serve`, and the same process owned listeners
  `*:18083`, `*:18084`, and `127.0.0.1:19093`.
- `onexplayer-lemonade`: connected, healthy, available, capacity `3`,
  `in_flight=0`, `queued=0`, repeat-guard capability present. Its Node
  version was `0.1.0`, SHA-256
  `fc269bf238880845c8b0f419b0857b36d34e5953a69514b59f3fbeffbef10f5a`,
  PID `15172`, start time `2026-07-29T09:58:46.5143780Z`; the associated
  Lemonade and llama processes and loopback `8001`/public `13305` listeners
  were present.
- `rtx5090-lemonade`: connected, healthy, available, capacity `1`,
  `in_flight=0`, `queued=0`, repeat-guard capability present. Its Node
  version was `0.1.0`, the same expected Node SHA-256, PID `44152`, start
  time `2026-07-29T19:40:19.0537930+09:00`; the associated Lemonade and
  llama processes and loopback `8001`/public `13305` listeners were present.
- Selected aggregate provider capacity was `4`, with final preflight
  `in_flight=0` and `queued=0`.
- The deployed gate was enabled in `dev`, selected `ornith:35b`, required
  capability `output.repeat_guard`, and used blocking enforcement with
  hold `500 ms` and timeout `5000 ms`. The private inbound API key was
  present but not printed.
- `/tmp/iop-repeat-guard-live/edge-observations.jsonl` was a regular,
  writable file actively held by Edge, and the sanitized-field scan found
  zero forbidden raw keys.
- `/tmp/iop-repeat-guard-live/repeat-prompt.txt` was `666` bytes and
  requested exactly six substantive Korean paragraphs of five to seven
  sentences without headings, lists, nesting, or repeated subsections. Its
  raw contents were not recorded.
- The prior raw artifact target was moved recoverably to
  `/tmp/iop-repeat-guard-live/repeat-guard-pre-G09`; a fresh mode-`0700`
  `/tmp/iop-repeat-guard-live/repeat-guard/` was empty and writable.

### Bounded Replacement 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 -timeout 90m -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:

Invocation count: exactly `1`; retry count: `0`. The API key was injected
from the private runner configuration without being printed. The prescribed
command above was used unchanged.

```text
=== RUN   TestDevRepeatGuardOrnithSmoke
    stream_gate_vertical_slice_test.go:2566: read observation segment for run=1: observation groups=6 complete=6, want 5
--- FAIL: TestDevRepeatGuardOrnithSmoke (360.10s)
FAIL
FAIL	iop/apps/edge/internal/openai	360.691s
FAIL
REMOTE_EXIT=1
```

Sanitized post-failure evidence:

- Run 1 produced exactly five mode-`0600` raw SSE files and no summary file.
  Their completion mtimes matched five of the six terminal observation
  groups. The additional complete group was
  `req.manual-1785324426339266000` on `rtx5090-lemonade`; it had no matching
  run-1 artifact completion time.
- The five unique SSE-derived expected correlation IDs had no intersection
  with the six Edge observation correlation IDs. This exact-ID mismatch was
  not reached by the harness because the earlier six-versus-five cardinality
  check failed.
- Reaching the observation read proves that the run-1 capacity observer
  returned through its validated path, whose enforced invariants are
  `configured=4`, `peak_in_flight=4`, `peak_queued>=1`,
  `final_in_flight=0`, and `final_queued=0`. The failure prevented the
  harness from emitting or persisting that row, and no rows exist for runs
  2 or 3; therefore the required three accepted capacity rows are absent.
- Post-run status was idle:
  `onexplayer-lemonade=available/healthy/capacity:3/in_flight:0/queued:0`
  and
  `rtx5090-lemonade=available/healthy/capacity:1/in_flight:0/queued:0`.
- Raw prompt/output, SSE bodies, credentials, and tokens remain outside the
  workspace and were not printed or added to tracked files.

Resume condition: a separately authorized follow-up must first isolate the
observation segment from unmatched same-model traffic and establish that the
SSE-derived expected IDs match the Edge observation correlation IDs. It must
then revalidate the same-ref/runtime/gate/capacity preconditions and explicitly
authorize a fresh live invocation; the replacement allowance in this plan 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: Fail
  - 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-G09.md:52`, `agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/CODE_REVIEW-cloud-G09.md:174`, `apps/edge/internal/openai/stream_gate_vertical_slice_test.go:2994`, `apps/edge/internal/openai/stream_gate_runtime.go:1415`, and `agent-roadmap/sdd/knowledge-tool-optimization-extension/openai-compatible-output-validation-filters/SDD.md:158`: `REVIEW_OFR-REPEAT-9-1` remains incomplete because the single authorized live invocation exited 1 during run 1. Its observation segment contained six complete same-model groups for five harness requests, including one unmatched manual request, so no isolated five-request batch, 15-correlation summary, or three accepted capacity rows exists. Fresh failure evidence also proves that all five provider SSE-derived IDs have no intersection with the Edge observation correlations: the live provider-tunnel path preserves provider-native SSE IDs while the Stream Evidence Gate stable correlation is derived from the internal dispatch `RunID`, so the harness's current `chatcmpl-*` to `req.*` equality assumption is invalid for this path. The follow-up must add deterministic regression coverage, separate provider-native SSE identity from Edge observation correlation, require an uncontaminated exact five-group observation segment without post-hoc filtering, preserve one terminal and one lifecycle per group, and only then authorize one fresh 5-concurrent × 3 live invocation that produces 15 unique Edge 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=10`, `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.
