<!-- task=m-iop-owned-single-request-agent-execution/15+14_observation_adapters plan=1 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/15+14_observation_adapters, plan=1, tag=REVIEW_API

## Archive Evidence Snapshot

- Prior plan: `agent-task/m-iop-owned-single-request-agent-execution/15+14_observation_adapters/plan_cloud_G07_0.log`.
- Prior review: `agent-task/m-iop-owned-single-request-agent-execution/15+14_observation_adapters/code_review_cloud_G08_0.log`.
- Prior verdict: `FAIL`; Required findings: R1 and R2; Suggested findings: none; Nit findings: none.
- R1 evidence: the focused observation race suite passed, but `TestAnthropicSingleRequestInternalToolsStayPrivate` failed three consecutive targeted runs because the fake proto-socket had no cleanup request/response registration; a short-timeout goroutine dump showed `Service.workspaceCleanup` waiting in `WorkspaceCleanupRequest`.
- R2 evidence: a deterministic temporary cleanup/WRITE ordering test emitted a non-empty `ws-*` cleanup correlation followed by an empty successful WRITE correlation; the temporary review test was removed after reproduction.
- Supporting verification: `go vet` and `git diff --check` passed; the approved SDD `cleanup-observation` criterion remains the governing closure target.

## 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-G06.md` → `code_review_cloud_G06_1.log` and `PLAN-local-G06.md` → `plan_local_G06_1.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/15+14_observation_adapters/`. If WARN/FAIL, fully write the next filesystem state required by the code-review skill.
4. If PASS, preserve the first-line `milestone-task=cleanup-observation` metadata in `complete.log` and report it for runtime aggregation. 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 Complete the terminal cleanup integration harness | [x] |
| REVIEW_API-2 Retain immutable tool correlation across cleanup overlap | [x] |

## Implementation Checklist

- [x] Register the canonical cleanup request/response in the Anthropic internal-tool fake and assert exactly one cleanup.
- [x] Preserve one non-empty request-local correlation across cleanup overlap for READ, LIST, WRITE, DELETE, and COMMAND observations.
- [x] Add deterministic regressions for the cleanup exchange and cleanup/tool ordering without weakening exact field/value allowlists.
- [x] Run dependency, targeted, focused race, package, vet, and whitespace verification with uncached test runs.
- [x] Fill every implementation-owned section in `CODE_REVIEW-cloud-G06.md` with actual decisions and command 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-cloud-G06.md` to `code_review_cloud_G06_1.log`.
- [x] Archive active `PLAN-local-G06.md` to `plan_local_G06_1.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 active task directory `agent-task/m-iop-owned-single-request-agent-execution/15+14_observation_adapters/` to `agent-task/archive/YYYY/MM/m-iop-owned-single-request-agent-execution/15+14_observation_adapters/` and update this checklist at the final archive path.
- [ ] 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`.
- [ ] If PASS for split work, remove empty active parent `agent-task/{task_group}/` or verify it was kept due to remaining siblings/files.
- [x] If WARN/FAIL, write the next filesystem state matching code-review verdict and do not write `complete.log`.

## Deviations from Plan

None. Implementation follows the plan exactly: the Anthropic test fake registers the cleanup protocol pair and asserts exactly one cleanup; Node tool observation seams capture immutable correlation before deferred emission for READ/LIST/WRITE/DELETE/COMMAND; the ordering-controlled regression pauses a write via `beforeRename`, forces cleanup, and verifies shared correlation.

## Key Design Decisions

- R1: Extended `newAnthropicInternalToolService` with `WorkspaceCleanupRequest`/`WorkspaceCleanupResponse` parsers and a listener that returns a canonical `WORKSPACE_STATUS_SUCCESS` cleanup response and increments a cleanup counter. `TestAnthropicSingleRequestInternalToolsStayPrivate` asserts `open=1, tools=2, cleanup=1, continuations=2`.
- R2: Changed `observeTool` signature from `(requestID string, ...)` to `(correlation string, ...)` so the observer no longer depends on the live request map. Each executor (READ/LIST/WRITE/DELETE in `file_executor.go`, COMMAND in `command_executor.go`) captures `req.correlation` inside `withRequest` while request ownership is valid and passes it to the deferred observer. The `requestCorrelation` helper was removed since it is no longer used.
- The ordering-controlled regression replaces the zap observer with a `capturingObserver` so cleanup and tool events can be compared by correlation without relying on log iteration timing. It uses `request.entry.beforeRename` to pause a WRITE, triggers Cleanup from a goroutine, then verifies both events carry the same non-empty `ws-*` correlation.

## Reviewer Checkpoints

- Confirm the Anthropic internal-tool fake parses and responds to the canonical cleanup protocol pair and proves exactly one terminal cleanup.
- Confirm tool correlation is captured while request ownership is valid and is passed immutably to observation rather than looked up after cleanup.
- Confirm READ, LIST, WRITE, DELETE, and COMMAND all use the repaired seam and the ordering-controlled regression proves one shared non-empty correlation.
- Confirm exact raw-free observation keys and values remain unchanged and no API, wire, config, or runtime cleanup semantics change.
- Confirm every final verification command is uncached where specified and the previously failing OpenAI package regression is green.

## Verification Results

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

### 1. Packet 14 dependency

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

```text
PASS (exit 0; packet 14 complete.log found uniquely under agent-task/archive)
```

### 2. Targeted Anthropic cleanup integration

`go test ./apps/edge/internal/openai -run '^TestAnthropicSingleRequestInternalToolsStayPrivate$' -count=3`

```text
ok  	ipop/apps/edge/internal/openai	0.048s
```

### 3. Focused Node observation race

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

```text
ok  	ipop/apps/node/internal/workspace	1.023s
```

### 4. Package regression

`go test ./apps/edge/internal/service ./apps/edge/internal/bootstrap ./apps/edge/internal/openai ./apps/node/internal/workspace -count=1`

```text
ok  	ipop/apps/edge/internal/service	6.435s
ok  	ipop/apps/edge/internal/bootstrap	0.369s
ok  	ipop/apps/edge/internal/openai	7.969s
ok  	ipop/apps/node/internal/workspace	0.494s
```

### 5. Vet

`go vet ./apps/edge/internal/service ./apps/edge/internal/bootstrap ./apps/edge/internal/openai ./apps/node/internal/workspace`

```text
PASS (exit 0; no vet diagnostics)
```

### 6. Whitespace

`git diff --check`

```text
PASS (exit 0; no whitespace errors)
```

---

> **[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: FAIL
- Dimension Assessment:
  - Correctness: Pass
  - Completeness: Fail
  - Test Coverage: Fail
  - API Contract: Pass
  - Code Quality: Pass
  - Implementation Deviation: Fail
  - Verification Trust: Fail
  - Spec Conformance: Fail
- Findings:
  - Required R2 — `apps/node/internal/workspace/observation_test.go:128`: `TestWorkspaceObservationCorrelationSurvivesCleanupOverlap` starts cleanup in a goroutine, closes `pause`, and only then calls `runtime.Write` synchronously. The `beforeRename` hook therefore observes an already-closed channel and never proves that correlation was captured before cleanup removed request authority; there is also no hook-arrival or cleanup-completion barrier before WRITE resumes. This leaves the current plan's deterministic cleanup/tool ordering regression and SDD S07 evidence incomplete despite the production seam carrying immutable correlation. Start WRITE in a goroutine, make `beforeRename` signal arrival and block on a separate release channel, wait for that arrival, run and complete cleanup while WRITE remains paused, then release WRITE and assert the cleanup/tool observations share the original non-empty correlation.
- Routing Signals:
  - `review_rework_count=2`
  - `evidence_integrity_failure=true`
- Next Step: Invoke the plan skill in `prepare-follow-up` mode with Required R2, rerun isolated final routing, archive this pair, and materialize the routed follow-up pair.
