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

# Code Review Reference - REVIEW_OFR-REPEAT-45

> **[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/02+01_repeat_guard, plan=46, tag=REVIEW_OFR-REPEAT-45

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

- Dependency `01_resume_notice_builder` is satisfied by `agent-task/archive/2026/07/m-openai-compatible-output-validation-filters/01_resume_notice_builder/complete.log`.
- The latest reviewed failure remains `agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/code_review_cloud_G08_44.log`: FAIL; Required=1, Suggested=0, Nit=0; live invocation count 0.
- The user-directed environment correction preserved the superseded no-verdict pair as `agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/plan_cloud_G08_45.log` and `agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/code_review_cloud_G08_45.log`.
- The superseded pair's local checks passed, but its Darwin source preflight ran on Linux and exited before SSH; the sole live authorization was not consumed.
- Fresh SSH evidence on 2026-07-30: `ssh toki@toki-labs.com` reaches Darwin/arm64 with `/bin/zsh`, Go 1.26.3, repo `/Users/toki/agent-work/iop-dev`, source HEAD `d1e32b6e06f7153a4db5a5a08b7026d6dd49fcfb`, and only `apps/edge/internal/openai/stream_gate_vertical_slice_test.go` modified at SHA-256 `8f0c767d6fb69175c6856fcd58f1398e89b9e13c6597dc950672b14b4013bd21`.
- The remote source tip `213eee4e28dfa69ff1e412faf23978ee9a9a3b9f` differs from the deployed runtime baseline only by the nine Agent-Ops policy files from the immediately preceding policy commit; no Go runtime or live-oracle source differs.
- Remote deterministic tests passed. Ports `18001`, `18083`, `18084`, and `19093` are open; all four nodes are connected; `onexplayer-lemonade` and `rtx5090-lemonade` are healthy and idle at capacity `3+1`; the prompt and observation files are present; the review-46 artifact directory is absent; and no live harness is running.

## 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_46.log` and `PLAN-cloud-G08.md` → `plan_cloud_G08_46.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-45-1 — Through `ssh toki@toki-labs.com`, rerun the complete remote preflight, execute exactly one fresh `ornith:35b` 5-concurrent × 3 live invocation, and record 15 provider responses, 15 Edge correlations, three accepted capacity rows, the sanitized final result, and cleanup evidence; if the remote preflight blocks execution, record exact output, invocation count 0, and the resume condition. | [x] |

## Implementation Checklist

- [x] [REVIEW_OFR-REPEAT-45-1] Through `ssh toki@toki-labs.com`, rerun the complete remote preflight, execute exactly one fresh `ornith:35b` 5-concurrent × 3 live invocation, and record 15 provider responses, 15 Edge correlations, three accepted capacity rows, the sanitized final result, and cleanup evidence; if the remote preflight blocks execution, record exact output, invocation count 0, and the resume condition.
- [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.

- [ ] Append one verdict of `PASS`, `WARN`, or `FAIL` and verified `review_rework_count`, `evidence_integrity_failure` to `Code Review Result`.
- [ ] Verify that verdict, `Dimension Assessment`, and Required/Suggested/Nit classifications match.
- [ ] Archive active `CODE_REVIEW-*-G??.md` to `code_review_cloud_G08_46.log`.
- [ ] Archive active `PLAN-*-G??.md` to `plan_cloud_G08_46.log`.
- [ ] 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.
- [ ] If WARN/FAIL, write the next filesystem state matching code-review verdict and do not write `complete.log`.

## Deviations from Plan

The planned sanitized-summary command exited at its initial `test -f` assertion because the failed live harness did not create `summary.json`; it therefore could not evaluate the planned cardinality/result predicates. No live invocation was retried. A read-only SSH cleanup probe was added solely to verify that the summary remained absent, both selected providers were idle, no harness process remained, and the reviewed source identity remained unchanged.

## Key Design Decisions

No source, configuration, runtime, or deployment change was made. The one authorized live invocation was preserved after the remote preflight passed. The HTTP 401 result is recorded as an external authentication prerequisite failure; retrying it would violate the single-invocation constraint.

## Reviewer Checkpoints

- Confirm every Darwin/source/runtime/live command crossed `ssh toki@toki-labs.com`; reject any local `zsh` attempt as non-evidence.
- Confirm the remote preflight proves the expected source HEAD, sole reviewed test delta/hash, fresh deterministic tests, listening Edge binary identity, config, four connected nodes, selected providers healthy/idle at capacity `3+1`, stable observation sink, absent artifact directory, and zero competing harnesses.
- Confirm exactly one live Go test starts after preflight and exits 0.
- Confirm `summary.json` has 15 globally unique provider response IDs, 15 globally unique Edge correlations, and three accepted capacity rows with `configured_capacity=4`, `peak_in_flight=4`, `peak_queued>=1`, `final_in_flight=0`, and `final_queued=0`.
- Confirm the sanitized result is `not_reproduced` or a valid `reproduced` lifecycle with fingerprint/offset; both providers return idle, no harness remains, source/runtime identities are unchanged, and no raw/secret-bearing material entered tracked evidence or stdout.
- If an SSH or user-controlled external prerequisite blocks the required evidence, apply the `external-execution` USER_REVIEW gate. Do not generate another plan that repeats a local or inaccessible preflight.

## Verification Results

Record actual stdout/stderr and exit codes for every command. Do not paste raw prompt, SSE, model output, credentials, tokens, private endpoint material, or full config/status payloads. If blocked, record the exact attempted SSH command/output, invocation count, and resume condition.

### Remote Preflight and Deterministic Verification

```bash
ssh -o BatchMode=yes -o ConnectTimeout=15 toki@toki-labs.com '/bin/zsh -lc "exec /bin/zsh -s"' <<'REMOTE'
set -euo pipefail
repo=/Users/toki/agent-work/iop-dev
expected_head=d1e32b6e06f7153a4db5a5a08b7026d6dd49fcfb
expected_test_hash=8f0c767d6fb69175c6856fcd58f1398e89b9e13c6597dc950672b14b4013bd21
test_file=apps/edge/internal/openai/stream_gate_vertical_slice_test.go
artifact_dir=/tmp/iop-repeat-guard-live/repeat-guard-review-46
prompt_file=/tmp/iop-repeat-guard-live/repeat-prompt.txt
observation_file=/tmp/iop-repeat-guard-live/edge-observations.jsonl
cd "$repo"
go_bin=$(command -v go)
jq_bin=$(command -v jq)
test "$(uname -s)" = Darwin
test "$(uname -m)" = arm64
test "$("$go_bin" env GOMOD)" = "$repo/go.mod"
test "$(git branch --show-current)" = feature/openai-compatible-output-validation-filters
test "$(git rev-parse HEAD)" = "$expected_head"
test "$(git diff --name-only)" = "$test_file"
test "$(/usr/bin/shasum -a 256 "$test_file" | /usr/bin/awk '{print $1}')" = "$expected_test_hash"
git diff --check
"$go_bin" test -count=1 ./apps/edge/internal/openai -run 'TestDevRepeatGuard(SmokeEvidence|ObservationCorrelation|ObservationQuiescence|CapacityEvidence)'
"$go_bin" test -count=1 ./packages/go/streamgate ./apps/edge/internal/openai
"$go_bin" test -count=1 ./packages/go/config
build/dev-runtime/bin/edge --config build/dev-runtime/edge.yaml config check >/dev/null
/usr/bin/grep -q '^    - filter: repeat_guard$' build/dev-runtime/edge.yaml
/usr/bin/grep -q '^        key: ornith:35b$' build/dev-runtime/edge.yaml
for port in 18001 18083 18084 19093; do /usr/bin/nc -z 127.0.0.1 "$port"; done
test -s "$prompt_file"
test -f "$observation_file"
test -w "$observation_file"
test ! -e "$artifact_dir"
observation_size_before=$(/usr/bin/stat -f %z "$observation_file")
sleep 2
observation_size_after=$(/usr/bin/stat -f %z "$observation_file")
test "$observation_size_before" = "$observation_size_after"
! /usr/bin/pgrep -fl '[T]estDevRepeatGuardOrnithSmoke' >/dev/null
edge_pid=$(/usr/sbin/lsof -tiTCP:18083 -sTCP:LISTEN)
test -n "$edge_pid"
edge_exe=$(/usr/sbin/lsof -a -p "$edge_pid" -d txt -Fn | /usr/bin/sed -n 's/^n//p' | /usr/bin/head -1)
test -n "$edge_exe"
test "$(/usr/bin/shasum -a 256 "$edge_exe" | /usr/bin/awk '{print $1}')" = "$(/usr/bin/shasum -a 256 build/dev-runtime/bin/edge | /usr/bin/awk '{print $1}')"
status_file=$(/usr/bin/mktemp -t iop-repeat-status.XXXXXX)
trap '/bin/rm -f "$status_file"' EXIT
/usr/bin/curl -fsS http://127.0.0.1:18001/edges/edge-toki-labs-dev/status > "$status_file"
"$jq_bin" -e '
  def provider($id): first(.nodes[].provider_snapshots[] | select(.id == $id));
  (.edge_id == "edge-toki-labs-dev") and
  ((.nodes | length) == 4) and
  (all(.nodes[]; .connected == true)) and
  (provider("onexplayer-lemonade").capacity == 3) and
  (provider("onexplayer-lemonade").health == "healthy") and
  (provider("onexplayer-lemonade").in_flight == 0) and
  (provider("onexplayer-lemonade").queued == 0) and
  (provider("rtx5090-lemonade").capacity == 1) and
  (provider("rtx5090-lemonade").health == "healthy") and
  (provider("rtx5090-lemonade").in_flight == 0) and
  (provider("rtx5090-lemonade").queued == 0)
' "$status_file" >/dev/null
printf 'remote_preflight=PASS head=%s test_hash=%s edge_pid=%s observation_size=%s providers=3+1_idle\n' "$expected_head" "$expected_test_hash" "$edge_pid" "$observation_size_after"
REMOTE
```

Expected: SSH exits 0; all fresh tests pass; the final line reports the reviewed HEAD/hash, one Edge PID, stable observation size, and idle `3+1` providers. This command does not start the live harness.

Implementation evidence:

Exit status: 0.

Sanitized stdout:

```text
ok  	iop/apps/edge/internal/openai	0.988s
ok  	iop/packages/go/streamgate	1.320s
ok  	iop/apps/edge/internal/openai	7.966s
ok  	iop/packages/go/config	0.546s
Connection to 127.0.0.1 port 18001 [tcp/*] succeeded!
Connection to 127.0.0.1 port 18083 [tcp/*] succeeded!
Connection to 127.0.0.1 port 18084 [tcp/*] succeeded!
Connection to 127.0.0.1 port 19093 [tcp/*] succeeded!
remote_preflight=PASS head=d1e32b6e06f7153a4db5a5a08b7026d6dd49fcfb test_hash=8f0c767d6fb69175c6856fcd58f1398e89b9e13c6597dc950672b14b4013bd21 edge_pid=11006 observation_size=66 providers=3+1_idle
```

All checks executed through the declared SSH boundary. The preflight did not start the live harness.

### Single Authorized Remote Live Invocation

```bash
ssh -o BatchMode=yes -o ConnectTimeout=15 toki@toki-labs.com '/bin/zsh -lc "exec /bin/zsh -s"' <<'REMOTE'
set -euo pipefail
cd /Users/toki/agent-work/iop-dev
go_bin=$(command -v go)
artifact_dir=/tmp/iop-repeat-guard-live/repeat-guard-review-46
test ! -e "$artifact_dir"
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="$artifact_dir" \
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_bin" test -timeout 90m -count=1 -v ./apps/edge/internal/openai -run '^TestDevRepeatGuardOrnithSmoke$'
REMOTE
```

Expected: invocation count 1 and exit 0.

Implementation evidence:

Exit status: 1. Invocation count: 1.

Sanitized stdout/stderr:

```text
=== RUN   TestDevRepeatGuardOrnithSmoke
    stream_gate_vertical_slice_test.go:2552: live repeat-guard request failed: run=1 attempt=1 returned non-2xx status 401
    stream_gate_vertical_slice_test.go:2552: live repeat-guard request failed: run=1 attempt=2 returned non-2xx status 401
    stream_gate_vertical_slice_test.go:2552: live repeat-guard request failed: run=1 attempt=5 returned non-2xx status 401
    stream_gate_vertical_slice_test.go:2552: live repeat-guard request failed: run=1 attempt=4 returned non-2xx status 401
    stream_gate_vertical_slice_test.go:2552: live repeat-guard request failed: run=1 attempt=3 returned non-2xx status 401
--- FAIL: TestDevRepeatGuardOrnithSmoke (2.01s)
FAIL
FAIL	iop/apps/edge/internal/openai	2.402s
FAIL
```

Blocker: the remote OpenAI-compatible endpoint rejected all five first-run requests with HTTP 401. No provider-response, lifecycle-correlation, capacity, or final-result summary was produced. Resume condition: restore the remote runner's authorized request authentication and explicitly authorize a new isolated live invocation; do not retry this consumed invocation.

### Sanitized Summary and Cleanup Verification

```bash
ssh -o BatchMode=yes -o ConnectTimeout=15 toki@toki-labs.com '/bin/zsh -lc "exec /bin/zsh -s"' <<'REMOTE'
set -euo pipefail
cd /Users/toki/agent-work/iop-dev
summary=/tmp/iop-repeat-guard-live/repeat-guard-review-46/summary.json
jq_bin=$(command -v jq)
test -f "$summary"
"$jq_bin" -e '
  (.model == "ornith:35b") and (.concurrency == 5) and (.runs == 3) and
  ((.provider_responses | length) == 15) and
  (([.provider_responses[].provider_response_id] | unique | length) == 15) and
  ((.lifecycles | length) == 15) and
  (([.lifecycles[].correlation_id] | unique | length) == 15) and
  ((.capacity_runs | length) == 3) and
  (all(.capacity_runs[];
    (.configured_capacity == 4) and (.peak_in_flight == 4) and
    (.peak_queued >= 1) and (.final_in_flight == 0) and (.final_queued == 0))) and
  ((.result == "not_reproduced") or
    ((.result == "reproduced") and
     any(.lifecycles[]; (.result == "reproduced") and ((.fingerprint // "") | length > 0) and (.offset >= 0))))
' "$summary" >/dev/null
status_file=$(/usr/bin/mktemp -t iop-repeat-cleanup.XXXXXX)
trap '/bin/rm -f "$status_file"' EXIT
/usr/bin/curl -fsS http://127.0.0.1:18001/edges/edge-toki-labs-dev/status > "$status_file"
"$jq_bin" -e '
  def provider($id): first(.nodes[].provider_snapshots[] | select(.id == $id));
  (provider("onexplayer-lemonade").in_flight == 0) and
  (provider("onexplayer-lemonade").queued == 0) and
  (provider("rtx5090-lemonade").in_flight == 0) and
  (provider("rtx5090-lemonade").queued == 0)
' "$status_file" >/dev/null
! /usr/bin/pgrep -fl '[T]estDevRepeatGuardOrnithSmoke' >/dev/null
test "$(git rev-parse HEAD)" = d1e32b6e06f7153a4db5a5a08b7026d6dd49fcfb
test "$(git diff --name-only)" = apps/edge/internal/openai/stream_gate_vertical_slice_test.go
test "$(/usr/bin/shasum -a 256 apps/edge/internal/openai/stream_gate_vertical_slice_test.go | /usr/bin/awk '{print $1}')" = 8f0c767d6fb69175c6856fcd58f1398e89b9e13c6597dc950672b14b4013bd21
printf 'remote_cleanup=PASS provider_responses=15 edge_correlations=15 capacity_runs=3 providers=idle\n'
REMOTE
```

Expected: exit 0 and one sanitized PASS line.

Implementation evidence:

The planned summary-and-cleanup command exited with status 1 and no stdout/stderr because `summary.json` was absent at its initial file assertion. Its 15-response, 15-correlation, capacity-row, and result predicates were therefore not evaluated.

The added read-only SSH cleanup probe exited with status 0:

```text
remote_failure_cleanup=PASS summary=absent providers=idle harness=absent source=unchanged
```

No sanitized final result exists because the live invocation was blocked by HTTP 401 before producing one.

---

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

## Superseded Task Record

- State: `SUPERSEDED_INCOMPLETE`
- This is not a code-review verdict. No `PASS`, `complete.log`, or roadmap completion is claimed for this task.
- The single authorized remote invocation was consumed and all five first-run requests returned HTTP 401 because the live command omitted the harness-supported `IOP_OPENAI_API_KEY`.
- The official review process ended without a verdict while its dispatcher state remained `running`; no corresponding dispatcher or agent process remained alive.
- On 2026-07-30, the user explicitly directed this task to be archived and replaced by an independent task 03 so the next loop does not inherit this task's repeated review history.
- Successor: `agent-task/m-openai-compatible-output-validation-filters/03_repeat_guard_s07_remote_evidence/`.
