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

# Shared-service composite isolation 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 prior follow-up added live waiter cleanup cases, but its concurrency fixture still isolates each request in a separate `Service` and Node harness. Its final output is synthesized from the tunnel session ID, so the test passes without proving that one shared runtime preserves each request's PLAN artifact and typed tool result. This follow-up replaces that ineffective 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_1.log` defines the attempted test-only R1 repair and its verification contract.
- `agent-task/m-iop-owned-single-request-agent-execution/21+20_single_request_executor/code_review_cloud_G06_1.log` records `FAIL` with Required R1: the concurrent fixture creates one service/harness per request and asserts only a session-derived final string, leaving shared artifact and typed-result isolation unproved.
- Fresh reviewer runs passed the predecessor check, focused executor race tests, service compatibility, OpenAI vet/regression, fixture/activation guards, formatting, and `git diff --check`; the failure is the missing behavioral oracle, not a command failure.

## Finding Resolution Map

| Finding | Mode | Exact fix evidence | Changed precondition |
|---------|------|--------------------|----------------------|
| Required R1 | direct-fix | Make the shared workspace test harness retain PLAN artifacts and typed tool evidence by request ID, then run all colliding executor requests through one `Service`, one Node transport, and one shared executor while asserting those maps and provider continuation bodies. | The race test will exercise shared state and will fail if a colliding continuation, PLAN artifact, typed result, or reviewer output crosses request ownership. |

## 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`
- `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 shared-service race oracle must prove that concurrent Plan/Work/Review requests retain request-local artifacts and typed continuations before the composite evidence can contribute 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_1.log`.
- Repository-native sources: Edge/testing domain rules, local Edge smoke rules, the approved SDD, matching specs/contracts, the composite executor, the Work continuation bridge, and their tests.
- Environment: current checkout, `go version go1.26.2 linux/arm64`; deterministic package tests need no provider credential, model endpoint, remote runner, or external service.
- Fresh reviewer evidence: predecessor resolution, focused executor race tests, service compatibility, OpenAI vet/regression, structural guards, formatting, and diff checks exited zero.
- Gap: the passing concurrency test creates a separate service and Node harness inside each goroutine and never checks request-indexed artifact or typed-result evidence.
- Confidence: high; the missing oracle is directly visible at `single_request_executor_test.go:304` and `:327`, and the single-slot harness is visible at `single_request_work_stage_test.go:190` and `:214`.

### Test Coverage Gaps

- Shared-service concurrent PLAN artifact isolation: not covered; each current request owns a separate harness.
- Shared typed tool-result isolation under a colliding tool-call ID: not covered; the resumed provider response does not depend on the typed result body.
- Request-specific reviewer terminal output: superficially asserted, but currently derived directly from `SessionID` and therefore cannot expose continuation crossover.
- Live waiter cleanup on success, post-registration failure, and cancellation with an unaffected peer: covered by `TestSingleRequestExecutorTerminalWaiterCleanup` and retained.

### Symbol References

- No production symbol is renamed or removed.
- Test-only `workNodeHarness.plan` and `workNodeHarness.result` consumers are confined to `single_request_work_stage_test.go` and the executor harness construction.

### Split Judgment

Keep one compact test-only packet. Request-indexed harness storage and the shared-service concurrency oracle form one indivisible test invariant; either half alone still permits a false-positive isolation result.

### Scope Rationale

Include only the shared workspace test harness and composite executor tests. Exclude production executor/stage/service behavior, input-manager activation, spec/contract updates, generic error/cancel work, and S12 external qualification because Required R1 is solely an evidence-quality 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=2` 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

- [ ] Replace the per-request concurrency setup with one shared `Service`, Node transport harness, and executor, and hold all colliding tool calls at a deterministic barrier before releasing typed responses.
- [ ] Store PLAN artifacts and workspace tool evidence by request ID, require each resumed provider request to contain its matching plan and typed result, and assert every request's artifact, tool call/result, and reviewer-approved output.
- [ ] Retain the live success, post-registration failure, and cancellation waiter-cleanup cases and run the dependency, focused 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_API-1] Prove shared-service request isolation

**Problem**

At `apps/edge/internal/openai/single_request_executor_test.go:304`, each concurrent goroutine calls `newTestServiceHarness`, so requests never share the service or Node artifact store used in production. At `apps/edge/internal/openai/single_request_executor_test.go:327`, the only request-specific assertion compares output generated directly from `req.Tunnel.SessionID`. The helper at `apps/edge/internal/openai/single_request_work_stage_test.go:190` stores one unkeyed PLAN and its default tool response at `:227` carries no request-distinguishing payload, so the test neither observes nor rejects artifact/result crossover.

**Solution**

Run the concurrent requests through one service and one Node transport. Change the test harness to keep PLAN and workspace-result evidence in mutex-protected request-indexed maps. Block all concurrent tool requests after their `colliding-tool-id` waiters are registered, return a request-specific typed read result, and make the resumed Work provider response conditional on seeing both the matching PLAN and typed result. Assert the exact artifact, tool request/result, final output, and zero pending waiter for every request.

Before (`apps/edge/internal/openai/single_request_executor_test.go:300`):

```go
for i := 0; i < concurrency; i++ {
    go func(id int) {
        svc, binding, _ := newTestServiceHarness(t, executor)
        // The final output is derived from the request session only.
    }(i)
}
```

After:

```go
svc, binding, node := newTestServiceHarness(t, executor)
node.requireConcurrentTools(concurrency)
for i := 0; i < concurrency; i++ {
    go runRequestThroughSharedService(svc, binding, i)
}
assertRequestIndexedArtifactsResultsAndOutputs(t, node, results)
```

**Modified Files and Checklist**

- [ ] Update `apps/edge/internal/openai/single_request_work_stage_test.go` so `workNodeHarness` stores and reads PLAN/result evidence by immutable request ID without weakening its existing Work-stage assertions.
- [ ] Update `apps/edge/internal/openai/single_request_executor_test.go` to reuse one service/harness, synchronize colliding waiters, require matching provider continuation content, and assert request-indexed 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 at least two concurrent requests, one shared service/Node transport/executor, the literal `colliding-tool-id`, a deterministic all-waiters barrier, distinct PLAN contents, distinct typed read results, distinct reviewer outputs, and explicit request-indexed map assertions. Retain `TestSingleRequestExecutorTerminalWaiterCleanup` unchanged except for harness API adaptations. Run executor and Work-stage fixtures under `-race` so the request-indexed helper is also checked for data races.

**Verification**

Run the focused race and structural guard in Final Verification. The race must fail if any request consumes another request's plan/result, and the guard must show the shared request-indexed oracle while preserving the no-direct-`clearRequest` condition.

## Modified Files Summary

| File | Items |
|------|-------|
| `apps/edge/internal/openai/single_request_executor_test.go` | REVIEW_REVIEW_API-1 |
| `apps/edge/internal/openai/single_request_work_stage_test.go` | 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_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 'TestSingleRequest(Executor|WorkStage)' -count=1` — shared-service composite isolation, live terminal waiter cleanup, and the request-indexed Work harness pass without races.
3. `go test ./apps/edge/internal/service -run 'TestSingleRequest(InternalToolLoop|Cleanup|EnvelopeOrdering)' -count=1` — service lifecycle compatibility passes freshly.
4. `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.
5. `bash -c 'set -euo pipefail; rg --sort path -n "TestSingleRequestExecutorConcurrentToolIsolation|plansByRequest|resultsByRequest|colliding-tool-id|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 "bridge\\.clearRequest" apps/edge/internal/openai/single_request_executor_test.go; then exit 1; else test $? -eq 1; fi'` — finds the shared request-indexed isolation oracle and no direct cleanup-helper call.
6. `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.
7. `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.
8. `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`.
