<!-- task=m-iop-hot-path-one-shot-execution/10+07,09_light_flow plan=1 tag=REVIEW_API milestone-task=light-flow -->

# Preserve Committed Correlations in Provider-Visible Stage Inputs

## For the Implementing Agent

Implement this follow-up, run every verification command, and fill the implementation-owned sections of `CODE_REVIEW-cloud-G05.md` with actual notes and stdout/stderr. Keep both active files in place and report ready for official review. If blocked, record only 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`; finalization belongs to code review.

## Background

The first light-flow review found that Edge validates committed selector/local correlations in `hotPathStageInput` but drops them while serializing the provider-visible stage request. Local and review providers therefore receive the immutable task and artifact paths without the predecessor success/output correlations required by SDD S08. This follow-up closes only that input-contract and regression-evidence gap.

## Archive Evidence Snapshot

- Current pair after review finalization: `plan_cloud_G10_0.log` and `code_review_cloud_G10_0.log`; verdict `FAIL`, `review_rework_count=1`, `evidence_integrity_failure=false`.
- Required finding: `hotPathStageInput.prompt` and `submitHotPathStage` omit `SelectorCommit`/`LocalCommit` from normalized and tunnel provider-visible inputs even though the structs validate those fields.
- Affected files: `apps/edge/internal/openai/hot_path_stage_input.go`, `apps/edge/internal/openai/hot_path_light_test.go`.
- Verified baseline: focused light/review race tests, common race tests, focused vet, formatting, and `git diff --check` pass; a supplemental full Edge suite also passes with a workspace-local executable `TMPDIR`.
- Predecessors remain satisfied by `agent-task/archive/2026/08/m-iop-hot-path-one-shot-execution/07+02,04,06_route_selector_direct/complete.log` and `agent-task/archive/2026/08/m-iop-hot-path-one-shot-execution/09+06,08_artifact_pair/complete.log`, both of which record PASS.

## Dependencies and Execution Order

- Index 07 is satisfied by `agent-task/archive/2026/08/m-iop-hot-path-one-shot-execution/07+02,04,06_route_selector_direct/complete.log`.
- Index 09 is satisfied by `agent-task/archive/2026/08/m-iop-hot-path-one-shot-execution/09+06,08_artifact_pair/complete.log`.
- Preserve the existing `10+07,09_light_flow` task path and implement this follow-up without reopening predecessor work.

## Analysis

### Files Read

- `agent-task/m-iop-hot-path-one-shot-execution/10+07,09_light_flow/PLAN-cloud-G10.md`
- `agent-task/m-iop-hot-path-one-shot-execution/10+07,09_light_flow/CODE_REVIEW-cloud-G10.md`
- `agent-roadmap/sdd/knowledge-tool-optimization-extension/iop-hot-path-one-shot-execution/SDD.md`
- `apps/edge/internal/openai/hot_path_stage_input.go`
- `apps/edge/internal/openai/hot_path_dispatch.go`
- `apps/edge/internal/openai/hot_path_light.go`
- `apps/edge/internal/openai/hot_path_review.go`
- `apps/edge/internal/openai/hot_path_light_test.go`
- `apps/edge/internal/openai/hot_path_review_test.go`

### SDD Criteria

The selected SDD is approved and unlocked. The preserved `milestone-task=light-flow` maps to Acceptance Scenario S08 and Evidence Map row S08: exact pair success must feed local input with immutable task, selector success correlation, and issued artifact paths; committed local success/output must then feed one fixed review stage. The implementation checklist therefore serializes only those safe correlation fields and the final verification inspects both normalized and tunnel request payloads without allowing credentials, provider targets, file contents, or prior prompts.

### Verification Context

No separate implementation handoff was supplied; the official review artifact, source, tests, SDD, and fresh local command output are the context. The repository runs Go `1.26.2 linux/arm64`. Focused light/review race tests, the common race package set, focused vet, formatting, and diff checks are reproducible from `/config/workspace/iop-s0`; fresh execution is required with `-count=1`. No external runner, credential, provider, device, or interactive verification is required because S08 assigns deterministic fake-service evidence here and S16 owns live smoke. Confidence is high because captured `ProviderPoolDispatchRequest` values expose the normalized `Run` payload and the tunnel preparation callback/body used by the provider path.

### Test Coverage Gaps

- Existing `TestHotPathStageInputIsolation` proves task/path presence and forbidden-string absence in the direct prompt builder, but does not assert the exact selector/local correlations.
- Existing scripted flow assertions prove current stage IDs and fixed model bindings, but do not inspect normalized `Run.Input` or the prepared tunnel body for predecessor correlations.
- Add exact local and review assertions for both endpoint variants, including negative assertions that local does not receive an uncommitted local correlation and neither stage receives forbidden state.

### Symbol References

None. No symbol rename or removal is planned.

### Split Judgment

Keep one compact plan: safe serialization and outbound-request regression coverage are one indivisible input-boundary fix and cannot independently PASS. The dependent subtask's indices remain valid: archived predecessor 07 and 09 completion logs satisfy both dependencies.

### Scope Rationale

Limit production changes to the centralized stage-input serializer and test changes to the existing scripted light fixture/assertions. Do not change phase transitions, route/credential revalidation, workspace call mapping, public response IDs/usage, cleanup/TTL, heavy mode, second-review behavior, endpoint ingress, external contracts, or live smoke.

### Final Routing

`evaluation_mode=isolated-reassessment`; `finalizer=finalize-task-policy.sh` pair. Build and review closures are all true. Build scores `(1,1,1,1,1)` produce G05 with base/final route `local-fit`, lane `local`, and `PLAN-local-G05.md`. Review scores `(1,1,1,1,1)` produce official cloud G05 and `CODE_REVIEW-cloud-G05.md` using Codex `gpt-5.6-sol` xhigh. `large_indivisible_context=false`; positive risks are `temporal_state`, `boundary_contract`, and `variant_product` (`loop_risk_count=3`); `review_rework_count=1`; `evidence_integrity_failure=false`; neither risk nor recovery boundary matches; no capability gap exists.

## Implementation Checklist

- [ ] Serialize safe committed selector/local correlations into provider-visible local/review stage inputs while preserving the immutable isolation boundary.
- [ ] Add exact normalized and prepared-tunnel request regressions for local/review correlations and forbidden-data absence across Chat and Messages.
- [ ] Run focused, common race, vet, format, and diff verification with fresh test execution.
- [ ] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

### [REVIEW_API-1] Preserve committed correlations at the provider boundary

#### Problem

`apps/edge/internal/openai/hot_path_stage_input.go:25` stores and validates `SelectorCommit` and `LocalCommit`, but the prompt serialization beginning at line 78 writes only the task and artifact paths. `apps/edge/internal/openai/hot_path_dispatch.go:840` uses that prompt for `Run.Prompt`, `Run.Input`, Chat tunnel bodies, and Messages tunnel bodies, so every provider path loses the predecessor correlation.

#### Solution

Add one deterministic safe correlation serializer in `hot_path_stage_input.go`. Emit the selector commit for both roles and the local commit only for review, using the immutable `hotPathStageCorrelation` fields already captured by Edge. Keep correlation values separate from credentials, provider targets, file contents, and prior prompts; all normalized and tunnel builders already consume the same prompt.

Before (`apps/edge/internal/openai/hot_path_stage_input.go:78`):

```go
var b strings.Builder
b.WriteString("User task:\n")
b.WriteString(in.ImmutableTask)
```

After:

```go
var b strings.Builder
b.WriteString("User task:\n")
b.WriteString(in.ImmutableTask)
writeStageCorrelation(&b, "selector", in.SelectorCommit)
if in.Role == "review" {
	writeStageCorrelation(&b, "local", in.LocalCommit)
}
```

#### Modified Files and Checklist

- [ ] `apps/edge/internal/openai/hot_path_stage_input.go` — serialize exact committed selector/local correlation fields into the common stage prompt.
- [ ] `apps/edge/internal/openai/hot_path_light_test.go` — inspect local/review normalized input and prepared tunnel bodies for exact correlation and isolation assertions across both endpoints.

#### Test Strategy

Extend `TestHotPathStageInputIsolation` with exact selector/local correlation assertions. Extend the scripted fixture's `assertCleanupPending` path to inspect captured local request index 2 and review request index 4: verify normalized `Run.Prompt`/`Run.Input` and a body produced through `PrepareProtocolTunnel` contain the pair-success selector stage/response; verify review also contains the committed local stage/response; verify local omits local correlation; and verify both omit credential secrets, provider targets, workspace file contents, and prior prompts. Reuse the existing OpenAI/Anthropic pass fixtures; do not add an external provider fixture.

#### Verification

```bash
go test -race -count=1 ./apps/edge/internal/openai -run 'TestHotPath(LightLocal|StageInput)'
```

Expected: PASS with fresh execution; exact correlation assertions pass for both endpoint variants and all forbidden-data assertions remain negative.

## Modified Files Summary

| File | Items |
|---|---|
| `apps/edge/internal/openai/hot_path_stage_input.go` | REVIEW_API-1 |
| `apps/edge/internal/openai/hot_path_light_test.go` | REVIEW_API-1 |
| `agent-task/m-iop-hot-path-one-shot-execution/10+07,09_light_flow/CODE_REVIEW-cloud-G05.md` | REVIEW_API-1 |

## Final Verification

```bash
go test -race -count=1 ./apps/edge/internal/openai -run 'TestHotPath(Light|Review|StageInput)'
go test -race -count=1 ./packages/go/streamgate ./packages/go/config ./apps/edge/internal/openai ./apps/edge/internal/service
go vet ./apps/edge/internal/openai
gofmt -d apps/edge/internal/openai/hot_path_stage_input.go apps/edge/internal/openai/hot_path_light_test.go
git diff --check
```

Expected: every command exits 0; test output is fresh because both Go test commands use `-count=1`; formatting and diff checks produce no output.

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