<!-- task=m-iop-owned-single-request-agent-execution/25+23,24_claude_smoke_qualification plan=23 tag=REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_API milestone-task=workspace-binding,claude-smoke -->

# Code Review Reference - Plan output and child cardinality repair

> **[IMPLEMENTING AGENT — READ FIRST]** Resolve R16/R17 with provider-free evidence, fill every implementation-owned section, and stop. Do not invoke a model/provider, append a verdict, archive files, or create a seventh guard.

## Overview

date=2026-08-08
task=m-iop-owned-single-request-agent-execution/25+23,24_claude_smoke_qualification, plan=23, tag=REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_API

## Archive Evidence Snapshot

- Prior pair: `plan_cloud_G10_22.log` / `code_review_cloud_G10_22.log`; verdict `FAIL`, Required R16/R17.
- Six guarded live attempts are consumed. This plan authorizes repair and provider-free validation only.

## For the Review Agent

Verify child-only retry ownership, exact structured-output authority, strict parser preservation, bounded terminal evidence, local/dev provider-free checks, and zero live-call drift. Append one verdict and materialize its required next state.

## Implementation Item Completion

| Item | Status |
|---|---|
| child-cardinality | [x] |
| structured-plan | [x] |
| terminal-evidence | [x] |
| provider-free-validation | [x] |

## Implementation Checklist

- [x] Freeze the Claude child with `CLAUDE_CODE_MAX_RETRIES=0` and prove an ambient nonzero parent cannot pass through.
- [x] Add an Edge-owned plan JSON schema request format that options cannot override.
- [x] Preserve strict plan parsing and add exact request-body/negative tests.
- [x] Add and test a bounded terminal-rejection log that distinguishes malformed from validation.
- [x] Run formatting, focused Go tests, shell self-test, and repository checks required by the dev test rules.
- [x] Sync only changed repair files to the disposable dev source, rebuild Edge, and run provider-free readiness/preflight only.
- [x] Fill implementation-owned review sections and stop for official review without a live call.

## Review-Only Checklist

- [ ] Append one verdict and verified routing signals.
- [ ] Verify R16/R17 evidence and absence of a seventh provider/model call.
- [ ] Archive the active pair and materialize the verdict's next state.

## Deviations from Plan

- The local container has no `rsync`; the same explicit reviewed file list was synchronized with a path-preserving `tar` stream.
- The first remote package test exposed that the isolated source lacked the pre-existing testing-only `SetSingleRequestObservationLoggerForTesting` dependency. The exact `single_request_metrics.go` dependency was added to the isolated source and both packages then passed.
- The first authenticated provider-free wrapper had a Python quoting error while constructing curl's in-memory header config and stopped at catalog HTTP 401. It made no count-token, provider, Messages, or Claude call and changed no ingress/guard/artifact state; the corrected memory-only wrapper passed.
- Final self-review found that the first terminal log hook covered buffered Messages only. The hook was extended to the streaming projector, tests proved exactly-one observation, and the disposable Edge was rebuilt a second time before final readiness.

## Key Design Decisions

- `CLAUDE_CODE_MAX_RETRIES=0` is scoped to the supervised Python/Claude child environment. The parent shell and user Claude configuration remain untouched; the fake parent deliberately supplies `9` and must observe child value `0`.
- Plan structured output is an Edge-owned typed `response_format={type:json_schema,...}` with required `plan` and `verification` string properties and `additionalProperties=false`. Frozen stage options cannot replace `response_format`; the existing exact/nonempty parser remains the semantic gate.
- The new `edge_single_request_terminal_rejection` event is shared by buffered and streaming projectors and contains only `surface`, closed terminal kind/error class, and HTTP status. It emits exactly once for error terminals and never stores raw provider/model/request/workspace/credential data.
- Google Gemini's official OpenAI compatibility documentation confirms structured output on the Chat Completions compatibility surface; no provider probe was needed to implement the supported request contract.

## Verification Results

### Local

- `gofmt`, `bash -n scripts/e2e-single-request-claude.sh`, and `git diff --check`: PASS.
- `go test ./apps/edge/internal/openai ./apps/edge/internal/service -count=1`: PASS (`8.386s`, `8.214s` on the final source).
- Focused race matrix covering terminal disposition, quality gate, buffered log projection, and streaming terminal projection: PASS (`1.111s`, `1.061s`).
- `scripts/e2e-single-request-claude.sh --self-test`: PASS; the fake inherited an ambient parent retry value `9` but required child value `0`.

### Disposable dev

- Runner/source/runtime: `toki@toki-labs.com`, isolated source `/Users/toki/agent-work/iop-s12-validation-20260808/source`, managed runtime `/Users/toki/agent-work/iop-s12-managed-validation-20260808/runtime`; canonical dev checkout was not changed.
- Remote ordinary and focused race package tests: PASS after exact source sync. Remote harness self-test: PASS with `child-only zero retry` evidence.
- Final Edge config check: PASS. Rebuilt Edge PID `81305`, digest `sha256:9f6cbf9836fe433b4ad6d3d58feb11a9abc576b18a50bfc04be6f7a6e5471053`; Node PID `47260` reconnected. Runtime evidence was atomically refreshed and harness identity validation passed.
- SOPS caller `tokens.toki-dev-cline` stayed in process memory. Provider-free results: catalog `200`, frozen local count-token `200`, unsupported context-hint neighbor `400`, harness preflight PASS.
- Closed cardinality: ingress `0 -> 0`, provider-tunnel delta `0`, stage delta `0`, six finalized guards, zero `.started`, zero Claude processes, and no manifest/workspace result.
- No Claude `--run`, Gemini generation, Ornith generation, direct provider request, seventh guard, retry, or success publication occurred.

---

> Implementer: fill every implementation-owned field, then stop for official review.

## Code Review Result

### Overall Verdict

FAIL

### Dimension Assessment

| Dimension | Assessment | Evidence |
|---|---|---|
| Correctness | Pass | R16 freezes the supervised Claude child at zero retries; R17 gives Gemini a stage-owned strict JSON Schema while retaining the exact semantic parser. |
| Completeness | Fail | The repair packet is complete, but S12 still lacks a successful real Claude-through-IOP execution and qualification manifest. |
| Test coverage | Pass | Local/remote ordinary and race tests, local/remote harness self-tests, exact body authority tests, buffered/streaming terminal projections, rebuild, and provider-free preflight all pass. |
| API contract | Pass | The plan output contract is provider-compatible and Edge-owned; buffered/streaming errors retain their public mapping while the new operational event is bounded and raw-free. |
| Code quality | Pass | Typed response-format structures, explicit override exclusion, child-only environment scope, and shared terminal callback keep authority and diagnostics narrow. |
| Implementation deviation | Pass | Missing `rsync`, one omitted isolated test dependency, one preflight-wrapper quoting error, and the streaming self-review repair were bounded, recorded, and reverified without live activity. |
| Verification trust | Pass | Final dev state independently agrees: ingress 0, provider/stage deltas 0, six finalized guards, zero started/Claude processes, absent artifacts, and identity-valid preflight. |
| Spec conformance | Fail | SDD S12 and the milestone still require ingress exactly 1 and the complete Gemini -> Ornith-fast -> Gemini sequence with verified workspace output and one terminal. |

### Findings

- Required R18 — `agent-roadmap/sdd/knowledge-tool-optimization-extension/iop-owned-single-request-agent-execution/SDD.md:119`: R16/R17 are closed and the rebuilt disposable runtime is provider-free ready, but S12 cannot be completed without one newly authorized real Claude-through-IOP execution. The sixth authorization is irreversibly consumed as `sole-live-6.rc-69`; it produced ingress delta 2 because the then-unfrozen Claude client retried a malformed-plan 502. Require a distinct seventh guard, one harness `--run`, no retry, and success publication only if ingress delta is exactly 1 with the full ordered stage/workspace/terminal evidence. Do not infer this authorization from the already consumed user instruction.

### Routing Signals

- `evaluation_mode=isolated-reassessment`
- `verdict=FAIL`
- `review_rework_count=22`
- `evidence_integrity_failure=false`
- `next_state=user-review`
- `finalizer=finalize-task-policy.sh`
- `finalizer_mode=pair`
- build route `worker/cloud/G10`; review route `review/cloud/G10`
