<!-- task=m-iop-owned-single-request-agent-execution/14+05,12,13_workspace_observation 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/14+05,12,13_workspace_observation, 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/14+05,12,13_workspace_observation/`. 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-1 Define closed observation and timing semantics | [ ] |
| API-2 Emit bounded Edge metrics/logs and safe Node events | [ ] |
| API-3 Link ingress, lifecycle, and documented evidence | [ ] |

## Implementation Checklist

- [ ] Define a closed, copy-safe single-request observation schema and explicit log/metric allowlists that exclude all raw or unbounded values.
- [ ] Measure request total, provider-active stage, Node tool, and cleanup durations/outcomes exactly once without counting tool time as stage pure time.
- [ ] Add failure-isolated bounded Prometheus/zap observers, wire them at Edge startup, and emit raw-free Node tool/cleanup logs.
- [ ] Prove cardinality, correlation, timing math, terminal races, observer panic/error isolation, secret sentinels, and ingress-to-total count consistency.
- [ ] Synchronize input/runtime specs with deterministic evidence and explicit external Claude/Mac smoke deferral.
- [ ] Run all dependency, focused race, package, vet, deterministic search, and whitespace verification.
- [ ] 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.

- [ ] Append verdict, routing signals, dimensions, and findings.
- [ ] 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.
- [ ] On WARN/FAIL write only the official next loop state.

## Deviations from Plan

_Record deviations and rationale._

## Key Design Decisions

_Record implemented decisions._

## Reviewer Checkpoints

- Confirm metric labels are closed/bounded and omit every request/stage/tool id and raw value.
- Confirm log keys are exact allowlists and sanitizer tests include path/command/output/credential sentinels.
- Confirm stage pure time pauses across tools, total includes cleanup/terminal resolution, and each terminal emits once.
- Confirm observer error/panic cannot alter response, cancellation, cleanup, or process ownership.
- Confirm Node and Edge events correlate safely and external Claude/Mac smoke remains unclaimed.

## Verification Results

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

### 1. Packet 05 dependency

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

```text
[fill]
```

### 2. Packet 12 dependency

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

```text
[fill]
```

### 3. Packet 13 dependency

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

```text
[fill]
```

### 4. Focused race tests

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

```text
[fill]
```

### 5. HTTP evidence

`go test ./apps/edge/internal/openai -run 'TestAnthropicSingleRequestObservation' -count=1`

```text
[fill]
```

### 6. Package regression

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

```text
[fill]
```

### 7. Vet

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

```text
[fill]
```

### 8. Spec search

`rg --sort path -n 'stage.*pure|tool.*duration|cleanup|total|raw|cardinality|Claude.*defer' agent-spec/input/openai-compatible-surface.md agent-spec/runtime/edge-node-execution.md`

```text
[fill]
```

### 9. Whitespace

`git diff --check`

```text
[fill]
```

---

> **[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 |
