<!-- task=m-iop-owned-single-request-agent-execution/20+19_review_repair plan=5 tag=REVIEW_API milestone-task=review-stage -->

# Finish the path-faithful Review evidence oracle

## For the Implementing Agent

Filling the implementation-owned sections of `CODE_REVIEW-cloud-G06.md` is the mandatory final implementation step. Run every verification command, paste actual output, keep both active files in place, and report ready for review. Only the official code-review skill may append a verdict, archive files, write `complete.log`, or classify the next state. If blocked, record only the exact blocker, attempted commands/output, and resume condition in implementation-owned evidence fields; do not ask the user, call user-input tools, create control-plane stop files, change ownership or scope, archive logs, or write `complete.log`.

## Background

The service-backed Node failure and Review continuation race fixtures now execute and all recorded commands pass. Required R1 remains open because the authority test still checks selected fields instead of complete frozen structures, while the coordinator failure test does not observe Review artifact or finalizing leakage. This follow-up replaces those partial oracles without changing production behavior.

## Archive Evidence Snapshot

- The reviewed pair is archived as `agent-task/m-iop-owned-single-request-agent-execution/20+19_review_repair/plan_cloud_G06_4.log` and `agent-task/m-iop-owned-single-request-agent-execution/20+19_review_repair/code_review_cloud_G06_4.log`; the official verdict is FAIL with Required R1 and no Suggested or Nit findings.
- R1: `TestSingleRequestReviewStageExactBodyAuthority` checks selected Run/Tunnel/body/tool fields instead of complete frozen equality, and `TestSingleRequestReviewStageCoordinatorToolFailure` does not observe Review artifact writes or finalizing state leakage.
- Fresh reviewer execution passed the dependency check, focused Review race test, service compatibility, OpenAI vet/regression, fixture and path guards, formatting, production Review hash, activation guard, lifecycle-table guard, and diff hygiene. Passing commands do not substitute for the missing assertions.
- The sole predecessor remains `agent-task/archive/2026/08/m-iop-owned-single-request-agent-execution/19+18_work_stage/complete.log`. The contribution remains `milestone-task=review-stage`; production composite activation and S12 external Claude/Mac qualification remain outside this follow-up.

## Finding Resolution Map

| Finding | Mode | Exact fix | Changed precondition |
|---------|------|-----------|----------------------|
| Required R1 | `direct-fix` | Replace selected Review request/dispatch checks with literal complete initial/resumed body and closed-schema equality, normalized full Run/Tunnel equality, and candidate behavior assertions; instrument the service-backed failure wrapper to count Review artifact writes and finalizing submissions and require both to remain zero in `apps/edge/internal/openai/single_request_review_stage_test.go`; replace active review evidence with fresh output. | Re-review receives independent complete authority oracles and directly observed no-REVIEW/no-finalizing evidence instead of another passing run of partial assertions. |

## Analysis

### Files Read

- `apps/edge/internal/openai/chat_types.go`
- `apps/edge/internal/openai/single_request_provider_stage_test.go`
- `apps/edge/internal/openai/single_request_review_stage.go`
- `apps/edge/internal/openai/single_request_review_stage_test.go`
- `apps/edge/internal/openai/single_request_work_stage.go`
- `apps/edge/internal/openai/single_request_work_stage_test.go`
- `apps/edge/internal/service/provider_pool.go`
- `apps/edge/internal/service/provider_tunnel.go`
- `apps/edge/internal/service/run_types.go`
- `apps/edge/internal/service/single_request.go`
- `apps/edge/internal/service/single_request_tool_loop.go`
- `apps/edge/internal/service/single_request_types.go`
- `agent-roadmap/phase/knowledge-tool-optimization-extension/milestones/iop-owned-single-request-agent-execution.md`
- `agent-roadmap/sdd/knowledge-tool-optimization-extension/iop-owned-single-request-agent-execution/SDD.md`
- `agent-spec/input/openai-compatible-surface.md`
- `agent-spec/runtime/edge-node-execution.md`
- `agent-contract/outer/anthropic-compatible-api.md`
- `agent-contract/inner/edge-node-runtime-wire.md`
- `agent-task/m-iop-owned-single-request-agent-execution/20+19_review_repair/plan_cloud_G06_4.log`
- `agent-task/m-iop-owned-single-request-agent-execution/20+19_review_repair/code_review_cloud_G06_4.log`

### SDD Criteria

- SDD: `agent-roadmap/sdd/knowledge-tool-optimization-extension/iop-owned-single-request-agent-execution/SDD.md`; status `[승인됨]`, lock released, no user review.
- First-line contribution: `milestone-task=review-stage`.
- Acceptance Scenario S10 requires Gemini high-reasoning Review to pass or repair/reverify and produce the final result. Its Evidence Map requires Review pass/defect/repair plus finalization evidence.
- The implementation checklist therefore requires an exact independent frozen Review authority oracle and a service/Node failure oracle that directly excludes Review artifact and finalizing leakage. S12 remains separate.

### Verification Context

- No external handoff was supplied. Repository-native fallback used `agent-test/local/rules.md`, `agent-test/local/edge-smoke.md`, the approved SDD, current source/tests, the active pair, and the exact predecessor completion.
- Workdir is the repository root on branch `feature/iop-owned-single-request-agent-execution`, HEAD `22a8b81201e89d75c1e6c92342a8081472e8e436`, with unrelated shared dirty changes preserved. Toolchain is `go1.26.2 linux/arm64` for a Go 1.24 module.
- Fresh commands passed: predecessor resolution, focused Review `-race`, service state/cleanup compatibility, OpenAI vet/regression, fixture/path guards, formatting, production source hash, activation guard, lifecycle-table guard, and `git diff --check`.
- No remote runner, provider, credential, port, or device is needed. Actual Claude/Mac full-cycle qualification remains S12 `claude-smoke`, not a substitute for this deterministic test repair. Confidence is high because the missing oracle fields and state observations are explicit in the current test.

### Test Coverage Gaps

- Partial: complete Review authority. The current test checks only selected Run/Tunnel fields, predicate presence, message fragments/identifiers, and tool names. It does not fail on omitted or changed zero-valued dispatch fields, candidate behavior, full message content, tool arguments/result content, descriptions, required lists, property schemas, or command/environment constraints.
- Partial: service-backed Node failure. It proves typed terminal, raw-text exclusion, one provider/tool call, zero continuation, cleanup, and zero bridge waiters, but not zero Review artifact write, zero finalizing submission, empty result, or terminal failed state.
- Covered and retained: Review pass persistence, inspection/repair state legality, provider/envelope failures, concurrent duplicate delivery, post-cancel stale delivery, production source boundary, and package regressions.

### Symbol References

- None. This is test-only evidence repair; no production symbol is renamed or removed.

### Split Judgment

- Keep one plan. Complete authority equality and failure-leak observation close one compact R1 oracle in the same Review test file and share the same captured request and coordinator harness.
- The `20+19_review_repair` predecessor index 19 is satisfied by `agent-task/archive/2026/08/m-iop-owned-single-request-agent-execution/19+18_work_stage/complete.log`.

### Scope Rationale

- Include only `apps/edge/internal/openai/single_request_review_stage_test.go` and the active review evidence file.
- Exclude production Review/Work/service code, composite executor installation, lifecycle-table changes, contracts/specs, generic error/cancel work, and S12 external qualification. The current production seams already expose every required assertion.

### Final Routing

- `evaluation_mode=isolated-reassessment`; build and review `scope_closed`, `context_closed`, `verification_closed`, `evidence_trusted`, `ownership_closed`, and `decision_closed` are all true; capability gap is absent.
- Build scores `1/2/0/2/1` produce G06 with base `local-fit`. `large_indivisible_context=false`; positive risks are `temporal_state`, `concurrent_consistency`, `boundary_contract`, and `structured_interpretation` (`loop_risk_count=4`).
- `review_rework_count=3` and `evidence_integrity_failure=true` select `recovery-boundary`: `worker/cloud/G06`, `PLAN-cloud-G06.md`.
- Review scores `1/2/0/2/1` produce `official-review`, `review/cloud/G06`, `CODE_REVIEW-cloud-G06.md`.
- Finalizer: `finalize-task-policy.sh`, mode `pair`.

## Dependencies and Execution Order

1. Resolve exactly one task-19 completion with Final Verification command 1.
2. Replace both partial oracles before rerunning the focused race command.
3. Fill `CODE_REVIEW-cloud-G06.md` only after every command completes.

## Implementation Checklist

- [ ] Deep-compare literal complete initial/resumed Review bodies, closed tool schemas, normalized full Run/Tunnel requests, and accepted/rejected candidate behavior.
- [ ] Count Review artifact writes and finalizing submissions in the service-backed Node failure harness and assert both remain zero together with failed state, empty result, cleanup, and zero waiters.
- [ ] Run dependency, focused race, service compatibility, OpenAI vet/regression, deterministic oracle guards, formatting, source-boundary, activation, lifecycle-diff, and diff-hygiene checks.
- [ ] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

### [REVIEW_API-1] Replace partial Review assertions with complete independent oracles

**Problem**

At `apps/edge/internal/openai/single_request_review_stage_test.go:472`, dispatch assertions enumerate selected fields and test only `AcceptCandidate != nil`. At lines 484-569 the body assertion uses key count, selected values, substring checks, and tool names instead of comparing the complete initial/resumed payload and schemas. At lines 851-865 the coordinator failure checks operational counts but never observes attempted REVIEW writes or finalizing submissions.

**Solution**

Create literal expected body/tool structures independent of `singleRequestWorkTools`, compare the decoded initial and resumed payload maps with `reflect.DeepEqual`, and compare complete `SubmitRunRequest`/`SubmitProviderTunnelRequest` values after clearing only the `BuildBody` function. Require all unused provider-pool preparers/recovery selectors to be zero and invoke `AcceptCandidate` against both the frozen provider and a rejected provider. Extend `reviewSequenceController` with executor-owned atomic counters for `SingleRequestArtifactReview` writes and `SingleRequestStateFinalizing` submissions, then require both counters to remain zero on a non-success Node response together with failed state and empty result.

Before (`single_request_review_stage_test.go:472`):

```go
if req.Run.NodeRef != "node" || req.Run.ModelGroupKey != dispatch.ModelGroupKey || req.Run.ProviderID != dispatch.ProviderID {
    t.Fatalf("dispatch %d Run mismatch: %+v", i, req.Run)
}
if req.AcceptCandidate == nil {
    t.Fatalf("dispatch %d missing AcceptCandidate predicate", i)
}
```

After:

```go
assertSingleRequestReviewDispatchAuthority(t, req, dispatch)
if !reflect.DeepEqual(payload, expectedSingleRequestReviewBodyAuthority(isResumed)) {
    t.Fatalf("body authority mismatch:\n got: %#v\nwant: %#v", payload, expectedSingleRequestReviewBodyAuthority(isResumed))
}
if harness.executor.reviewWriteCount.Load() != 0 || harness.executor.finalizingCount.Load() != 0 || execution.State() != edgeservice.SingleRequestStateFailed || waitRes.result.Output != "" {
    t.Fatalf("review/finalizing leak: writes=%d finalizing=%d state=%s result=%q", harness.executor.reviewWriteCount.Load(), harness.executor.finalizingCount.Load(), execution.State(), waitRes.result.Output)
}
```

**Modified Files and Checklist**

- [ ] Update `apps/edge/internal/openai/single_request_review_stage_test.go` with literal body/schema authority, normalized complete dispatch checks, candidate behavior, and explicit Review/finalizing leak counters.
- [ ] Update `agent-task/m-iop-owned-single-request-agent-execution/20+19_review_repair/CODE_REVIEW-cloud-G06.md` with actual implementation decisions and command output.

**Test Strategy**

Strengthen `TestSingleRequestReviewStageExactBodyAuthority` and `TestSingleRequestReviewStageCoordinatorToolFailure`; do not add production code. The first fixture must fail for any added, removed, or changed body/schema/dispatch field. The second must fail if the error path attempts a Review write, enters finalizing, retains output, misses cleanup, continues the provider, or leaks a waiter.

**Verification**

Run Final Verification commands 2, 4, 5, and 6. The focused suite must pass under `-race`, and the deterministic guards must find the prescribed complete-equality and no-leak oracles.

## Modified Files Summary

| File | Items |
|------|-------|
| `apps/edge/internal/openai/single_request_review_stage_test.go` | REVIEW_API-1 |
| `agent-task/m-iop-owned-single-request-agent-execution/20+19_review_repair/CODE_REVIEW-cloud-G06.md` | REVIEW_API-1 |

## Final Verification

Fresh output is required; Go tests use `-count=1` and cached output is not acceptable.

1. `bash -c 'set -euo pipefail; shopt -s nullglob; candidates=(agent-task/m-iop-owned-single-request-agent-execution/19_*/complete.log agent-task/m-iop-owned-single-request-agent-execution/19+*/complete.log agent-task/archive/*/*/m-iop-owned-single-request-agent-execution/19_*/complete.log agent-task/archive/*/*/m-iop-owned-single-request-agent-execution/19+*/complete.log); printf "%s\n" "${candidates[@]}"; ((${#candidates[@]} == 1))'` — prints exactly one predecessor completion path and exits zero.
2. `go test -race ./apps/edge/internal/openai -run 'TestSingleRequestReviewStage' -count=1` — exact authority, real coordinator/Node failure, provider/envelope failure, continuation correlation, cancellation, and cleanup pass without races.
3. `go test ./apps/edge/internal/service -run 'TestSingleRequest(InternalToolLoop|Cleanup|EnvelopeOrdering)' -count=1` — shared coordinator lifecycle remains compatible.
4. `go vet ./apps/edge/internal/openai && go test ./apps/edge/internal/openai -count=1` — the changed package vets and regresses cleanly.
5. `rg --sort path -n '^func (expectedSingleRequestReviewBodyAuthority|assertSingleRequestReviewDispatchAuthority|TestSingleRequestReviewStage(ExactBodyAuthority|CoordinatorToolFailure))' apps/edge/internal/openai/single_request_review_stage_test.go` — finds both independent authority helpers and both strengthened fixtures.
6. `bash -c 'set -euo pipefail; authority=$(sed -n "/^func TestSingleRequestReviewStageExactBodyAuthority/,/^}/p" apps/edge/internal/openai/single_request_review_stage_test.go); failure=$(sed -n "/^func TestSingleRequestReviewStageCoordinatorToolFailure/,/^}/p" apps/edge/internal/openai/single_request_review_stage_test.go); rg -Fq "reflect.DeepEqual(payload, expectedSingleRequestReviewBodyAuthority" <<<"$authority"; rg -Fq "assertSingleRequestReviewDispatchAuthority" <<<"$authority"; rg -Fq "reviewWriteCount.Load() != 0" <<<"$failure"; rg -Fq "finalizingCount.Load() != 0" <<<"$failure"; rg -Fq "execution.State() != edgeservice.SingleRequestStateFailed" <<<"$failure"'` — proves the named fixtures contain complete equality and explicit no-leak state oracles.
7. `test -z "$(gofmt -d apps/edge/internal/openai/single_request_review_stage_test.go)"` — the changed test file is formatted.
8. `test "$(git hash-object apps/edge/internal/openai/single_request_review_stage.go)" = '1fa8c84bdd5af917dbb091d2843bb1c6e0bb3ac2'` — production Review source remains unchanged.
9. `test ! -e apps/edge/internal/openai/single_request_executor.go && bash -c 'set -euo pipefail; if rg --sort path -n "NewSingleRequestExecutor|SetSingleRequestExecutor" apps/edge/internal/input/manager.go; then exit 1; else test $? -eq 1; fi'` — composite construction and activation remain deferred.
10. `bash -c 'set -euo pipefail; if git diff --unified=0 HEAD -- apps/edge/internal/service/single_request.go | rg -n "isValidTransition|SingleRequestState(Reviewing|Repairing)"; then exit 1; else test $? -eq 1; fi'` — no lifecycle-table delta exists.
11. `git diff --check` — exits zero with no whitespace errors.

External Claude/Mac full-cycle qualification remains S12 `claude-smoke` and is not performed by this test-only private component.

After completing all code changes, fill implementation-owned sections in `CODE_REVIEW-*-G??.md`.
