<!-- task=m-iop-hot-path-one-shot-execution/19+17,18_observation_lifecycle plan=4 tag=REVIEW_REVIEW_REVIEW_API milestone-task=route-observability -->

# Repair the OpenAI direct-tool cancellation regression fixture

## For the Implementing Agent

Implement only this plan. Run every verification command exactly as written, paste actual stdout/stderr into `CODE_REVIEW-cloud-G01.md`, complete its implementation-owned sections, and leave both active files in place for official review. If blocked, record the exact blocker, attempted command/output, and resume condition only in those implementation-owned evidence fields. Do not ask the user, call user-input tools, create control-plane stop files, classify the next state, archive task files, or write `complete.log`.

## Background

The post-write terminal ownership implementation is correct, but the OpenAI direct-tool regression does not reach it. Its provider response is a Go raw string whose nested `function.arguments` value is escaped twice. The resulting outer JSON is invalid, so the handler writes an early error before Hot Path dispatch and the required focused, targeted, and common race suites fail.

## Archive Evidence Snapshot

- `agent-task/m-iop-hot-path-one-shot-execution/19+17,18_observation_lifecycle/plan_cloud_G07_3.log` and `agent-task/m-iop-hot-path-one-shot-execution/19+17,18_observation_lifecycle/code_review_cloud_G07_3.log` contain the reviewed post-write ownership plan, implementation evidence, fresh failing outputs, and the current FAIL verdict.
- Fresh reviewer runs fail deterministically only at `TestHotPathObservationLifecycle_DirectCallerWriteFailure/openai/tool` with `direct write failure did not emit a dispatch request id: []`.
- A temporary one-line correction of the nested JSON made the focused race command pass (`ok iop/apps/edge/internal/openai 3.345s`); the correction was reverted after the probe so this follow-up starts from the reviewed checkout.
- The directory predecessors remain satisfied by `agent-task/archive/2026/08/m-iop-hot-path-one-shot-execution/17+14,15,16_endpoint_error_matrix/complete.log` and `agent-task/archive/2026/08/m-iop-hot-path-one-shot-execution/18+17_observation_schema/complete.log`. Roadmap contribution remains `route-observability` under SDD S15.

## Analysis

### Files Read

- `agent-roadmap/phase/knowledge-tool-optimization-extension/milestones/iop-hot-path-one-shot-execution.md`
- `agent-roadmap/sdd/knowledge-tool-optimization-extension/iop-hot-path-one-shot-execution/SDD.md`
- `agent-spec/runtime/stream-evidence-gate.md`
- `agent-spec/input/openai-compatible-surface.md`
- `agent-contract/outer/openai-compatible-api.md`
- `agent-contract/outer/anthropic-compatible-api.md`
- `apps/edge/internal/openai/hot_path_direct.go`
- `apps/edge/internal/openai/hot_path_light.go`
- `apps/edge/internal/openai/hot_path_observation_test.go`
- `agent-test/local/rules.md`
- `agent-test/local/edge-smoke.md`

### SDD Criteria

- The approved and unlocked SDD maps this task to S15 through `milestone-task=route-observability`.
- S15 requires joined raw-free lifecycle evidence for direct, Light, and failure requests. The OpenAI direct-tool row must therefore enter Hot Path dispatch and prove exactly one post-write `caller_cancel` terminal rather than pass through an unrelated early parse error.
- No production behavior, public API, schema, or contract change is required.

### Verification Context

- The submitted focused race command fails at `hot_path_observation_test.go:2298`; the recorder is empty because the provider response is invalid before dispatch.
- The targeted lifecycle and common race commands fail at the same row. `gofmt -d` and `git diff --check` pass without output.
- A temporary replacement of `"arguments":"{\\"path\\":\\"README.md\\"}"` with `"arguments":"{\"path\":\"README.md\"}"` made the complete focused matrix pass under `-race`. This is a deterministic in-process oracle and requires no external service, credential, device, or network.
- The worktree contains unrelated changes. Modify only the exact files claimed below, and do not run `iop-agent`.

### Test Coverage Gap

- The OpenAI direct-tool table row currently double-escapes the nested JSON inside a raw string. It fails before the test can observe dispatch, the terminal trace, or the terminal metric deltas.
- The Anthropic tool row, both final rows, and every Light length/output-budget row already exercise the intended branches.

### Symbol References

- No symbol rename, removal, export, or production call-site change is planned.
- The only code edit is the OpenAI `tool` fixture body in `TestHotPathObservationLifecycle_DirectCallerWriteFailure` at `apps/edge/internal/openai/hot_path_observation_test.go:2263`.

### Split Judgment

- Do not split. One fixture literal and its five required verification commands form a minimal indivisible correction packet.

### Scope Rationale

- Include only the malformed OpenAI direct-tool provider fixture, preservation of the exact trace/metric assertions, and fresh capture of every required command.
- Exclude production terminal logic, endpoint encoding, observation schemas, metric definitions, cleanup/orphan flows, external provider smoke, and unrelated milestone tasks.

### Final Routing

- `evaluation_mode=isolated-reassessment`; build and review each have `scope_closed=true`, `context_closed=true`, `verification_closed=true`, `evidence_trusted=true`, `ownership_closed=true`, and `decision_closed=true`; no capability gap exists.
- Finalizer: `finalize-task-policy.sh pair`.
- Build scores `0/0/0/0/1` = G01. `large_indivisible_context=false`; matched positive risks are `structured_interpretation` and `variant_product` (2); `review_rework_count=3`; `evidence_integrity_failure=true`.
- Finalizer output: build `recovery-boundary` -> `PLAN-cloud-G01.md`; review scores `0/0/0/0/1` = G01 and `official-review` -> `CODE_REVIEW-cloud-G01.md` with Codex `gpt-5.6-sol` xhigh.

## Implementation Checklist

- [ ] [REVIEW_REVIEW_REVIEW_API-1] Correct the OpenAI direct-tool provider fixture and capture non-vacuous regression evidence.
- [ ] Fill implementation-owned sections in `CODE_REVIEW-cloud-G01.md` with actual implementation notes and verification output.

### [REVIEW_REVIEW_REVIEW_API-1] Correct the OpenAI direct-tool provider fixture and capture non-vacuous regression evidence

**Problem:** The OpenAI `tool` response in `TestHotPathObservationLifecycle_DirectCallerWriteFailure` is a Go raw string, but its nested `function.arguments` JSON uses two backslashes before every quote. JSON parsing treats the first slash as escaping the second and then encounters an unescaped quote, invalidating the outer provider response. The test reaches `ResponseWriter.Write` only through an early error response and observes no Hot Path dispatch.

**Solution:** Encode the nested JSON exactly once for the outer JSON string. Change only the OpenAI tool fixture from `"arguments":"{\\"path\\":\\"README.md\\"}"` to `"arguments":"{\"path\":\"README.md\"}"`. Preserve the failing writer, exact dispatch-to-`caller_cancel` trace, and exact `caller_cancel`/`length`/`provider_error` metric-delta assertions.

Before:

```go
"arguments":"{\\"path\\":\\"README.md\\"}"
```

After:

```go
"arguments":"{\"path\":\"README.md\"}"
```

**Modified Files and Checklist:**

- [ ] Modify `apps/edge/internal/openai/hot_path_observation_test.go` only at the OpenAI direct-tool fixture literal.
- [ ] Fill actual implementation notes, deviations, decisions, and raw command output in `agent-task/m-iop-hot-path-one-shot-execution/19+17,18_observation_lifecycle/CODE_REVIEW-cloud-G01.md`.

**Test Strategy:** Run the focused matrix first to prove all OpenAI/Anthropic direct final/tool and Light provider-length/output-budget rows reach their intended branches. Then run the full targeted lifecycle and common race suites without weakening exact trace or metric assertions.

**Verification:** Every command in Final Verification must exit 0. The focused output must be a package pass, not an early-error assertion change or skipped row.

## Dependencies and Execution Order

1. Read the two exact archive evidence files above for the prior failure and temporary-probe context.
2. Correct the fixture literal without changing production code or assertions.
3. Run and capture every Final Verification command in order.
4. Complete the implementation-owned sections in `CODE_REVIEW-cloud-G01.md` and leave both active `.md` files for official review.

## Modified Files Summary

| File | Item |
|---|---|
| `apps/edge/internal/openai/hot_path_observation_test.go` | REVIEW_REVIEW_REVIEW_API-1 |
| `agent-task/m-iop-hot-path-one-shot-execution/19+17,18_observation_lifecycle/CODE_REVIEW-cloud-G01.md` | REVIEW_REVIEW_REVIEW_API-1 |

## Final Verification

```bash
go test -race -count=1 ./apps/edge/internal/openai -run '^TestHotPathObservationLifecycle_(DirectCallerWriteFailure|LightLengthCallerWriteFailure)$'
go test -race -count=1 ./apps/edge/internal/openai -run 'TestHotPath(ObservationLifecycle|ObservationRejectsRawValues|MetricLabels|ObserverFailureIsolation|EndpointTerminalMatrix|Cleanup)'
go test -race -count=1 ./packages/go/streamgate ./packages/go/config ./apps/edge/internal/openai ./apps/edge/internal/service
gofmt -d apps/edge/internal/openai/hot_path_direct.go apps/edge/internal/openai/hot_path_light.go apps/edge/internal/openai/hot_path_observation_test.go
git diff --check
```

Expected: every command exits 0; all Go tests are fresh and race-clean; the OpenAI direct-tool row emits dispatch followed by exactly one `caller_cancel` terminal; all direct and Light rows retain exact terminal metric deltas; `gofmt -d` and `git diff --check` print no output. Cached test output is not acceptable because every Go command uses `-count=1`. The commands must not invoke `iop-agent`.

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