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

# Code Review Reference - REVIEW_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=7, tag=REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_API

## Archive Evidence Snapshot

- `plan_cloud_G06_6.log` and `code_review_cloud_G06_6.log`: current-pair predicted archives; verdict `FAIL` with 1 Required, 0 Suggested, and 0 Nit findings. Fresh focused, wire race, package, affected race, process, vet, diff, and secret guards passed. Production channel admission is correct, but `TestEdgeServerStopCancelsProjectionRefreshWaitingForPriorBatch` uses `time.Sleep(50 * time.Millisecond)` without observing a queued waiter.
- `plan_cloud_G07_5.log` and `code_review_cloud_G07_5.log`: prior production finding requiring context-aware batch admission. The current source satisfies that production requirement.
- `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-G04.md` → `code_review_cloud_G04_7.log` and `PLAN-cloud-G04.md` → `plan_cloud_G04_7.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_REVIEW_API-1 Make queued-refresh shutdown evidence deterministic | [x] |

## Implementation Checklist

- [x] Replace the sleep-driven queued-refresh `Stop` regression with an observable, deterministic waiter-entry precondition; prove `Stop` cancels and joins that refresh before the occupied batch gate is released.
- [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_G04_7.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G04_7.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/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.
- [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.

## Key Design Decisions

Replaced sleep-based waiting in `TestEdgeServerStopCancelsProjectionRefreshWaitingForPriorBatch` with a test-owned `doneObservedContext`. When `acquireProjectionBatch` evaluates context selection while waiting on the occupied `broadcastGate`, `doneObservedContext.Done()` triggers `once.Do` to close an observation channel. The test waits for `observed` before calling `Stop()`, guaranteeing that `BroadcastProjection` is queued behind the occupied gate. `Stop()` cancels the refresh context and waits for the refresh goroutine to exit. The test asserts both `Stop()` completion and `context.Canceled` error return from `BroadcastProjection` before releasing the occupied batch gate.

## Reviewer Checkpoints

- Confirm the test observes `Done()` evaluation at queued batch admission before it calls `Stop`.
- Confirm the original batch gate remains occupied until `Stop` and the queued broadcast have both returned.
- Confirm the queued broadcast returns an error matching `context.Canceled`.
- Confirm automatic ticker refresh is disabled or otherwise cannot satisfy the observation through a different path.
- Confirm production `EdgeServer` admission and fan-out code are unchanged apart from already reviewed comment formatting.
- Confirm repeated focused 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.

### Deterministic Queued-Refresh 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=20 ./apps/control-plane/internal/wire -run 'TestEdgeServer(BroadcastProjectionCancellationDoesNotWaitForPriorBatch|StopCancelsProjectionRefreshWaitingForPriorBatch)$'
```

_Actual output:_

```text
ok  	iop/apps/control-plane/internal/wire	0.039s
```

### 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:_

```text
ok  	iop/apps/control-plane/internal/wire	3.043s
```

### 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:_

```text
/config/.local/bin/go
go version go1.26.2 linux/arm64
/config/opt/go
ok  	iop/packages/go/auth	10.077s
ok  	iop/packages/go/config	0.749s
ok  	iop/packages/go/credentiallease	0.046s
ok  	iop/apps/control-plane/cmd/control-plane	6.541s
ok  	iop/apps/control-plane/internal/credentiallease	0.542s
ok  	iop/apps/control-plane/internal/credentialops	3.662s
ok  	iop/apps/control-plane/internal/credentialseal	0.316s
ok  	iop/apps/control-plane/internal/credentialstore	7.386s
ok  	iop/apps/control-plane/internal/wire	2.131s
ok  	iop/apps/edge/cmd/edge	0.937s
ok  	iop/apps/edge/internal/authprojection	0.044s
ok  	iop/apps/edge/internal/bootstrap	7.333s
ok  	iop/apps/edge/internal/configrefresh	0.789s
ok  	iop/apps/edge/internal/controlplane	6.621s
ok  	iop/apps/edge/internal/edgecmd	0.244s
ok  	iop/apps/edge/internal/edgevalidate	0.066s
ok  	iop/apps/edge/internal/events	0.047s
ok  	iop/apps/edge/internal/input	0.093s
ok  	iop/apps/edge/internal/input/a2a	0.078s
ok  	iop/apps/edge/internal/node	0.071s
ok  	iop/apps/edge/internal/openai	7.594s
ok  	iop/apps/edge/internal/opsconsole	0.088s
ok  	iop/apps/edge/internal/service	5.986s
ok  	iop/apps/edge/internal/transport	4.889s
ok  	iop/apps/node/cmd/node	0.092s
ok  	iop/apps/node/internal/adapters	0.056s
?   	iop/apps/node/internal/adapters/mock	[no test files]
ok  	iop/apps/node/internal/adapters/ollama	0.035s
ok  	iop/apps/node/internal/adapters/openai_compat	0.168s
ok  	iop/apps/node/internal/adapters/vllm	0.146s
ok  	iop/apps/node/internal/bootstrap	1.531s
ok  	iop/apps/node/internal/node	0.903s
ok  	iop/apps/node/internal/router	0.514s
ok  	iop/apps/node/internal/store	0.073s
ok  	iop/apps/node/internal/transport	5.576s
ok  	iop/packages/go/auth	11.369s
ok  	iop/packages/go/credentiallease	1.124s
ok  	iop/apps/control-plane/internal/credentiallease	1.356s
ok  	iop/apps/control-plane/internal/wire	3.072s
ok  	iop/apps/edge/internal/authprojection	1.091s
ok  	iop/apps/edge/internal/controlplane	7.652s
ok  	iop/apps/edge/internal/service	6.993s
ok  	iop/apps/edge/internal/transport	5.969s
ok  	iop/apps/node/internal/node	2.245s
./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=29089 cp_ws=31079 cp_edge_wire=31843 edge_node=32446 edge_bootstrap=34053 edge_metrics=34381
[cp-edge-wire] building temp binaries...
[cp-edge-wire] starting Control Plane...
[cp-edge-wire] waiting for Control Plane edge wire port 31843 (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":1785602293.0385094,"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:31079"}
{"level":"info","ts":1785602293.0392416,"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:31843"}
{"level":"info","ts":1785602293.0396318,"caller":"wire/client.go:92","msg":"starting client wire WS server","host":"127.0.0.1","port":31079,"path":"/client"}
{"level":"info","ts":1785602293.041283,"caller":"wire/edge_server.go:231","msg":"starting edge wire TCP server","host":"127.0.0.1","port":31843,"transport":"proto-socket-tcp"}
{"level":"info","ts":1785602293.0417707,"caller":"control-plane/server.go:227","msg":"control-plane http endpoint listening","listen":"127.0.0.1:29089"}
{"level":"info","ts":1785602293.5472972,"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":1785602294.0281746,"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.242958ms
[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 534.958µs
=== EDGE LOG ===
{"level":"info","ts":1785602293.5448651,"caller":"transport/server.go:154","msg":"edge listening for nodes","addr":"127.0.0.1:32446"}
{"level":"warn","ts":1785602293.5455709,"logger":"bootstrap","caller":"bootstrap/artifact_server.go:35","msg":"bootstrap artifact directory does not exist","dir":"/config/workspace/.gotmp-iop-secure-delivery/tmp.YJQtZKHN7w/artifacts"}
{"level":"info","ts":1785602293.545962,"logger":"bootstrap","caller":"bootstrap/artifact_server.go:59","msg":"bootstrap artifact server listening","addr":"127.0.0.1:34053","dir":"/config/workspace/.gotmp-iop-secure-delivery/tmp.YJQtZKHN7w/artifacts"}
{"level":"info","ts":1785602293.5476844,"logger":"controlplane","caller":"controlplane/connector.go:358","msg":"connected to control plane","wire_addr":"127.0.0.1:31843","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.123s
```

---

> **[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 — the test observes `Done()` evaluation while the projection batch gate is occupied, then proves `Stop()` cancels and joins the queued refresh before that gate is released.
  - Completeness: Pass — the fixed-sleep setup is removed, the test-owned refresh lifecycle matches the plan, and every implementation-owned checklist item is complete.
  - Test coverage: Pass — the focused cancellation tests pass for 20 fresh repetitions and the complete wire package passes under the race detector.
  - API contract: Pass — the follow-up changes only test evidence; production projection admission, transport APIs, and protobuf contracts remain unchanged from the previously reviewed implementation.
  - Code quality: Pass — the observation context is test-local, one-shot, race-safe, and leaves no sleep-driven waiter assumption or debug artifact.
  - Implementation deviation: Pass — the implementation follows the planned observed-context lifecycle and keeps automatic refresh disabled so no unrelated ticker can satisfy the handshake.
  - Verification trust: Pass — fresh focused, wire-race, package, affected-race retry, process-smoke, vet, diff, and secret-structure checks pass. One unrelated connector state timeout did not reproduce in 20 focused race runs or the full affected-race rerun.
  - Spec conformance: Pass — deterministic bounded refresh shutdown evidence supports SDD S02 and the S09-S13 secure-delivery evidence set without changing their implementation contract.
- Findings: None
- Routing Signals: `review_rework_count=6`, `evidence_integrity_failure=false`
- Next Step: Archive the PASS pair, write `complete.log`, move the split task to the monthly archive, and emit Milestone completion event metadata for runtime aggregation.
