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

# Synchronize Workspace Cleanup Terminal Regression Coverage

## For the Implementing Agent

Update only the listed regression test, run every verification command exactly, and fill the implementation-owned sections of `CODE_REVIEW-cloud-G02.md` with actual notes and output. Keep the active pair in place and report ready for review. If blocked, record the exact blocker, attempted commands/output, and resume condition only 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 is owned by the code-review skill.

## Background

Review loop 1 found that the production cleanup terminal authority and wire contract use the new canonical cleanup outcomes, but the package regression test still asserts the prior placeholder behavior. This contradicts the implementation evidence claiming the supporting tests were synchronized and leaves the changed common package red.

## 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.

## Finding Resolution Map

| Finding | Mode | Exact fix evidence | Changed precondition |
|---------|------|--------------------|----------------------|
| Required R1 | `direct-fix` | Update `packages/go/workspaceprotocol/terminal_test.go` to assert every canonical `CleanupTerminal` pair implemented in `terminal.go` and representative contradictory pairs. | The changed common package becomes green under a fresh uncached package test instead of retaining the stale deferred/internal expectations. |

## Analysis

### Files Read

- `packages/go/workspaceprotocol/terminal.go`
- `packages/go/workspaceprotocol/terminal_test.go`
- `agent-contract/inner/edge-node-runtime-wire.md`
- `agent-spec/runtime/edge-node-execution.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`
- `agent-task/m-iop-owned-single-request-agent-execution/13+12_workspace_cleanup/plan_cloud_G09_1.log`
- `agent-task/m-iop-owned-single-request-agent-execution/13+12_workspace_cleanup/code_review_cloud_G10_1.log`

### SDD Criteria

- SDD: `agent-roadmap/sdd/knowledge-tool-optimization-extension/iop-owned-single-request-agent-execution/SDD.md`, status `[승인됨]`, lock released.
- Milestone task: `cleanup-observation`; targeted scenario: S07.
- S07 and its Evidence Map require trustworthy cleanup/error evidence while preserving user results. This follow-up changes no cleanup behavior; it restores deterministic regression coverage for the closed cleanup outcomes used by that evidence.

### Verification Context

- No separate verification handoff was supplied. Repository-native evidence came from the archived loop 1 pair, local test rules, the canonical terminal source/test, and fresh reviewer commands.
- Local preflight: `/config/workspace/iop-s0`, `/config/.local/bin/go`, `go version go1.26.2 linux/arm64`, dirty shared worktree. No credential or external runner is required.
- Reproduced failure: `go test ./packages/go/workspaceprotocol -count=1` fails at `terminal_test.go:101` and `terminal_test.go:104`.
- Preconditions: packet 12 has one archived `complete.log`; cleanup source and contract remain unchanged.
- Constraints: do not edit production cleanup behavior, generated protocol files, unrelated task artifacts, or later observation work. Fresh uncached Go results are required.
- Confidence: high; the failure is isolated to two stale assertions in one table-oriented test.

### Test Coverage Gaps

- `CleanupTerminal` valid-pair coverage is stale for `UNSUPPORTED/UNSUPPORTED` and `ERROR/INTERNAL`.
- The current cleanup test does not enumerate the other canonical cleanup pairs together, making future drift easier. Replace the ad hoc assertions with a complete valid table and representative invalid table.

### Symbol References

- No symbols are renamed or removed.

### Split Judgment

- Keep one compact packet. One test table owns the complete canonical cleanup terminal regression boundary and has an independent deterministic PASS command.

### Scope Rationale

- Include only `packages/go/workspaceprotocol/terminal_test.go` and the active review evidence file.
- Exclude `terminal.go`, Node cleanup, Edge coordinator, wire/spec text, protobuf output, and observation code because fresh review found their current behavior aligned with the active contract.

### Final Routing

- `evaluation_mode=isolated-reassessment`; finalizer `finalize-task-policy.sh` pair mode.
- Build closures: scope/context/verification/evidence/ownership/decision all true. Scores `0/0/0/1/1` = G02, base `local-fit`; `large_indivisible_context=false`, no positive loop-risk signatures, `review_rework_count=1`, `evidence_integrity_failure=true`, so final basis is `recovery-boundary`, lane `cloud`, filename `PLAN-cloud-G02.md`.
- Review closures: scope/context/verification/evidence/ownership/decision all true. Scores `0/0/0/1/1` = G02, basis `official-review`, lane `cloud`, filename `CODE_REVIEW-cloud-G02.md`.
- Capability gap: none.

## Implementation Checklist

- [ ] Update cleanup terminal regression expectations and cover every canonical cleanup pair plus representative contradictory pairs.
- [ ] Run the fresh common-package regression and the inherited cleanup verification suite without changing production behavior.
- [ ] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

## Implementation Plan

### [REVIEW_API-1] Align the cleanup terminal test with the canonical authority

**Problem**

`packages/go/workspaceprotocol/terminal_test.go:100-104` still contains the pre-cleanup placeholder expectations:

```go
if msg, ok := workspaceprotocol.CleanupTerminal(...UNSUPPORTED, ...UNSUPPORTED); !ok || msg != "workspace cleanup deferred" {
    // failure
}
if _, ok := workspaceprotocol.CleanupTerminal(...ERROR, ...INTERNAL); ok {
    // failure
}
```

The production mapping and wire contract now define both pairs as canonical non-success outcomes, so the changed package test fails.

**Solution**

Replace the two ad hoc cleanup assertions with a table covering success, not-ready, unsupported, not-found, invalid-request, timeout, and internal cleanup outcomes, followed by representative invalid status/code combinations. Keep exact messages aligned with `CleanupTerminal`; do not change production code to satisfy the stale expectations.

**Modified Files and Checklist**

- [ ] `packages/go/workspaceprotocol/terminal_test.go` — replace stale cleanup assertions with complete canonical and contradictory-pair coverage.
- [ ] `agent-task/m-iop-owned-single-request-agent-execution/13+12_workspace_cleanup/CODE_REVIEW-cloud-G02.md` — record actual implementation and verification evidence.

**Test Strategy**

- Update `TestWorkspaceTerminalOpenAndCleanup` in `packages/go/workspaceprotocol/terminal_test.go`.
- Assert exact canonical messages for every accepted cleanup status/code pair and rejection for representative contradictory pairs.
- Retain the existing open-terminal assertions. No new production fixture is required.

**Verification**

- `go test ./packages/go/workspaceprotocol -count=1`
- Expected: the package passes uncached and both loop 1 failures are removed without production changes.

## Modified Files Summary

| File | Item |
|------|------|
| `packages/go/workspaceprotocol/terminal_test.go` | REVIEW_API-1 |
| `agent-task/m-iop-owned-single-request-agent-execution/13+12_workspace_cleanup/CODE_REVIEW-cloud-G02.md` | REVIEW_API-1 |

## Final Verification

1. `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`
2. `go test ./packages/go/workspaceprotocol -count=1`
3. `go test -race ./apps/node/internal/workspace -run 'TestWorkspaceCleanup' -count=1`
4. `go test -race ./apps/node/internal/node ./apps/edge/internal/service -run 'Test(NodeWorkspaceCleanup|SingleRequestCleanup)' -count=1`
5. `go test ./packages/go/workspaceprotocol ./apps/node/internal/workspace ./apps/node/internal/node ./apps/edge/internal/service -count=1`
6. `go vet ./packages/go/workspaceprotocol ./apps/node/internal/workspace ./apps/node/internal/node ./apps/edge/internal/service`
7. `GOOS=darwin GOARCH=arm64 go test -c -o /tmp/iop-workspace-cleanup-darwin.test ./apps/node/internal/workspace`
8. `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`
9. `git diff --check`

Expected: the prerequisite is unique; the canonical cleanup terminal package and all inherited cleanup regressions pass fresh; vet and Darwin compile succeed; deterministic search shows synchronized canonical outcomes; whitespace is clean. Cached test output is not acceptable.

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