<!-- task=m-principal-provider-credential-slot-routing/07+01,02,05_secret_material plan=3 tag=REVIEW_REVIEW_API milestone-task=secret-at-rest -->

# 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/07+01,02,05_secret_material, plan=3, tag=REVIEW_REVIEW_API

## Archive Evidence Snapshot

- `agent-task/m-principal-provider-credential-slot-routing/07+01,02,05_secret_material/plan_local_G06_2.log` and `agent-task/m-principal-provider-credential-slot-routing/07+01,02,05_secret_material/code_review_cloud_G06_2.log`: current pair closed with `FAIL`; Required findings are exact unknown-kind no-mutation assertions and real Client/Edge listener-start assertions.
- Fresh reviewer commands passed the focused and full Control Plane suites, `go vet`, `git diff --check`, reviewer-probe guard, and credential leak guard. Production correctness is accepted; test evidence is incomplete. `review_rework_count=2`; `evidence_integrity_failure=true`.
- `plan_cloud_G08_1.log` and `code_review_cloud_G09_1.log` remain the earlier production-boundary failure evidence. `plan_cloud_G08_0.log` and `code_review_cloud_G09_0.log` remain the unimplemented scaffold.
- The exact predecessor completions for indices 01, 02, and 05 remain satisfied.

## 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-G04.md` → `code_review_cloud_G04_3.log` and `PLAN-cloud-G04.md` → `plan_cloud_G04_3.log`.
3. If PASS, write `complete.log` and move active task directory to `agent-task/archive/YYYY/MM/m-principal-provider-credential-slot-routing/07+01,02,05_secret_material/`. 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_REVIEW_API-1 Prove rejected credential kinds leave durable state unchanged | [x] |
| REVIEW_REVIEW_API-2 Observe the real Client and Edge listener-start boundaries | [x] |

## Implementation Checklist

- [x] Add exact pre/post slot, revision-row, and projection-generation assertions to the unknown credential-kind regression while preserving the zero-sealer-call assertion.
- [x] Match the actual Client/Edge startup log messages in the encryption-without-database run regression alongside the existing HTTP listener assertion.
- [x] Run fresh focused and full Control Plane verification, vet, structural/diff/leak guards, and confirm no reviewer probe remains.
- [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_G04_3.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G04_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-principal-provider-credential-slot-routing/07+01,02,05_secret_material/` to `agent-task/archive/YYYY/MM/m-principal-provider-credential-slot-routing/07+01,02,05_secret_material/` and update this checklist at the final archive path.
- [x] 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`.
- [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. Preflight disk cleanup was performed on `/tmp` before verification when stale temporary cache directories exhausted `/tmp` storage, and `TMPDIR=/config/tmp` was explicitly set alongside existing `GOCACHE` and `GOTMPDIR` flags.

## Key Design Decisions

- Added inline helper function `credentialState` inside `unknown-kind-rejected-before-sealer` in `apps/control-plane/internal/credentialops/service_test.go` to record `ListSlots`, `credential_slot_revisions` count, and `ProjectionGeneration` before and after the rejected `CreateSlot` call, asserting exact state equality as well as zero slots and zero revision rows.
- Replaced non-existent listener log strings `client wire endpoint listening` and `edge wire endpoint listening` in `apps/control-plane/cmd/control-plane/credential_store_test.go` with production start log strings `starting client wire WS server` and `starting edge wire TCP server` emitted by `ClientServer.Start` and `EdgeServer.Start`.

## Reviewer Checkpoints

- Confirm the unknown-kind subtest captures exact slot state, revision-row count, and projection generation before rejection and compares the exact state afterward.
- Confirm the unknown-kind subtest still asserts `ErrInvalidCredentialKind` and zero sealer calls.
- Confirm the run regression matches `starting client wire WS server` and `starting edge wire TCP server`, plus the existing HTTP listener message.
- Confirm only the two planned test files and this review evidence file changed for the follow-up; production behavior remains untouched.
- Confirm fresh package/full Control Plane results, structural guard, diff check, reviewer-probe guard, and secret leak guard are present and trustworthy.

## Verification Results

Paste actual stdout/stderr below each command. Do not summarize or reconstruct it. A replacement command requires a matching `Deviations from Plan` entry.

### REVIEW_REVIEW_API-1

```bash
GOCACHE=/tmp/gocache-secret-material-evidence GOTMPDIR=/config/tmp go test -count=1 ./apps/control-plane/internal/credentialops -run 'TestServiceCreateCanonicalizesCredentialKindForAAD|TestServiceSecretHandlingFailureIsBlindAndDoesNotMutate'
```

_Actual output:_

```text
ok  	iop/apps/control-plane/internal/credentialops	0.701s
```

### REVIEW_REVIEW_API-2

```bash
GOCACHE=/tmp/gocache-secret-material-evidence GOTMPDIR=/config/tmp go test -count=1 ./apps/control-plane/cmd/control-plane -run 'TestComposeCredentialRuntimeEncryptionRequiresDatabase|TestRunWithEncryptionAndNoDatabaseDoesNotStartListener|TestRunAllowsUnconfiguredDatabase|TestComposeCredentialRuntimeSecretDisabledMode'
```

_Actual output:_

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

### Final Verification

```bash
mkdir -p /config/tmp /tmp/gocache-secret-material-evidence
command -v go && go version && go env GOROOT
git status --short --branch
GOCACHE=/tmp/gocache-secret-material-evidence GOTMPDIR=/config/tmp go test -count=1 ./apps/control-plane/internal/credentialops -run 'TestServiceCreateCanonicalizesCredentialKindForAAD|TestServiceSecretHandlingFailureIsBlindAndDoesNotMutate'
GOCACHE=/tmp/gocache-secret-material-evidence GOTMPDIR=/config/tmp go test -count=1 ./apps/control-plane/cmd/control-plane -run 'TestComposeCredentialRuntimeEncryptionRequiresDatabase|TestRunWithEncryptionAndNoDatabaseDoesNotStartListener|TestRunAllowsUnconfiguredDatabase|TestComposeCredentialRuntimeSecretDisabledMode'
GOCACHE=/tmp/gocache-secret-material-evidence GOTMPDIR=/config/tmp go test -count=1 ./apps/control-plane/internal/credentialseal ./apps/control-plane/internal/credentialstore ./apps/control-plane/internal/credentialops
GOCACHE=/tmp/gocache-secret-material-evidence GOTMPDIR=/config/tmp go test -count=1 ./apps/control-plane/...
GOCACHE=/tmp/gocache-secret-material-evidence GOTMPDIR=/config/tmp go vet ./apps/control-plane/...
if rg --sort path -n '_ = (slots|gen)|client wire endpoint listening|edge wire endpoint listening' apps/control-plane/internal/credentialops/service_test.go apps/control-plane/cmd/control-plane/credential_store_test.go; then exit 1; fi
git diff --check
test ! -e apps/control-plane/internal/credentialops/reviewer_probe_test.go
credential_leak_pattern='BEGIN'' AGE PRIVATE KEY|active_key_value[[:space:]]*:[[:space:]]*[^<$]'
if rg --sort path -n --hidden --glob '!agent-task/archive/**' --glob '!*.sops.yaml' --glob '!PLAN-*.md' --glob '!*.log' "$credential_leak_pattern" apps/control-plane configs agent-task/m-principal-provider-credential-slot-routing/07+01,02,05_secret_material; then exit 1; fi
```

_Actual output:_

```text
/config/.local/bin/go
go version go1.26.2 linux/arm64
/config/opt/go
## agent/dispatcher-work-log-artifact-loop...origin/agent/dispatcher-work-log-artifact-loop
 M agent-contract/index.md
 M agent-contract/inner/control-plane-edge-wire.md
 M agent-contract/outer/anthropic-compatible-api.md
 M agent-contract/outer/openai-compatible-api.md
 M agent-roadmap/phase/operational-observability-provider-management/PHASE.md
 M agent-roadmap/phase/operational-observability-provider-management/milestones/principal-provider-credential-slot-routing.md
 D agent-task/m-principal-provider-credential-slot-routing/01_principal_store/CODE_REVIEW-cloud-G06.md
 D agent-task/m-principal-provider-credential-slot-routing/01_principal_store/PLAN-local-G06.md
 D agent-task/m-principal-provider-credential-slot-routing/02+01_credential_catalog/CODE_REVIEW-cloud-G07.md
 D agent-task/m-principal-provider-credential-slot-routing/02+01_credential_catalog/PLAN-local-G07.md
 D agent-task/m-principal-provider-credential-slot-routing/02+01_credential_catalog/code_review_cloud_G07_0.log
 D agent-task/m-principal-provider-credential-slot-routing/02+01_credential_catalog/plan_local_G07_0.log
 D agent-task/m-principal-provider-credential-slot-routing/03+01,02_projection_auth/CODE_REVIEW-cloud-G09.md
 D agent-task/m-principal-provider-credential-slot-routing/03+01,02_projection_auth/PLAN-cloud-G09.md
 D agent-task/m-principal-provider-credential-slot-routing/03+01,02_projection_auth/code_review_cloud_G10_0.log
 D agent-task/m-principal-provider-credential-slot-routing/03+01,02_projection_auth/plan_cloud_G10_0.log
 D agent-task/m-principal-provider-credential-slot-routing/04+03_principal_routes/CODE_REVIEW-cloud-G08.md
 D agent-task/m-principal-provider-credential-slot-routing/04+03_principal_routes/PLAN-local-G07.md
 D agent-task/m-principal-provider-credential-slot-routing/04+03_principal_routes/code_review_cloud_G09_0.log
 D agent-task/m-principal-provider-credential-slot-routing/04+03_principal_routes/plan_local_G08_0.log
 D agent-task/m-principal-provider-credential-slot-routing/05+01,02_management_core/CODE_REVIEW-cloud-G06.md
 D agent-task/m-principal-provider-credential-slot-routing/05+01,02_management_core/PLAN-local-G06.md
 D agent-task/m-principal-provider-credential-slot-routing/05+01,02_management_core/code_review_cloud_G08_1.log
 D agent-task/m-principal-provider-credential-slot-routing/05+01,02_management_core/code_review_cloud_G10_0.log
 D agent-task/m-principal-provider-credential-slot-routing/05+01,02_management_core/plan_cloud_G10_0.log
 D agent-task/m-principal-provider-credential-slot-routing/05+01,02_management_core/plan_local_G07_1.log
 D agent-task/m-principal-provider-credential-slot-routing/06+01,02_host_local_bootstrap/CODE_REVIEW-cloud-G06.md
 D agent-task/m-principal-provider-credential-slot-routing/06+01,02_host_local_bootstrap/PLAN-local-G06.md
 M apps/client/lib/gen/proto/iop/control.pb.dart
 M apps/client/lib/gen/proto/iop/control.pbjson.dart
 M apps/control-plane/cmd/control-plane/config_test.go
 M apps/control-plane/cmd/control-plane/main.go
 M apps/control-plane/cmd/control-plane/server.go
 M apps/edge/internal/input/manager.go
 M apps/edge/internal/input/manager_test.go
 M apps/edge/internal/openai/anthropic_handler.go
 M apps/edge/internal/openai/anthropic_surface_test.go
 M apps/edge/internal/openai/chat_handler.go
 M apps/edge/internal/openai/dispatch_context.go
 M apps/edge/internal/openai/identity_metering_test.go
 M apps/edge/internal/openai/principal.go
 M apps/edge/internal/openai/provider_tunnel.go
 M apps/edge/internal/openai/responses_handler.go
 M apps/edge/internal/openai/route_resolution.go
 M apps/edge/internal/openai/routes.go
 M apps/edge/internal/openai/server.go
 M apps/edge/internal/openai/stream_gate_runtime.go
 M configs/control-plane.yaml
 M go.mod
 M go.sum
 M go.work.sum
 M proto/gen/iop/control.pb.go
 M proto/iop/control.proto
?? agent-task/archive/2026/08/m-principal-provider-credential-slot-routing/
?? agent-task/m-principal-provider-credential-slot-routing/07+01,02,05_secret_material/
?? agent-task/m-principal-provider-credential-slot-routing/08+03,04,07_secure_delivery/
?? agent-task/m-principal-provider-credential-slot-routing/09+08_migration_attribution/
?? agent-task/m-principal-provider-credential-slot-routing/10+08,09_verification_contracts/
?? agent-task/m-principal-provider-credential-slot-routing/WORK_LOG.md
?? apps/control-plane/cmd/control-plane/credential_commands.go
?? apps/control-plane/cmd/control-plane/credential_commands_test.go
?? apps/control-plane/cmd/control-plane/credential_store_test.go
?? apps/control-plane/internal/credentialops/
?? apps/control-plane/internal/credentialseal/
?? apps/control-plane/internal/credentialstore/
?? apps/edge/internal/authprojection/
?? apps/edge/internal/openai/principal_routes.go
?? apps/edge/internal/openai/principal_routes_test.go
ok  	iop/apps/control-plane/internal/credentialops	0.620s
ok  	iop/apps/control-plane/cmd/control-plane	1.362s
ok  	iop/apps/control-plane/internal/credentialseal	0.107s
ok  	iop/apps/control-plane/internal/credentialstore	2.963s
ok  	iop/apps/control-plane/internal/credentialops	1.159s
ok  	iop/apps/control-plane/cmd/control-plane	4.641s
ok  	iop/apps/control-plane/internal/credentialops	1.885s
ok  	iop/apps/control-plane/internal/credentialseal	0.241s
ok  	iop/apps/control-plane/internal/credentialstore	3.783s
ok  	iop/apps/control-plane/internal/wire	1.504s
```

---

> **[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:** PASS
- **Dimension Assessment:**
  - Correctness: Pass — rejected unknown credential kinds preserve the exact slot snapshot, revision-row count, and projection generation, and configured encryption without a database returns before any HTTP, Client wire, or Edge wire listener starts.
  - Completeness: Pass — both follow-up items and every integrated verification requirement are implemented and evidenced.
  - Test coverage: Pass — the focused regressions assert the two previously missing invariants, and the fresh credential-package and full Control Plane suites pass.
  - API contract: Pass — the tests preserve the accepted fail-closed credential-store and listener lifecycle boundaries without changing production contracts.
  - Code quality: Pass — the scoped changes contain no stale listener strings, discarded state probes, debug artifacts, or reviewer probe file.
  - Implementation deviation: Pass — only the two planned test files and implementation-owned review evidence changed after the prior review; production behavior remained untouched.
  - Verification trust: Pass — fresh reviewer execution reproduced all submitted focused/full test, vet, diff, structure, and credential-leak guard results with exit code 0.
  - Spec conformance: Pass — the implementation evidence satisfies the `secret-at-rest` contribution to SDD S09 and its encrypted-store/secret-scan evidence requirements.
- **Findings:** None
- **Routing Signals:** `review_rework_count=2`, `evidence_integrity_failure=false`
- **Next Step:** Archive the reviewed pair, write `complete.log`, and move the completed split task to the August 2026 task archive while preserving `milestone-task=secret-at-rest` for runtime aggregation.
