<!-- task=m-iop-owned-single-request-agent-execution/03+02_single_request_coordinator plan=4 tag=REVIEW_API milestone-task=single-ingress -->

# Code Review Reference - REVIEW_API

> **[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.
> Execute the plan's selected root cause, scope, files, and dependency decisions as written. Do not choose another owner, narrow/expand the write boundary, or replace a fix with another verification attempt.
> 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-08-06
task=m-iop-owned-single-request-agent-execution/03+02_single_request_coordinator, plan=4, tag=REVIEW_API

## Archive Evidence Snapshot

- Current archived pair: `plan_local_G07_3.log` and `code_review_cloud_G08_3.log`; the review verdict is FAIL with Required R1-R5, zero Suggested findings, and zero Nits.
- Fresh reviewer verification passed the dependency check, focused race suite, formatting check, service package tests, Edge vet, full Edge tests, runtime-spec search, and `git diff --check`; `evidence_integrity_failure=true` because those tests did not exercise production paths that contradicted the checked implementation claims.
- The defects are confined to `apps/edge/internal/service/single_request.go` and its tests: acknowledgement bypass, early-return hangs, mutable binding/result aliases, stale or duplicate tool envelopes, and unsafe progress projection/delivery.
- Roadmap carryover remains `milestone-task=single-ingress`: this packet supplies the S01 coordinator foundation only. Packet 05 still owns HTTP admission, the Edge ingress counter, endpoint tests, and outer/input documentation.

## 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_4.log` and `PLAN-cloud-G08.md` → `plan_cloud_G08_4.log`.
3. If PASS, write `complete.log` and move active task directory to `agent-task/archive/YYYY/MM/m-iop-owned-single-request-agent-execution/03+02_single_request_coordinator/`. 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>`, preserve the first-line `milestone-task` metadata in `complete.log` and report it for the runtime aggregation event. Roadmap state evaluation belongs to `sync-milestone-workstate`.
5. Check applicable `Review-Only Checklist` items at the final `.log` location before reporting.

---

## Implementation Item Completion

| Item | Status |
|------|--------|
| REVIEW_API-1 Harden coordinator lifecycle and surface boundary | [x] |
| REVIEW_API-2 Add complete fail-closed regression coverage | [x] |

## Implementation Checklist

- [x] Make surface acknowledgement the only path to `completed` and fail closed on every premature executor return.
- [x] Enforce private immutable binding/result copies, monotonic envelope order, exact saved-stage tool resume, and closed redacted progress with reliable final-candidate delivery.
- [x] Add deterministic R1-R5 regressions, including an acknowledgement-ready exactly-one terminal race, and run them under `-race`.
- [x] Run dependency, formatting, focused race, package, vet, full Edge, and `git diff --check` verification.
- [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_G08_4.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G08_4.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-iop-owned-single-request-agent-execution/03+02_single_request_coordinator/` to `agent-task/archive/YYYY/MM/m-iop-owned-single-request-agent-execution/03+02_single_request_coordinator/` and update this checklist at the final archive path.
- [ ] If PASS and task group is `m-<milestone-slug>`, preserve and report `milestone-task` metadata for runtime aggregation, without modifying roadmap or directly calling `update-roadmap`.
- [ ] If PASS for split work, remove empty active parent `agent-task/m-iop-owned-single-request-agent-execution/` 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

None.

## Key Design Decisions

- `completed` is reachable only from `AcknowledgeTerminal(true)`. Executor envelopes cannot submit it, and every normal executor return outside `finalizing` becomes a failure.
- Admission is reconstructed through `NewSingleRequestBinding`; the coordinator, executor, and caller each have independent binding values. Accepted results are copied before storage.
- Executor envelopes require a non-zero strictly increasing sequence. Tool entry and resume carry the exact saved active stage, and repeated `internal_tool` is rejected.
- Progress discards executor-controlled message, error, and result fields. The bounded channel reserves two slots for the finalizing candidate and terminal outcome, while ordinary updates remain lossy.

## Reviewer Checkpoints

- Required R1-R5 remain stable and each maps to a production change plus deterministic regression.
- Packet 02 completion remains uniquely satisfied; no preset-binding file is modified by this follow-up.
- Executor-supplied `completed` cannot bypass acknowledgement, and all premature executor returns release `Wait()` with failure.
- Caller, executor, and submitted result mutation cannot alter coordinator-owned state after admission.
- Envelope sequence and saved-stage validation reject duplicate, delayed, reordered, and mismatched tool transitions.
- Progress exposes no raw internal message/error and the finalizing candidate remains observable after ordinary progress saturation.
- The terminal race starts from acknowledgement-ready `finalizing` and proves exactly one terminal outcome.
- No HTTP/Anthropic ingress, concrete Node/workspace/provider runtime, contract/spec wording, or real Claude evidence is claimed.

## Verification Results

### Dependency

Command: `test -f agent-task/m-iop-owned-single-request-agent-execution/02+01_preset_binding/complete.log || test "$(compgen -G 'agent-task/archive/*/*/m-iop-owned-single-request-agent-execution/02+01_preset_binding/complete.log' | wc -l)" -eq 1`

_Actual output/status:_

Exit 0; no stdout or stderr.

### Formatting

Command: `test -z "$(gofmt -l apps/edge/internal/service/single_request.go apps/edge/internal/service/single_request_test.go)"`

_Actual output/status:_

Exit 0; no stdout or stderr.

### Focused race and state graph

Command: `go test -race ./apps/edge/internal/service -run 'TestSingleRequest' -count=1`

_Actual output:_

```text
ok  \tiop/apps/edge/internal/service\t1.082s
```

### Service regression

Command: `go test ./apps/edge/internal/service -count=1`

_Actual output:_

```text
ok  \tiop/apps/edge/internal/service\t5.923s
```

### Edge vet

Command: `go vet ./apps/edge/...`

_Actual output:_

Exit 0; no stdout or stderr.

### Full Edge regression

Command: `go test ./apps/edge/... -count=1`

_Actual output:_

```text
ok  \tiop/apps/edge/cmd/edge\t0.131s
ok  \tiop/apps/edge/internal/authprojection\t0.049s
ok  \tiop/apps/edge/internal/bootstrap\t0.439s
ok  \tiop/apps/edge/internal/configrefresh\t0.071s
ok  \tiop/apps/edge/internal/controlplane\t6.610s
ok  \tiop/apps/edge/internal/edgecmd\t0.071s
ok  \tiop/apps/edge/internal/edgevalidate\t0.038s
ok  \tiop/apps/edge/internal/events\t0.025s
ok  \tiop/apps/edge/internal/input\t0.051s
ok  \tiop/apps/edge/internal/input/a2a\t0.046s
ok  \tiop/apps/edge/internal/node\t0.040s
ok  \tiop/apps/edge/internal/openai\t7.884s
ok  \tiop/apps/edge/internal/opsconsole\t0.037s
ok  \tiop/apps/edge/internal/service\t5.971s
ok  \tiop/apps/edge/internal/transport\t4.769s
```

### Diff check

Command: `git diff --check`

_Actual output:_

Exit 0; no stdout or stderr.

---

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

| Dimension | Assessment | Evidence |
|-----------|------------|----------|
| Correctness | Fail | Required R1 and R5 still allow a success without a retained candidate and provide no surface-readable final result before acknowledgement. |
| Completeness | Fail | The final-candidate validation and delivery portions of the inherited findings remain incomplete. |
| Test coverage | Fail | The progress regression treats every non-nil `Result` as a leak and therefore never proves that the surface can read the final user result. |
| API contract | Fail | `Progress()` is the only pre-acknowledgement surface channel, but its finalizing event omits the candidate that the surface must commit. |
| Code quality | Pass | The follow-up is localized, formatted, and free of relevant debug or dead-code residue. |
| Implementation deviation | Fail | The implementation claims reliable final-candidate delivery while publishing only the finalizing stage marker. |
| Verification trust | Fail | Fresh commands pass, but the focused test explicitly asserts the behavior that contradicts the planned surface handoff. |
| Spec conformance | Fail | SDD D02/D10 require Edge-owned final output and one outer terminal; the current API cannot obtain that output before acknowledging the terminal. |

### Findings

- **Required R1** — `apps/edge/internal/service/single_request.go:255`, `apps/edge/internal/service/single_request.go:256`, and `apps/edge/internal/service/single_request.go:268`: a `finalizing` envelope may omit `Result`, and a result attached to any earlier stage remains eligible for `AcknowledgeTerminal(true)`. The acknowledgement path never verifies that a final candidate exists, so the coordinator can report `completed` with an empty or stale result. Reject result payloads outside `finalizing`, require and defensively copy a non-nil finalizing candidate before changing state, guard successful acknowledgement against a missing retained candidate, and add nil/stale-candidate regressions.
- **Required R5** — `apps/edge/internal/service/single_request.go:383` and `apps/edge/internal/service/single_request_test.go:287`: `emitProgressLocked` never sets `SingleRequestProgress.Result`, and the test requires every progress result to be nil. Because `Wait()` blocks until after `AcknowledgeTerminal`, the future surface has no API path to read and commit the final user result before acknowledging it; observing only the `finalizing` enum is not final-candidate delivery. Publish a separately cloned result only on the reserved finalizing progress event, keep executor message/error and non-final result data redacted, and assert immutable candidate delivery under saturation before acknowledgement.

### Routing Signals

- `review_rework_count=2`
- `evidence_integrity_failure=true`

### Next Step

Invoke the plan skill in `prepare-follow-up` mode with stable Required R1 and R5, then archive this pair and materialize the freshly routed follow-up pair.
