<!-- task=m-iop-owned-single-request-agent-execution/25+23,24_claude_smoke_qualification plan=17 tag=REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_REVIEW_API milestone-task=workspace-binding,claude-smoke -->

# Repair Claude tool-search request compatibility

## For the Implementing Agent

Resolve only R10: support the two bounded compatibility inputs emitted by the installed Claude Code 2.1.177 tool-search request path, prove that they grant no IOP authority and do not enter normalized Chat provider bodies, update the contract, and rebuild only the disposable managed dev Edge. Do not invoke Claude, Gemini, Ornith, or any provider directly. Run every selected verification and fill the implementation-owned sections of the active review; leave verdict, log archive, next-state classification, and `complete.log` to official review.

## Background

The third explicitly authorized Claude-through-IOP call was consumed exactly once as `sole-live-3.rc-69` and failed with HTTP 400 before accepted ingress. Provider-free count-token probes independently show the current Edge rejects `advanced-tool-use-2025-11-20` and boolean tool `defer_loading`, while static inspection of the installed Claude builder ties both to its first-party tool-search request path. The exact deleted live response subtype is unavailable, so this plan repairs only those independently proven inputs and does not broaden the schema speculatively.

## Archive Evidence Snapshot

- Closed pair: `plan_cloud_G10_16.log` / `code_review_cloud_G10_16.log`; verdict `FAIL`, Required R10, `review_rework_count=15`, `evidence_integrity_failure=false`.
- The authorized execution created `sole-live-3.rc-69`, had ingress delta 0, no Gemini/Ornith stage or model output, no manifest, and no retry. All three live guards are immutable.
- Before repair, authenticated provider-free probes returned baseline 200, `advanced-tool-use-2025-11-20` 400, tool `defer_loading` 400, and unsupported tool `strict`, `eager_input_streaming`, and thinking-display shapes 400, with generation deltas zero.
- Disposable runtime root is `/Users/toki/agent-work/iop-s12-managed-validation-20260808`; isolated source is `/Users/toki/agent-work/iop-s12-validation-20260808/source`; canonical `/Users/toki/agent-work/iop-dev` remains read-only.

## Finding Resolution Map

| Finding | Mode | Exact fix/dependency evidence | Changed precondition |
|---|---|---|---|
| R10 | direct-fix | `apps/edge/internal/openai/anthropic_types.go`, `apps/edge/internal/openai/anthropic_bridge_test.go`, `agent-contract/outer/anthropic-compatible-api.md`; exact provider-free dev probes | The installed tool-search beta and `defer_loading` change from strict-decoder HTTP 400 to compatibility HTTP 200 while normalized provider requests, routing authority, and unsupported neighboring fields remain unchanged. |

## Analysis

### Files Read

- `apps/edge/internal/openai/anthropic_types.go`
- `apps/edge/internal/openai/anthropic_handler.go`
- `apps/edge/internal/openai/anthropic_bridge.go`
- `apps/edge/internal/openai/anthropic_bridge_test.go`
- `agent-contract/outer/anthropic-compatible-api.md`
- `agent-roadmap/phase/knowledge-tool-optimization-extension/milestones/iop-owned-single-request-agent-execution.md`
- `agent-roadmap/sdd/knowledge-tool-optimization-extension/iop-owned-single-request-agent-execution/SDD.md`
- `agent-test/dev/rules.md`
- `agent-task/m-iop-owned-single-request-agent-execution/25+23,24_claude_smoke_qualification/plan_cloud_G10_16.log`
- `agent-task/m-iop-owned-single-request-agent-execution/25+23,24_claude_smoke_qualification/code_review_cloud_G10_16.log`

### SDD Criteria

- SDD status is approved and milestone-linked with `milestone-task=workspace-binding,claude-smoke`.
- Acceptance Scenario S12 requires one actual Claude request, ingress exactly 1, ordered Gemini -> Ornith-fast -> Gemini stages, stage/total timing, verified workspace result, and one terminal. Its Evidence Map requires the actual Claude, ingress counter, Edge/Node/provider timings, and workspace before/after.
- This repair is a prerequisite to repeat S12 but cannot itself satisfy S12. The checklist therefore proves the ingress compatibility boundary and leaves all PASS-only S12 owners unchanged.

### Verification Context

- No separate handoff was supplied. Current review evidence, source, contract, milestone/SDD, installed Claude 2.1.177 static request-builder inspection, and provider-free dev probes are the inputs.
- Runner is `toki@toki-labs.com` (Darwin/arm64). Canonical checkout `/Users/toki/agent-work/iop-dev` is read-only. Reviewed files are synchronized only to `/Users/toki/agent-work/iop-s12-validation-20260808/source`; runtime root is `/Users/toki/agent-work/iop-s12-managed-validation-20260808`.
- Revalidate managed CP/Edge/Node identity, source sync, config/runtime evidence, ports, fleet health, catalog, guards, zero Claude process, and zero generation activity before and after the bounded Edge rebuild. Use `/opt/homebrew/bin/go`; use remote SOPS caller material only in process memory for authenticated IOP count-token/catalog/preflight requests and never print it.
- Confidence is high for the two input gaps because each is independently reproduced without generation and tied to the installed request builder. Confidence is intentionally insufficient for `strict`, `eager_input_streaming`, or thinking-display support; those remain rejected.

### Test Coverage Gaps

- Missing beta acceptance: add it to the representative Claude Code bridge request and preserve unknown-beta rejection.
- Missing tool compatibility field: add `defer_loading:true` to that request and assert the normalized Chat tool contains only its existing function fields.
- Boundary preservation: provider-free probes must keep unsupported adjacent shapes at HTTP 400 and all generation/activity deltas at zero.

### Symbol References

No symbol is renamed or removed. `anthropicTool` is decoded in `anthropic_types.go`, converted field-by-field in `anthropic_bridge.go`, and serialized for provider-free token counting in `anthropic_handler.go`; the new field is compatibility-only and is intentionally omitted by the normalized converter.

### Split Judgment

This is one indivisible compatibility boundary: beta allowlist, nested tool decoding, normalized omission, external contract, regression test, and disposable runtime probe must agree. Splitting would permit source, contract, and deployed behavior to diverge.

### Scope Rationale

Exclude `strict`, `eager_input_streaming`, and thinking-display because the installed default path was not proven to emit them for this call. Exclude harness changes, success-only S12 contract/spec statements, direct provider calls, any new live Claude call, canonical dev checkout mutation, and common Agent-Ops files.

### Final Routing

- `evaluation_mode=isolated-reassessment`; `finalizer=finalize-task-policy.sh`; `finalizer_mode=pair`.
- Build route `worker/cloud/G10`, `PLAN-cloud-G10.md`; review route `review/cloud/G10`, `CODE_REVIEW-cloud-G10.md`.
- `base_route_basis=grade-boundary`; build/review scores `2/2/2/2/2`; `large_indivisible_context=true`.
- Positive loop risks: `temporal_state`, `concurrent_consistency`, `boundary_contract`, `variant_product`; count 4.
- `review_rework_count=15`, `evidence_integrity_failure=false`; risk and recovery boundaries match without replacing the grade basis.

## Implementation Checklist

- [ ] Add bounded `advanced-tool-use-2025-11-20` and boolean tool `defer_loading` compatibility without normalized Chat authority or forwarding.
- [ ] Add regression and boundary assertions, and update the external Anthropic compatibility contract.
- [ ] Rebuild only the disposable managed dev Edge and pass exact provider-free repaired/unsupported-field probes with zero generation activity.
- [ ] Run fresh local and remote focused/race/harness/diff/redaction gates without any live or direct provider call.
- [ ] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

### REVIEW_API-1 — Add bounded tool-search compatibility

**Problem:** `apps/edge/internal/openai/anthropic_types.go:19` rejects `advanced-tool-use-2025-11-20`, and the strict nested decoder rejects `defer_loading` because `anthropicTool` at line 59 does not declare it.

**Solution:** add one sorted beta entry and one boolean compatibility field. The normalized converter continues constructing Chat tools only from name, description, and input schema.

Before (`apps/edge/internal/openai/anthropic_types.go:19`):

```go
var supportedAnthropicBetas = map[string]struct{}{
	"claude-code-20250219": {},
```

After:

```go
var supportedAnthropicBetas = map[string]struct{}{
	"advanced-tool-use-2025-11-20": {},
	"claude-code-20250219":          {},
```

Before (`apps/edge/internal/openai/anthropic_types.go:59`):

```go
type anthropicTool struct {
	Name         string          `json:"name"`
```

After:

```go
type anthropicTool struct {
	Name         string          `json:"name"`
	DeferLoading bool            `json:"defer_loading,omitempty"`
```

**Modified Files and Checklist:**

- [ ] `apps/edge/internal/openai/anthropic_types.go` — add only the bounded beta and boolean tool field.

**Test Strategy:** covered by REVIEW_API-2 regression tests.

**Verification:** `gofmt -w apps/edge/internal/openai/anthropic_types.go` and `go test -count=1 ./apps/edge/internal/openai`; expect PASS.

### REVIEW_API-2 — Lock regression and contract semantics

**Problem:** `apps/edge/internal/openai/anthropic_bridge_test.go:224` lacks the actual tool-search inputs, and `agent-contract/outer/anthropic-compatible-api.md:227` does not describe their bounded compatibility semantics.

**Solution:** extend the representative Claude request with the beta and `defer_loading:true`; assert the beta header and field are absent from normalized Chat output. Document beta acceptance and `defer_loading` as non-authoritative compatibility input. Preserve rejection tests for unknown beta and unsupported nested fields.

**Modified Files and Checklist:**

- [ ] `apps/edge/internal/openai/anthropic_bridge_test.go` — add representative acceptance and normalized omission assertions.
- [ ] `agent-contract/outer/anthropic-compatible-api.md` — document accepted beta and bounded tool field.

**Test Strategy:** update `TestAnthropicChatBridgeClaudeCodeRequest`; retain `TestAnthropicRejectsUnknownFieldsAndBetas`. Assert HTTP 200, no forwarded Anthropic beta, no `defer_loading` in the normalized tool/function object, and existing unknown/invalid shapes still fail.

**Verification:** `go test -count=1 ./apps/edge/internal/openai -run 'TestAnthropic(ChatBridgeClaudeCodeRequest|RejectsUnknownFieldsAndBetas)'`; expect PASS.

### REVIEW_API-3 — Qualify the disposable dev Edge provider-free

**Problem:** source-only success would not prove the managed Edge serving `127.0.0.1:18483` matches the repair.

**Solution:** sync only the three reviewed files to the isolated source, run remote focused/race tests, build a replacement Edge, preserve the old binary/runtime evidence as recoverable backups, restart only that Edge, atomically refresh runtime evidence, and run authenticated IOP catalog/count-token probes. Do not invoke any generation route.

**Modified Files and Checklist:**

- [ ] `agent-task/m-iop-owned-single-request-agent-execution/25+23,24_claude_smoke_qualification/CODE_REVIEW-cloud-G10.md` — record source/binary/runtime identity, process/fleet health, exact statuses, counters, and no-live proof.

**Test Strategy:** provider-free boundary probes are required. After repair expect baseline, advanced beta, and tool `defer_loading` HTTP 200; expect tool `strict`, tool `eager_input_streaming`, and thinking-display HTTP 400. Require catalog HTTP 200/selected count 1, one Edge, one Node, two healthy snapshots, all prior guards unchanged, Claude process count 0, and generation/activity deltas 0.

**Verification:** synchronize the exact reviewed files with `scp`; on the remote isolated source run `/opt/homebrew/bin/go test -count=1 ./apps/edge/internal/openai` and `/opt/homebrew/bin/go test -count=1 -race ./apps/edge/internal/openai ./apps/edge/internal/service`; rebuild/restart the disposable Edge and execute the six authenticated count-token probes plus harness `--preflight-only`. Expect the statuses above and no Claude process or generation change.

### REVIEW_API-4 — Record closed evidence

**Problem:** official review needs exact evidence without secrets, raw prompts, provider/model output, or speculative attribution of the deleted live error.

**Solution:** fill the active review with actual command output, deviations, guarded no-live evidence, repaired/unsupported probe matrix, and privacy/hygiene checks.

**Modified Files and Checklist:**

- [ ] `agent-task/m-iop-owned-single-request-agent-execution/25+23,24_claude_smoke_qualification/CODE_REVIEW-cloud-G10.md` — complete implementation-owned evidence.

**Test Strategy:** no separate behavioral test; reviewer cross-checks source, runtime identities, probe status matrix, counters, and guards.

**Verification:** `git diff --check` and targeted redaction/placeholder scans must pass; active plan/review and all prior logs must be unignored by Git.

## Modified Files Summary

| File | Item |
|---|---|
| `apps/edge/internal/openai/anthropic_types.go` | REVIEW_API-1 |
| `apps/edge/internal/openai/anthropic_bridge_test.go` | REVIEW_API-2 |
| `agent-contract/outer/anthropic-compatible-api.md` | REVIEW_API-2 |
| `agent-task/m-iop-owned-single-request-agent-execution/25+23,24_claude_smoke_qualification/CODE_REVIEW-cloud-G10.md` | REVIEW_API-3, REVIEW_API-4 |

## Final Verification

1. `gofmt -w apps/edge/internal/openai/anthropic_types.go apps/edge/internal/openai/anthropic_bridge_test.go`
2. `go test -count=1 ./apps/edge/internal/openai`
3. `go test -count=1 -race ./apps/edge/internal/openai ./apps/edge/internal/service`
4. `bash -n scripts/e2e-single-request-claude.sh && scripts/e2e-single-request-claude.sh --self-test`
5. `git diff --check`
6. Sync only the three reviewed source/contract files to the isolated macOS source. Run the same focused/race tests with `/opt/homebrew/bin/go`, rebuild/restart only the disposable managed Edge, refresh runtime evidence, and require catalog 200 plus repaired probe statuses `200/200/200` and unsupported statuses `400/400/400` with zero generation/activity and zero Claude processes.
7. Run harness `--preflight-only` with a fresh temporary Claude config, managed CA, and in-memory SOPS caller. Require PASS with no guard change, no child invocation, no result/manifest, and no ingress/generation change.
8. Confirm no new `sole-live*` guard, no direct provider request, no stable S12 manifest, no secret/raw output, and no change to canonical `/Users/toki/agent-work/iop-dev`.

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