<!-- task=m-iop-hot-path-one-shot-execution/05+02,04_request_coordinator plan=1 tag=API milestone-task=request-identity -->

# Edge-Local Logical Request Coordinator

## For the Implementing Agent

Start only after predecessors 02 and 04 have `complete.log`. Implement, run every command, and fill `CODE_REVIEW-cloud-G08.md` with actual evidence. Keep active files for official review; finalization is review-agent-only.

## Background

Hot Path needs an Edge-local owner that correlates repeated full-history calls while preventing transcript/tool-schema mutation, cross-principal resume, duplicate frontier consumption, and concurrent stage execution.

## Dependencies and Execution Order

- Required predecessors: `02+01_preset_generation` and `04+02,03_preset_model_authorization`.

## Analysis

### Files Read

- `agent-roadmap/sdd/knowledge-tool-optimization-extension/iop-hot-path-one-shot-execution/SDD.md`
- `apps/edge/internal/openai/server.go`
- `apps/edge/internal/openai/chat_decode.go`
- `apps/edge/internal/openai/chat_types.go`
- `apps/edge/internal/openai/anthropic_types.go`
- `apps/edge/internal/openai/dispatch_context.go`
- `apps/edge/internal/openai/principal.go`
- `agent-spec/runtime/stream-evidence-gate.md`

### SDD Criteria

SDD scenario S05 requires immutable lineage/toolset/principal ownership, opaque request/call/stage ids, one unconsumed frontier, duplicate/missing-state rejection, and concurrency race safety.

### Verification Context

Injected id/time sources and deterministic histories make local fresh/race tests sufficient; no external agents are needed. Confidence: high.

### Test Coverage Gaps

Existing ingress snapshots are request-local and do not span calls or prove exactly-once concurrent frontier consumption.

### Symbol References

`Server` gains an Edge-local coordinator owner; endpoint handler integration is reserved for child 06.

### Split Judgment

This is the first refined child of the former request-identity pair. The bounded store, lineage fence, and concurrency contract are independently testable before either HTTP endpoint joins it.

### Scope Rationale

Exclude handler integration, mode transitions, workspace tools, artifact binding, direct/light stages, cleanup, durable storage, and cross-Edge recovery.

### Final Routing

`evaluation_mode=isolated-reassessment`; finalizer pair. Build closures are true; scores `(1,2,1,1,2)` yield G07/local-fit base, matched risks `temporal_state,concurrent_consistency,structured_interpretation,variant_product` (4) trigger `risk-boundary`, so build is cloud `PLAN-cloud-G07.md`. Review scores `(1,2,1,2,2)` yield official cloud G08 in `CODE_REVIEW-cloud-G08.md`. No large context/rework/evidence failure/capability gap.

## Implementation Checklist

- [ ] Implement opaque request/call/stage identity, owner affinity, immutable lineage/toolset fingerprints, and bounded state.
- [ ] Enforce one active transition and exactly-once expected-frontier consumption under races.
- [ ] Run dependency, deterministic concurrency, race, vet, and diff verification exactly as written.
- [ ] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual notes and output.

### [API-1] Build the bounded logical-request store and lineage fence

#### Problem

`Server` has config/runtime locks but no cross-call state. Hot Path requires one active stage, immutable prefix/transcript/toolset, a single unconsumed frontier, and terminal exactly-once behavior.

#### Solution

Add a bounded store keyed by a cryptographically random, path-safe id with injected id/time sources. Canonicalize Chat and Messages histories into endpoint-tagged hashes, pin principal/preset generation/toolset fingerprints, map public/provider tool ids, and lock each request so only one active resume consumes the exact expected set.

#### Modified Files and Checklist

- [ ] `apps/edge/internal/openai/request_coordinator.go` — identities, state enum, bounded store, collision/replay/concurrency rules.
- [ ] `apps/edge/internal/openai/request_lineage.go` — canonical Chat/Messages transcript and toolset fingerprints.
- [ ] `apps/edge/internal/openai/request_coordinator_test.go` — owner, lineage, expected-set, id collision, and exactly-once race matrix.

#### Test Strategy

Write `TestLogicalRequestContinuationMatrix`, `TestLogicalRequestConcurrentFrontierExactlyOnce`, and `TestLogicalRequestIDCollisionRegenerates`. Unknown, duplicate, missing, cross-owner, and mutated histories must never advance state.

#### Verification

Run `go test -race -count=1 ./apps/edge/internal/openai -run 'TestLogicalRequest'`; expect PASS.

## Modified Files Summary

| File | Items |
|------|-------|
| `apps/edge/internal/openai/request_coordinator.go` | API-1 |
| `apps/edge/internal/openai/request_lineage.go` | API-1 |
| `apps/edge/internal/openai/request_coordinator_test.go` | API-1 |
| `agent-task/m-iop-hot-path-one-shot-execution/05+02,04_request_coordinator/CODE_REVIEW-cloud-G08.md` | API-1 |

## Final Verification

```bash
test -f agent-task/m-iop-hot-path-one-shot-execution/02+01_preset_generation/complete.log
test -f agent-task/m-iop-hot-path-one-shot-execution/04+02,03_preset_model_authorization/complete.log
go test -race -count=1 ./apps/edge/internal/openai -run 'TestLogicalRequest'
go test -race -count=1 ./packages/go/streamgate ./apps/edge/internal/openai ./apps/edge/internal/service
go vet ./apps/edge/internal/openai
git diff --check
```

Expected: all commands exit 0 and exactly one concurrent continuation advances while rejected continuations change no state.
