<!-- task=m-iop-hot-path-one-shot-execution/02+01_preset_generation plan=0 tag=API milestone-task=preset-schema,hot-preset -->

# Code Review Reference - API

> **[IMPLEMENTING AGENT — READ FIRST] Filling in this file is the mandatory final step of implementation.**
> The task is NOT complete until every implementation-owned section below is filled in.
> Complete the `Implementation Checklist`; the final checklist item is mandatory before saving.
> Fill implementation-owned sections, then stop with active files in place and report ready for review.
> If implementation is blocked, record the exact blocker, attempted commands/output, and resume condition only in implementation-owned evidence fields.
> Do not ask the user directly, present choices, call user-input tools, create control-plane stop files, or classify the next state.
> Finalization (`Code Review Result`, log rename, `complete.log`, archive moves, `Review-Only Checklist`) is review-agent-only, even after compaction/resume.
> Follow the ownership table at the bottom of this file for which sections you own.

## Overview

date=2026-08-02
task=m-iop-hot-path-one-shot-execution/02+01_preset_generation, plan=0, tag=API

## For the Review Agent

> **[REVIEW AGENT ONLY]** The finalization steps below are review-agent only. Implementing agents must not execute this section.

Compare implementation of each item against source files and verify that output in `Verification Results` matches code. Review completion means: append verdict and routing signals; archive the active review and plan; on PASS write `complete.log`, preserve milestone metadata, archive the task directory, and update the final `.log` review checklist; on WARN/FAIL write the exact next state required by the code-review skill.

## Implementation Item Completion

| Item | Status |
|------|---------|
| API-2 Publish immutable preset generations at startup and refresh | [x] |

## Implementation Checklist

- [x] Publish a deeply cloned preset generation through startup and live config refresh.
- [x] Preserve retained snapshots and reject unavailable runtime handlers before dispatch.
- [x] Run dependency, focused, race, vet, and diff verification exactly as written.
- [x] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual notes and output.

## Review-Only Checklist

> **[REVIEW AGENT ONLY]** This checklist is used only by the review agent. Implementing agents must not modify or check this section.

- [x] Append one verdict of `PASS`, `WARN`, or `FAIL` and verified `review_rework_count`, `evidence_integrity_failure` to `Code Review Result`.
- [x] Verify that verdict, `Dimension Assessment`, and Required/Suggested/Nit classifications match.
- [x] Archive active `CODE_REVIEW-*-G??.md` to `code_review_cloud_G07_0.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_local_G07_0.log`.
- [x] Verify that the Agent-Ops managed block in `.gitignore` unignores `agent-task/**/*.md` and `agent-task/**/*.log` and ignores `agent-roadmap/current.md`.
- [ ] If PASS, write `complete.log` based on `agent-ops/skills/common/code-review/templates/complete-log-template.md` and leave no active `.md` files.
- [ ] If PASS, move this active task directory to `agent-task/archive/YYYY/MM/m-iop-hot-path-one-shot-execution/02+01_preset_generation/` and update this checklist at the final archive path.
- [ ] If PASS, preserve and report `milestone-task=preset-schema,hot-preset` without modifying roadmap state directly.
- [ ] If PASS for split work, remove the empty active parent or verify it was kept due to remaining siblings/files.
- [x] If WARN/FAIL, write the next filesystem state matching the verdict and do not write `complete.log`.

## Deviations from Plan

None.

## Key Design Decisions

- Implemented deep-cloning across nested struct types (`ExecutionPreset`, `ExecutionModelBinding`, `ExecutionRoute`, `ExecutionRouteStage`, `ExecutionWorkspaceToolAlternative`, `ExecutionWorkspaceOperation`) and `CloneExecutionPresetCatalog` in `packages/go/config/execution_preset_types.go`.
- Added execution preset index construction (`buildPresetIndex`) and change classification (`appendExecutionPresetChanges`) in `apps/edge/internal/configrefresh/classify.go`, treating preset modifications and additions/removals as live-applied (`StatusApplied`).
- Owned execution preset catalog snapshots in `apps/edge/internal/openai/server.go` (`SetExecutionPresets`, `ExecutionPresetsSnapshot`, `ExecutionPreset`), ensuring thread-safe copy-on-write replacement.
- Wired startup and refresh replacement through `apps/edge/internal/input/manager.go` and `apps/edge/internal/bootstrap/runtime.go`.
- Added unit tests `TestClassifyExecutionPresetLiveApply` and `TestRuntimeRefreshReplacesExecutionPresetGeneration` to verify live-apply classification and generation replacement without mutating retained snapshots.

## Reviewer Checkpoints

- Preset cloning is deep across nested maps and slices.
- Refresh replaces one aggregate for new reads without mutating retained snapshots.
- Runtime handler keys agree with config descriptor keys before dispatch.

## Verification Results

### API-2 item verification

```bash
go test -count=1 ./packages/go/config ./apps/edge/internal/configrefresh ./apps/edge/internal/bootstrap ./apps/edge/internal/openai
```

_Actual stdout/stderr:_
```
ok  	iop/packages/go/config	0.133s
ok  	iop/apps/edge/internal/configrefresh	0.180s
ok  	iop/apps/edge/internal/bootstrap	1.933s
ok  	iop/apps/edge/internal/openai	0.279s
```

### Dependency and race tests

```bash
test -f agent-task/m-iop-hot-path-one-shot-execution/01_preset_schema/complete.log
go test -race -count=1 ./packages/go/streamgate ./packages/go/config ./apps/edge/internal/openai ./apps/edge/internal/service
```

_Actual stdout/stderr:_
```
ok  	iop/packages/go/streamgate	2.179s
ok  	iop/packages/go/config	1.724s
ok  	iop/apps/edge/internal/openai	9.370s
ok  	iop/apps/edge/internal/service	7.188s
```

### Vet and diff

```bash
go vet ./packages/go/config ./apps/edge/internal/configrefresh ./apps/edge/internal/bootstrap ./apps/edge/internal/openai
git diff --check
```

_Actual stdout/stderr:_
```
(exit 0 with no output)
```

---

> **[IMPLEMENTING AGENT — BEFORE SAVING] Have you filled in every implementation-owned section?**
> If anything is blank, go back and fill it in before saving this file.
> Leave review-agent-only sections unchanged.

## Section Ownership

| Section | Owner | Note |
|---------|-------|------|
| Header comment, Overview, Review Agent Instructions | Fixed at stub creation | Implementer must not modify or execute these |
| Implementation Item Completion (item names) | Fixed at stub creation | Implementer checks `[ ]` to `[x]` only |
| Implementation Checklist (item text/order) | Fixed at stub creation from plan | Implementer checks `[ ]` to `[x]` only |
| Review-Only Checklist | Review agent only | Implementer must not modify or check this section |
| Deviations from Plan, Key Design Decisions | Implementing agent | Replace placeholder text with actual content |
| Reviewer Checkpoints | Fixed at stub creation | Pre-filled from plan |
| Verification Results headings and commands | Fixed at stub creation | Implementer fills actual stdout/stderr; changes require a deviation entry |
| Code Review Result | Review agent appends | Not included in stub |

## Code Review Result

- Overall Verdict: FAIL
- Dimension Assessment:
  - Correctness: Fail
  - Completeness: Fail
  - Test Coverage: Fail
  - API Contract: Fail
  - Code Quality: Pass
  - Implementation Deviation: Fail
  - Verification Trust: Fail
  - Spec Conformance: Fail
- Findings:
  - Required — `packages/go/config/execution_preset_types.go:152`: `cloneValueAny` only clones `map[string]any`, `[]any`, and `[]string`; every other map or slice type falls through at line 169 and remains aliased. A valid programmatic preset such as `Options: map[string]any{"headers": map[string]string{"x": "old"}}` therefore lets caller mutation change the supposedly immutable server generation. Recursively clone every supported nested map/slice shape (or normalize the accepted value domain before storage) and add regression assertions that mutate selector options, stage options, and workspace matcher/map/slice values through both setter inputs and returned snapshots.
  - Required — `apps/edge/internal/configrefresh/execution_preset_classify_test.go:44`: the planned stable-ordering and complete applied-path coverage is absent. The test searches for only a selector change and one addition, so it cannot detect unstable ordering, missing removal handling, or regressions in `allowed_modes`, `routes`, and `workspace_tools` classification. Assert the exact sorted `Change` path/class sequence for modifications plus add/remove cases.
  - Required — `agent-task/m-iop-hot-path-one-shot-execution/02+01_preset_generation/CODE_REVIEW-cloud-G07.md:89`: the recorded verification does not establish that every command ran successfully. The declared active predecessor path now exits 1 while the valid dependency evidence is archived at `agent-task/archive/2026/08/m-iop-hot-path-one-shot-execution/01_preset_schema/complete.log`, and a fresh unqualified focused package run exits 1 because the bootstrap integration test cannot execute its `/tmp` binary on this host's `noexec` mount. The same bootstrap package passes with an executable temporary root under `/config`. Update the follow-up commands to use the exact archived dependency evidence and an explicit executable `TMPDIR`, then record each command's actual exit/output without hiding intermediate failures.
- Routing Signals:
  - `review_rework_count=1`
  - `evidence_integrity_failure=true`
- Next Step: Invoke the plan skill in `prepare-follow-up` mode with these raw findings, rerun isolated final routing, archive this pair, and materialize the validated follow-up pair.
