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

# Code Review Reference - 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=2, tag=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_1.log` and `agent-task/m-iop-agent-cli-runtime/24+19,21,22,23_daemon_wiring/code_review_cloud_G08_1.log`.
- Verdict: FAIL; Required=3, Suggested=0, Nit=0.
- Required findings: task-runtime reads/mutations emit success without `agenttask.Manager`; partial client launch is not rolled back; production `main` never converts SIGINT/SIGTERM into daemon cancellation.
- Affected files: `apps/agent/internal/bootstrap/module.go`, `apps/agent/internal/bootstrap/module_test.go`, `apps/agent/cmd/agent/main.go`, and `apps/agent/cmd/agent/main_test.go`.
- Fresh baseline passed focused race tests, adjacent adapter tests, vet, agent build, Darwin arm64 cross-build, help, and `git diff --check`. The focused reviewer rollback reproducer failed with `first client remains alive after daemon startup failure`.
- Roadmap carryover: this task remains Milestone-adjacent and has no `Roadmap Targets`; authenticated S14 evidence remains in child 25, and full task-loop/cutover ownership remains in child 26.

## 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-local-G08.md` → `plan_local_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/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_TEST-1 Fail closed without task runtime ownership | [x] |
| REVIEW_TEST-2 Roll back a partially started client component | [x] |
| REVIEW_TEST-3 Handle production termination signals | [x] |

## Implementation Checklist

- [x] Keep unwired task-runtime reads and project mutations fail-closed while preserving only host/client projections backed by composed state, and verify no success response or state-change event is emitted.
- [x] Make configured client startup fault-atomic, preserve launch and cleanup error identities, and add the partial-launch rollback regression.
- [x] Add signal-aware production daemon cancellation, return cleanup failures, and add a built-binary signal shutdown regression.
- [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_G08_2.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_local_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/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.
- [ ] 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.

## Key Design Decisions

- Unwired task-runtime reads (`ProjectStatus`, `OverlayStatus`, `IntegrationStatus`, `BlockerList`) and mutations (`StartProject`, `StopProject`, `ResumeProject`) return `ErrTaskRuntimeUnavailable`, causing localcontrol `Service` to produce error envelopes without appending events to the ledger.
- `clientProcessAdapter.Start` closes the client process manager with a non-cancelled context on `StartConfigured` failure, rolling back any earlier launched clients and returning `errors.Join(launchErr, cleanupErr)`.
- Production `runMain` uses `signal.NotifyContext` to handle SIGINT/SIGTERM, unblocking `Serve` which executes `daemon.Close` with a bounded 5s non-cancelled context.

## Reviewer Checkpoints

- Every task-runtime read/mutation without an authoritative owner returns an error and cannot emit a success response or mutation event.
- A later configured-client launch failure reaps every earlier client and retains launch plus cleanup error identities.
- SIGINT/SIGTERM reaches the production daemon context, cleanup is bounded, and cleanup failures affect the process result.
- The fix does not introduce task-loop fallbacks or duplicate files owned by the parity-cutover child.

## 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_TEST-1 fail-closed task runtime

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

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

### REVIEW_TEST-2 partial-launch rollback

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

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

### REVIEW_TEST-3 production signal shutdown

```bash
go test -count=1 ./apps/agent/cmd/agent -run '^Test(BuiltBinarySignalShutdownCleansDaemon|RunServeCancellationAndCleanup)$'
```

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

### Final verification

```bash
gofmt -w apps/agent/internal/bootstrap/module.go apps/agent/internal/bootstrap/module_test.go apps/agent/cmd/agent/main.go apps/agent/cmd/agent/main_test.go
go test -count=1 ./apps/agent/internal/bootstrap -run 'TestDaemon(TaskRuntimeFailsClosedWithoutOwner|PartialClientLaunchFailureRollsBack|CompositionAndLifecycle|ClientExitIsolation)'
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.070s
ok  	iop/apps/agent/cmd/agent	3.018s
ok  	iop/apps/agent/internal/bootstrap	1.067s
ok  	iop/apps/agent/cmd/agent	3.016s
ok  	iop/apps/agent/internal/command	1.031s
ok  	iop/apps/agent/internal/clientprocess	1.642s
ok  	iop/apps/agent/internal/localcontrol	0.887s
ok  	iop/apps/agent/internal/projectlog	0.007s
ok  	iop/packages/go/agentstate	0.015s
mkdir -p build/bin
go build -trimpath -o build/bin/iop-agent ./apps/agent/cmd/agent
ok  	iop/apps/agent/cmd/agent	3.017s
ok  	iop/apps/agent/internal/bootstrap	0.089s
ok  	iop/apps/agent/internal/clientprocess	1.603s
ok  	iop/apps/agent/internal/command	0.033s
ok  	iop/apps/agent/internal/host	0.005s
ok  	iop/apps/agent/internal/localcontrol	0.871s
ok  	iop/apps/agent/internal/projectlog	0.006s
ok  	iop/packages/go/agentconfig	0.006s
ok  	iop/packages/go/agentstate	0.016s
ok  	iop/packages/go/agenttask	0.004s
```

---

> **[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: Pass
  - Completeness: Fail
  - Test Coverage: Fail
  - API Contract: Pass
  - Code Quality: Pass
  - Implementation Deviation: Fail
  - Verification Trust: Pass
- Findings:
  - Required — `apps/agent/internal/bootstrap/module_test.go:687`: `TestDaemonTaskRuntimeFailsClosedWithoutOwner` exercises task-runtime reads only through the bridge and exercises only `project.start` through `localcontrol.Service`; it does not issue the planned service-level `project.status` request or assert the stable typed error code for either response. Add service requests for the unavailable read and mutation boundaries, require `invalid_state` error envelopes with no success payload, and retain the zero-event assertion.
  - Required — `apps/agent/internal/bootstrap/module_test.go:817`: `TestDaemonPartialClientLaunchFailureRollsBack` can produce only the later launch error because its cleanup `Signal`/`Kill` methods always return nil, and the test asserts only `errors.Is(runErr, launchErr)`. The plan requires proof that the adapter preserves both launch and cleanup error identities. Add a cleanup-error case whose backend still reaps the first client, then assert `errors.Is` for both errors and the existing no-survivor invariant.
  - Required — `apps/agent/cmd/agent/main_test.go:633`: `TestBuiltBinarySignalShutdownCleansDaemon` uses a config with no launch-on-start client and proves only socket removal. The inherited finding and current plan require production SIGTERM evidence for both socket and owned-client cleanup. Configure a deterministic long-lived fixture client, wait for its readiness/PID evidence, send SIGTERM, and require bounded clean exit with both the socket and client process gone.
- Routing Signals:
  - `review_rework_count=2`
  - `evidence_integrity_failure=false`
- Next Step: Create a freshly routed follow-up plan from these Required findings.
