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

# Typed-result collision barrier evidence

## For the Implementing Agent

Filling the implementation-owned sections of `CODE_REVIEW-cloud-G06.md` is the mandatory final step. Run every verification command, paste actual output, keep both active files in place, and report ready for review. Only the official code-review skill may append a verdict, archive files, write `complete.log`, or classify the next state. If blocked, record only the exact blocker, attempted commands/output, and resume condition in implementation-owned evidence fields; do not ask the user, call user-input tools, create control-plane stop files, change the selected owner/scope, archive logs, or write `complete.log`.

## Background

The shared-service follow-up now stores request-indexed PLAN and tool-request input, but its Node harness still returns the same empty typed success result for every request. Its barrier runs only after each result has already resumed the provider, so the passing test does not prove simultaneous colliding waiters or request-specific typed-result delivery. This follow-up replaces that remaining false-positive oracle without changing production behavior.

## 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.

## Finding Resolution Map

| Finding | Mode | Exact fix evidence | Changed precondition |
|---------|------|--------------------|----------------------|
| Required R1 | direct-fix | Make the shared Node harness capture immutable request-indexed tool requests and typed responses, hold every colliding request before returning any Node response, and resume each provider only after receiving distinct typed `Content` owned by that request. | The test will observe all colliding bridge waiters simultaneously and will fail if a request receives a peer typed result, if typed result content is absent, or if the provider succeeds from echoed tool-call arguments alone. |

## Analysis

### Files Read

- `apps/edge/internal/openai/single_request_executor.go`
- `apps/edge/internal/openai/single_request_executor_test.go`
- `apps/edge/internal/openai/single_request_work_stage.go`
- `apps/edge/internal/openai/single_request_work_stage_test.go`
- `apps/edge/internal/service/single_request_tool_types.go`
- `agent-spec/input/openai-compatible-surface.md`
- `agent-spec/runtime/edge-node-execution.md`
- `agent-contract/outer/anthropic-compatible-api.md`
- `agent-contract/inner/edge-node-runtime-wire.md`
- `agent-roadmap/phase/knowledge-tool-optimization-extension/PHASE.md`
- `agent-roadmap/phase/knowledge-tool-optimization-extension/milestones/iop-owned-single-request-agent-execution.md`
- `agent-roadmap/sdd/knowledge-tool-optimization-extension/iop-owned-single-request-agent-execution/SDD.md`

### SDD Criteria

- SDD: `agent-roadmap/sdd/knowledge-tool-optimization-extension/iop-owned-single-request-agent-execution/SDD.md`; status `[approved]`, lock released.
- Milestone contribution: `review-stage`; targeted Acceptance Scenario S10 and its Evidence Map row require deterministic Review pass/defect/repair and finalization evidence.
- The checklist requires one shared composite runtime, simultaneous request-local continuations, distinct typed Node results, and reviewer-owned terminal assertions so this packet can contribute trustworthy isolation evidence to S10. S12 external Claude/Mac qualification remains outside this packet.

### Verification Context

- Handoff source: Required R1 and routing signals from `code_review_cloud_G06_2.log`.
- Repository-native sources: Edge/testing domain rules, local Edge smoke rules, the approved SDD, matching specs/contracts, the composite executor, Work continuation body construction, and the shared Node test harness.
- Environment: current checkout, `go version go1.26.2 linux/arm64`; deterministic tests require no provider credential, model endpoint, remote runner, or external service.
- Fresh reviewer evidence: predecessor discovery, `go test -race ./apps/edge/internal/openai -run 'TestSingleRequest(Executor|WorkStage)' -count=1`, service compatibility, OpenAI vet/regression, structural guards, formatting, and diff checks exited zero.
- Gap: the Node handler stores WRITE request content at `single_request_work_stage_test.go:248`, returns an identical empty success response at `:254`, and the provider barrier at `single_request_executor_test.go:286` runs only after that response. The resumed body retains assistant tool-call arguments, so searching for `data-<request>` does not prove typed-result ownership.
- Confidence: high; the false-positive path is explicit in the harness and in `single_request_work_stage.go:222-225`, which serializes both the prior assistant call and the typed tool result into the resumed request.

### Test Coverage Gaps

- Simultaneous colliding continuation waiters before Node response release: not covered; the current barrier is after result delivery.
- Request-distinguishing typed Node result delivery: not covered; every response has the same success-only payload.
- Request-indexed PLAN artifact capture: covered and retained.
- Live success, post-registration failure, cancellation with an unaffected peer, and final zero waiter count: covered and retained.

### Symbol References

- No production symbol is renamed or removed.
- Test-only request/result evidence fields are confined to `single_request_work_stage_test.go` and `single_request_executor_test.go`.

### Split Judgment

Keep one compact test-only packet. The harness response capture and the shared-service collision fixture form one oracle; either change alone remains a false positive. Split predecessor `20` is satisfied by `agent-task/archive/2026/08/m-iop-owned-single-request-agent-execution/20+19_review_repair/complete.log`.

### Scope Rationale

Include only the shared Node test harness, the composite isolation fixture, and active review evidence. Exclude production executor/stage/service behavior, input-manager activation, spec/contract changes, generic error/cancel work, and S12 external qualification because Required R1 is solely a test-evidence defect.

### Final Routing

- `evaluation_mode=isolated-reassessment`; finalizer `finalize-task-policy.sh`, mode `pair`.
- Build closures `scope/context/verification/evidence/ownership/decision=true`; scores `1/2/0/2/1` => G06, base `local-fit`, final basis `recovery-boundary` because `review_rework_count=3` and `evidence_integrity_failure=true`; route `worker/cloud/G06`, `PLAN-cloud-G06.md`.
- Review closures `scope/context/verification/evidence/ownership/decision=true`; scores `1/2/0/2/1` => G06; route `official-review`, `review/cloud/G06`, `CODE_REVIEW-cloud-G06.md`.
- `large_indivisible_context=false`; positive loop risks `temporal_state`, `concurrent_consistency`, and `boundary_contract` (3); no capability gap.

## Implementation Checklist

- [ ] Make the shared Node harness capture immutable request-indexed tool requests and typed response payloads while preserving existing Work-stage assertions.
- [ ] 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.
- [ ] 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.
- [ ] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

### [REVIEW_REVIEW_REVIEW_API-1] Prove pre-response collision and typed-result ownership

**Problem**

At `apps/edge/internal/openai/single_request_work_stage_test.go:237`, the shared harness receives each workspace tool request, but at `:248` it names the WRITE input `resultsByRequest` and at `:254` returns the same empty success result for every request. At `apps/edge/internal/openai/single_request_executor_test.go:286`, the barrier is in the second provider dispatch, after the tool response has already crossed the service and bridge. The assertion at `:291` finds `data-<request>` in the retained assistant tool-call arguments, so it cannot detect a missing or crossed typed response.

**Solution**

Capture cloned request and response protobufs by immutable request ID in `workNodeHarness`. In the composite fixture, make both requests emit `workspace_read` with the literal `colliding-tool-id`; have the Node responder signal each arrival and block on one release channel before returning distinct `Content: []byte("typed-result-" + requestID)`. Wait for both arrivals, assert `pendingCount()==concurrency`, release the Node responses together, and require each resumed provider body to contain its matching PLAN and typed result while excluding peer values.

Before (`apps/edge/internal/openai/single_request_work_stage_test.go:237` and `apps/edge/internal/openai/single_request_executor_test.go:286`):

```go
h.resultsByRequest[reqID] = append([]byte(nil), req.GetWrite().GetContent()...)
return &iop.WorkspaceToolResponse{RequestId: req.GetRequestId(), Status: iop.WorkspaceStatus_WORKSPACE_STATUS_SUCCESS}

toolBarrierWg.Done()
toolBarrierWg.Wait()
if !strings.Contains(bodyStr, wantData) { /* fail */ }
```

After:

```go
nodeHarness.toolResponder = func(req *iop.WorkspaceToolRequest) *iop.WorkspaceToolResponse {
    toolArrived <- req.GetRequestId()
    <-releaseToolResponses
    return &iop.WorkspaceToolResponse{
        RequestId: req.GetRequestId(), StageId: req.GetStageId(), ToolCallId: req.GetToolCallId(),
        Status: iop.WorkspaceStatus_WORKSPACE_STATUS_SUCCESS,
        Content: []byte("typed-result-" + req.GetRequestId()),
    }
}
waitForAllToolArrivals(t, toolArrived, concurrency)
if got := executor.bridge.pendingCount(); got != concurrency { /* fail */ }
close(releaseToolResponses)
```

**Modified Files and Checklist**

- [ ] Update `apps/edge/internal/openai/single_request_work_stage_test.go` so `workNodeHarness` captures cloned tool requests and returned typed responses by request ID after any custom responder has produced the response.
- [ ] Update `apps/edge/internal/openai/single_request_executor_test.go` to block both live bridge waiters before response release, use distinct typed READ content, and assert exact per-request request/result/provider evidence.
- [ ] Fill `agent-task/m-iop-owned-single-request-agent-execution/21+20_single_request_executor/CODE_REVIEW-cloud-G06.md` with actual implementation and command evidence.

**Test Strategy**

Keep `TestSingleRequestExecutorConcurrentToolIsolation` as the regression name. Use exactly one shared `Service`, Node transport harness, and executor; at least two requests; the literal `colliding-tool-id`; a pre-response all-waiters barrier; distinct PLAN and typed READ content; immutable request/response maps; peer-exclusion checks; distinct reviewer outputs; and final `pendingCount()==0`. Preserve all existing Work-stage harness tests and terminal waiter cleanup cases. Run the focused fixture repeatedly under `-race` before the broader race set.

**Verification**

Run commands 2, 3, and 6 in Final Verification. The repeated focused race must pass, and the structural guard must find the request/response capture plus pre-response release controls while rejecting the obsolete request-input result oracle.

## Modified Files Summary

| File | Items |
|------|-------|
| `apps/edge/internal/openai/single_request_executor_test.go` | REVIEW_REVIEW_REVIEW_API-1 |
| `apps/edge/internal/openai/single_request_work_stage_test.go` | REVIEW_REVIEW_REVIEW_API-1 |
| `agent-task/m-iop-owned-single-request-agent-execution/21+20_single_request_executor/CODE_REVIEW-cloud-G06.md` | REVIEW_REVIEW_REVIEW_API-1 |

## Final Verification

Fresh Go test output is required; cached output is not acceptable.

1. `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))'` — prints exactly one predecessor completion path and exits zero.
2. `go test -race ./apps/edge/internal/openai -run '^TestSingleRequestExecutorConcurrentToolIsolation$' -count=20` — the pre-response collision and distinct typed-result oracle passes repeatedly without races.
3. `go test -race ./apps/edge/internal/openai -run 'TestSingleRequest(Executor|WorkStage)' -count=1` — composite lifecycle, terminal waiter cleanup, and Work fixtures pass without races.
4. `go test ./apps/edge/internal/service -run 'TestSingleRequest(InternalToolLoop|Cleanup|EnvelopeOrdering)' -count=1` — service lifecycle compatibility passes freshly.
5. `go vet ./apps/edge/internal/openai && go test ./apps/edge/internal/service ./apps/edge/internal/openai -count=1` — changed-path packages vet and regress cleanly.
6. `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'` — finds the typed request/response collision oracle and rejects the obsolete input-derived result/barrier fields.
7. `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'` — exits zero with no output while production activation remains deferred.
8. `test -z "$(gofmt -d apps/edge/internal/openai/single_request_executor_test.go apps/edge/internal/openai/single_request_work_stage_test.go)"` — both modified tests are formatted.
9. `git diff --check` — no whitespace errors.

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

After completing all code changes, fill implementation-owned sections in `CODE_REVIEW-*-G??.md`.
