<!-- task=m-iop-owned-single-request-agent-execution/01_preset_config plan=1 tag=API milestone-task=preset-binding -->

# Fixed Single-request Preset Config

## For the Implementing Agent

Implement this plan exactly within the listed write boundary. Run every verification command, fill all implementation-owned sections of `CODE_REVIEW-cloud-G07.md` with actual notes and stdout/stderr, keep both active files in place, and report ready for review. Finalization belongs only to the code-review skill. 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`.

## Archive Evidence Snapshot

- Superseded pair: `plan_local_G07_0.log`, `code_review_cloud_G07_0.log`.
- The superseded pair contained no implementation evidence or review verdict; implementation has not started.
- Self-review correction: use the real domain-rule paths and add the package-profile vet check. The packet's schema/refresh ownership remains valid.

## Background

The execution-preset schema has generic `direct` and caller-continuation `light` forms but no operator-owned marker for the approved fixed single-request path. SDD S02 requires an opaque workspace capability plus immutable request/stage limits while preserving existing preset compatibility and live-refresh generation isolation.

## Analysis

### Files Read

- `AGENTS.md`
- `agent-ops/rules/project/rules.md`
- `agent-ops/rules/common/rules-roadmap.md`
- `agent-ops/rules/common/rules-agent-spec.md`
- `agent-ops/rules/project/domain/edge/rules.md`
- `agent-ops/rules/project/domain/platform-common/rules.md`
- `agent-test/local/rules.md`
- `agent-test/local/edge-smoke.md`
- `agent-test/local/platform-common-smoke.md`
- `agent-roadmap/phase/knowledge-tool-optimization-extension/milestones/iop-owned-single-request-agent-execution.md`
- `agent-roadmap/sdd/knowledge-tool-optimization-extension/iop-owned-single-request-agent-execution/SDD.md`
- `packages/go/config/execution_preset_types.go`
- `packages/go/config/execution_preset_config_test.go`
- `apps/edge/internal/configrefresh/classify.go`
- `apps/edge/internal/configrefresh/execution_preset_classify_test.go`
- `configs/edge.yaml`
- `agent-contract/inner/edge-config-runtime-refresh.md`
- `agent-spec/runtime/provider-pool-config-refresh.md`

### SDD Criteria

- SDD: `agent-roadmap/sdd/knowledge-tool-optimization-extension/iop-owned-single-request-agent-execution/SDD.md`; status approved and implementation lock released.
- First-line Milestone task: `preset-binding`; targeted Acceptance Scenario: S02.
- Evidence Map: fixed-light decode/authorization/model-echo/workspace-snapshot evidence under `preset-binding`. This packet supplies decode, validation, cloning, refresh, and schema evidence; packet 02 supplies authorization/model echo.
- Those rows require the config boundary and refresh checks in the implementation checklist and fresh config/configrefresh commands in Final Verification.

### Verification Context

- No separate verification handoff was supplied. Repository-native fallback came from the local test rules, platform/Edge smoke profiles, existing preset tests, refresh classifier tests, and approved SDD.
- Starting HEAD is `3331e5f8d20e2137d1cd1ae5600efedb42be291e`; no implementation change existed when replanning began.
- Preconditions: none. Constraints: ordinary presets remain compatible; no external runner/provider is used. Gap: runtime authorization is packet 02 and actual Claude/provider evidence belongs to later Milestone work.
- Commands were selected from `platform-common-smoke.md` and `edge-smoke.md`: focused/package Go tests, `go vet`, full package regression, and `git diff --check`. Confidence is high for local schema and refresh behavior.

### Test Coverage Gaps

- Existing config tests do not cover a fixed single-request marker, typed limits, legacy workspace-tool exclusion, dynamic-mode rejection, or deep-clone isolation.
- Existing refresh tests do not report this policy as its own live-applied path.

### Symbol References

- No symbol is renamed or removed. `ExecutionPreset.Clone`, `CloneExecutionPresetCatalog`, and `appendExecutionPresetChanges` are the existing consumers extended by this packet.

### Split Judgment

- Stable child contract: a validated, cloned, refresh-aware typed preset independently passes config/configrefresh tests. It has no predecessor and produces the schema consumed by packet 02.

### Scope Rationale

- Exclude Edge route resolution, handlers, provider execution, Node/workspace execution, protobuf, and SSE because they do not participate in config validation/refresh.
- Keep unmarked direct/light presets compatible. `workspace_ref` remains opaque; add no endpoint, credential, Node id, raw path, dynamic selection, or silent default.

### Final Routing

- `evaluation_mode=isolated-reassessment`; finalizer `finalize-task-policy.sh` in `pair` mode.
- Build closures scope/context/verification/evidence/ownership/decision are true; scores 2/1/2/1/1 = G07; base/final route `local-fit`; lane `local`; canonical filename `PLAN-local-G07.md`.
- Build signals: `large_indivisible_context=false`; positive loop risks `boundary_contract`, `structured_interpretation`, `variant_product` (3); `review_rework_count=0`; `evidence_integrity_failure=false`; no capability gap.
- Review closures are true; scores 2/1/2/1/1 = G07; route `official-review`; lane `cloud`; canonical filename `CODE_REVIEW-cloud-G07.md`.

## Implementation Checklist

- [ ] Add and validate the optional fixed single-request preset policy, deep-clone it, and prove valid, boundary, invalid, legacy, and clone-isolation cases.
- [ ] Classify policy changes as live-applied, add a secret-free commented config example, and synchronize the config contract and current implementation spec.
- [ ] Run targeted, package, vet, full profile regression, and `git diff --check` verification.
- [ ] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

## Implementation Plan

### [API-1] Add the typed fixed single-request policy

**Problem**

- `packages/go/config/execution_preset_types.go:13` defines no marker that distinguishes operator-owned single-request execution from generic caller-continuation light presets.
- `ExecutionPreset.Clone` at line 61 does not have a policy pointer/nested map to clone, and `validatePreset` at line 281 cannot enforce the approved fixed shape.

**Solution**

Before (`packages/go/config/execution_preset_types.go:15`):

```go
ID string `mapstructure:"id" yaml:"id"`
// Selector is the fused selector/planner model binding and options.
Selector ExecutionModelBinding `mapstructure:"selector" yaml:"selector"`
// AllowedModes is the set of registered mode descriptors this preset permits.
AllowedModes []string `mapstructure:"allowed_modes" yaml:"allowed_modes"`
// Routes maps each allowed mode descriptor to its ordered downstream stages.
Routes map[string]ExecutionRoute `mapstructure:"routes" yaml:"routes"`
```

After:

```go
// Existing fields stay source-compatible.
SingleRequest *ExecutionSingleRequestPolicy `mapstructure:"single_request" yaml:"single_request,omitempty"`
```

Add typed workspace/limit structs and server-owned absolute caps: wall clock 30 minutes, each stage timeout 10 minutes, 64 tool iterations per stage, and 16 MiB output per stage. Require every configured value in `1..cap`, each stage timeout not to exceed the request wall clock, and the stage map to contain exactly `plan`, `work`, and `review`. A marked preset allows only `light`, binds selector/review to high reasoning, rejects high reasoning on work, and rejects legacy caller `workspace_tools`. Preserve unmarked validation. Deep-copy the pointer and nested stage map.

**Modified Files and Checklist**

- [ ] `packages/go/config/execution_preset_types.go` — add typed policy, named absolute caps, normalization, fail-closed validation, and deep cloning.
- [ ] `packages/go/config/single_request_execution_preset_config_test.go` — cover valid decode, cap/cap+1 and timeout-vs-wall-clock boundaries, missing/extra stages, dynamic modes, option leakage, legacy tools, unknown fields, and clone isolation.

**Test Strategy**

- Add `TestLoadEdgeSingleRequestExecutionPreset`, `TestLoadEdgeSingleRequestExecutionPresetRejectsInvalidShape`, and `TestCloneExecutionPresetSingleRequestIsolation` using Gemini plan/review, ornith-fast work, an opaque workspace ref, and explicit positive bounded limits. Include zero, exact cap, cap+1, and stage-timeout-greater-than-wall-clock rows for every limit family.
- Rerun existing generic catalog/rejection tests to prove compatibility.

**Verification**

- `go test ./packages/go/config -run 'Test(LoadEdgeSingleRequestExecutionPreset|CloneExecutionPresetSingleRequestIsolation|LoadEdgeExecutionPresetCatalog|LoadEdgeExecutionPresetRejectsInvalidShape)$' -count=1`
- Expected: valid/exact-cap and legacy cases pass; zero/cap+1/cross-limit/malformed shapes fail; clone mutation cannot affect the source.

### [API-2] Preserve refresh semantics and publish the schema

**Problem**

- `apps/edge/internal/configrefresh/classify.go:371` compares selector, modes, routes, and workspace tools but cannot report the new policy independently.
- `configs/edge.yaml` and the refresh contract/spec do not describe a secret-free fixed single-request generation.

**Solution**

Before (`apps/edge/internal/configrefresh/classify.go:383`):

```go
appendDeepIfChanged(changes, fmt.Sprintf("execution_presets[%q].selector", id), StatusApplied, cur.Selector, next.Selector)
appendDeepIfChanged(changes, fmt.Sprintf("execution_presets[%q].allowed_modes", id), StatusApplied, cur.AllowedModes, next.AllowedModes)
appendDeepIfChanged(changes, fmt.Sprintf("execution_presets[%q].routes", id), StatusApplied, cur.Routes, next.Routes)
appendDeepIfChanged(changes, fmt.Sprintf("execution_presets[%q].workspace_tools", id), StatusApplied, cur.WorkspaceTools, next.WorkspaceTools)
```

After:

```go
appendDeepIfChanged(changes, fmt.Sprintf("execution_presets[%q].routes", id), StatusApplied, cur.Routes, next.Routes)
appendDeepIfChanged(changes, fmt.Sprintf("execution_presets[%q].single_request", id), StatusApplied, cur.SingleRequest, next.SingleRequest)
appendDeepIfChanged(changes, fmt.Sprintf("execution_presets[%q].workspace_tools", id), StatusApplied, cur.WorkspaceTools, next.WorkspaceTools)
```

Classify the policy as live-applied and document the exact absolute caps plus the rule that refresh affects only new request snapshots. Add only a commented, secret-free YAML example; synchronize contract/spec without claiming runtime execution.

**Modified Files and Checklist**

- [ ] `apps/edge/internal/configrefresh/classify.go` — emit the precise single-request change path.
- [ ] `apps/edge/internal/configrefresh/execution_preset_classify_test.go` — prove value capture and deterministic ordering.
- [ ] `configs/edge.yaml` — add a commented fixed-light example only.
- [ ] `agent-contract/inner/edge-config-runtime-refresh.md` — define validation, compatibility, refresh generation, and secret rules.
- [ ] `agent-spec/runtime/provider-pool-config-refresh.md` — synchronize current schema and executable evidence.

**Test Strategy**

- Extend `TestClassifyExecutionPresetLiveApply` with differing policy snapshots and assert the exact sorted change path plus previous/next values.
- Use the config loader tests from API-1 as the decoder/validator oracle; no external config smoke is needed.

**Verification**

- `go test ./apps/edge/internal/configrefresh -run 'TestClassifyExecutionPresetLiveApply$' -count=1`
- Expected: the classifier reports the policy path as applied with deterministic ordering.

## Modified Files Summary

| File | Item |
|------|------|
| `packages/go/config/execution_preset_types.go` | API-1 |
| `packages/go/config/single_request_execution_preset_config_test.go` | API-1 |
| `apps/edge/internal/configrefresh/classify.go` | API-2 |
| `apps/edge/internal/configrefresh/execution_preset_classify_test.go` | API-2 |
| `configs/edge.yaml` | API-2 |
| `agent-contract/inner/edge-config-runtime-refresh.md` | API-2 |
| `agent-spec/runtime/provider-pool-config-refresh.md` | API-2 |
| `agent-task/m-iop-owned-single-request-agent-execution/01_preset_config/CODE_REVIEW-cloud-G07.md` | API-1, API-2 |

## Final Verification

1. `go test ./packages/go/config -run 'Test(LoadEdgeSingleRequestExecutionPreset|CloneExecutionPresetSingleRequestIsolation|LoadEdgeExecutionPresetCatalog|LoadEdgeExecutionPresetRejectsInvalidShape)$' -count=1`
2. `go test ./apps/edge/internal/configrefresh -run 'TestClassifyExecutionPresetLiveApply$' -count=1`
3. `go test ./packages/go/config ./apps/edge/internal/configrefresh -count=1`
4. `go vet ./packages/go/...`
5. `go test ./packages/go/... ./apps/edge/... -count=1`
6. `git diff --check`

Expected: all commands exit 0; ordinary presets stay compatible; invalid marked shapes fail closed; refresh reports the new path. Actual Claude/provider execution remains outside this packet.

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