<!-- task=m-iop-hot-path-one-shot-execution/11+09,10_cleanup plan=0 tag=API milestone-task=cleanup -->

# Code Review Reference - API

> **[IMPLEMENTING AGENT — READ FIRST] Filling in this file is the mandatory final step of implementation.**
> Fill item statuses, deviations, decisions, and actual output, then stop with active files and report ready. Record blockers only in implementation evidence. Do not ask the user, create control state, classify, archive, or write `complete.log`; review owns finalization.

## Overview

date=2026-08-02
task=m-iop-hot-path-one-shot-execution/11+09,10_cleanup, plan=0, tag=API

## For the Review Agent

> **[REVIEW AGENT ONLY]** Implementers must not execute this section.

Compare source/evidence, append verdict/signals, archive the pair, and on PASS write `complete.log`, preserve metadata, archive the directory, and update the final `.log` checklist. WARN/FAIL must create the exact next state.
## Implementation Item Completion

| Item | Status |
|------|---------|
| API-1 Confirm cleanup before logical terminal | [ ] |
| API-2 Bound state TTL and report workspace orphan responsibility | [ ] |

## Implementation Checklist

- [ ] Gate light success/error completion on one exact caller-executed delete result while preserving primary terminal intent and cancellation semantics.
- [ ] Reclaim only server state by bounded TTL and emit raw-free orphan identity/path observations without hidden cleanup after disconnect.
- [ ] Run cleanup/TTL/concurrency, common race, vet, and diff verification exactly as written.
- [ ] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

## Review-Only Checklist

> **[REVIEW AGENT ONLY]** Implementers must not modify or check this section.

- [x] Append one PASS/WARN/FAIL verdict with verified `review_rework_count` and `evidence_integrity_failure`.
- [x] Verify verdict, Dimension Assessment, and Required/Suggested/Nit classifications match.
- [x] Archive the active review to `code_review_cloud_G10_0.log`.
- [x] Archive the active plan to `plan_cloud_G09_0.log`.
- [x] Verify the Agent-Ops `.gitignore` block.
- [ ] On PASS write `complete.log` from `agent-ops/skills/common/code-review/templates/complete-log-template.md` and leave no active `.md`.
- [ ] On PASS archive to `agent-task/archive/YYYY/MM/m-iop-hot-path-one-shot-execution/11+09,10_cleanup/` and update this checklist there.
- [ ] On PASS preserve/report `milestone-task=cleanup` without direct roadmap mutation.
- [ ] On PASS remove the active parent only if no siblings/files remain.
- [x] On WARN/FAIL create the mandatory next state without `complete.log`.

## Deviations from Plan

Blocked before implementation because both required predecessor completion logs are missing.

Attempt 1:

```bash
test -f agent-task/m-iop-hot-path-one-shot-execution/09+06,08_artifact_pair/complete.log && test -f agent-task/m-iop-hot-path-one-shot-execution/10+07,09_light_flow/complete.log
```

Output:

```text
no stdout
exit status 1
```

Attempt 2:

```bash
for f in agent-task/m-iop-hot-path-one-shot-execution/09+06,08_artifact_pair/complete.log agent-task/m-iop-hot-path-one-shot-execution/10+07,09_light_flow/complete.log; do if [ -f "$f" ]; then printf '%s\\tPRESENT\\n' "$f"; else printf '%s\\tMISSING\\n' "$f"; fi; done
```

Output:

```text
agent-task/m-iop-hot-path-one-shot-execution/09+06,08_artifact_pair/complete.log	MISSING
agent-task/m-iop-hot-path-one-shot-execution/10+07,09_light_flow/complete.log	MISSING
exit status 0
```

Resume condition: both predecessor completion logs exist at the exact paths above.

## Key Design Decisions

No implementation decisions were made because the predecessor gate failed.

## Reviewer Checkpoints

- Success/error terminal intent commits only after exact delete acknowledgement and at most once.
- Disconnect produces no hidden model/tool cleanup work.
- TTL removes server state only; orphan observation has fixed ids/path and no raw content.

## Verification Results

Paste actual stdout/stderr below.

### API-1 item verification

```bash
go test -race -count=1 ./apps/edge/internal/openai -run TestHotPathCleanup
```

_Actual stdout/stderr:_

### API-2 item verification

```bash
go test -race -count=1 ./apps/edge/internal/openai -run 'Test(LogicalRequestTTL|HotPathCleanup)'
```

_Actual stdout/stderr:_

### Dependencies and focused race

```bash
test -f agent-task/m-iop-hot-path-one-shot-execution/09+06,08_artifact_pair/complete.log
test -f agent-task/m-iop-hot-path-one-shot-execution/10+07,09_light_flow/complete.log
go test -race -count=1 ./apps/edge/internal/openai -run 'Test(LogicalRequestTTL|HotPathCleanup)'
```

_Actual stdout/stderr:_

```text
Focused race test not run because the predecessor preflight failed.
Preflight: no stdout; exit status 1.
agent-task/m-iop-hot-path-one-shot-execution/09+06,08_artifact_pair/complete.log	MISSING
agent-task/m-iop-hot-path-one-shot-execution/10+07,09_light_flow/complete.log	MISSING
Diagnostic exit status 0.
```

### Common race tests

```bash
go test -race -count=1 ./packages/go/streamgate ./packages/go/config ./apps/edge/internal/openai ./apps/edge/internal/service
```

_Actual stdout/stderr:_

### Vet and diff

```bash
go vet ./apps/edge/internal/openai
git diff --check
```

_Actual stdout/stderr:_

---

> **[IMPLEMENTING AGENT — BEFORE SAVING] Have you filled in every implementation-owned section?** Leave review-only sections unchanged.

## Section Ownership

| Section | Owner | Note |
|---------|-------|------|
| Fixed structure, item names/checklist/checkpoints/commands | Fixed | Do not rewrite |
| Item status, deviations, decisions, actual output | Implementer | Must complete |
| Review checklist and verdict/finalization | Review agent | Implementer must not modify |

## Code Review Result

- Overall Verdict: FAIL
- Dimension Assessment:
  - Correctness: Fail — the current light flow returns the review completion before any caller-executed delete acknowledgement.
  - Completeness: Fail — both implementation items and every implementation checklist item remain incomplete.
  - Test Coverage: Fail — no `TestHotPathCleanup*` or `TestLogicalRequestTTL*` test is registered.
  - API Contract: Fail — SDD scenario S09 cleanup, terminal, disconnect, TTL, and orphan-observation semantics are not implemented.
  - Code Quality: Pass — no new implementation was added, and the existing baseline tests and `git diff --check` pass.
  - Implementation Deviation: Fail — implementation stopped at a predecessor preflight that checked only active paths even though both predecessors now have archived completion evidence.
  - Verification Trust: Fail — required focused race, common race, and vet outputs are absent, so the requested behavior is not verifiable.
  - Spec Conformance: Fail — the `cleanup` Evidence Map row has no implementation or deterministic evidence.
- Findings:
  - Required — `apps/edge/internal/openai/hot_path_review.go:15`: cleanup classification only marks `cleanup_pending` and immediately returns the final output at line 19. Add an exact delete-tool frontier, persist one pending terminal intent, and commit success/error only after the mapped delete receipt; preserve a primary error and stop without hidden cleanup after cancellation.
  - Required — `apps/edge/internal/openai/request_coordinator.go:444`: terminal state is retained, while expiry at lines 463-466 deletes records silently without distinguishing active work or emitting raw-free orphan responsibility evidence. Add bounded state-only reclamation, protect active in-flight transitions, remove terminal state exactly once, and emit only fixed request/path/stage/reason metadata.
  - Required — `agent-task/m-iop-hot-path-one-shot-execution/11+09,10_cleanup/CODE_REVIEW-cloud-G10.md:22`: API-1/API-2 and their required verification remain unchecked. Implement the missing cleanup/TTL files and deterministic race tests, then run every listed verification command with archive-aware predecessor checks.
- Routing Signals:
  - `review_rework_count=1`
  - `evidence_integrity_failure=false`
- Next Step: Invoke the plan skill for a FAIL follow-up using these raw findings and the archived predecessor completion evidence; do not create `USER_REVIEW.md`.
