<!-- task=m-iop-owned-single-request-agent-execution/13+12_workspace_cleanup plan=2 tag=REVIEW_API milestone-task=cleanup-observation -->

# Code Review Reference - REVIEW_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.
> Execute the plan's selected root cause, scope, files, and dependency decisions as written. Do not choose another owner, narrow/expand the write boundary, or replace a fix with another verification attempt.
> 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-07
task=m-iop-owned-single-request-agent-execution/13+12_workspace_cleanup, plan=2, tag=REVIEW_API

## Archive Evidence Snapshot

- Review loop 1 is preserved at `agent-task/m-iop-owned-single-request-agent-execution/13+12_workspace_cleanup/plan_cloud_G09_1.log` and `agent-task/m-iop-owned-single-request-agent-execution/13+12_workspace_cleanup/code_review_cloud_G10_1.log` with verdict `FAIL`.
- Required R1: `packages/go/workspaceprotocol/terminal_test.go:100` expects `"workspace cleanup deferred"` and rejects `ERROR/INTERNAL`, while the production authority and contract require `"workspace cleanup unsupported"` and `"workspace cleanup failed"`.
- Fresh reviewer evidence: `go test ./packages/go/workspaceprotocol -count=1` failed both stale assertions; all eight prior cleanup-plan verification commands passed when rerun.
- Roadmap carryover remains `milestone-task=cleanup-observation`; this packet restores cleanup contract test trust and does not assert completion of the later raw-free observation contribution.

## 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 the following steps are finished:

1. Append verdict and `review_rework_count` / `evidence_integrity_failure` routing signals.
2. Archive `CODE_REVIEW-cloud-G02.md` → `code_review_cloud_G02_2.log` and `PLAN-cloud-G02.md` → `plan_cloud_G02_2.log`.
3. If PASS, write `complete.log` and move active task directory to `agent-task/archive/YYYY/MM/m-iop-owned-single-request-agent-execution/13+12_workspace_cleanup/`. If WARN/FAIL, fully write the next filesystem state required by the code-review skill.
4. If PASS and task group is `m-iop-owned-single-request-agent-execution`, preserve the first-line `milestone-task=cleanup-observation` metadata in `complete.log` and report it for the runtime aggregation event. Roadmap state evaluation belongs to `sync-milestone-workstate`.
5. Check applicable `Review-Only Checklist` items at the final `.log` location before reporting.

---

## Implementation Item Completion

| Item | Status |
|------|---------|
| REVIEW_API-1 Align the cleanup terminal test with the canonical authority | [x] |

## Implementation Checklist

- [x] Update cleanup terminal regression expectations and cover every canonical cleanup pair plus representative contradictory pairs.
- [x] Run the fresh common-package regression and the inherited cleanup verification suite without changing production behavior.
- [x] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification 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_G02_2.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G02_2.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`.
- [x] If PASS, write `complete.log` based on `agent-ops/skills/common/code-review/templates/complete-log-template.md` and leave no active `.md` files.
- [x] If PASS, move active task directory `agent-task/m-iop-owned-single-request-agent-execution/13+12_workspace_cleanup/` to `agent-task/archive/YYYY/MM/m-iop-owned-single-request-agent-execution/13+12_workspace_cleanup/` and update this checklist at the final archive path.
- [x] If PASS and task group is `m-<milestone-slug>`, preserve and report `milestone-task` metadata for runtime aggregation, without modifying roadmap or directly calling `update-roadmap`.
- [x] If PASS for split work, remove empty active parent `agent-task/m-iop-owned-single-request-agent-execution/` or verify it was kept due to remaining siblings/files.
- [ ] If WARN/FAIL, write the next filesystem state matching code-review verdict and do not write `complete.log`.

## Deviations from Plan

No deviations from PLAN were required. Command scope and touched files remained as specified.

## Key Design Decisions

1. Kept production implementation untouched and only updated the stale regression assertions in `packages/go/workspaceprotocol/terminal_test.go`.
2. Replaced ad-hoc cleanup checks with explicit canonical-valid/invalid pair tables to make drift on all implemented cleanup outcomes obvious.
3. Chose canonical messages from `packages/go/workspaceprotocol/terminal.go` so test coverage remains aligned to the authority without inference or extra heuristics.

## Reviewer Checkpoints

- Confirm production `packages/go/workspaceprotocol/terminal.go` is unchanged.
- Confirm the valid cleanup table covers success, not-ready, unsupported, not-found, invalid-request, timeout, and internal outcomes with exact canonical messages.
- Confirm representative contradictory cleanup status/code pairs remain rejected.
- Confirm the fresh common-package regression and every inherited cleanup command pass.

## Verification Results

Paste actual stdout/stderr for every command; record replacements under deviations.

### 1. Dependency

`test -f agent-task/m-iop-owned-single-request-agent-execution/12+05,06,08,11_internal_tool_loop/complete.log || test "$(compgen -G 'agent-task/archive/*/*/m-iop-owned-single-request-agent-execution/12+05,06,08,11_internal_tool_loop/complete.log' | wc -l)" -eq 1`

```text
PASS (exit 0, no output).
```

### 2. Canonical terminal package

`go test ./packages/go/workspaceprotocol -count=1`

```text
ok  	iop/packages/go/workspaceprotocol	0.011s
```

### 3. Node cleanup race tests

`go test -race ./apps/node/internal/workspace -run 'TestWorkspaceCleanup' -count=1`

```text
ok  	iop/apps/node/internal/workspace	1.114s
```

### 4. Handler/coordinator race tests

`go test -race ./apps/node/internal/node ./apps/edge/internal/service -run 'Test(NodeWorkspaceCleanup|SingleRequestCleanup)' -count=1`

```text
ok  	iop/apps/node/internal/node	1.062s
ok  	iop/apps/edge/internal/service	1.050s
```

### 5. Package regression

`go test ./packages/go/workspaceprotocol ./apps/node/internal/workspace ./apps/node/internal/node ./apps/edge/internal/service -count=1`

```text
ok  	iop/packages/go/workspaceprotocol	0.016s
ok  	iop/apps/node/internal/workspace	0.534s
ok  	iop/apps/node/internal/node	0.991s
ok  	iop/apps/edge/internal/service	6.194s
```

### 6. Vet

`go vet ./packages/go/workspaceprotocol ./apps/node/internal/workspace ./apps/node/internal/node ./apps/edge/internal/service`

```text
PASS (exit 0, no output).
```

### 7. Darwin compile

`GOOS=darwin GOARCH=arm64 go test -c -o /tmp/iop-workspace-cleanup-darwin.test ./apps/node/internal/workspace`

```text
PASS (exit 0, no output).
```

### 8. Canonical contract search

`rg --sort path -n 'workspace cleanup (unsupported|failed)|CleanupTerminal' packages/go/workspaceprotocol/terminal.go packages/go/workspaceprotocol/terminal_test.go agent-contract/inner/edge-node-runtime-wire.md`

```text
packages/go/workspaceprotocol/terminal.go:64:// CleanupTerminal returns the exact canonical message for a cleanup status and error code pair.
packages/go/workspaceprotocol/terminal.go:66:func CleanupTerminal(status iop.WorkspaceStatus, code iop.WorkspaceErrorCode) (string, bool) {
packages/go/workspaceprotocol/terminal.go:73:		return "workspace cleanup unsupported", true
packages/go/workspaceprotocol/terminal.go:81:		return "workspace cleanup failed", true
packages/go/workspaceprotocol/terminal.go:107:		{iop.WorkspaceStatus_WORKSPACE_STATUS_UNSUPPORTED, iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_UNSUPPORTED, "workspace cleanup unsupported"},
packages/go/workspaceprotocol/terminal_test.go:111:		{iop.WorkspaceStatus_WORKSPACE_STATUS_ERROR, iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_INTERNAL, "workspace cleanup failed"},
packages/go/workspaceprotocol/terminal_test.go:115:		msg, ok := workspaceprotocol.CleanupTerminal(tc.status, tc.code)
packages/go/workspaceprotocol/terminal_test.go:117:			t.Errorf("CleanupTerminal(%v, %v) = (%q, %v), want (%q, true)", tc.status, tc.code, msg, ok, tc.message)
packages/go/workspaceprotocol/terminal_test.go:135:		msg, ok := workspaceprotocol.CleanupTerminal(tc.status, tc.code)
packages/go/workspaceprotocol/terminal_test.go:133:		{iop.WorkspaceStatus_WORKSPACE_STATUS_UNSUPPORTED, iop.WorkspaceErrorCode_WORKSPACE_ERROR_CODE_INVALID_REQUEST},
packages/go/workspaceprotocol/terminal_test.go:135:			t.Errorf("CleanupTerminal(%v, %v) unexpectedly succeeded with %q", tc.status, tc.code, msg)
```

### 9. Whitespace

`git diff --check`

```text
PASS (exit 0, 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 | Implementing agent must not modify or execute these (archive, complete.log, and task-directory archive move are review-agent only) |
| Archive Evidence Snapshot | Fixed at stub creation from plan when present | Implementing agent uses it as default prior-loop context; read only the specific archive files cited there when more detail is required |
| Implementation Item Completion (item names) | Fixed at stub creation | Implementing agent checks `[ ]` → `[x]` only |
| Implementation Checklist (item text/order) | Fixed at stub creation from plan | Implementing agent checks `[ ]` → `[x]` only |
| Review-Only Checklist | Review agent only | Implementing agent 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 (section headings + commands) | Fixed at stub creation | Implementing agent fills in command output only; command changes require a `Deviations from Plan` entry |
| Code Review Result | Review agent appends | Not included in stub |

## Code Review Result

- Overall Verdict: PASS
- Dimension Assessment:
  - Correctness: Pass — the cleanup terminal regression now accepts all seven canonical status/code/message triples and rejects representative contradictory pairs.
  - Completeness: Pass — Required R1 is fully resolved within the planned test-only write boundary, and production cleanup authority remains aligned with the wire contract.
  - Test Coverage: Pass — fresh package, focused race, combined regression, vet, and Darwin compile checks all passed.
  - API Contract: Pass — cleanup messages and accepted pairs match `CleanupTerminal` and the active Edge-Node runtime wire contract.
  - Code Quality: Pass — the table-driven assertions are deterministic, focused, formatted, and contain no debug or dead code.
  - Implementation Deviation: Pass — no change outside the planned regression test and implementation evidence was required for this follow-up.
  - Verification Trust: Pass — all nine recorded verification commands were rerun by the reviewer and passed with fresh output.
  - Spec Conformance: Pass — the repaired regression provides trustworthy cleanup outcome evidence for S07 without asserting the later raw-free observation contribution complete.
- Findings: None
- Routing Signals:
  - `review_rework_count=1`
  - `evidence_integrity_failure=false`
- Next Step: Archive this PASS pair, write `complete.log`, move the task to the monthly archive, and report Milestone completion metadata for runtime aggregation.
