<!-- task=m-principal-provider-credential-slot-routing/06+01,02_host_local_bootstrap 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-08-01
task=m-principal-provider-credential-slot-routing/06+01,02_host_local_bootstrap, plan=2, tag=REVIEW_REVIEW_API

## Archive Evidence Snapshot

- Current pair after archive: `agent-task/m-principal-provider-credential-slot-routing/06+01,02_host_local_bootstrap/plan_local_G07_1.log`, `agent-task/m-principal-provider-credential-slot-routing/06+01,02_host_local_bootstrap/code_review_cloud_G07_1.log`.
- Verdict: FAIL with two Required findings, zero Suggested findings, and zero remaining Nits.
- Required scope: make separate SQLite pools/processes wait for the first bootstrap commit and return `ErrPrincipalAlreadyExists`; replace the narrow shared source regex with file-specific proto/ClientServer/Dart guards plus sensitivity fixtures.
- Affected files: `apps/control-plane/internal/credentialstore/store.go`, `apps/control-plane/internal/credentialstore/principal_test.go`, and `apps/control-plane/cmd/control-plane/credential_commands_test.go`.
- Fresh reviewer evidence: all focused/repeated Control Plane tests, vet, formatting, deterministic search, sequential compiled bootstrap, predecessor checks, and `git diff --check` passed; a five-process compiled race yielded `successes=1 token_outputs=1 already_exists=0 locked=4`, and four forbidden source candidates all missed the current regex; `evidence_integrity_failure=false`.
- Roadmap carryover: this packet remains preparatory and must not check `credential-management`; later encrypted-store and confidential transport rollout remains required.

## 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-principal-provider-credential-slot-routing/06+01,02_host_local_bootstrap/`. 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 Make SQLite first-bootstrap contention deterministic | [x] |
| REVIEW_REVIEW_API-2 Make the wire-absence guard sensitive to real variants | [x] |

## Implementation Checklist

- [x] Make every SQLite credential-store connection wait through bounded first-bootstrap contention and prove independent stores/processes return exactly one token plus typed `already exists` losers.
- [x] Replace the narrow shared wire-absence regex with file-specific proto/ClientServer/Dart checks and mutation fixtures that reject representative management variants while allowing the reserved projection foundation.
- [x] Run fresh separate-store race, guard sensitivity, focused bootstrap, Control Plane regression, vet, compiled multi-process, formatting, predecessor, 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`.
- [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-principal-provider-credential-slot-routing/06+01,02_host_local_bootstrap/` to `agent-task/archive/YYYY/MM/m-principal-provider-credential-slot-routing/06+01,02_host_local_bootstrap/` 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-principal-provider-credential-slot-routing/` 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

- SQLite DSNs append `_pragma=busy_timeout%3d5000` before any fragment so the modernc driver applies the bounded timeout to every pool connection while preserving existing path, query, in-memory, and fragment forms.
- The first-bootstrap race uses five independently opened `Store` handles over one initialized file, so it exercises connection-pool boundaries rather than serializing one pool to one connection.
- The wire guard parses only proto message declarations with an exact reserved projection allowlist, while ClientServer and Dart sources reject case-insensitive bootstrap, credential, and principal management symbols. Fixtures prove both rejection and allowed current foundations.

## Reviewer Checkpoints

- Confirm no `Roadmap Targets` section exists and PASS cannot check `credential-management`.
- Verify SQLite DSN normalization installs the bounded busy timeout on every pool connection, preserves plain/file/query DSNs, does not expose raw URLs, and leaves PostgreSQL unchanged.
- Prove independent `Store` handles and five compiled processes yield one token, four `ErrPrincipalAlreadyExists` refusals, one principal, one token, and no busy/locked error.
- Confirm file-specific guard fixtures reject the four reviewer candidates while allowing only current Client hello and the exact reserved projection foundation.
- Re-run focused/full Control Plane tests, vet, formatting, and the compiled oracle without recording any raw token.

## Verification Results

Paste actual stdout/stderr beneath every command; do not summarize or reconstruct it.

### REVIEW_REVIEW_API-1

`GOTMPDIR=/config/workspace/iop-s0/.cache/go-build GOCACHE=/config/workspace/iop-s0/.cache/go-cache go test -count=50 -race ./apps/control-plane/internal/credentialstore -run 'CreateFirstPrincipalWithToken'`

```text
ok  	iop/apps/control-plane/internal/credentialstore	12.407s
```

### REVIEW_REVIEW_API-2

`GOTMPDIR=/config/workspace/iop-s0/.cache/go-build GOCACHE=/config/workspace/iop-s0/.cache/go-cache go test -count=1 ./apps/control-plane/cmd/control-plane -run 'BootstrapManagement(IsAbsentFromWireSources|GuardRejectsForbiddenVariants)|BootstrapCommandRemainsCLIOnly'`

```text
ok  	iop/apps/control-plane/cmd/control-plane	0.039s
```

### Final Verification

1. `test "$(find agent-task/archive -type f -path '*/m-principal-provider-credential-slot-routing/01_principal_store/complete.log' -print | wc -l)" -eq 1 && test "$(find agent-task/archive -type f -path '*/m-principal-provider-credential-slot-routing/02+01_credential_catalog/complete.log' -print | wc -l)" -eq 1`

```text

```

2. `gofmt -d apps/control-plane/internal/credentialstore/store.go apps/control-plane/internal/credentialstore/principal_test.go apps/control-plane/cmd/control-plane/credential_commands.go apps/control-plane/cmd/control-plane/credential_commands_test.go`

```text

```

3. `GOTMPDIR=/config/workspace/iop-s0/.cache/go-build GOCACHE=/config/workspace/iop-s0/.cache/go-cache go test -count=50 -race ./apps/control-plane/internal/credentialstore -run 'CreateFirstPrincipalWithToken'`

```text
ok  	iop/apps/control-plane/internal/credentialstore	12.407s
```

4. `GOTMPDIR=/config/workspace/iop-s0/.cache/go-build GOCACHE=/config/workspace/iop-s0/.cache/go-cache go test -count=1 ./apps/control-plane/cmd/control-plane -run 'PrincipalBootstrap|Bootstrap'`

```text
ok  	iop/apps/control-plane/cmd/control-plane	0.504s
```

5. `GOTMPDIR=/config/workspace/iop-s0/.cache/go-build GOCACHE=/config/workspace/iop-s0/.cache/go-cache go test -count=1 ./apps/control-plane/...`

```text
ok  	iop/apps/control-plane/cmd/control-plane	2.912s
ok  	iop/apps/control-plane/internal/credentialops	0.130s
ok  	iop/apps/control-plane/internal/credentialstore	3.610s
ok  	iop/apps/control-plane/internal/wire	1.552s
```

6. `GOTMPDIR=/config/workspace/iop-s0/.cache/go-build GOCACHE=/config/workspace/iop-s0/.cache/go-cache go vet ./apps/control-plane/...`

```text

```

7. Run exactly:

```bash
set -euo pipefail
bootstrap_race_dir=$(mktemp -d /config/workspace/iop-s0/.cache/bootstrap-race-final.XXXXXX)
case "$bootstrap_race_dir" in
  /config/workspace/iop-s0/.cache/bootstrap-race-final.*) ;;
  *) exit 97 ;;
esac
bootstrap_race_bin="$bootstrap_race_dir/control-plane"
bootstrap_race_db="$bootstrap_race_dir/race.db"
cleanup_bootstrap_race() {
  shopt -s nullglob
  for bootstrap_race_path in "$bootstrap_race_dir"/*; do
    if [ -f "$bootstrap_race_path" ]; then
      unlink "$bootstrap_race_path"
    fi
  done
  rmdir "$bootstrap_race_dir"
}
trap cleanup_bootstrap_race EXIT
GOTMPDIR=/config/workspace/iop-s0/.cache/go-build GOCACHE=/config/workspace/iop-s0/.cache/go-cache go build -o "$bootstrap_race_bin" ./apps/control-plane/cmd/control-plane
set +e
timeout 2s env IOP_DATABASE_URL="$bootstrap_race_db" IOP_LISTEN=127.0.0.1:0 IOP_WIRE_LISTEN=127.0.0.1:0 IOP_EDGE_WIRE_LISTEN=127.0.0.1:0 "$bootstrap_race_bin" --config configs/control-plane.yaml serve >"$bootstrap_race_dir/init.out" 2>"$bootstrap_race_dir/init.err"
bootstrap_init_status=$?
set -e
if [ "$bootstrap_init_status" -ne 0 ] && [ "$bootstrap_init_status" -ne 124 ]; then
  exit 96
fi
test -f "$bootstrap_race_db"
bootstrap_race_pids=()
for i in 1 2 3 4 5; do
  env IOP_DATABASE_URL="$bootstrap_race_db" "$bootstrap_race_bin" --config configs/control-plane.yaml principal bootstrap --alias "race-$i" >"$bootstrap_race_dir/out.$i" 2>"$bootstrap_race_dir/err.$i" &
  bootstrap_race_pids+=("$!")
done
bootstrap_race_statuses=()
for bootstrap_race_pid in "${bootstrap_race_pids[@]}"; do
  set +e
  wait "$bootstrap_race_pid"
  bootstrap_race_statuses+=("$?")
  set -e
done
bootstrap_successes=0
bootstrap_already_exists=0
bootstrap_locked=0
bootstrap_other=0
bootstrap_token_outputs=0
for i in 1 2 3 4 5; do
  if [ "${bootstrap_race_statuses[$((i-1))]}" -eq 0 ]; then
    bootstrap_successes=$((bootstrap_successes+1))
  fi
  if rg -q 'already exists' "$bootstrap_race_dir/err.$i"; then
    bootstrap_already_exists=$((bootstrap_already_exists+1))
  elif rg -q 'locked|SQLITE_BUSY|database is busy' "$bootstrap_race_dir/err.$i"; then
    bootstrap_locked=$((bootstrap_locked+1))
  elif [ "${bootstrap_race_statuses[$((i-1))]}" -ne 0 ]; then
    bootstrap_other=$((bootstrap_other+1))
  fi
  bootstrap_output=$(tr -d '\r\n' < "$bootstrap_race_dir/out.$i")
  if [ "${#bootstrap_output}" -eq 64 ] && [[ "$bootstrap_output" != *[!0-9a-f]* ]]; then
    bootstrap_token_outputs=$((bootstrap_token_outputs+1))
  fi
done
test "$bootstrap_successes" -eq 1
test "$bootstrap_token_outputs" -eq 1
test "$bootstrap_already_exists" -eq 4
test "$bootstrap_locked" -eq 0
test "$bootstrap_other" -eq 0
printf '%s\n' 'PASS: five compiled bootstrap processes produced one token and four typed refusals'
```

```text
PASS: five compiled bootstrap processes produced one token and four typed refusals
```

8. `git diff --check`

```text

```

---

> **[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: PASS — write `complete.log`, archive this active pair, and move the completed split subtask under `agent-task/archive/2026/08/` without modifying the roadmap.
