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

## Archive Evidence Snapshot

- Prior plan: `agent-task/m-iop-owned-single-request-agent-execution/15+14_observation_adapters/plan_local_G06_1.log`.
- Prior review: `agent-task/m-iop-owned-single-request-agent-execution/15+14_observation_adapters/code_review_cloud_G06_1.log`.
- Prior verdict: `FAIL`; Required findings: R2; Suggested findings: none; Nit findings: none.
- R1 is closed: the canonical cleanup request/response fake, exact-one cleanup assertion, targeted Anthropic test, and affected-package regression pass.
- R2 production propagation is present for READ, LIST, WRITE, DELETE, and COMMAND, and the focused race suite passes. The remaining gap is that `TestWorkspaceObservationCorrelationSurvivesCleanupOverlap` does not block WRITE before cleanup or wait for cleanup before release.
- Predecessor evidence: `agent-task/archive/2026/08/m-iop-owned-single-request-agent-execution/14+05,12,13_observation_timing/complete.log`.

## 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-G04.md` → `code_review_cloud_G04_2.log` and `PLAN-cloud-G04.md` → `plan_cloud_G04_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/15+14_observation_adapters/`. If WARN/FAIL, fully write the next filesystem state required by the code-review skill.
4. If PASS and task group is `m-<milestone-slug>`, preserve the first-line `milestone-task` 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 Enforce cleanup between correlation capture and observation | [x] |

## Implementation Checklist

- [x] Force WRITE to reach and block at `beforeRename`, complete cleanup while it is blocked, then release it and assert exactly one cleanup/tool pair shares the original non-empty correlation.
- [x] Run predecessor, repeated ordering race, focused observation race, Anthropic regression, affected-package, formatting, vet, and whitespace verification with uncached Go tests.
- [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_G04_2.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G04_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/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.
- [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

None. All implementation steps and verification commands were executed as specified in PLAN-cloud-G04.md.

## Key Design Decisions

Updated `TestWorkspaceObservationCorrelationSurvivesCleanupOverlap` in `apps/node/internal/workspace/observation_test.go` to use explicit arrival (`entered`) and release (`release`) channels around the `beforeRename` hook.
1. `runtime.Write` is invoked asynchronously in a goroutine.
2. The test waits for `beforeRename` to signal arrival (`<-entered`), guaranteeing correlation capture before cleanup.
3. `runtime.Cleanup` is executed synchronously while WRITE remains blocked.
4. `release` channel is closed to allow WRITE to complete.
5. Exact assertions check that write and cleanup return success, produce exactly one cleanup observation and one tool observation, and both carry the expected original correlation.

## Reviewer Checkpoints

- Confirm WRITE signals arrival at `beforeRename` before cleanup begins and remains blocked until cleanup returns.
- Confirm cleanup observation is emitted before WRITE is released and the test asserts exactly one cleanup event and one WRITE tool event.
- Confirm both events carry the same original non-empty `ws-*` correlation.
- Confirm no production runtime, observation schema, API, wire, config, or spec file changes for this follow-up.
- Confirm every Go test is uncached and the repeated race run, R1 Anthropic regression, package regression, formatting, vet, and whitespace checks are 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
Exit status: 0
```

### 2. Repeated ordering race

`go test -race ./apps/node/internal/workspace -run '^TestWorkspaceObservationCorrelationSurvivesCleanupOverlap$' -count=50`

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

### 3. Focused observation race

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

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

### 4. Anthropic cleanup regression

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

```text
ok  	iop/apps/edge/internal/openai	0.031s
```

### 5. Affected-package regression

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

```text
ok  	iop/apps/edge/internal/service	6.416s
ok  	iop/apps/edge/internal/bootstrap	0.374s
ok  	iop/apps/edge/internal/openai	7.954s
ok  	iop/apps/node/internal/workspace	0.562s
```

### 6. Formatting

`gofmt -d apps/node/internal/workspace/observation_test.go`

```text
(clean output)
```

### 7. Vet

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

```text
(clean output)
```

### 8. Whitespace

`git diff --check`

```text
(clean 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
  - Completeness: Pass
  - Test Coverage: Pass
  - API Contract: Pass
  - Code Quality: Pass
  - Implementation Deviation: Pass
  - Verification Trust: Pass
  - Spec Conformance: Pass
- Findings: None
- Routing Signals:
  - `review_rework_count=2`
  - `evidence_integrity_failure=false`
- Next Step: Write `complete.log`, archive the reviewed task under `agent-task/archive/2026/08/`, and report the milestone completion event metadata without modifying the roadmap.
