<!-- task=m-iop-agent-cli-runtime/23+14,16,22_client_process_manager plan=2 tag=REVIEW_REVIEW_API -->

# Code Review Reference - REVIEW_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.
> 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-iop-agent-cli-runtime/23+14,16,22_client_process_manager, plan=2, tag=REVIEW_REVIEW_API

## Roadmap Targets

- Milestone: `agent-roadmap/phase/automation-runtime-bridge/milestones/iop-agent-cli-runtime.md`
- Milestone link: [Milestone document](agent-roadmap/phase/automation-runtime-bridge/milestones/iop-agent-cli-runtime.md)
- Task ids:
  - `client-process-manager`: daemon-owned Flutter/Unity start, stop, reconnect, crash recovery, and detail routing
- Completion mode: check-on-pass

## Archive Evidence Snapshot

- Prior plan: `agent-task/m-iop-agent-cli-runtime/23+14,16,22_client_process_manager/plan_local_G07_1.log`
- Prior review: `agent-task/m-iop-agent-cli-runtime/23+14,16,22_client_process_manager/code_review_cloud_G07_1.log`
- Verdict: FAIL
- Findings: 3 Required, 0 Suggested, 0 Nit.
- Affected boundary: checksum-covered `clientprocess.Record` receipts, internal daemon start/stop generations, and close-time focus/detail/connection mutation fencing.
- Verified evidence: focused, repeated race, package, vet, Darwin arm64 cross-build, formatting, `./packages/go/...`, and `./apps/agent/...` checks passed. Reviewer barrier regressions failed because a restarted daemon skipped launch-on-start and an in-flight focus context remained live after `Close`.
- Roadmap carryover: S15 / `client-process-manager` remains incomplete until exact accepted-incomplete recovery and lifecycle closure pass with PID/start/focus evidence.

## 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_2.log` and `PLAN-cloud-G08.md` → `plan_cloud_G08_2.log`.
3. If PASS, write `complete.log` and move active task directory to `agent-task/archive/YYYY/MM/m-iop-agent-cli-runtime/23+14,16,22_client_process_manager/`. 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_REVIEW_API-1 Exact receipt recovery | [x] |
| REVIEW_REVIEW_API-2 Daemon lifecycle generations | [x] |
| REVIEW_REVIEW_API-3 Closure-fenced mutations | [x] |
| REVIEW_REVIEW_API-4 S15 evidence anchors | [x] |

## Implementation Checklist

- [x] Make process receipts action-aware, strictly validated, retained for every ledger-visible command, and capable of replaying the immutable original result after intervening state changes.
- [x] Separate automatic daemon lifecycle actions from caller command receipt replay and prove each daemon generation launches and stops its current process.
- [x] Bind focus/detail and connection mutations to manager-owned closure admission, cancellation, and completion fencing.
- [x] Update S15 contract evidence and pass fresh focused, repeated race, package, vet, Darwin cross-build, formatting, and diff 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_2.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G08_2.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-agent-cli-runtime/23+14,16,22_client_process_manager/` to `agent-task/archive/YYYY/MM/m-iop-agent-cli-runtime/23+14,16,22_client_process_manager/` 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-iop-agent-cli-runtime/` 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. The planned files and verification commands were used. The existing launch-close regression was strengthened so that `Close` must wait for an already admitted launch before it returns.

## Key Design Decisions

- Completed receipts store an immutable local-control projection and validate the command/result action relationship, lifecycle/connection coherence, and an empty pending projection.
- External command IDs are retained through the local-control ledger capacity; capacity exhaustion is rejected instead of evicting a recoverable receipt. Daemon lifecycle work uses an empty internal ID and cannot replay external receipts.
- Every external mutation is admitted through the manager-owned closure fence. `Close` blocks new admission, cancels and joins admitted work, then stops the current client with the internal lifecycle path.
- Process launch keeps the manager lifetime context because the OS backend uses it to own a successfully launched child; the closure fence aborts a process returned after closure rather than cancelling a live child after a successful command returns.

## Reviewer Checkpoints

- Accepted-incomplete recovery reaches the manager receipt after a failed ledger finish, returns the immutable original result after intervening state changes, and performs zero repeated process mutations.
- Receipt validation rejects action/result corruption and retains every command that the 4096-entry local-control ledger may still recover.
- A second daemon generation executes launch-on-start and close against its current process without replaying prior internal lifecycle receipts.
- Manager close cancels and joins in-flight focus/detail work, fences connection projection changes, reaps the exact client identity, and commits no post-close mutation.
- S15 contract anchors name the new recovery, generation, and closure tests, and the PID/start/focus lifecycle trace remains deterministic.

## Verification Results

Run every command exactly as written and paste actual stdout/stderr. If a command changes, record the replacement and reason in `Deviations from Plan`. Cached Go test output is not accepted.

### Exact receipt recovery

```bash
go test -count=1 ./apps/agent/internal/clientprocess ./apps/agent/internal/localcontrol -run 'TestAcceptedIncompleteClient|TestCommandReceipt|TestRecordRejectsInvalidCommandReceiptProjection'
```

```text
ok   iop/apps/agent/internal/clientprocess  0.005s
ok   iop/apps/agent/internal/localcontrol   0.102s
```

### Daemon lifecycle generations

```bash
go test -count=25 -race ./apps/agent/internal/clientprocess -run 'TestStartConfiguredLaunchesAfterDaemonRestart|TestCloseStopsCurrentGenerationAfterPriorLifecycleReceipts'
```

```text
ok   iop/apps/agent/internal/clientprocess  2.378s
```

### Closure-fenced mutations

```bash
go test -count=25 -race ./apps/agent/internal/clientprocess -run 'TestConcurrentClose'
```

```text
ok   iop/apps/agent/internal/clientprocess  3.578s
```

### S15 contract anchors

```bash
rg -n --sort path 'TestAcceptedIncompleteClientCommandReusesExactManagerReceiptAfterStateChange|TestCommandReceiptCapacityMatchesLedger|TestStartConfiguredLaunchesAfterDaemonRestart|TestCloseStopsCurrentGenerationAfterPriorLifecycleReceipts|TestConcurrentCloseCancelsInFlightFocus|TestConcurrentCloseCancelsInFlightDetail|TestConcurrentCloseFencesConnectionMutation' apps/agent/internal/clientprocess apps/agent/internal/localcontrol agent-contract/inner/iop-agent-cli-runtime.md
```

```text
apps/agent/internal/clientprocess/manager_test.go:675:func TestStartConfiguredLaunchesAfterDaemonRestart(t *testing.T) {
apps/agent/internal/clientprocess/manager_test.go:746:func TestCloseStopsCurrentGenerationAfterPriorLifecycleReceipts(t *testing.T) {
apps/agent/internal/clientprocess/manager_test.go:970:func TestConcurrentCloseCancelsInFlightFocus(t *testing.T) {
apps/agent/internal/clientprocess/manager_test.go:976:func TestConcurrentCloseCancelsInFlightDetail(t *testing.T) {
apps/agent/internal/clientprocess/manager_test.go:1050:func TestConcurrentCloseFencesConnectionMutation(t *testing.T) {
apps/agent/internal/clientprocess/store_test.go:318:func TestCommandReceiptCapacityMatchesLedger(t *testing.T) {
apps/agent/internal/localcontrol/client_operations_test.go:300:func TestAcceptedIncompleteClientCommandReusesExactManagerReceiptAfterStateChange(t *testing.T) {
agent-contract/inner/iop-agent-cli-runtime.md:49:| S15 | `TestManagerOwnsSingletonAndReapsClient`, `TestDuplicateLaunchConvergesAfterManagerRestart`, `TestDaemonSurvivesCrashAndBoundedRestart`, `TestS15ClientLifecycleTrace`, `TestReconcileBlocksAmbiguousIdentityWithoutLaunch`, `TestClientOperationMatrix`, `TestUnityDetailStartsOrFocusesFlutter`, `TestRejectedClientCommandHasZeroProcessCalls`, `TestAcceptedIncompleteClientCommandReusesExactManagerReceiptAfterStateChange`, `TestCommandReceiptCapacityMatchesLedger`, `TestStartConfiguredLaunchesAfterDaemonRestart`, `TestCloseStopsCurrentGenerationAfterPriorLifecycleReceipts`, `TestConcurrentCloseCancelsInFlightFocus`, `TestConcurrentCloseCancelsInFlightDetail`, and `TestConcurrentCloseFencesConnectionMutation`; fresh focused/race suites and Darwin arm64 cross-build | `client-process-manager` proves one PID/start identity per kind, exact reaping, live adoption without duplicate launch, bounded crash restart, disconnect/reconnect without daemon cancellation, fail-closed ambiguous recovery, and Unity detail routing only to daemon-owned Flutter start/focus. Completed external client receipts replay only an immutable accepted result for the matching command action; daemon lifecycle generations do not create or reuse external command receipts, and close cancels admitted mutations before reaping the current identity. |
```

### Final verification

```bash
gofmt -w apps/agent/internal/clientprocess/types.go apps/agent/internal/clientprocess/store.go apps/agent/internal/clientprocess/manager.go apps/agent/internal/clientprocess/store_test.go apps/agent/internal/clientprocess/manager_test.go apps/agent/internal/localcontrol/client_operations_test.go
go test -count=1 ./apps/agent/internal/clientprocess ./apps/agent/internal/localcontrol -run 'TestAcceptedIncompleteClient|TestCommandReceipt|TestRecordRejectsInvalidCommandReceiptProjection|TestStartConfiguredLaunchesAfterDaemonRestart|TestCloseStopsCurrentGenerationAfterPriorLifecycleReceipts|TestConcurrentClose'
go test -count=1 ./packages/go/agentconfig ./apps/agent/internal/clientprocess ./apps/agent/internal/localcontrol
go test -count=1 -race ./apps/agent/internal/clientprocess ./apps/agent/internal/localcontrol ./packages/go/agentstate
go test -count=25 -race ./apps/agent/internal/clientprocess ./apps/agent/internal/localcontrol -run 'TestAcceptedIncompleteClient|TestStartConfiguredLaunchesAfterDaemonRestart|TestCloseStopsCurrentGenerationAfterPriorLifecycleReceipts|TestConcurrentClose'
go vet ./packages/go/agentconfig ./apps/agent/internal/clientprocess ./apps/agent/internal/localcontrol
review_darwin_dir=$(mktemp -d) && review_darwin_bin="$review_darwin_dir/clientprocess.test" && GOOS=darwin GOARCH=arm64 go test -c -o "$review_darwin_bin" ./apps/agent/internal/clientprocess && test -s "$review_darwin_bin"
go test -count=1 ./packages/go/...
go test -count=1 ./apps/agent/...
git diff --check
```

```text
ok   iop/apps/agent/internal/clientprocess  0.181s
ok   iop/apps/agent/internal/localcontrol   0.092s
ok   iop/packages/go/agentconfig            0.035s
ok   iop/apps/agent/internal/clientprocess  0.820s
ok   iop/apps/agent/internal/localcontrol   0.167s
ok   iop/apps/agent/internal/clientprocess  7.941s
ok   iop/apps/agent/internal/localcontrol   1.236s
ok   iop/packages/go/agentstate             1.096s
ok   iop/apps/agent/internal/clientprocess  4.819s
ok   iop/apps/agent/internal/localcontrol   3.773s
go vet, Darwin arm64 compile, package suite, agent suite, and git diff --check produced no stdout/stderr and exited 0.
```

---

> **[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
  - Completeness: Fail
  - Test coverage: Fail
  - API contract: Fail
  - Code quality: Pass
  - Implementation deviation: Fail
  - Verification trust: Pass
  - Spec conformance: Fail
- Findings:
  - Required — `apps/agent/internal/clientprocess/manager.go:719-725` and `apps/agent/internal/clientprocess/manager.go:980-984`: a failed completion receipt save aborts the newly launched process but leaves the in-memory completed receipt and lifecycle projection intact. A reviewer fault-injection regression made the second client-record CAS fail, observed the first `Start` return the injected error and abort its child, then observed the same `command_id` retry return a successful immutable `start` result without another live process. Restore or reload the last durable projection on completion-save failure so a non-durable completed receipt cannot be replayed, keep the command fail-closed as pending/ambiguous, and add deterministic start-completion persistence-failure coverage.
  - Required — `apps/agent/internal/clientprocess/types.go:117-140` and `apps/agent/internal/clientprocess/store.go:147-162`: completed receipt validation checks only the process action for `start`, `focus`, and `detail`, so impossible projections such as a completed `start` in `stopped`/`crashed` state or a completed `focus` in `stopped` state pass durable decoding and replay as accepted results. Enforce the action-specific lifecycle, connection, and changed-result invariants produced by the manager and extend `TestRecordRejectsInvalidCommandReceiptProjection` with every invalid action/state combination.
  - Required — `apps/agent/internal/clientprocess/manager.go:580-589` and `apps/agent/internal/clientprocess/manager.go:856-873`: `Close` suppresses `ErrIdentityAmbiguous`, then cancels the manager and waits unconditionally for all watchers, while an adopted watcher intentionally loops forever after cancellation as long as identity inspection remains ambiguous. A retained ambiguous identity can therefore be reported as a successful close when no watcher was admitted or make `Close` hang beyond its context after adoption. Preserve fail-closed identity evidence while surfacing the close error, make watcher joining honor a bounded close path without falsely recording exit, and add deterministic ambiguous-identity close tests for both pre-adoption and adopted records.
- Routing Signals:
  - `review_rework_count=3`
  - `evidence_integrity_failure=false`
- Next Step: Invoke the plan skill with these raw findings and route the smallest complete follow-up for durable receipt rollback, strict action-state validation, and bounded ambiguous-identity closure.
