<!-- task=m-iop-agent-cli-runtime/24+19,21,22,23_daemon_wiring plan=3 tag=REVIEW_REVIEW_TEST -->

# Code Review Reference - REVIEW_REVIEW_TEST

> **[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/24+19,21,22,23_daemon_wiring, plan=3, tag=REVIEW_REVIEW_TEST

## Archive Evidence Snapshot

- Current pair after finalization: `agent-task/m-iop-agent-cli-runtime/24+19,21,22,23_daemon_wiring/plan_local_G08_2.log` and `agent-task/m-iop-agent-cli-runtime/24+19,21,22,23_daemon_wiring/code_review_cloud_G08_2.log`.
- Verdict: FAIL; Required=3, Suggested=0, Nit=0.
- Required findings: service-level unavailable reads lack typed envelope assertions; partial-start rollback does not test joined cleanup error identity; built-binary SIGTERM does not prove configured-client cleanup.
- Affected files: `apps/agent/internal/bootstrap/module_test.go` and `apps/agent/cmd/agent/main_test.go`.
- Fresh reviewer verification passed focused tests, race suites, adjacent packages, vet, agent build, Darwin arm64 cross-build, built help, whole-Go tests, and `git diff --check`.
- Roadmap carryover: this remains a regression-only Milestone-adjacent packet with no `Roadmap Targets`; it must not claim S10, S11, or S15 completion.

## 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-G06.md` → `code_review_cloud_G06_3.log` and `PLAN-cloud-G06.md` → `plan_cloud_G06_3.log`.
3. If PASS, write `complete.log` and move active task directory to `agent-task/archive/YYYY/MM/m-iop-agent-cli-runtime/24+19,21,22,23_daemon_wiring/`. 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_TEST-1 Assert typed fail-closed service responses | [x] |
| REVIEW_REVIEW_TEST-2 Preserve launch and cleanup error identities | [x] |
| REVIEW_REVIEW_TEST-3 Reap a configured client on production SIGTERM | [x] |

## Implementation Checklist

- [x] Prove unavailable task-runtime reads and mutations produce typed local-control `invalid_state` envelopes, no success payload, and no retained event.
- [x] Prove partial configured-client startup preserves both launch and cleanup error identities while reaping the earlier client.
- [x] Prove built-binary SIGTERM removes the daemon socket and terminates a deterministic configured fixture client within the shutdown bound.
- [x] Run the complete fresh focused, race, adjacent-package, vet, build, Darwin cross-build, whole-Go, help, 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_G06_3.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G06_3.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`.
- [x] If PASS, write `complete.log` based on `agent-ops/skills/common/code-review/templates/complete-log-template.md` and leave no active `.md` files.
- [x] If PASS, move active task directory `agent-task/m-iop-agent-cli-runtime/24+19,21,22,23_daemon_wiring/` to `agent-task/archive/YYYY/MM/m-iop-agent-cli-runtime/24+19,21,22,23_daemon_wiring/` and update this checklist at the final archive path.
- [x] If PASS and task group is `m-<milestone-slug>`, report completion event metadata for runtime, without modifying roadmap or directly calling `update-roadmap`.
- [x] 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.
- [ ] 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

- Extended `TestDaemonTaskRuntimeFailsClosedWithoutOwner` in `apps/agent/internal/bootstrap/module_test.go` to send both `project.status` read and `project.start` mutation requests to `localcontrol.Service`, asserting `invalid_state` error code, no response payload, and no events in durable ledger replay.
- Extended `TestDaemonPartialClientLaunchFailureRollsBack` in `apps/agent/internal/bootstrap/module_test.go` to provide a cleanup failure sentinel to `partialFailBackend`, asserting that `daemon.Run` returns a joined error matching both launch and cleanup error sentinels while preserving client reaping.
- Enhanced `TestBuiltBinarySignalShutdownCleansDaemon` in `apps/agent/cmd/agent/main_test.go` to append a configured Flutter client process fixture (`/bin/sh -c "echo $$ > <pidfile>; exec /bin/sleep 60"`), ensuring both socket and PID readiness before sending SIGTERM, and verifying that the daemon socket is removed and the child process PID is terminated.

## Reviewer Checkpoints

- The service-level status and start requests return exact `invalid_state` error envelopes with no success payload or retained event.
- The partial-start cleanup regression reaps the first client even when cleanup returns an error, and the daemon error matches both sentinels.
- The built binary starts a deterministic long-lived configured client, handles SIGTERM, and leaves neither the socket nor client PID alive.
- The follow-up changes tests and implementation evidence only; production daemon behavior remains unchanged.

## Verification Results

> **[IMPLEMENTING AGENT]** Run the commands exactly as written and paste actual stdout/stderr below each block. If a command changes, record the replacement and reason in `Deviations from Plan`.

### REVIEW_REVIEW_TEST-1 typed fail-closed envelopes

```bash
go test -count=1 ./apps/agent/internal/bootstrap -run '^TestDaemonTaskRuntimeFailsClosedWithoutOwner$'
```

```
ok  	iop/apps/agent/internal/bootstrap	0.047s
```

### REVIEW_REVIEW_TEST-2 joined rollback errors

```bash
go test -count=1 ./apps/agent/internal/bootstrap -run '^TestDaemonPartialClientLaunchFailureRollsBack$'
```

```
ok  	iop/apps/agent/internal/bootstrap	0.034s
```

### REVIEW_REVIEW_TEST-3 configured-client SIGTERM cleanup

```bash
go test -count=1 ./apps/agent/cmd/agent -run '^TestBuiltBinarySignalShutdownCleansDaemon$'
```

```
ok  	iop/apps/agent/cmd/agent	1.949s
```

### Final verification

```bash
gofmt -w apps/agent/internal/bootstrap/module_test.go apps/agent/cmd/agent/main_test.go
go test -count=1 ./apps/agent/internal/bootstrap -run 'TestDaemon(TaskRuntimeFailsClosedWithoutOwner|PartialClientLaunchFailureRollsBack)'
go test -count=1 ./apps/agent/cmd/agent -run 'Test(BuiltBinarySignalShutdownCleansDaemon|RunServeCancellationAndCleanup)'
go test -count=1 -race ./apps/agent/internal/bootstrap ./apps/agent/cmd/agent ./apps/agent/internal/command
go test -count=1 ./apps/agent/internal/clientprocess ./apps/agent/internal/localcontrol ./apps/agent/internal/projectlog ./packages/go/agentstate
go vet ./apps/agent/internal/bootstrap ./apps/agent/cmd/agent ./apps/agent/internal/command
make build-agent
review_tmp_dir=$(mktemp -d)
GOOS=darwin GOARCH=arm64 go build -trimpath -o "$review_tmp_dir/iop-agent-darwin-arm64" ./apps/agent/cmd/agent
test -s "$review_tmp_dir/iop-agent-darwin-arm64"
build/bin/iop-agent --help >/dev/null
go test -count=1 ./...
git diff --check
```

```
ok  	iop/apps/agent/internal/bootstrap	0.050s
ok  	iop/apps/agent/cmd/agent	2.136s
ok  	iop/apps/agent/internal/bootstrap	1.189s
ok  	iop/apps/agent/cmd/agent	3.767s
ok  	iop/apps/agent/internal/command	1.036s
ok  	iop/apps/agent/internal/clientprocess	1.533s
ok  	iop/apps/agent/internal/localcontrol	0.408s
ok  	iop/apps/agent/internal/projectlog	3.096s
ok  	iop/packages/go/agentstate	0.242s
mkdir -p build/bin
go build -trimpath -o build/bin/iop-agent ./apps/agent/cmd/agent
ok  	iop/apps/agent/cmd/agent	5.687s
ok  	iop/apps/agent/internal/bootstrap	0.425s
ok  	iop/apps/agent/internal/clientprocess	2.921s
ok  	iop/apps/agent/internal/command	0.030s
ok  	iop/apps/agent/internal/host	0.011s
ok  	iop/apps/agent/internal/localcontrol	0.721s
ok  	iop/apps/agent/internal/projectlog	5.359s
ok  	iop/apps/control-plane/cmd/control-plane	0.147s
ok  	iop/apps/control-plane/internal/wire	1.490s
ok  	iop/apps/edge/cmd/edge	0.097s
ok  	iop/apps/edge/internal/bootstrap	6.783s
ok  	iop/apps/edge/internal/configrefresh	0.057s
ok  	iop/apps/edge/internal/controlplane	4.462s
ok  	iop/apps/edge/internal/edgecmd	0.054s
ok  	iop/apps/edge/internal/edgevalidate	0.006s
ok  	iop/apps/edge/internal/events	0.005s
ok  	iop/apps/edge/internal/input	0.009s
ok  	iop/apps/edge/internal/input/a2a	0.008s
ok  	iop/apps/edge/internal/node	0.007s
ok  	iop/apps/edge/internal/openai	7.346s
ok  	iop/apps/edge/internal/opsconsole	0.011s
ok  	iop/apps/edge/internal/service	5.870s
ok  	iop/apps/edge/internal/transport	4.748s
ok  	iop/apps/node/cmd/node	0.016s
ok  	iop/apps/node/internal/adapters	0.014s
?   	iop/apps/node/internal/adapters/mock	[no test files]
ok  	iop/apps/node/internal/adapters/ollama	0.014s
ok  	iop/apps/node/internal/adapters/openai_compat	0.162s
ok  	iop/apps/node/internal/adapters/vllm	0.160s
ok  	iop/apps/node/internal/bootstrap	1.425s
ok  	iop/apps/node/internal/node	0.833s
ok  	iop/apps/node/internal/router	0.507s
ok  	iop/apps/node/internal/store	0.076s
ok  	iop/apps/node/internal/transport	5.567s
?   	iop/apps/worker/cmd/worker	[no test files]
ok  	iop/cmd/iop-provider-smoke	0.012s
ok  	iop/packages/go/agentconfig	0.036s
ok  	iop/packages/go/agentguard	0.015s
ok  	iop/packages/go/agentpolicy	0.010s
ok  	iop/packages/go/agentprovider/catalog	0.059s
ok  	iop/packages/go/agentprovider/cli	30.613s
?   	iop/packages/go/agentprovider/cli/internal/testutil	[no test files]
ok  	iop/packages/go/agentprovider/cli/status	40.099s
ok  	iop/packages/go/agentruntime	0.654s
ok  	iop/packages/go/agentstate	0.145s
ok  	iop/packages/go/agenttask	1.909s
ok  	iop/packages/go/agentworkspace	11.971s
ok  	iop/packages/go/audit	0.002s
?   	iop/packages/go/auth	[no test files]
ok  	iop/packages/go/config	0.066s
?   	iop/packages/go/events	[no test files]
ok  	iop/packages/go/hostsetup	0.005s
?   	iop/packages/go/jobs	[no test files]
?   	iop/packages/go/metadata	[no test files]
ok  	iop/packages/go/observability	0.014s
?   	iop/packages/go/policy	[no test files]
ok  	iop/packages/go/streamgate	1.039s
?   	iop/packages/go/version	[no test files]
?   	iop/proto/gen/iop	[no test files]
ok  	iop/scripts/inventory-query	0.007s
```

---

> **[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: PASS
- Dimension Assessment:
  - Correctness: Pass
  - Completeness: Pass
  - Test Coverage: Pass
  - API Contract: Pass
  - Code Quality: Pass
  - Implementation Deviation: Pass
  - Verification Trust: Pass
- Findings: None.
- Routing Signals:
  - `review_rework_count=2`
  - `evidence_integrity_failure=false`
- Next Step: Write `complete.log` and archive the completed task.
