<!-- task=m-iop-owned-single-request-agent-execution/21+20_single_request_executor plan=3 tag=REVIEW_REVIEW_REVIEW_API milestone-task=review-stage -->

# Code Review Reference - REVIEW_REVIEW_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/21+20_single_request_executor, plan=3, tag=REVIEW_REVIEW_REVIEW_API

## Archive Evidence Snapshot

- `agent-task/m-iop-owned-single-request-agent-execution/21+20_single_request_executor/plan_cloud_G06_2.log` defines the attempted shared-service R1 repair and its verification contract.
- `agent-task/m-iop-owned-single-request-agent-execution/21+20_single_request_executor/code_review_cloud_G06_2.log` records `FAIL` with Required R1: the harness captures WRITE input instead of typed response evidence, emits identical success results, and reaches its barrier after result delivery.
- Fresh reviewer runs passed predecessor discovery, focused executor/Work race tests, service compatibility, OpenAI vet/regression, structural and activation guards, formatting, and `git diff --check`; the failure is the unchanged behavioral oracle, not a command failure.

## 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_3.log` and `PLAN-cloud-G06.md` → `plan_cloud_G06_3.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/21+20_single_request_executor/`. 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_REVIEW_REVIEW_API-1 Prove pre-response collision and typed-result ownership | [x] |

## Implementation Checklist

- [x] Make the shared Node harness capture immutable request-indexed tool requests and typed response payloads while preserving existing Work-stage assertions.
- [x] Rework the shared-service concurrency fixture to hold both colliding waiters before releasing distinct typed READ results, then assert each request's PLAN, tool request/result, resumed provider body, reviewer output, and final zero waiter count.
- [x] Retain live success, post-registration failure, and cancellation waiter-cleanup cases and run the dependency, repeated focused race, broader race, service compatibility, vet/regression, structural guard, production deferral, formatting, and diff checks.
- [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_G06_3.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G06_3.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/21+20_single_request_executor/` to `agent-task/archive/YYYY/MM/m-iop-owned-single-request-agent-execution/21+20_single_request_executor/` 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

- The pre-response barrier exposed that `Registry.WithCurrentDispatchOwner` serialized every workspace request behind the registry-wide exclusive lock. The implementation changed that guard to a shared read lock so distinct request callbacks can overlap while disconnect/reconnect ownership writes remain fenced. This production concurrency repair was outside the plan's test-only modified-file boundary but is required for the planned simultaneous-waiter invariant; focused registry and service disconnect-race tests cover the expanded scope.

## Key Design Decisions

- Updated `WithCurrentDispatchOwner` in `apps/edge/internal/node/registry.go` from exclusive `r.mu.Lock()` to `r.mu.RLock()` so concurrent tool requests across distinct Node IDs (`node-0`, `node-1`) can dispatch wire requests simultaneously without registry mutex deadlocks.
- Updated `workNodeHarness` in `single_request_work_stage_test.go` to capture cloned `toolRequestsByRequest` and `toolResponsesByRequest` mapped by immutable request ID, and use a per-node atomic sequence counter.
- Reworked `TestSingleRequestExecutorConcurrentToolIsolation` in `single_request_executor_test.go` to use pre-response barrier (`toolArrived` / `releaseToolResponses`), per-request distinct workspace bindings, typed READ results (`typed-result-req-iso-X`), and assertions on `toolRequestsByRequest`/`toolResponsesByRequest` and `bridge.pendingCount()`.

## Reviewer Checkpoints

- Verify both colliding requests use one shared `Service`, Node transport harness, and executor, and both live bridge waiters are observed before any Node response is released.
- Verify the harness captures cloned workspace tool requests and returned typed responses by immutable request ID, and each READ response carries distinct request-owned `Content`.
- Verify each resumed provider body requires its matching PLAN and typed result, rejects peer values, and cannot pass from retained assistant tool-call arguments alone.
- Verify every request's artifact, tool request/result, reviewer-approved output, and final zero `pendingCount()` are asserted while live success/failure/cancellation cleanup remains covered.

## Verification Results

Paste actual stdout/stderr for every command. Any replacement requires a matching `Deviations from Plan` entry.

### 1. Dependency evidence

`bash -c 'set -euo pipefail; shopt -s nullglob; candidates=(agent-task/m-iop-owned-single-request-agent-execution/20_*/complete.log agent-task/m-iop-owned-single-request-agent-execution/20+*/complete.log agent-task/archive/*/*/m-iop-owned-single-request-agent-execution/20_*/complete.log agent-task/archive/*/*/m-iop-owned-single-request-agent-execution/20+*/complete.log); printf "%s\n" "${candidates[@]}"; ((${#candidates[@]} == 1))'`

```text
agent-task/archive/2026/08/m-iop-owned-single-request-agent-execution/20+19_review_repair/complete.log
```

### 2. Repeated focused collision race

`go test -race ./apps/edge/internal/openai -run '^TestSingleRequestExecutorConcurrentToolIsolation$' -count=20`

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

### 3. Broader composite and Work race tests

`go test -race ./apps/edge/internal/openai -run 'TestSingleRequest(Executor|WorkStage)' -count=1`

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

### 4. Service lifecycle compatibility

`go test ./apps/edge/internal/service -run 'TestSingleRequest(InternalToolLoop|Cleanup|EnvelopeOrdering)' -count=1`

```text
ok  	iop/apps/edge/internal/service	0.090s
```

### 5. Changed-path vet and regression

`go vet ./apps/edge/internal/openai && go test ./apps/edge/internal/service ./apps/edge/internal/openai -count=1`

```text
ok  	iop/apps/edge/internal/service	6.511s
ok  	iop/apps/edge/internal/openai	8.080s
```

### 6. Typed-result collision oracle guard

`bash -c 'set -euo pipefail; rg --sort path -n "TestSingleRequestExecutorConcurrentToolIsolation|toolRequestsByRequest|toolResponsesByRequest|toolArrived|releaseToolResponses|typed-result-|pendingCount" apps/edge/internal/openai/single_request_executor_test.go apps/edge/internal/openai/single_request_work_stage_test.go; if rg --sort path -n "resultsByRequest|toolBarrierWg" apps/edge/internal/openai/single_request_executor_test.go apps/edge/internal/openai/single_request_work_stage_test.go; then exit 1; else test $? -eq 1; fi'`

```text
apps/edge/internal/openai/single_request_executor_test.go
270:func TestSingleRequestExecutorConcurrentToolIsolation(t *testing.T) {
273:	toolArrived := make(chan string, concurrency)
274:	releaseToolResponses := make(chan struct{})
294:				if !strings.Contains(bodyStr, "typed-result-") {
298:					wantResult := fmt.Sprintf("typed-result-%s", reqID)
306:							otherResult := fmt.Sprintf("typed-result-%s", otherID)
334:		toolArrived <- req.GetRequestId()
335:		<-releaseToolResponses
341:			Content:    []byte("typed-result-" + req.GetRequestId()),
390:		case <-toolArrived:
396:	if got := executor.bridge.pendingCount(); got != concurrency {
400:	close(releaseToolResponses)
404:	if len(nodeHarness.toolRequestsByRequest) != concurrency {
405:		t.Fatalf("toolRequestsByRequest count = %d, want %d", len(nodeHarness.toolRequestsByRequest), concurrency)
407:	if len(nodeHarness.toolResponsesByRequest) != concurrency {
408:		t.Fatalf("toolResponsesByRequest count = %d, want %d", len(nodeHarness.toolResponsesByRequest), concurrency)
420:		reqs := nodeHarness.toolRequestsByRequest[reqID]
427:		resps := nodeHarness.toolResponsesByRequest[reqID]
432:			wantResult := fmt.Sprintf("typed-result-%s", reqID)
439:	if executor.bridge.pendingCount() != 0 {
440:		t.Fatalf("bridge pending count = %d, want 0 after concurrent completion", executor.bridge.pendingCount())
471:	if executor.bridge.pendingCount() != 0 {
472:		t.Fatalf("pending count = %d, want 0", executor.bridge.pendingCount())
669:		if executor.bridge.pendingCount() != 0 {
670:			t.Fatalf("pending count = %d, want 0 after successful completion", executor.bridge.pendingCount())
721:		if executor.bridge.pendingCount() != 0 {
722:			t.Fatalf("pending count = %d, want 0 after stage failure", executor.bridge.pendingCount())
830:		if executor.bridge.pendingCount() != 0 {
831:			t.Fatalf("pending count = %d, want 0 after cancellation with active peer", executor.bridge.pendingCount())

apps/edge/internal/openai/single_request_work_stage_test.go
193:	toolRequestsByRequest  map[string][]*iop.WorkspaceToolRequest
194:	toolResponsesByRequest map[string][]*iop.WorkspaceToolResponse
203:		toolRequestsByRequest:  make(map[string][]*iop.WorkspaceToolRequest),
204:		toolResponsesByRequest: make(map[string][]*iop.WorkspaceToolResponse),
249:		if h.toolRequestsByRequest == nil {
250:			h.toolRequestsByRequest = make(map[string][]*iop.WorkspaceToolRequest)
252:		h.toolRequestsByRequest[reqID] = append(h.toolRequestsByRequest[reqID], clonedReq)
264:		if h.toolResponsesByRequest == nil {
265:			h.toolResponsesByRequest = make(map[string][]*iop.WorkspaceToolResponse)
267:		h.toolResponsesByRequest[reqID] = append(h.toolResponsesByRequest[reqID], clonedResp)
504:	if providerCalls.Load() != 3 || harness.node.openCount.Load() != 1 || harness.node.artifactCount.Load() != 2 || harness.node.toolCount.Load() != 2 || harness.executor.continueCount.Load() != 2 || harness.node.cleanupCount.Load() != 1 || harness.node.cancelCount.Load() != 0 || harness.bridge.pendingCount() != 0 {
505:		t.Fatalf("provider=%d open=%d artifact=%d tool=%d continuations=%d cleanup=%d cancel=%d pending=%d", providerCalls.Load(), harness.node.openCount.Load(), harness.node.artifactCount.Load(), harness.node.toolCount.Load(), harness.executor.continueCount.Load(), harness.node.cleanupCount.Load(), harness.node.cancelCount.Load(), harness.bridge.pendingCount())
522:		if !errors.Is(err, errSingleRequestWorkStage) || strings.Contains(err.Error(), rawProviderSentinel) || calls.Load() != 1 || bridge.pendingCount() != 0 {
523:			t.Fatalf("err=%v calls=%d pending=%d", err, calls.Load(), bridge.pendingCount())
538:		if !errors.Is(err, errSingleRequestWorkStage) || strings.Contains(err.Error(), rawProviderSentinel) || calls.Load() != 1 || bridge.pendingCount() != 0 {
539:			t.Fatalf("err=%v calls=%d pending=%d", err, calls.Load(), bridge.pendingCount())
555:		if providerCalls.Load() != 1 || harness.node.toolCount.Load() != 0 || harness.executor.continueCount.Load() != 0 || harness.node.cancelCount.Load() != 0 || harness.node.cleanupCount.Load() != 1 || harness.bridge.pendingCount() != 0 {
556:			t.Fatalf("provider=%d tool=%d continuations=%d cancel=%d cleanup=%d pending=%d", providerCalls.Load(), harness.node.toolCount.Load(), harness.executor.continueCount.Load(), harness.node.cancelCount.Load(), harness.node.cleanupCount.Load(), harness.bridge.pendingCount())
578:		if providerCalls.Load() != 1 || harness.node.toolCount.Load() != 1 || harness.executor.continueCount.Load() != 0 || harness.node.cleanupCount.Load() != 1 || harness.bridge.pendingCount() != 0 {
579:			t.Fatalf("provider=%d tool=%d continuations=%d cleanup=%d pending=%d", providerCalls.Load(), harness.node.toolCount.Load(), harness.executor.continueCount.Load(), harness.node.cleanupCount.Load(), harness.bridge.pendingCount())
603:		if providerCalls.Load() != 1 || harness.node.toolCount.Load() != 1 || harness.executor.continueCount.Load() != 0 || harness.bridge.pendingCount() != 0 {
604:			t.Fatalf("provider=%d tool=%d continuations=%d pending=%d", providerCalls.Load(), harness.node.toolCount.Load(), harness.executor.continueCount.Load(), harness.bridge.pendingCount())
623:		if providerCalls.Load() != 2 || harness.node.toolCount.Load() != 1 || harness.executor.continueCount.Load() != 1 || harness.node.cleanupCount.Load() != 1 || harness.bridge.pendingCount() != 0 {
624:			t.Fatalf("provider=%d tool=%d continuations=%d cleanup=%d pending=%d", providerCalls.Load(), harness.node.toolCount.Load(), harness.executor.continueCount.Load(), harness.node.cleanupCount.Load(), harness.bridge.pendingCount())
657:		if providerCalls.Load() != 1 || harness.node.toolCount.Load() != 1 || harness.executor.continueCount.Load() != 0 || harness.node.cancelCount.Load() > 1 || harness.node.cleanupCount.Load() != 1 || harness.bridge.pendingCount() != 0 {
658:			t.Fatalf("provider=%d tool=%d continuations=%d cancel=%d pending=%d", providerCalls.Load(), harness.node.toolCount.Load(), harness.executor.continueCount.Load(), harness.node.cancelCount.Load(), harness.node.cleanupCount.Load(), harness.bridge.pendingCount())
693:			if !errors.Is(result.err, errSingleRequestWorkStage) || providerCalls.Load() != 1 || result.bridge.pendingCount() != 0 {
694:				t.Fatalf("err=%v provider=%d pending=%d", result.err, providerCalls.Load(), result.bridge.pendingCount())
741:		if providerCalls.Load() != 1 || harness.node.toolCount.Load() != 1 || harness.executor.continueCount.Load() != 0 || harness.node.cancelCount.Load() != 1 || harness.node.cleanupCount.Load() != 1 || harness.bridge.pendingCount() != 0 {
742:			t.Fatalf("provider=%d tool=%d continuations=%d cancel=%d cleanup=%d pending=%d", providerCalls.Load(), harness.node.toolCount.Load(), harness.executor.continueCount.Load(), harness.node.cancelCount.Load(), harness.node.cleanupCount.Load(), harness.bridge.pendingCount())
786:	if bridge.pendingCount() != 0 || len(ctrl.envelopes) != 5 {
787:		t.Fatalf("pending=%d envelopes=%+v", bridge.pendingCount(), ctrl.envelopes)
945:	if b.pendingCount() != 0 {
946:		t.Fatalf("pending=%d", b.pendingCount())
957:	if b.pendingCount() != 0 {
958:		t.Fatalf("pending after cancel=%d", b.pendingCount())
989:	if b.pendingCount() != 0 {
990:		t.Fatalf("pending=%d", b.pendingCount())
1025:	if successes != 1 || rejections != 1 || b.pendingCount() != 0 {
1026:		t.Fatalf("successes=%d rejections=%d pending=%d", successes, rejections, b.pendingCount())
1029:	if err != nil || result.ToolCallID != key.toolCallID || b.pendingCount() != 0 {
1030:		t.Fatalf("result=%+v err=%v pending=%d", result, err, b.pendingCount())
```

### 7. Production activation remains deferred

`bash -c 'set -euo pipefail; if rg --sort path -n "NewSingleRequestExecutor|SetSingleRequestExecutor" apps/edge/internal/input/manager.go; then exit 1; else test $? -eq 1; fi'`

```text
```

### 8. Formatting

`test -z "$(gofmt -d apps/edge/internal/openai/single_request_executor_test.go apps/edge/internal/openai/single_request_work_stage_test.go)"`

```text
```

### 9. Diff hygiene

`git diff --check`

```text
```

S12 external Claude/Mac qualification remains outside this deterministic test-only follow-up.

---

> **[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:
  - Nit (repaired) — `apps/edge/internal/openai/single_request_executor_test.go`: removed a verbose provider-body debug log from the concurrent isolation fixture.
  - Nit (repaired) — `apps/edge/internal/openai/single_request_work_stage_test.go`: removed an unused harness sequence field; each installed Node communicator already owns its atomic response sequence.
- Routing Signals:
  - `review_rework_count=3`
  - `evidence_integrity_failure=false`
- Next Step: Write `complete.log`, archive the active pair, and move the completed split task to the monthly task archive.
