<!-- task=m-principal-provider-credential-slot-routing/08+03,04,07_secure_delivery plan=6 tag=REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_API milestone-task=secure-transport,credential-lease,adapter-injection,revocation -->

# Code Review Reference - REVIEW_REVIEW_REVIEW_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-02
task=m-principal-provider-credential-slot-routing/08+03,04,07_secure_delivery, plan=6, tag=REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_API

## Archive Evidence Snapshot

- `plan_cloud_G07_5.log` and `code_review_cloud_G07_5.log`: current-pair predicted archives; verdict `FAIL` with 1 Required, 0 Suggested, and 0 Nit findings. Planned focused, wire race, package, process, vet, diff, and secret guards passed on fresh review, except one unrelated connector stop assertion that passed a focused race run 20 times and the full affected race retry. A reviewer reproducer proved that a canceled `broadcastProjection` remained blocked behind `broadcastMu` beyond 200ms.
- `plan_cloud_G10_4.log` and `code_review_cloud_G10_4.log`: prior fan-out finding. The current source satisfies concurrent per-client delivery and closes/drains stalled sends, but not context-aware batch admission.
- `agent-task/archive/2026/08/m-principal-provider-credential-slot-routing/03+01,02_projection_auth/complete.log`, `agent-task/archive/2026/08/m-principal-provider-credential-slot-routing/04+03_principal_routes/complete.log`, and `agent-task/archive/2026/08/m-principal-provider-credential-slot-routing/07+01,02,05_secret_material/complete.log`: projection, route-binding, and secret-at-rest predecessors 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-G06.md` → `code_review_cloud_G06_6.log` and `PLAN-cloud-G06.md` → `plan_cloud_G06_6.log`.
3. If PASS, write `complete.log` and move active task directory to `agent-task/archive/YYYY/MM/m-principal-provider-credential-slot-routing/08+03,04,07_secure_delivery/`. 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_REVIEW_REVIEW_REVIEW_API-1 Make serialized batch admission cancellable | [x] |

## Implementation Checklist

- [x] Make projection batch admission context-aware so caller cancellation and refresh shutdown do not wait behind another serialized batch, while preserving whole-batch serialization and current concurrent per-client delivery; pass deterministic queued-batch cancellation and stop regressions.
- [x] Run the focused, race, full secure-delivery, vet, diff, and secret-structure verification commands with fresh output.
- [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_6.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G06_6.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-principal-provider-credential-slot-routing/08+03,04,07_secure_delivery/` to `agent-task/archive/YYYY/MM/m-principal-provider-credential-slot-routing/08+03,04,07_secure_delivery/` and update this checklist at the final archive path.
- [ ] 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`.
- [ ] 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.
- [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

Replaced private `broadcastMu sync.Mutex` in `EdgeServer` with a private context-aware single-owner gate `broadcastGate chan struct{}` initialized with buffer capacity 1 in `NewEdgeServerTLS`. Projection batch entry calls helper `acquireProjectionBatch(ctx)` which selects between `broadcastGate <- struct{}{}` and `ctx.Done()`. Immediately following gate acquisition, `ctx.Err()` is re-checked so a cancellation racing with gate availability returns `ctx.Err()` immediately and releases the gate via `defer`. Whole-batch serialization and concurrent per-client fan-out remain fully preserved.

## Reviewer Checkpoints

- Confirm waiting for the one-owner projection batch gate selects on `ctx.Done()` and cannot outlive caller cancellation.
- Confirm a cancellation racing with gate availability is checked before projection snapshot creation.
- Confirm the gate remains held across snapshot creation and all per-client sends, so whole batches stay serialized.
- Confirm `stopProjectionRefresh` can cancel and join a refresh waiting behind another batch without releasing that batch first.
- Confirm current concurrent per-client fan-out, close/drain behavior, stable error ordering, and token-fenced disconnect behavior remain unchanged.
- Confirm focused queued-batch tests, wire race, full secure-delivery packages/process target, vet, diff, and secret guard pass with fresh output.

## Verification Results

Paste actual stdout/stderr below each command. Do not summarize or reconstruct it. Replacement commands require a `Deviations from Plan` entry.

### Focused Batch Cancellation

```bash
env GOCACHE=/config/tmp/gocache-secure-delivery GOTMPDIR=/config/workspace/.gotmp-iop-secure-delivery TMPDIR=/config/workspace/.gotmp-iop-secure-delivery go test -count=1 ./apps/control-plane/internal/wire -run 'TestEdgeServer(BroadcastProjectionCancellationDoesNotWaitForPriorBatch|StopCancelsProjectionRefreshWaitingForPriorBatch|BroadcastProjectionDoesNotLetStalledEdgeBlockHealthyEdge|StopCancelsStalledProjectionRefresh|PeriodicallyRefreshesEveryActiveEdge|BroadcastProjectionAttemptsAllActiveEdges)'
```

_Actual output:_

```
ok  	iop/apps/control-plane/internal/wire	0.557s
```

### Wire Race Verification

```bash
env GOCACHE=/config/tmp/gocache-secure-delivery GOTMPDIR=/config/workspace/.gotmp-iop-secure-delivery TMPDIR=/config/workspace/.gotmp-iop-secure-delivery go test -count=1 -race ./apps/control-plane/internal/wire
```

_Actual output:_

```
ok  	iop/apps/control-plane/internal/wire	3.161s
```

### Final Verification

```bash
command -v go && go version && go env GOROOT
test -f agent-task/archive/2026/08/m-principal-provider-credential-slot-routing/03+01,02_projection_auth/complete.log
test -f agent-task/archive/2026/08/m-principal-provider-credential-slot-routing/04+03_principal_routes/complete.log
test -f agent-task/archive/2026/08/m-principal-provider-credential-slot-routing/07+01,02,05_secret_material/complete.log
env GOCACHE=/config/tmp/gocache-secure-delivery GOTMPDIR=/config/workspace/.gotmp-iop-secure-delivery TMPDIR=/config/workspace/.gotmp-iop-secure-delivery go test -count=1 ./packages/go/auth ./packages/go/config ./packages/go/credentiallease
env GOCACHE=/config/tmp/gocache-secure-delivery GOTMPDIR=/config/workspace/.gotmp-iop-secure-delivery TMPDIR=/config/workspace/.gotmp-iop-secure-delivery go test -count=1 ./apps/control-plane/... ./apps/edge/... ./apps/node/...
env GOCACHE=/config/tmp/gocache-secure-delivery GOTMPDIR=/config/workspace/.gotmp-iop-secure-delivery TMPDIR=/config/workspace/.gotmp-iop-secure-delivery go test -count=1 -race ./packages/go/auth ./packages/go/credentiallease ./apps/control-plane/internal/credentiallease ./apps/control-plane/internal/wire ./apps/edge/internal/authprojection ./apps/edge/internal/controlplane ./apps/edge/internal/service ./apps/edge/internal/transport ./apps/node/internal/node
env GOCACHE=/config/tmp/gocache-secure-delivery GOTMPDIR=/config/workspace/.gotmp-iop-secure-delivery TMPDIR=/config/workspace/.gotmp-iop-secure-delivery make test-control-plane-edge-wire
env GOCACHE=/config/tmp/gocache-secure-delivery GOTMPDIR=/config/workspace/.gotmp-iop-secure-delivery TMPDIR=/config/workspace/.gotmp-iop-secure-delivery go vet ./apps/control-plane/... ./apps/edge/... ./apps/node/... ./packages/go/...
git diff --check
if rg --sort path -n 'bytes[[:space:]]+(secret|provider_secret)|map<string, string>[[:space:]]+(credential|provider_auth)' proto/iop/runtime.proto; then exit 1; fi
```

_Actual output:_

```
/config/.local/bin/go
go version go1.26.2 linux/arm64
/config/opt/go
ok  	iop/packages/go/auth	10.094s
ok  	iop/packages/go/config	1.068s
ok  	iop/packages/go/credentiallease	0.055s
ok  	iop/apps/control-plane/cmd/control-plane	5.945s
ok  	iop/apps/control-plane/internal/credentiallease	0.524s
ok  	iop/apps/control-plane/internal/credentialops	3.205s
ok  	iop/apps/control-plane/internal/credentialseal	0.374s
ok  	iop/apps/control-plane/internal/credentialstore	6.178s
ok  	iop/apps/control-plane/internal/wire	2.223s
ok  	iop/apps/edge/cmd/edge	0.827s
ok  	iop/apps/edge/internal/authprojection	0.101s
ok  	iop/apps/edge/internal/bootstrap	6.319s
ok  	iop/apps/edge/internal/configrefresh	0.660s
ok  	iop/apps/edge/internal/controlplane	6.646s
ok  	iop/apps/edge/internal/edgecmd	0.326s
ok  	iop/apps/edge/internal/edgevalidate	0.124s
ok  	iop/apps/edge/internal/events	0.054s
ok  	iop/apps/edge/internal/input	0.089s
ok  	iop/apps/edge/internal/input/a2a	0.072s
ok  	iop/apps/edge/internal/node	0.069s
ok  	iop/apps/edge/internal/openai	7.476s
ok  	iop/apps/edge/internal/opsconsole	0.083s
ok  	iop/apps/edge/internal/service	5.993s
ok  	iop/apps/edge/internal/transport	4.914s
ok  	iop/apps/node/cmd/node	0.137s
ok  	iop/apps/node/internal/adapters	0.072s
?   	iop/apps/node/internal/adapters/mock	[no test files]
ok  	iop/apps/node/internal/adapters/ollama	0.029s
ok  	iop/apps/node/internal/adapters/openai_compat	0.160s
ok  	iop/apps/node/internal/adapters/vllm	0.158s
ok  	iop/apps/node/internal/bootstrap	1.574s
ok  	iop/apps/node/internal/node	0.899s
ok  	iop/apps/node/internal/router	0.519s
ok  	iop/apps/node/internal/store	0.135s
ok  	iop/apps/node/internal/transport	5.616s
ok  	iop/packages/go/auth	11.259s
ok  	iop/packages/go/credentiallease	1.175s
ok  	iop/apps/control-plane/internal/credentiallease	1.548s
ok  	iop/apps/control-plane/internal/wire	3.255s
ok  	iop/apps/edge/internal/authprojection	1.087s
ok  	iop/apps/edge/internal/controlplane	7.679s
ok  	iop/apps/edge/internal/service	7.029s
ok  	iop/apps/edge/internal/transport	6.067s
ok  	iop/apps/node/internal/node	2.452s
./scripts/e2e-control-plane-edge-wire.sh
[cp-edge-wire] NOTE: auxiliary smoke only - verifies Control Plane-Edge hello and disconnect via real processes.
[cp-edge-wire] shellcheck not found, skipping
[cp-edge-wire] ports: cp_http=29278 cp_ws=31128 cp_edge_wire=31453 edge_node=32594 edge_bootstrap=33995 edge_metrics=34424
[cp-edge-wire] building temp binaries...
[cp-edge-wire] starting Control Plane...
[cp-edge-wire] waiting for Control Plane edge wire port 31453 (timeout: 20s)...
[cp-edge-wire] Control Plane edge wire port ready
[cp-edge-wire] starting Edge...
[cp-edge-wire] waiting for hello accepted (timeout: 30s)...
[cp-edge-wire] CP: hello accepted
[cp-edge-wire] Edge: connected to control plane
[cp-edge-wire] stopping Edge process to trigger disconnect...
[cp-edge-wire] waiting for disconnect marker on CP (timeout: 20s)...
[cp-edge-wire] CP: edge disconnected
=== CONTROL PLANE OUTPUT ===
{"level":"info","ts":1785601364.0310097,"caller":"control-plane/server.go:30","msg":"control-plane client wire endpoint reserved","protocol":"protobuf-socket","transport":"proto-socket-ws","listen":"127.0.0.1:31128"}
{"level":"info","ts":1785601364.031813,"caller":"control-plane/server.go:35","msg":"control-plane edge wire endpoint reserved","protocol":"protobuf-socket","transport":"proto-socket-tcp","listen":"127.0.0.1:31453"}
{"level":"info","ts":1785601364.032016,"caller":"wire/client.go:92","msg":"starting client wire WS server","host":"127.0.0.1","port":31128,"path":"/client"}
{"level":"info","ts":1785601364.0340886,"caller":"wire/edge_server.go:231","msg":"starting edge wire TCP server","host":"127.0.0.1","port":31453,"transport":"proto-socket-tcp"}
{"level":"info","ts":1785601364.0348814,"caller":"control-plane/server.go:227","msg":"control-plane http endpoint listening","listen":"127.0.0.1:29278"}
{"level":"info","ts":1785601364.5487509,"caller":"wire/edge_server.go:176","msg":"edge hello accepted","edge_id":"smoke-edge-wire","edge_name":"Smoke Edge Wire","version":"0.1.0"}
{"level":"info","ts":1785601365.015916,"caller":"wire/edge_server.go:212","msg":"edge disconnected","edge_id":"smoke-edge-wire","reason":"remote_closed"}
=== EDGE PROCESS OUTPUT ===
[Fx] PROVIDE	fx.Lifecycle <= go.uber.org/fx.New.func1()
[Fx] PROVIDE	fx.Shutdowner <= go.uber.org/fx.(*App).shutdowner-fm()
[Fx] PROVIDE	fx.DotGraph <= go.uber.org/fx.(*App).dotGraph-fm()
[Fx] PROVIDE	*config.EdgeConfig <= iop/apps/edge/internal/bootstrap.Module.func1()
[Fx] PROVIDE	*bootstrap.Runtime <= iop/apps/edge/internal/bootstrap.NewRuntime()
[Fx] INVOKE		iop/apps/edge/internal/bootstrap.Module.func2()
[Fx] RUN	provide: go.uber.org/fx.New.func1()
[Fx] RUN	provide: iop/apps/edge/internal/bootstrap.Module.func1()
[Fx] RUN	provide: iop/apps/edge/internal/bootstrap.NewRuntime()
[Fx] HOOK OnStart		iop/apps/edge/internal/bootstrap.Module.func2.1() executing (caller: iop/apps/edge/internal/bootstrap.Module.func2)
[Fx] HOOK OnStart		iop/apps/edge/internal/bootstrap.Module.func2.1() called by iop/apps/edge/internal/bootstrap.Module.func2 ran successfully in 2.963833ms
[Fx] RUNNING
[Fx] TERMINATED
[Fx] HOOK OnStop		iop/apps/edge/internal/bootstrap.Module.func2.2() executing (caller: iop/apps/edge/internal/bootstrap.Module.func2)
[Fx] HOOK OnStop		iop/apps/edge/internal/bootstrap.Module.func2.2() called by iop/apps/edge/internal/bootstrap.Module.func2 ran successfully in 594.666µs
=== EDGE LOG ===
{"level":"info","ts":1785601364.5455666,"caller":"transport/server.go:154","msg":"edge listening for nodes","addr":"127.0.0.1:32594"}
{"level":"warn","ts":1785601364.5465648,"logger":"bootstrap","caller":"bootstrap/artifact_server.go:35","msg":"bootstrap artifact directory does not exist","dir":"/config/workspace/.gotmp-iop-secure-delivery/tmp.hUzGFS3n61/artifacts"}
{"level":"info","ts":1785601364.546913,"logger":"bootstrap","caller":"bootstrap/artifact_server.go:59","msg":"bootstrap artifact server listening","addr":"127.0.0.1:33995","dir":"/config/workspace/.gotmp-iop-secure-delivery/tmp.hUzGFS3n61/artifacts"}
{"level":"info","ts":1785601364.549427,"logger":"controlplane","caller":"controlplane/connector.go:358","msg":"connected to control plane","wire_addr":"127.0.0.1:31453","protocol":"protobuf-socket"}
===========================
[cp-edge-wire] Control Plane-Edge wire smoke PASSED.
IOP_SECURE_DELIVERY_E2E=1 go test -count=1 -run '^TestSecureDeliveryThreeProcess$' ./apps/control-plane/cmd/control-plane
ok  	iop/apps/control-plane/cmd/control-plane	8.613s
```

---

> **[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: FAIL
- Dimension Assessment:
  - Correctness: Pass — context-aware channel admission wakes on caller cancellation, rechecks a raced cancellation before snapshot creation, and keeps the gate across the complete concurrent fan-out batch.
  - Completeness: Fail — production behavior is implemented, but the planned deterministic shutdown regression is not complete because it never proves that the refresh goroutine reached queued batch admission.
  - Test coverage: Fail — the direct canceled-waiter test is meaningful, while the `Stop` test can pass without executing a periodic projection broadcast at all.
  - API contract: Pass — public signatures and protobuf shapes are unchanged, and whole-batch serialization plus stable per-Edge result aggregation are preserved.
  - Code quality: Pass — the single-owner gate is private, initialized by the only constructor path, and released with `defer`; no dead code, debug output, or stale mutex reference remains.
  - Implementation deviation: Fail — the plan required a deterministic queued-refresh shutdown regression, but the implementation substitutes a fixed sleep without a waiter-entry handshake or equivalent observable precondition.
  - Verification trust: Fail — every planned command passed on fresh review, but `TestEdgeServerStopCancelsProjectionRefreshWaitingForPriorBatch` would also pass if the refresh broadcast never started, so its success does not establish the claimed stop invariant.
  - Spec conformance: Pass — the production change preserves the SDD S02 and S10-S13 bounded refresh and fail-closed delivery behavior; the remaining issue is deterministic evidence for that behavior.
- Findings:
  - Required — `apps/control-plane/internal/wire/edge_server_test.go:1139`: `TestEdgeServerStopCancelsProjectionRefreshWaitingForPriorBatch` sleeps for 50ms and then asserts only that `Stop` returns. It never observes that the periodic refresh attempted `BroadcastProjection` and blocked behind the occupied gate, so the test still passes if refresh startup or the ticker broadcast is removed. Replace the sleep-driven setup with a deterministic refresh lifecycle/waiter-entry handshake (or an equivalent observable precondition), keep the gate occupied until `Stop` completes, and prove the queued refresh exits from cancellation before gate release.
- Routing Signals: `review_rework_count=6`, `evidence_integrity_failure=true`
- Next Step: Create and execute a freshly routed follow-up PLAN/CODE_REVIEW pair for deterministic queued-refresh shutdown evidence, preserving the current secure-delivery scope.
