<!-- task=m-iop-owned-single-request-agent-execution/15+14_observation_adapters plan=0 tag=API milestone-task=cleanup-observation -->

# Code Review Reference - 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-06
task=m-iop-owned-single-request-agent-execution/15+14_observation_adapters, plan=0, tag=API

## 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-G08.md` → `code_review_cloud_G08_0.log` and `PLAN-cloud-G07.md` → `plan_cloud_G07_0.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 |
|------|---------|
| API-2 Emit bounded Edge metrics/logs and safe Node events | [x] |

## Implementation Checklist

- [x] Add failure-isolated bounded Prometheus/zap observers, wire them at Edge startup, and emit raw-free Node tool/cleanup logs.
- [x] Prove collector cardinality, exact outcome counts, duplicate-terminal protection, exact log allowlists, secret-sentinel rejection, and observer panic/error isolation.
- [x] Preserve packet 05 ingress ownership while exposing only the bounded test correlation needed by the later closure packet.
- [x] Run dependency, focused race, package, vet, and whitespace verification.
- [x] 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/check this section.

- [x] Append verdict, routing signals, dimensions, and findings.
- [x] Archive the active pair to routed suffix `0` logs and verify `.gitignore`.
- [ ] On PASS write `complete.log`, preserve/report Milestone metadata, move this directory, and keep the parent while siblings remain.
- [x] On WARN/FAIL write only the official next loop state.

## Deviations from Plan

`Runtime.Execute` does not exist in the current workspace runtime. The raw-free tool projection therefore wraps the actual common terminal return paths for READ, LIST, WRITE, DELETE, and COMMAND (`file_executor.go` and `command_executor.go`) while keeping the observer implementation and request-local correlation in `runtime.go`/`observation.go`. This does not alter the Edge-Node wire, workspace result shape, lifecycle outcome, or tool authorization.

The required package regression command reaches an existing timeout in `TestAnthropicSingleRequestInternalToolsStayPrivate`. The focused race suite, the changed Edge service/bootstrap packages, and the workspace package pass. The timed-out Anthropic coordinator/HTTP test is outside this packet's observation-only boundary and was not changed.

## Key Design Decisions

- Edge installs a once-registered default Prometheus collector set before input-server construction. Labels are limited to closed event, stage, operation, outcome, and error-class values; generated correlation remains log-only.
- Edge zap records use exactly `correlation`, `event_class`, `stage`, `operation`, `outcome`, `error_class`, `duration_ms`, `tool_count`, and `has_result`. The service-owned safe observer continues to absorb observer panics and errors.
- Node generates one random `ws-` correlation when an immutable workspace request opens. Tool and cleanup projections never log request ids, workspace refs, paths, command ids, environment, content, stdout/stderr, credentials, or raw errors.
- Node observer failures are recovered after operation completion, so they cannot change tool results, cleanup ownership, or process cancellation.

## Reviewer Checkpoints

- Confirm metric labels are closed/bounded and omit request/stage/tool ids and every raw value.
- Confirm Edge and Node log keys are exact allowlists with path/command/output/credential sentinels rejected.
- Confirm collectors register once and duplicate terminal attempts do not double-count.
- Confirm observer error/panic cannot alter response, cancellation, cleanup, or process ownership.

## 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. Focused race tests

`go test -race ./apps/edge/internal/service ./apps/edge/internal/bootstrap ./apps/node/internal/workspace -run 'Test(SingleRequestMetrics|SingleRequestObservationWiring|WorkspaceObservation)' -count=1`

```text
ok  iop/apps/edge/internal/service  1.059s
ok  iop/apps/edge/internal/bootstrap  1.063s
ok  iop/apps/node/internal/workspace  1.038s
```

### 3. 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.419s
ok  iop/apps/edge/internal/bootstrap  0.373s
--- FAIL: TestAnthropicSingleRequestInternalToolsStayPrivate (5.00s)
    single_request_handler_test.go:445: POST /v1/messages: Post "http://127.0.0.1:36011/v1/messages": context deadline exceeded
FAIL
FAIL  iop/apps/edge/internal/openai  12.887s
ok  iop/apps/node/internal/workspace  0.516s
FAIL

Focused confirmation:
--- FAIL: TestAnthropicSingleRequestInternalToolsStayPrivate (5.01s)
    single_request_handler_test.go:445: POST /v1/messages: Post "http://127.0.0.1:45581/v1/messages": context deadline exceeded
FAIL
FAIL  iop/apps/edge/internal/openai  5.037s
```

### 4. 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)
```

### 5. 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: Fail
  - Completeness: Fail
  - Test Coverage: Fail
  - API Contract: Pass
  - Code Quality: Pass
  - Implementation Deviation: Pass
  - Verification Trust: Pass
  - Spec Conformance: Fail
- Findings:
  - Required R1 — `apps/edge/internal/openai/single_request_handler_test.go:370`: `newAnthropicInternalToolService` registers only workspace open/tool parsers and listeners. The now-required terminal cleanup reaches `Service.workspaceCleanup`, waits for an unhandled `WorkspaceCleanupResponse`, and deterministically times out `TestAnthropicSingleRequestInternalToolsStayPrivate`; the plan-required package regression therefore remains red. Register the cleanup request/response pair in the fake proto-socket, return the canonical successful cleanup response, assert exactly one cleanup, and rerun the package regression.
  - Required R2 — `apps/node/internal/workspace/observation.go:184`: tool observation resolves correlation by looking up `requestID` after the operation returns, while cleanup removes the request authority at `apps/node/internal/workspace/cleanup.go:171`. A deterministic concurrent cleanup/WRITE reproducer emitted a `ws-*` cleanup event followed by a successful WRITE event with empty correlation, violating SDD S07's linked raw-free tool/cleanup evidence. Capture the immutable request correlation while the operation still owns the request, pass that value to the deferred observer for READ/LIST/WRITE/DELETE/COMMAND, and add an ordering regression that proves tool and cleanup events retain the same non-empty correlation.
- Routing Signals:
  - `review_rework_count=1`
  - `evidence_integrity_failure=false`
- Next Step: Invoke the plan skill in `prepare-follow-up` mode with R1 and R2, rerun isolated final routing, archive this pair, and materialize the routed follow-up pair.
