<!-- task=m-openai-compatible-output-validation-filters/03_repeat_guard_s07_remote_evidence plan=6 tag=REVIEW_OFR-S07-STALE-LEASE-6 -->

# Code Review Reference - REVIEW_OFR-S07-STALE-LEASE-6

> **[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, mutation count, invocation count, 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=6, tag=REVIEW_OFR-S07-STALE-LEASE-6

## 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_0.log` / `code_review_cloud_G08_0.log`: authentication blocker; `invocation_count=0`.
- `plan_cloud_G08_1.log` / `code_review_cloud_G08_1.log`: one consumed incomplete invocation; no accepted summary.
- `user_review_1.log`: resolved authorization/replan boundary and zero-provider-snapshot diagnosis.
- `plan_cloud_G09_2.log` / `code_review_cloud_G09_2.log`: no-change Edge apply left provider snapshots absent; `invocation_count=0`.
- `plan_cloud_G10_3.log` / `code_review_cloud_G10_3.log`: the rebuilt image came from the wrong sibling checkout and still exposed no provider snapshots; `invocation_count=0`.
- `plan_cloud_G10_4.log` / `code_review_cloud_G10_4.log`: the pinned image and current status contract were restored, but OneXPlayer remained at `in_flight=1`; three latest OneXPlayer correlations were terminal, the harness was absent, and `invocation_count=0`.
- `plan_cloud_G10_5.log` / `code_review_cloud_G10_5.log`: the stale-lease gate passed, but the focused non-login SSH command could not resolve `go`; the run stopped before mutation with `node_stop_count=0 node_create_count=0 invocation_count=0`. Review independently passed the same tests with `/opt/homebrew/bin/go`.
- Preserve all existing `/tmp/iop-repeat-guard-live/repeat-guard-task-03-*` artifacts. The only new result path is `/tmp/iop-repeat-guard-live/repeat-guard-task-03-plan-6`.

## 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_6.log` and `PLAN-cloud-G10.md` → `plan_cloud_G10_6.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-STALE-LEASE-6-1 | [x] |
| REVIEW_OFR-S07-STALE-LEASE-6-2 | [ ] |

## Implementation Checklist

- [x] [REVIEW_OFR-S07-STALE-LEASE-6-1] Revalidate the bounded stale-lease evidence, pass the focused generation-settlement tests, then stop and recreate only the OneXPlayer Node process exactly once and require a new connected generation with both selected providers healthy and idle at capacities `3+1`.
- [ ] [REVIEW_OFR-S07-STALE-LEASE-6-2] Only after the generation/status gate passes, start exactly one caller-owned foreground 5-concurrent x 3-run S07 invocation on the fresh plan-6 path, validate the raw-free summary and idle cleanup, and preserve every prior artifact.
- [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_6.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G10_6.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 two direct provider-status predicates suppressed their JSON payloads and emitted sanitized PASS markers instead. The predicates were unchanged; this avoided recording a raw status payload.
- The one-use PowerShell reset command exited `0` but emitted no JSON stdout. It was not retried. Its built-in `newPid != oldPid` assertion therefore passed, and a separate read-only probe identified the new process as PID `42004`, created at `2026-07-30T12:32:26.9448610+09:00`.
- The foreground S07 invocation exited `1` after `remote_live_start`. Per the no-retry rule, the successful-only summary command was not executed. A raw-free read-only post-failure probe was used to confirm process exit, provider cleanup, artifact preservation, and source identity.
- The first post-failure probe exited `1` with no output because `pgrep` correctly found no harness and `pipefail` propagated that no-match status. The read-only probe was corrected to allow a no-match result and rerun; no Node mutation or model invocation was repeated.
- The credential grep body was suppressed to avoid printing a possible credential from unrelated user changes. The exact tracked-file grep expression was executed, followed by a path-only scan. Because the active task directory is untracked, a separate `rg` scan checked the active plan/review pair.

## Key Design Decisions

- Treat the reset and foreground invocation as consumed exactly once even when expected stdout or the model test result was unsuccessful.
- Preserve `/tmp/iop-repeat-guard-live/repeat-guard-task-03-plan-6` exactly as produced. Do not synthesize a summary, delete partial artifacts, or reuse the path.
- Stop after the terminal-count failure. Resume requires a new reviewed packet that diagnoses the missing SSE terminal and explicitly authorizes another fresh-path, one-use invocation.

## Reviewer Checkpoints

- Verify the read-only gate proves the exact latest OneXPlayer correlation is terminal, no later OneXPlayer observation exists, the S07 harness is absent, and three current snapshots retain `in_flight=1`.
- Verify the source/image contract and the three focused generation-settlement tests pass before mutation.
- Verify exactly one matching OneXPlayer `iop-node.exe` is stopped and exactly one different PID is launched through `Win32_Process.Create`.
- Verify Lemonade, the loaded model, Control Plane, Edge, configuration, other Nodes, credentials, and prior artifacts are untouched.
- Verify the post-reconnect gate has four connected nodes and healthy/idle OneXPlayer/RTX5090 snapshots at capacities `3+1`.
- Verify SOPS authentication prints no raw token, token hash, or Authorization value.
- Verify the foreground Go process starts at most once, stays caller-owned until terminal exit, and is never retried.
- Verify accepted summary cardinalities, capacity rows, result classification, idle cleanup, source identity, artifact isolation, and secret hygiene.
- Verify PASS reports only `repeat-guard`, not `ops-evidence`.

## Verification Results

### Bounded stale-lease, identity, and focused-test gate

Commands:

- Execute the exact `Bounded read-only stale-lease and identity gate` commands in `PLAN-cloud-G10.md`.
- Execute the exact `Focused generation-settlement tests` command in `PLAN-cloud-G10.md`.

Implementation evidence:

Direct provider predicates and bounded stale-lease gate:

```text
onexplayer_direct_status=PASS ready=true health=ok model_loaded=true node_processes=1 edge_connected=true
rtx5090_direct_status=PASS ready=true health=ok model_loaded=true edge_connected=true
stale_lease_gate=PASS latest_correlation=req.manual-1785372720434474000 latest_kind=terminal_committed samples=3 onex_in_flight=1 harness=absent source=unchanged image=pinned node_stop_count=0 node_create_count=0 invocation_count=0
```

Exit status: `0`.

Pinned toolchain and focused tests:

```text
go version go1.26.3 darwin/arm64
/Users/toki/agent-work/iop-dev/go.mod
ok  	iop/apps/edge/internal/service	0.548s
```

Exit status: `0`. The three focused tests ran with `/opt/homebrew/bin/go`, `-count=1`, and the exact anchored test-name expression from the plan.

### Single OneXPlayer Node generation reset

Command:

- Execute the exact `Single OneXPlayer Node generation reset` commands in `PLAN-cloud-G10.md` once.

Implementation evidence:

The exact one-use reset command exited `0` and emitted no stdout. It was not retried. Because the command throws if the new PID equals the old PID, exit `0` proves the old/new PID distinction. A read-only follow-up identified the new process and verified the exact command match:

```text
node_process_gate=PASS count=1 pid=42004 creation_time=2026-07-30T12:32:26.9448610+09:00 command_match=true
node_generation_gate=PASS nodes=4 providers=3+1_idle onex_in_flight=0 node_stop_count=1 node_create_count=1 invocation_count=0
onexplayer_post_reset_status=PASS ready=true health=ok model_loaded=true node_processes=1 edge_connected=true
```

Exit status: `0`. Final reset counts: `node_stop_count=1 node_create_count=1 invocation_count=0`. No retry, Lemonade/model restart, Edge/Control Plane mutation, config change, or other-Node action was performed.

### Foreground S07 invocation

Command:

- Execute the exact `Foreground invocation` command in `PLAN-cloud-G10.md` at most once and only after the generation gate passes.

Implementation evidence:

The single caller-owned foreground invocation started once:

```text
remote_live_start invocation_count=1 ownership=foreground artifact=plan-6
=== RUN   TestDevRepeatGuardOrnithSmoke
    stream_gate_vertical_slice_test.go:2542: live repeat-guard request failed: run=1 attempt=1 invalid SSE: terminal event count=0, want 1
--- FAIL: TestDevRepeatGuardOrnithSmoke (311.62s)
FAIL
FAIL	iop/apps/edge/internal/openai	312.199s
FAIL
```

Exit status: `1`. The invocation was consumed and was not retried. Final counts: `node_stop_count=1 node_create_count=1 invocation_count=1`.

### Sanitized summary and cleanup

Command:

- Execute the exact `Sanitized summary and cleanup` command in `PLAN-cloud-G10.md` only after a successful foreground invocation.

Implementation evidence:

Not executed because the foreground invocation did not exit `0`; its exact blocker was `run=1 attempt=1 invalid SSE: terminal event count=0, want 1`. No accepted `summary.json` exists.

The first read-only post-failure probe exited `1` with no output because a no-match `pgrep` result propagated through `pipefail`. After correcting only that read-only predicate, the probe returned:

```text
post_failure_probe=PASS artifact_present=true summary_present=false harness_count=0 source_head=750cb1d1cb88066a10d3c703c99f1326306d8e15 source_dirty_count=0 nodes=4 connected=4 onex_capacity=3 onex_in_flight=0 onex_queued=0 rtx_capacity=1 rtx_in_flight=0 rtx_queued=0 node_stop_count=1 node_create_count=1 invocation_count=1
onexplayer_post_failure_status=PASS ready=true health=ok model_loaded=true node_processes=1 edge_connected=true
```

Corrected probe exit status: `0`. The failed run artifact remains isolated at plan-6, the harness is absent, both providers are idle, and prior artifacts were not modified. Resume condition: diagnose the missing SSE terminal from the preserved plan-6 artifact, create a new reviewed packet with a fresh artifact path, and explicitly authorize one new invocation; this packet cannot be reused.

### Local workspace hygiene

Commands:

```bash
git diff --check
git status --short
git grep -nE '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` produced no output and exited `0`.

`git status --short` exited `0` and returned:

```text
 M --check
 M agent-ops/skills/common/code-review/templates/user-review-template.md
 M agent-ops/skills/project/orchestrate-agent-task-loop/SKILL.md
 M agent-ops/skills/project/orchestrate-agent-task-loop/scripts/dispatch.py
 M agent-ops/skills/project/orchestrate-agent-task-loop/tests/test_dispatch.py
 D agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/CODE_REVIEW-cloud-G10.md
 D agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/PLAN-cloud-G10.md
 D agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/code_review_cloud_G10_0.log
 D agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/code_review_cloud_G10_1.log
 D agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/code_review_cloud_G10_2.log
 D agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/code_review_cloud_G10_3.log
 D agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/code_review_cloud_G10_4.log
 D agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/code_review_cloud_G10_5.log
 D agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/code_review_cloud_G10_6.log
 D agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/code_review_cloud_G10_7.log
 D agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/plan_cloud_G10_0.log
 D agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/plan_cloud_G10_1.log
 D agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/plan_cloud_G10_2.log
 D agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/plan_cloud_G10_3.log
 D agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/plan_cloud_G10_4.log
 D agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/plan_cloud_G10_5.log
 D agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/plan_cloud_G10_6.log
 D agent-task/m-openai-compatible-output-validation-filters/02+01_repeat_guard/plan_cloud_G10_7.log
 M agent-task/m-openai-compatible-output-validation-filters/WORK_LOG.md
 M apps/edge/internal/openai/stream_gate_vertical_slice_test.go
?? agent-task/archive/2026/07/m-openai-compatible-output-validation-filters/02+01_repeat_guard/
?? agent-task/archive/2026/07/m-openai-compatible-output-validation-filters/work_log_1.log
?? agent-task/m-openai-compatible-output-validation-filters/03_repeat_guard_s07_remote_evidence/
```

These were all present in the initial workspace status, including the untracked active task directory. This implementation changed only this review file inside that directory.

The exact credential grep expression exited `0` because it found existing examples/fixtures in 21 tracked paths, and the path-only scan also exited `0`. No raw grep body was printed. The active task directory is untracked and therefore is not covered by `git grep`; a separate broad `rg` scan self-matched only the two stored grep command lines, while a token-shaped scan for `sk-` credentials or alphanumeric bearer values returned no matches (`exit 1`). Final counts: `node_stop_count=1 node_create_count=1 invocation_count=1`.

---

> **[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 — the repeat guard exhausted its three recovery dispatches and committed an internal error terminal, but the post-header tunnel sink emitted neither an error event nor `[DONE]`; the caller observed a truncated SSE stream.
  - Completeness: Fail — the foreground S07 smoke stopped in run 1 attempt 1, so the required three-run capacity+1 evidence and accepted `summary.json` do not exist.
  - Test Coverage: Fail — focused local tests pass, but there is no tunnel-path regression proving endpoint-valid terminal framing when repeat recovery is exhausted after a response prefix has been committed.
  - API Contract: Fail — a `200` OpenAI-compatible Chat SSE response ended with zero terminal markers, violating the required endpoint-native terminal sequence and the S03 single-`[DONE]` continuation contract.
  - Code Quality: Pass — the reviewed implementation remains localized and the plan-6 evidence is sanitized, bounded, and internally consistent.
  - Implementation Deviation: Pass — the implementing agent performed exactly one Node stop, one Node create, and one foreground model invocation, then stopped without retry after the failure as required.
  - Verification Trust: Pass — fresh uncached local tests passed, the preserved plan-6 artifact contains five parseable SSE attempts, and correlated observations independently show three recovery dispatches followed by one committed error terminal for the truncated caller request.
  - Spec Conformance: Fail — S03 terminal framing and the S07 three-run Evidence Map row remain unsatisfied, so the targeted `repeat-guard` milestone task cannot close.
- Findings:
  - Required — `apps/edge/internal/openai/stream_gate_release_sink.go:388`: after response headers and an accepted prefix are committed, `openAITunnelReleaseSink.CommitTerminal` returns `TerminalCommitted` for an error without writing any caller-visible terminal frame. The preserved plan-6 artifact proves the impact: its first request has zero error events, zero finish reasons, and zero `[DONE]` markers, while the correlated observation records four repeat violations, three recovery dispatches, and a final internal error terminal. Change the stream-evidence-gated Chat tunnel error path to serialize one endpoint-native error event followed by exactly one `[DONE]` after the committed prefix, without replaying rejected provider bytes; add a tunnel cap-exhaustion regression that asserts the preserved prefix, sanitized error, one `[DONE]`, no later event, and no duplicate terminal.
  - Required — `apps/edge/internal/openai/stream_gate_vertical_slice_test.go:2995`: `validateDevRepeatGuardSSE` increments `terminalCount` for an error envelope and again for the following `[DONE]`, so it would reject the required normalized error sequence as two terminals. Model a logical terminal sequence instead: accept either a success completion followed by one final `[DONE]` or one error event followed by one final `[DONE]`, while rejecting a missing/duplicate `[DONE]`, multiple error events, mixed success/error terminal state, and any event after `[DONE]`; cover those cases with focused validator tests before another bounded live run.
- Routing Signals:
  - `review_rework_count=7`
  - `evidence_integrity_failure=false`
- Next Step: Prepare the smallest fresh follow-up plan that fixes post-commit tunnel terminal framing and the live validator, then reruns the bounded local gates and a newly authorized one-use S07 smoke with a fresh artifact path; do not write `complete.log`.
