<!-- task=m-principal-provider-credential-slot-routing/03+01,02_projection_auth plan=1 tag=API -->

# Code Review Reference - 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/03+01,02_projection_auth, plan=1, tag=API

## Archive Evidence Snapshot

- Prior pair: `agent-task/m-principal-provider-credential-slot-routing/03+01,02_projection_auth/plan_cloud_G10_0.log`, `agent-task/m-principal-provider-credential-slot-routing/03+01,02_projection_auth/code_review_cloud_G10_0.log`.
- Verdict/evidence: implementation had not started; no verdict or verification output.
- Replan reason: the previous plan pushed authorization state over the current unauthenticated plain TCP connector and incorrectly claimed S02/S03 completion before S10 `secure-transport`.
- Roadmap carryover: this is foundation-only. PASS must not check `auth-projection` or `surface-auth`; authenticated CP–Edge activation 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-G09.md` → `code_review_cloud_G09_1.log` and `PLAN-cloud-G09.md` → `plan_cloud_G09_1.log`.
3. If PASS, write `complete.log` and move active task directory to `agent-task/archive/YYYY/MM/m-principal-provider-credential-slot-routing/03+01,02_projection_auth/`. If WARN/FAIL, fully write the next filesystem state required by the code-review skill.
4. If PASS and task group is `m-principal-provider-credential-slot-routing`, 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 |
|------|---------|
| API-1 Define durable secret-free projection snapshots | [x] |
| API-2 Add a shared bounded Edge cache | [x] |
| API-3 Add dormant managed-mode surface authentication | [x] |

## Implementation Checklist

- [x] Build durable, secret-free projection snapshots with monotonic generation and additive generated message types, covering the S02 data/state fixtures without transport activation.
- [x] Build a bounded immutable Edge cache that applies only higher fresh generations and remains managed fail-closed after expiry/revocation under race tests.
- [x] Make OpenAI bearer and Anthropic bearer/x-api-key authentication consume the shared cache only when a verified snapshot is installed, with S03 mismatch and zero-handler-call fixtures.
- [x] Document and test that the current unauthenticated CP–Edge connector cannot install or receive the projection; leave S02/S03 Roadmap completion for secure-transport rollout.
- [x] Run fresh generation, race, Edge/client regression, dormant-activation search, 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_G09_1.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G09_1.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/03+01,02_projection_auth/` to `agent-task/archive/YYYY/MM/m-principal-provider-credential-slot-routing/03+01,02_projection_auth/` and update this checklist at the final archive path.
- [x] If PASS and task group is `m-principal-provider-credential-slot-routing`, 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

- No product or activation-scope deviation. The current Control Plane-Edge parser, server, connector, and bootstrap runtime remain unchanged and cannot apply a projection.
- `agent-contract/index.md` was additionally updated because the required `update-contract` workflow requires current read triggers and canonical source paths for every changed contract.
- Additional repository-native verification was run beyond the fixed plan: `make test-openai-ollama` passed with a deterministic fake provider, and `make test-control-plane-edge-wire` passed with real local Control Plane/Edge processes. The first wire-smoke attempt used `/tmp` and failed with `Permission denied` on this noexec host; the required workspace `TMPDIR=/config/workspace/iop-s0/.cache/tmp` rerun passed.

## Key Design Decisions

- The Control Plane stores one durable projection generation row. Every successful token, slot, and route mutation increments it inside the same SQL transaction; failed CAS/validation mutations cannot advance it.
- Snapshot construction uses a serializable transaction, deterministic ordering, injected time, hard token/route/wire-byte bounds, and active-token plus active-route/active-slot filtering. The protobuf contains verifier digests and safe references/revisions only.
- The Edge cache normalizes protobuf input into private immutable values and swaps a whole snapshot with `atomic.Pointer`. It accepts only a higher currently fresh generation, performs constant-time digest comparison across the bounded candidate set, and never returns to unmanaged compatibility mode after expiry or a revocation snapshot.
- `input.Manager` creates exactly one cache and gives the same narrow reader to the OpenAI server. No current wire/runtime component receives the cache writer.
- OpenAI and Anthropic surfaces share header normalization. Managed mode takes precedence over all static sources; malformed, mismatched, unknown, removed, or expired credentials return the surface-specific 401 before the wrapped handler. Unmanaged mode preserves existing static principal and legacy bearer behavior.

## Reviewer Checkpoints

- Confirm no Roadmap Targets section exists and PASS cannot check S02/S03.
- Verify generation commits with mutations and the cache bounds/deep-copy/atomic higher-generation fence under `-race`.
- Confirm managed expiry/revocation rejects before handlers while unmanaged config behavior remains unchanged.
- Prove Connector, EdgeServer, and Runtime have no projection listener/push/wiring on current plain transport.
- Check contracts describe reserved/gated behavior rather than active production rollout.

## Verification Results

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

### API-1

`make proto && make proto-dart && GOTMPDIR=/config/workspace/iop-s0/.cache/go-build GOCACHE=/config/workspace/iop-s0/.cache/go-cache go test -count=1 ./apps/control-plane/internal/credentialstore`

```text
protoc \
	--go_out=. \
	--go_opt=module=iop \
	--proto_path=. \
	proto/iop/agent.proto \
	proto/iop/runtime.proto \
	proto/iop/node.proto \
	proto/iop/control.proto \
	proto/iop/job.proto
mkdir -p apps/client/lib/gen
protoc \
	--plugin=protoc-gen-dart=/config/.local/bin/protoc-gen-dart \
	--dart_out=apps/client/lib/gen \
	--proto_path=. \
	--proto_path=/config/.local/include \
	proto/iop/runtime.proto \
	proto/iop/node.proto \
	proto/iop/control.proto \
	proto/iop/job.proto
ok  	iop/apps/control-plane/internal/credentialstore	3.808s
```

### API-2

`GOTMPDIR=/config/workspace/iop-s0/.cache/go-build GOCACHE=/config/workspace/iop-s0/.cache/go-cache go test -count=1 -race ./apps/edge/internal/authprojection ./apps/edge/internal/input`

```text
ok  	iop/apps/edge/internal/authprojection	1.030s
ok  	iop/apps/edge/internal/input	1.045s
```

### API-3

`GOTMPDIR=/config/workspace/iop-s0/.cache/go-build GOCACHE=/config/workspace/iop-s0/.cache/go-cache go test -count=1 ./apps/edge/internal/openai -run 'Managed|Principal|Anthropic.*Auth'`

```text
ok  	iop/apps/edge/internal/openai	0.048s
```

### 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`
2. `command -v go && go version && command -v protoc && protoc --version && command -v protoc-gen-go && command -v protoc-gen-dart && command -v flutter && flutter --version`
3. `mkdir -p .cache/go-build .cache/go-cache`
4. `make proto && make proto-dart`
5. `GOTMPDIR=/config/workspace/iop-s0/.cache/go-build GOCACHE=/config/workspace/iop-s0/.cache/go-cache go vet ./apps/control-plane/internal/credentialstore ./apps/edge/internal/authprojection ./apps/edge/internal/input ./apps/edge/internal/openai`
6. `GOTMPDIR=/config/workspace/iop-s0/.cache/go-build GOCACHE=/config/workspace/iop-s0/.cache/go-cache go test -count=1 -race ./apps/control-plane/internal/credentialstore ./apps/edge/internal/authprojection ./apps/edge/internal/input ./apps/edge/internal/openai`
7. `make client-test`
8. `if rg --sort path -n 'PrincipalProjection' apps/control-plane/internal/wire/edge_server.go apps/edge/internal/controlplane/connector.go apps/edge/internal/bootstrap/runtime.go; then exit 1; else exit 0; fi`
9. `git diff --check`

1. Exit 0; no stdout/stderr.

2.

```text
/config/.local/bin/go
go version go1.26.2 linux/arm64
/config/.local/bin/protoc
libprotoc 29.3
/config/.local/bin/protoc-gen-go
/config/.local/bin/protoc-gen-dart
/sdk/flutter/bin/flutter
Flutter 3.41.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 2c9eb20739 (5 months ago) • 2026-03-17 16:14:01 -0700
Engine • hash c1db59d880ca73dd86cec08a6663f287522d9f39 (revision 052f31d115) (4 months ago) • 2026-03-17 20:29:11.000Z
Tools • Dart 3.11.3 • DevTools 2.54.2
```

3. Exit 0; no stdout/stderr.

4.

```text
protoc \
	--go_out=. \
	--go_opt=module=iop \
	--proto_path=. \
	proto/iop/agent.proto \
	proto/iop/runtime.proto \
	proto/iop/node.proto \
	proto/iop/control.proto \
	proto/iop/job.proto
mkdir -p apps/client/lib/gen
protoc \
	--plugin=protoc-gen-dart=/config/.local/bin/protoc-gen-dart \
	--dart_out=apps/client/lib/gen \
	--proto_path=. \
	--proto_path=/config/.local/include \
	proto/iop/runtime.proto \
	proto/iop/node.proto \
	proto/iop/control.proto \
	proto/iop/job.proto
```

5. Exit 0; no stdout/stderr.

6.

```text
ok  	iop/apps/control-plane/internal/credentialstore	10.128s
ok  	iop/apps/edge/internal/authprojection	1.122s
ok  	iop/apps/edge/internal/input	1.167s
ok  	iop/apps/edge/internal/openai	9.137s
```

7.

```text
cd apps/client && flutter test
00:00 +0: loading /config/workspace/iop-s0/apps/client/test/app_shell_test.dart
00:00 +0: /config/workspace/iop-s0/apps/client/test/app_shell_test.dart: Client App basic rendering and success handshake test
00:01 +1: /config/workspace/iop-s0/apps/client/test/edge_nodes_panels_test.dart: Client App opens Edges panel and displays Edge details
00:01 +2: /config/workspace/iop-s0/apps/client/test/edge_nodes_panels_test.dart: Client App opens Edges panel and displays Edge details
00:01 +3: /config/workspace/iop-s0/apps/client/test/edge_nodes_panels_test.dart: Client App opens Edges panel and displays Edge details
00:01 +4: /config/workspace/iop-s0/apps/client/test/edge_nodes_panels_test.dart: Client App opens Edges panel and displays Edge details
00:01 +5: /config/workspace/iop-s0/apps/client/test/edge_nodes_panels_test.dart: Client App opens Edges panel and displays Edge details
00:01 +6: /config/workspace/iop-s0/apps/client/test/app_shell_test.dart: Client App mobile screen layout verification for layout and overflow
00:01 +7: /config/workspace/iop-s0/apps/client/test/app_shell_test.dart: Client App mobile screen layout verification for layout and overflow
00:01 +8: /config/workspace/iop-s0/apps/client/test/edge_nodes_panels_test.dart: Client App opens Nodes panel and displays active Nodes and configurations
00:01 +9: /config/workspace/iop-s0/apps/client/test/edge_nodes_panels_test.dart: Client App opens Nodes panel and displays active Nodes and configurations
00:01 +10: /config/workspace/iop-s0/apps/client/test/edge_nodes_panels_test.dart: Client App opens Nodes panel and displays active Nodes and configurations
00:01 +11: /config/workspace/iop-s0/apps/client/test/edge_nodes_panels_test.dart: Client App opens Nodes panel and displays active Nodes and configurations
00:02 +12: /config/workspace/iop-s0/apps/client/test/edge_nodes_panels_test.dart: Client App Nodes panel displays Provider Catalog for nodes with snapshots
00:02 +13: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App opens Operations & Domain Agents panel and verifies agents, operations history, and command triggering
00:02 +14: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App opens Operations & Domain Agents panel and verifies agents, operations history, and command triggering
00:02 +15: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App opens Operations & Domain Agents panel and verifies agents, operations history, and command triggering
00:02 +16: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App opens Operations & Domain Agents panel and verifies agents, operations history, and command triggering
00:02 +17: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App opens Operations & Domain Agents panel and verifies agents, operations history, and command triggering
00:03 +18: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App opens Operations & Domain Agents panel and verifies agents, operations history, and command triggering
00:03 +19: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App opens Operations & Domain Agents panel and verifies agents, operations history, and command triggering
00:03 +20: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App opens Operations & Domain Agents panel and verifies agents, operations history, and command triggering
00:03 +21: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App opens Operations & Domain Agents panel and verifies agents, operations history, and command triggering
00:03 +22: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App opens Operations & Domain Agents panel and verifies agents, operations history, and command triggering
00:03 +23: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App opens Operations & Domain Agents panel and verifies agents, operations history, and command triggering
00:03 +24: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App opens Operations & Domain Agents panel and verifies agents, operations history, and command triggering
00:03 +25: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App opens Operations & Domain Agents panel and verifies agents, operations history, and command triggering
00:03 +26: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App opens Operations & Domain Agents panel and verifies agents, operations history, and command triggering
00:03 +27: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App opens Operations & Domain Agents panel and verifies agents, operations history, and command triggering
00:03 +28: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App opens Operations & Domain Agents panel and verifies agents, operations history, and command triggering
00:03 +29: /config/workspace/iop-s0/apps/client/test/provider_status_test.dart: Provider with health=degraded and status=active shows DEGRADED text with yellow color
00:03 +30: /config/workspace/iop-s0/apps/client/test/provider_status_test.dart: Provider with health=degraded and status=active shows DEGRADED text with yellow color
00:03 +31: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App handles unsupported or error command responses and shows error banner
00:03 +32: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App handles unsupported or error command responses and shows error banner
00:04 +33: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App handles unsupported or error command responses and shows error banner
00:04 +34: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App handles unsupported or error command responses and shows error banner
00:04 +35: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App handles unsupported or error command responses and shows error banner
00:04 +36: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: Client App gates agent.status and agent.command without required inputs
00:04 +37: /config/workspace/iop-s0/apps/client/test/notification_integration_test.dart: notification stream from NexoNotificationHostIntegration connects to UI snackbar
00:04 +38: /config/workspace/iop-s0/apps/client/test/notification_integration_test.dart: notification stream from NexoNotificationHostIntegration connects to UI snackbar
00:05 +39: /config/workspace/iop-s0/apps/client/test/runtime_panel_test.dart: RuntimePanel renders operations empty and fetch error states
00:05 +40: /config/workspace/iop-s0/apps/client/test/notification_integration_test.dart: notification stream shows channel-only message when sender is empty
00:05 +41: /config/workspace/iop-s0/apps/client/test/notification_integration_test.dart: notification stream ignores non-message events (e.g. system)
00:05 +42: All tests passed!
```

8. Exit 0; no stdout/stderr.

9. Exit 0; no stdout/stderr.

---

> **[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=0`, `evidence_integrity_failure=false`
- Next Step: Archive the active pair, write `complete.log`, move the completed split task to the August 2026 task archive, and report the Milestone-task completion event without changing the roadmap.
