<!-- task=m-iop-hot-path-one-shot-execution/09+06,08_artifact_pair plan=1 tag=REVIEW_API milestone-task=artifact-pair -->

# Complete the Exact Plan/Review Artifact Frontier

## For the Implementing Agent

Implement every checklist item, run every verification command exactly as written, and fill the implementation-owned sections of `CODE_REVIEW-cloud-G09.md` with actual notes and stdout/stderr. Keep both active artifacts in place and report ready for review; finalization belongs only to the code-review agent. If blocked, record the exact blocker, attempted commands/output, and resume condition in 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 first implementation loop left the classified `light` branch as an HTTP 501 terminal and did not add the planned artifact frontier or tests. This follow-up must connect the already-compiled workspace binding and logical-request frontier so the caller receives only an exact prepare or exact Plan/Review pair, and only correlated successful receipts make the request locally eligible.

## Archive Evidence Snapshot

- Prior artifacts after review finalization: `agent-task/m-iop-hot-path-one-shot-execution/09+06,08_artifact_pair/plan_cloud_G08_0.log` and `agent-task/m-iop-hot-path-one-shot-execution/09+06,08_artifact_pair/code_review_cloud_G09_0.log`.
- Prior verdict: FAIL with 3 Required, 0 Suggested, and 0 Nit findings; `review_rework_count=1` and `evidence_integrity_failure=true`.
- Required findings: replace `hot_path_dispatch.go:810` HTTP 501 with a pinned-binding prepare/pair frontier; validate endpoint-native result status/body in `request_identity_ingress.go:34,110` before exactly-once frontier consumption; add the absent `artifact_pair.go`, `artifact_pair_test.go`, `TestArtifactPairFrontierMatrix`, and fresh implementation evidence.
- Affected files: `apps/edge/internal/openai/hot_path_dispatch.go`, `apps/edge/internal/openai/request_identity_ingress.go`, `apps/edge/internal/openai/server.go`, `apps/edge/internal/openai/artifact_pair.go`, and `apps/edge/internal/openai/artifact_pair_test.go`.
- Fresh review evidence: `go test -race -count=1 ./apps/edge/internal/openai -run 'Test(Workspace|ArtifactPair)'`, the shared race suite, `go vet ./apps/edge/internal/openai`, and `git diff --check` passed, but `go test ./apps/edge/internal/openai -list 'Test(Workspace|ArtifactPair)'` listed only five `TestWorkspace...` tests and no `TestArtifactPair...` test. The planned production and test files were absent.
- Roadmap carryover: approved SDD scenario S06 and Evidence Map row `artifact-pair` remain the sole scope; local/review model execution belongs to later milestone children.

## Dependencies and Execution Order

- Predecessor 06 is satisfied by `agent-task/archive/2026/08/m-iop-hot-path-one-shot-execution/06+04,05_request_identity_ingress/complete.log`.
- Predecessor 08 is satisfied by `agent-task/archive/2026/08/m-iop-hot-path-one-shot-execution/08+02,04,06_workspace_binding/complete.log`.
- Implement REVIEW_API-1 before REVIEW_API-2 so the matrix exercises the integrated frontier rather than a test-only model.

## Analysis

### Files Read

- `agent-roadmap/phase/knowledge-tool-optimization-extension/PHASE.md`
- `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/input/openai-compatible-surface.md`
- `agent-contract/outer/openai-compatible-api.md`
- `agent-contract/outer/anthropic-compatible-api.md`
- `agent-test/local/rules.md`
- `apps/edge/internal/openai/hot_path_dispatch.go`
- `apps/edge/internal/openai/hot_path_direct.go`
- `apps/edge/internal/openai/hot_path_selector.go`
- `apps/edge/internal/openai/request_identity_ingress.go`
- `apps/edge/internal/openai/request_coordinator.go`
- `apps/edge/internal/openai/server.go`
- `apps/edge/internal/openai/workspace_tool_binding.go`
- `apps/edge/internal/openai/workspace_tool_codec.go`
- `apps/edge/internal/openai/hot_path_direct_test.go`
- `apps/edge/internal/openai/hot_path_selector_test.go`
- `apps/edge/internal/openai/request_identity_handler_test.go`
- `apps/edge/internal/openai/workspace_tool_binding_test.go`

### SDD Criteria

- SDD: `agent-roadmap/sdd/knowledge-tool-optimization-extension/iop-hot-path-one-shot-execution/SDD.md`, approved.
- First-line milestone contribution: `milestone-task=artifact-pair`.
- Target: S06 and Evidence Map row `artifact-pair`.
- S06 requires exact `.iop/job/<request_id>/plan.md` and `review.md` mapping, optional prepare, one exact two-write frontier, reversed result-order acceptance, and fail-closed missing/extra/duplicate/opaque/failed/path/replay handling before local eligibility. REVIEW_API-1 owns this invariant; REVIEW_API-2 makes every S06 branch explicit in final verification.

### Verification Context

- Handoff: none supplied.
- Verification sources read: `agent-test/local/rules.md`, the approved SDD, the two API contracts, the matching implementation spec, and the source/test files listed above.
- Fresh commands already applied during review: Go 1.26.2 preflight, predecessor-log checks, focused and shared `-race -count=1` tests, `go vet`, `git diff --check`, and test listing. All executable baseline commands passed; the listing proved the artifact matrix was absent.
- Preconditions: both decoded predecessors have archived PASS `complete.log` files at the exact paths above. The checkout is dirty with sibling milestone work, so implementation must preserve unrelated changes and edit only claimed files.
- Constraints: no filesystem workspace tool or external service may be executed; endpoint-native fake continuations must provide deterministic evidence. Fresh test output is required and Go cache output is not acceptable.
- Gap: no target production file, target test file, or artifact frontier integration exists.
- Confidence: high for the failure diagnosis and required boundary; repository-native unit/race evidence is sufficient for this child.

### Test Coverage Gaps

- Existing workspace tests cover binding selection, encoding, containment, and individual receipt matching, but not the cross-request prepare/pair state machine.
- Existing request identity tests cover lineage and ID sets, but accept result IDs without workspace result status/body correlation.
- Existing direct tests cover endpoint rendering, but the `light` branch terminates at 501 and has no Chat/Messages artifact response coverage.

### Symbol References

- No symbol is renamed or removed.
- New frontier construction/consumption call sites are limited to `Server` initialization, `dispatchPresetTurn`, `joinPresetChatIngress`, and `joinPresetAnthropicIngress`.

### Split Judgment

The indivisible invariant is one pinned workspace binding plus one logical-request frontier across prepare emission, same-selector resume, pair emission, and exactly-once successful receipt consumption. Predecessor 06 is satisfied by archived `06+04,05_request_identity_ingress/complete.log`; predecessor 08 is satisfied by archived `08+02,04,06_workspace_binding/complete.log`. No dependency is missing or ambiguous.

### Scope Rationale

Exclude binding compilation rules, workspace filesystem execution, local/review model dispatch, cleanup, manifest persistence, revision gates, contracts/specs, and sibling task files because their milestone children own those behaviors or their current definitions already match S06. The artifact frontier may expose local eligibility but must not start the later local worker.

### Final Routing

`evaluation_mode=isolated-reassessment`; finalizer `finalize-task-policy.sh pair`. Build closure checks for algorithm, interface, schema, control flow, and test contract are all true; build scores `(2,2,2,2,1)` route by `grade-boundary` to cloud G09 at `PLAN-cloud-G09.md`. Review closure checks are all true; review scores `(2,2,2,2,1)` route by `official-review` to cloud G09 at `CODE_REVIEW-cloud-G09.md`. `large_indivisible_context=false`. Positive loop risks are `temporal_state`, `concurrent_consistency`, `boundary_contract`, `structured_interpretation`, and `variant_product` (5). Recovery signals are `review_rework_count=1` and `evidence_integrity_failure=true`; no capability gap exists.

## Implementation Checklist

- [ ] Implement REVIEW_API-1 as one pinned, bounded, exactly-once prepare/pair frontier for Chat and Messages.
- [ ] Implement REVIEW_API-2 with the complete deterministic S06 matrix and run every focused/common verification command.
- [ ] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

### [REVIEW_API-1] Wire the pinned prepare/pair frontier

#### Problem

`apps/edge/internal/openai/hot_path_dispatch.go:810-818` terminates every valid `light` decision:

```go
// apps/edge/internal/openai/hot_path_dispatch.go:810-818
case modeLight:
	s.terminalPresetRequest(requestID, ownerEdgeID)
	errMsg := "mode light execution is unhandled in direct selector task"
	if protocol == "anthropic" {
		writeAnthropicError(w, http.StatusNotImplemented, "not_implemented_error", errMsg)
	} else {
		writeError(w, http.StatusNotImplemented, "not_implemented_error", errMsg)
	}
	return fmt.Errorf("%s", errMsg)
```

`apps/edge/internal/openai/request_identity_ingress.go:34-51` and `:110-127` then treat any matching result-ID set as a generic continuation, clear the frontier, and allocate a new stage without workspace receipt validation:

```go
// apps/edge/internal/openai/request_identity_ingress.go:34-51
snap, err := s.requestCoordinator.consumeContinuationByLineage(ownerEdgeID, principalRef, contLineage)
if err != nil {
	return fmt.Errorf("preset continuation rejected: %w", err)
}
stageID, err := s.requestCoordinator.newStageID()
// ...
if _, err := s.requestCoordinator.activateStage(snap.ID, ownerEdgeID, stageID); err != nil {
	return err
}
```

#### Solution

Add a bounded mutex-protected artifact frontier store to `Server`, initialized beside `requestCoordinator`. At initial preset ingress, decode the caller's `tools`, compile and pin one immutable `workspaceBinding` for the logical request, and retain the original selector stage ID. On `modeLight`, accept only the classifier's exact prepare or exact Plan/Review output, encode each call through the pinned binding, store the sealed payloads, register their public/provider IDs and issued-call hash with `awaitToolResults`, and render the mapped calls with the existing endpoint-native direct response writers. Never execute a workspace operation.

For continuations, parse Chat `tool` messages and Messages `tool_result` blocks into `workspaceResult` values before generic consumption. Under one artifact-frontier critical section, require an exact ID set and require every `matchResultReceipt` to succeed; only then call `consumeContinuationByLineage` and commit the phase transition. A prepare success reactivates the retained selector stage ID; a pair success marks local eligibility exactly once. Missing, extra, duplicate, opaque, failed, mixed, wrong-path, alternate-request, and replayed results fail before state advancement or downstream dispatch.

Use these imports for the new production file; add no package without a concrete use:

```go
import (
	"encoding/json"
	"fmt"
	"strings"
	"sync"
)
```

Replace the terminal branch with the integrated turn:

```go
// apps/edge/internal/openai/hot_path_dispatch.go:810-818 (after)
case modeLight:
	turn := &hotPathTurn{
		RequestID: requestID, StageID: stageID, CallID: callID, OwnerEdgeID: ownerEdgeID,
		PrincipalRef: runMeta[principalMetaRef], Preset: preset, Dispatch: dispatch,
		Protocol: protocol, Stream: stream, PublicModelID: dispatch.ExternalModelID,
		Writer: w, Request: r,
	}
	return s.runArtifactPairTurn(turn, output)
```

The ingress hook must validate an artifact frontier before the generic path and leave direct/general tool continuations unchanged:

```go
// apps/edge/internal/openai/request_identity_ingress.go:34 (after; same shape for Messages at line 110)
if snap, disposition, matched, err := s.artifactFrontiers.consumeChat(
	ownerEdgeID, principalRef, rawBody, contLineage, s.requestCoordinator,
); matched {
	if err != nil {
		return fmt.Errorf("artifact continuation rejected: %w", err)
	}
	return s.applyArtifactDisposition(snap, disposition, runMeta)
}
snap, err := s.requestCoordinator.consumeContinuationByLineage(ownerEdgeID, principalRef, contLineage)
```

#### Modified Files and Checklist

- [ ] `apps/edge/internal/openai/artifact_pair.go` — bounded pinned state, endpoint result decoding, exact emission, receipt validation, same-stage resume, local eligibility, and replay rejection.
- [ ] `apps/edge/internal/openai/hot_path_dispatch.go` — replace the 501 `light` terminal with artifact turn dispatch.
- [ ] `apps/edge/internal/openai/request_identity_ingress.go` — pin initial bindings and route artifact continuations through receipt validation before generic consumption.
- [ ] `apps/edge/internal/openai/server.go` — own and initialize the artifact frontier store.

#### Test Strategy

Production behavior is covered by REVIEW_API-2. Direct/general continuation tests must remain unchanged and pass to prove the artifact hook is selective.

#### Verification

Run `go test -race -count=1 ./apps/edge/internal/openai -run 'Test(Workspace|ArtifactPair)'`; expect exact artifact tests plus existing workspace tests to pass without a race or filesystem execution.

### [REVIEW_API-2] Add the S06 endpoint and rejection matrix

#### Problem

`apps/edge/internal/openai/artifact_pair_test.go` does not exist, and the focused pattern currently lists only `TestWorkspace...` tests. There is no evidence for Chat/Messages prepare, reversed pair success, malformed frontier rejection, or replay safety.

#### Solution

Add table-driven fake-frontier tests around the integrated server methods. The fixture must construct the same workspace binding alternatives and endpoint-native tool shapes used by existing binding tests, generate a stable logical request ID, issue exact reserved paths, capture endpoint responses, and feed continuations without invoking a filesystem command or external service.

```go
func TestArtifactPairFrontierMatrix(t *testing.T) {
	for _, endpoint := range []string{"openai", "anthropic"} {
		// Run parent-capable pair, prepare-then-pair, reversed success,
		// and every S06 rejection case against the same frontier contract.
	}
}
```

Assert exact one-call prepare and two-call pair payloads, public/provider ID correlation, original selector-stage reuse after prepare, no local eligibility before both pair successes, eligibility exactly once afterward, and no state change/provider/filesystem dispatch for missing, extra, duplicate, opaque, failed, mixed, traversal, alternate-request, or replayed results. Include concurrent duplicate consumption under `-race` so only one goroutine can advance.

#### Modified Files and Checklist

- [ ] `apps/edge/internal/openai/artifact_pair_test.go` — `TestArtifactPairFrontierMatrix` with Chat/Messages success, ordering, rejection, and concurrent replay cases.

#### Test Strategy

Write the regression test; skipping is not allowed because the first loop omitted all target evidence. Reuse in-package binding and logical-request helpers, `httptest.ResponseRecorder`, and pure fake continuation JSON. Do not run generated containment guards or caller workspace tools.

#### Verification

Run `go test ./apps/edge/internal/openai -list 'TestArtifactPair' | rg --fixed-strings 'TestArtifactPairFrontierMatrix'` and the focused race command; expect the named test to be listed once and all subtests to pass.

## Modified Files Summary

| File | Items |
|------|-------|
| `apps/edge/internal/openai/artifact_pair.go` | REVIEW_API-1 |
| `apps/edge/internal/openai/hot_path_dispatch.go` | REVIEW_API-1 |
| `apps/edge/internal/openai/request_identity_ingress.go` | REVIEW_API-1 |
| `apps/edge/internal/openai/server.go` | REVIEW_API-1 |
| `apps/edge/internal/openai/artifact_pair_test.go` | REVIEW_API-2 |
| `agent-task/m-iop-hot-path-one-shot-execution/09+06,08_artifact_pair/CODE_REVIEW-cloud-G09.md` | REVIEW_API-1, REVIEW_API-2 |

## Final Verification

```bash
test -f agent-task/m-iop-hot-path-one-shot-execution/06+04,05_request_identity_ingress/complete.log || test -f agent-task/archive/2026/08/m-iop-hot-path-one-shot-execution/06+04,05_request_identity_ingress/complete.log
test -f agent-task/m-iop-hot-path-one-shot-execution/08+02,04,06_workspace_binding/complete.log || test -f agent-task/archive/2026/08/m-iop-hot-path-one-shot-execution/08+02,04,06_workspace_binding/complete.log
go test ./apps/edge/internal/openai -list 'TestArtifactPair' | rg --fixed-strings 'TestArtifactPairFrontierMatrix'
go test -race -count=1 ./apps/edge/internal/openai -run 'Test(Workspace|ArtifactPair)'
go test -race -count=1 ./packages/go/streamgate ./apps/edge/internal/openai ./apps/edge/internal/service
go vet ./apps/edge/internal/openai
gofmt -d apps/edge/internal/openai/artifact_pair.go apps/edge/internal/openai/artifact_pair_test.go apps/edge/internal/openai/hot_path_dispatch.go apps/edge/internal/openai/request_identity_ingress.go apps/edge/internal/openai/server.go
git diff --check
```

Expected: every command exits 0 with fresh uncached race results; the named matrix is present, both endpoint variants accept reversed exact success once, every malformed/replayed frontier fails closed, and no workspace tool is executed. Full local/review execution remains deferred to its mapped milestone children.

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