<!-- task=m-multi-provider-protocol-profile-native-messages/05+03,04_contract_spec_sync plan=2 tag=REVIEW_DOC -->

# Close remaining Anthropic and protocol-profile contract drift

## For the Implementing Agent

Fill the implementation-owned sections of `CODE_REVIEW-cloud-G06.md` as the mandatory final implementation step. Run every verification command, record actual stdout/stderr or the prescribed retained evidence path plus metadata, keep the active files in place, and report ready for review; finalization belongs only to the code-review skill. If blocked, record only the exact blocker, attempted commands/output, and resume condition in the implementation-owned evidence fields. Do not ask the user, call user-input tools, create control-plane stop files, classify the next state, archive logs, or write `complete.log`.

## Background

The second documentation closure pass fixed the major ownership boundaries and its fresh regressions pass, but official review found three remaining statements that contradict the implemented Anthropic and protocol-profile behavior. That pass also repeated the prior evidence-integrity defect by replacing complete search and suite output with selected excerpts and prose. This follow-up is restricted to those contract/spec corrections and review-retained deterministic evidence.

## Archive Evidence Snapshot

- Earlier pair: `agent-task/m-multi-provider-protocol-profile-native-messages/05+03,04_contract_spec_sync/plan_local_G06_01.log` and `agent-task/m-multi-provider-protocol-profile-native-messages/05+03,04_contract_spec_sync/code_review_cloud_G06_01.log`; verdict FAIL with 5 Required, 0 Suggested, and 0 Nit findings.
- Immediate prior pair: `agent-task/m-multi-provider-protocol-profile-native-messages/05+03,04_contract_spec_sync/plan_cloud_G07_01.log` and `agent-task/m-multi-provider-protocol-profile-native-messages/05+03,04_contract_spec_sync/code_review_cloud_G07_01.log`; verdict FAIL with 4 Required, 0 Suggested, and 0 Nit findings.
- Remaining required scope: document the local-first Anthropic count-tokens path, the actual Anthropic error envelope and ingress-413 type, full-URL `ResolveOperationURL` semantics, and complete retained verification evidence.
- Reviewer evidence: the focused OpenAI suite, all package/Edge/Node tests and vet suites, the Pi installer test, shell syntax, and `git diff --check` passed independently. Runtime behavior is not the defect; the published statements and implementation-owned evidence are.
- Dependency evidence remains at `agent-task/archive/2026/08/m-multi-provider-protocol-profile-native-messages/03+02_responses_profile/complete.log` and `agent-task/archive/2026/08/m-multi-provider-protocol-profile-native-messages/04+02_pi_responses_regression/complete.log`.
- Roadmap carryover: `contract-sync` and `responses-regression` remain incomplete until this follow-up passes.

## Roadmap Targets

- Milestone: `agent-roadmap/phase/operational-observability-provider-management/milestones/multi-provider-protocol-profile-native-messages.md`
- Milestone link: [Milestone document](agent-roadmap/phase/operational-observability-provider-management/milestones/multi-provider-protocol-profile-native-messages.md)
- Task ids:
  - `contract-sync`: synchronize profile config, tunnel operation, Chat/Messages public/inner contracts, and current implementation specs
  - `responses-regression`: preserve optional Responses drivers and Pi consumption behavior
- Completion mode: check-on-pass

## Analysis

### Files Read

- `agent-roadmap/phase/operational-observability-provider-management/milestones/multi-provider-protocol-profile-native-messages.md`
- `agent-roadmap/sdd/operational-observability-provider-management/multi-provider-protocol-profile-native-messages/SDD.md`
- `agent-contract/index.md`
- `agent-contract/outer/anthropic-compatible-api.md`
- `agent-contract/inner/edge-config-runtime-refresh.md`
- `agent-spec/index.md`
- `agent-spec/runtime/edge-node-execution.md`
- `agent-spec/runtime/provider-pool-config-refresh.md`
- `packages/go/config/protocol_profile.go`
- `packages/go/config/protocol_profile_test.go`
- `apps/edge/internal/openai/common_types.go`
- `apps/edge/internal/openai/anthropic_types.go`
- `apps/edge/internal/openai/anthropic_handler.go`
- `apps/edge/internal/openai/anthropic_surface_test.go`
- `apps/edge/internal/openai/stream_gate_ingress_test.go`
- `agent-task/m-multi-provider-protocol-profile-native-messages/05+03,04_contract_spec_sync/PLAN-cloud-G07.md`
- `agent-task/m-multi-provider-protocol-profile-native-messages/05+03,04_contract_spec_sync/CODE_REVIEW-cloud-G07.md`
- `agent-task/m-multi-provider-protocol-profile-native-messages/05+03,04_contract_spec_sync/plan_local_G06_01.log`
- `agent-task/m-multi-provider-protocol-profile-native-messages/05+03,04_contract_spec_sync/code_review_cloud_G06_01.log`

### SDD Criteria

- SDD: `agent-roadmap/sdd/operational-observability-provider-management/multi-provider-protocol-profile-native-messages/SDD.md`, status approved and unlocked.
- S04 maps to `contract-sync`; its Acceptance Scenario and Evidence Map require public/inner contracts and current spec indexes to agree with the implementation paths after a deterministic drift check.
- S08 maps to `responses-regression`; its Acceptance Scenario and Evidence Map require the existing focused Responses/provider-auth and Pi regressions to remain green.
- S04 drives REVIEW_DOC-1 and REVIEW_DOC-2 plus the retained source/contract searches. S08 drives the focused and full regression commands in REVIEW_DOC-3 even though no Responses behavior changes.

### Verification Context

- No external handoff was supplied. The active FAIL review, local contracts/specs, implementation source, existing tests, and fresh reviewer runs are the evidence sources.
- Preconditions: the index 03 and 04 predecessor `complete.log` files exist; Go 1.26.2 and Python 3.12.3 are available; `/var/tmp` supports executable Go artifacts.
- Fresh reviewer commands already proved the focused OpenAI tests, all package/Edge/Node tests and vet suites, Pi installer test, shell syntax, and workspace diff check pass. Fresh Go execution remains required with `-count=1`; cached results are not acceptable.
- Long output must be redirected directly to exact files under `/var/tmp/iop-contract-spec-sync-followup-g06/`. The files must remain present through official review. The implementation evidence must record each exact producing command, path, exit status, line count, byte count, and SHA-256 digest; excerpts or prose summaries are not substitutes.
- No remote runner, live provider, device, credential, or user-owned execution is required. Confidence is high because all disputed behavior is explicit in local handler/config source and tests.

### Test Coverage Gaps

- Local deterministic count-tokens and native fallback selection are covered by `TestAnthropicCountTokensNativeLocalUnsupported`; no production test change is required.
- Full-URL resolution, absolute-URL preservation, and relative-path joining are covered by `TestBuiltInProtocolProfileURLs`, `TestProtocolProfileResolveOperationURLAbsolute`, and provider-endpoint overlay assertions; no production test change is required.
- Shared ingress overflow has boundary tests, but no direct Anthropic 413 assertion was found. This packet changes documentation only, so it does not add a runtime test; the handler and serializer search is mandatory evidence.
- Documentation-to-source agreement has no unit-test oracle. Retained deterministic searches and their metadata are mandatory closure evidence.

### Symbol References

- No symbol is renamed or removed.
- The corrected documents reference existing `ConcreteProtocolProfile.ResolveOperationURL`, `Server.handleAnthropicCountTokens`, `writeAnthropicIngressError`, `writeAnthropicError`, `anthropicErrorResponse`, and `OperationCountTokens` definitions only.

### Split Judgment

- Keep one compact packet because the outer contract and runtime spec must describe the same count-tokens/error paths, while the inner contract and runtime spec must describe the same resolver result. Each pair would be internally inconsistent if only one side were updated.
- `large_indivisible_context=false`: explicit local rules and deterministic verification fully reduce the packet.
- The subtask dependencies are satisfied by the archived index 03 and 04 `complete.log` paths listed above.

### Scope Rationale

- Production Go, protobuf, tests, indexes, the OpenAI outer contract, Pi scripts, roadmap state, and SDD state are excluded. Reviewer execution shows no runtime regression, and none of the remaining findings requests behavior changes.
- Do not add new Anthropic metering or change token-counter admission. This packet documents the current local-first/fallback behavior only.
- Evidence files belong outside the repository at the exact `/var/tmp` paths below and must not be added to workspace claims or version control.

### Final Routing

- `status=routed`; `evaluation_mode=isolated-reassessment`; `finalizer=finalize-task-policy.sh`; `finalizer_mode=pair`.
- Build closures: scope/context/verification/evidence/ownership/decision are all true; capability gap none.
- Build grade scores: scope_coupling=2, state_concurrency=0, blast_irreversibility=1, evidence_diagnosis=2, verification_complexity=1, producing G06.
- Build route: base `local-fit`; `large_indivisible_context=false`; matched loop risk `boundary_contract` (count 1); `review_rework_count=2`; `evidence_integrity_failure=true`; risk boundary not matched; recovery boundary matched; final route `recovery-boundary`, cloud.
- Review closures: scope/context/verification/evidence/ownership/decision are all true; grade scores 2/0/1/2/1, producing G06; route `official-review`, cloud, Codex `gpt-5.6-sol`, xhigh.
- Canonical files: `PLAN-cloud-G06.md` and `CODE_REVIEW-cloud-G06.md`.

## Dependencies and Execution Order

1. Keep the completed index 03 and 04 predecessor evidence unchanged.
2. Correct the paired outer/runtime Anthropic statements and paired inner/runtime resolver statements.
3. Capture all searches and regressions to retained deterministic files, then fill the active review evidence.

## Implementation Checklist

- [ ] Align the Anthropic outer contract and execution spec with local-first count-tokens, native fallback admission, and the implemented error envelope/type.
- [ ] Align the config inner contract and provider-pool config spec with full-URL operation resolution semantics.
- [ ] Run deterministic source/contract searches and fresh focused/full regressions, retaining complete outputs and recording exact evidence metadata.
- [ ] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

### [REVIEW_DOC-1] Correct Anthropic count-tokens and error contracts

**Problem**

`agent-contract/outer/anthropic-compatible-api.md:240,259` and `agent-spec/runtime/edge-node-execution.md:232` require provider-pool dispatch and `count_tokens` profile admission for every request, while `apps/edge/internal/openai/anthropic_handler.go:104-117` returns a local catalog count first. `agent-contract/outer/anthropic-compatible-api.md:210,228` also misdescribes the nested error envelope and assigns `request_entity_too_large` to 413 even though `apps/edge/internal/openai/anthropic_handler.go:293-298` emits `invalid_request_error`.

**Solution**

```text
Before (anthropic-compatible-api.md:240,259):
All count-tokens requests use provider-pool routing and require count_tokens capability/operation.

After:
A configured model-catalog TokenCounter returns a deterministic local count without provider selection. Only the native upstream fallback requires an anthropic_messages candidate with count_tokens capability/operation; Chat profiles remain unsupported for that fallback.
```

Describe the error body as top-level `type` plus nested `error.type` and `error.message`, and list ingress 413 under `invalid_request_error`.

**Modified Files and Checklist**

- [ ] Update `agent-contract/outer/anthropic-compatible-api.md` routing, profile admission, and error sections.
- [ ] Update `agent-spec/runtime/edge-node-execution.md` with the local-first/fallback distinction.

**Test Strategy**

No new test file. This is a documentation correction against existing handler and surface tests; focused Anthropic tests and direct source/contract searches are required.

**Verification**

```bash
evidence_root=/var/tmp/iop-contract-spec-sync-followup-g06
install -d -m 700 "$evidence_root"
rg -n --sort path 'TokenCounter|OperationCountTokens|count_tokens|writeAnthropicIngressError|anthropicErrorResponse|request_entity_too_large|invalid_request_error' apps/edge/internal/openai packages/go/config agent-contract/outer/anthropic-compatible-api.md agent-spec/runtime/edge-node-execution.md > "$evidence_root/anthropic-contract-search.txt" 2>&1
wc -l -c "$evidence_root/anthropic-contract-search.txt"
sha256sum "$evidence_root/anthropic-contract-search.txt"
```

Expected: the retained output exposes the local-first path, native fallback admission, nested error envelope, and 413 `invalid_request_error`; both documents agree with them.

### [REVIEW_DOC-2] Correct operation URL resolution semantics

**Problem**

`agent-contract/inner/edge-config-runtime-refresh.md:39` and `agent-spec/runtime/provider-pool-config-refresh.md:158` say `ConcreteProtocolProfile.ResolveOperationURL` returns an HTTP path. `packages/go/config/protocol_profile.go:633-671` returns a full URL by preserving an absolute operation URL or joining a relative operation path to the normalized base URL once.

**Solution**

```text
Before (edge-config-runtime-refresh.md:39):
ResolveOperationURL returns the HTTP path for an operation.

After:
ResolveOperationURL returns the complete resolved upstream URL. Absolute operation URLs are unchanged; relative operation paths are joined once to the normalized base URL. The listed /v1/... values are operation-path inputs, not return values.
```

**Modified Files and Checklist**

- [ ] Update `agent-contract/inner/edge-config-runtime-refresh.md`.
- [ ] Update `agent-spec/runtime/provider-pool-config-refresh.md` with the same concise semantics.

**Test Strategy**

No new test file. Existing protocol-profile tests cover absolute preservation and relative joining; run the focused tests fresh.

**Verification**

```bash
evidence_root=/var/tmp/iop-contract-spec-sync-followup-g06
install -d -m 700 "$evidence_root"
rg -n --sort path 'ResolveOperationURL|resolveOperationURL|BaseURL|operation path|full URL|complete resolved upstream URL' packages/go/config/protocol_profile.go packages/go/config/protocol_profile_test.go agent-contract/inner/edge-config-runtime-refresh.md agent-spec/runtime/provider-pool-config-refresh.md > "$evidence_root/operation-url-search.txt" 2>&1
wc -l -c "$evidence_root/operation-url-search.txt"
sha256sum "$evidence_root/operation-url-search.txt"
```

Expected: the retained output shows the source, tests, contract, and spec consistently distinguish relative operation-path inputs from full resolved URLs.

### [REVIEW_DOC-3] Preserve complete deterministic closure evidence

**Problem**

The prior review at `code_review_cloud_G07_01.log:169-194,225-249` reports a 588-line search and multi-suite success but retains only selected lines and prose. That repeats the preceding evidence-integrity failure and prevents official review from auditing the exact output claimed by the implementation.

**Solution**

Redirect every potentially long search, test, vet, syntax, and diff result directly to an exact task-specific `/var/tmp` file. Keep the files until official review and record the exact command, path, exit status, line count, byte count, and SHA-256 digest in `CODE_REVIEW-cloud-G06.md`. Do not reconstruct, excerpt, summarize, or delete the retained output.

**Modified Files and Checklist**

- [ ] Fill `agent-task/m-multi-provider-protocol-profile-native-messages/05+03,04_contract_spec_sync/CODE_REVIEW-cloud-G06.md` with complete evidence metadata and actual short command output.

**Test Strategy**

No new test file. Run all prescribed fresh regressions because this item establishes review trust across the milestone closure packet.

**Verification**

Run the exact `Final Verification` block. Expected: exit 0, every exact evidence file remains readable through review, forbidden-drift outputs are empty with `rg` exit 1, and all metadata is recorded without prose substitution.

## Modified Files Summary

| File | Items |
|------|-------|
| `agent-contract/outer/anthropic-compatible-api.md` | REVIEW_DOC-1 |
| `agent-spec/runtime/edge-node-execution.md` | REVIEW_DOC-1 |
| `agent-contract/inner/edge-config-runtime-refresh.md` | REVIEW_DOC-2 |
| `agent-spec/runtime/provider-pool-config-refresh.md` | REVIEW_DOC-2 |
| `agent-task/m-multi-provider-protocol-profile-native-messages/05+03,04_contract_spec_sync/CODE_REVIEW-cloud-G06.md` | REVIEW_DOC-3, implementation evidence |

## Final Verification

```bash
set -e
test -f agent-task/archive/2026/08/m-multi-provider-protocol-profile-native-messages/03+02_responses_profile/complete.log
test -f agent-task/archive/2026/08/m-multi-provider-protocol-profile-native-messages/04+02_pi_responses_regression/complete.log
command -v go && go version && go env GOROOT
command -v python3 && python3 --version
evidence_root=/var/tmp/iop-contract-spec-sync-followup-g06
review_build_tmp=/var/tmp/iop-contract-spec-sync-followup-g06-go-tmp
install -d -m 700 "$evidence_root" "$review_build_tmp"
rg -n --sort path 'TokenCounter|OperationCountTokens|count_tokens|writeAnthropicIngressError|anthropicErrorResponse|request_entity_too_large|invalid_request_error' apps/edge/internal/openai packages/go/config agent-contract/outer/anthropic-compatible-api.md agent-spec/runtime/edge-node-execution.md > "$evidence_root/anthropic-contract-search.txt" 2>&1
rg -n --sort path 'ResolveOperationURL|resolveOperationURL|BaseURL|operation path|full URL|complete resolved upstream URL' packages/go/config/protocol_profile.go packages/go/config/protocol_profile_test.go agent-contract/inner/edge-config-runtime-refresh.md agent-spec/runtime/provider-pool-config-refresh.md > "$evidence_root/operation-url-search.txt" 2>&1
if rg -n --sort path 'Messages and count-tokens require a .*provider-pool route|Anthropic .*count_tokens.*요청은.*count_tokens.*capability.*operation.*요구한다|request_entity_too_large.*413|ResolveOperationURL\(op\).*HTTP path를 반환한다' agent-contract agent-spec > "$evidence_root/forbidden-contract-drift.txt" 2>&1; then echo 'forbidden contract/spec drift remains' >&2; exit 1; else test "$?" -eq 1; fi
python3 agent-client/pi/install_test.py > "$evidence_root/pi-install-test.txt" 2>&1
bash -n agent-client/pi/install.sh > "$evidence_root/pi-install-syntax.txt" 2>&1
env GOCACHE=/config/.cache/iop-contract-spec-sync-followup-g06 GOTMPDIR="$review_build_tmp" go test -count=1 ./packages/go/config -run 'TestBuiltInProtocolProfileURLs|TestProtocolProfileResolveOperationURLAbsolute|TestProtocolProfileProviderEndpointOverlay' > "$evidence_root/go-test-config-focused.txt" 2>&1
env GOCACHE=/config/.cache/iop-contract-spec-sync-followup-g06 GOTMPDIR="$review_build_tmp" go test -count=1 ./apps/edge/internal/openai -run 'TestAnthropic|TestResponses|Test.*ProviderAuth' > "$evidence_root/go-test-openai-focused.txt" 2>&1
env GOCACHE=/config/.cache/iop-contract-spec-sync-followup-g06 GOTMPDIR="$review_build_tmp" go vet ./packages/go/... > "$evidence_root/go-vet-packages.txt" 2>&1
env GOCACHE=/config/.cache/iop-contract-spec-sync-followup-g06 GOTMPDIR="$review_build_tmp" go vet ./apps/edge/... > "$evidence_root/go-vet-edge.txt" 2>&1
env GOCACHE=/config/.cache/iop-contract-spec-sync-followup-g06 GOTMPDIR="$review_build_tmp" go vet ./apps/node/... > "$evidence_root/go-vet-node.txt" 2>&1
env GOCACHE=/config/.cache/iop-contract-spec-sync-followup-g06 GOTMPDIR="$review_build_tmp" go test -count=1 ./packages/go/... > "$evidence_root/go-test-packages.txt" 2>&1
env GOCACHE=/config/.cache/iop-contract-spec-sync-followup-g06 GOTMPDIR="$review_build_tmp" go test -count=1 ./apps/edge/... > "$evidence_root/go-test-edge.txt" 2>&1
env GOCACHE=/config/.cache/iop-contract-spec-sync-followup-g06 GOTMPDIR="$review_build_tmp" go test -count=1 ./apps/node/... > "$evidence_root/go-test-node.txt" 2>&1
git diff --check > "$evidence_root/git-diff-check.txt" 2>&1
wc -l -c "$evidence_root/anthropic-contract-search.txt" "$evidence_root/operation-url-search.txt" "$evidence_root/forbidden-contract-drift.txt" "$evidence_root/pi-install-test.txt" "$evidence_root/pi-install-syntax.txt" "$evidence_root/go-test-config-focused.txt" "$evidence_root/go-test-openai-focused.txt" "$evidence_root/go-vet-packages.txt" "$evidence_root/go-vet-edge.txt" "$evidence_root/go-vet-node.txt" "$evidence_root/go-test-packages.txt" "$evidence_root/go-test-edge.txt" "$evidence_root/go-test-node.txt" "$evidence_root/git-diff-check.txt"
sha256sum "$evidence_root/anthropic-contract-search.txt" "$evidence_root/operation-url-search.txt" "$evidence_root/forbidden-contract-drift.txt" "$evidence_root/pi-install-test.txt" "$evidence_root/pi-install-syntax.txt" "$evidence_root/go-test-config-focused.txt" "$evidence_root/go-test-openai-focused.txt" "$evidence_root/go-vet-packages.txt" "$evidence_root/go-vet-edge.txt" "$evidence_root/go-vet-node.txt" "$evidence_root/go-test-packages.txt" "$evidence_root/go-test-edge.txt" "$evidence_root/go-test-node.txt" "$evidence_root/git-diff-check.txt"
```

Expected: exit 0; all fresh focused/full tests, vets, Pi checks, and workspace checks pass; forbidden drift produces an empty retained file via `rg` exit 1; all other complete outputs remain at the exact paths above through official review; the review records the producing commands, exit statuses, line/byte counts, and SHA-256 values.

After completing all code changes, fill implementation-owned sections in `CODE_REVIEW-*-G??.md`.
