← Back to Pull requests

fix(controller): refuse unmediated reconstruction replay #288

Merged
Tatsinnit merged 47 files (2248 lines) on Nov 22, 2026 01:00 UTC
View on GitHub
Tatsinnit Tatsinnit commented on Nov 19, 2026 22:24 UTC
Author

Summary

  • add an explicit mediated/unmediated harness class to HarnessDescriptor and the Go SPI

  • refuse reconstruction replay for explicitly unmediated or unknown classes before Harness.Run

  • bind remote reconstruction admission to the exact Harness.Connect stream before sending Start

  • reject the contradictory declaration UNMEDIATED + STATELESS_REPLAY before compute or journal effects

  • declare Claude Code unmediated while keeping raw Sessions.Replay and interrupted-turn Resume unchanged
  • Problem

    controller.Replay reconstructs completed executions by invoking the supplied harness against recorded effects. That is safe for a mediated harness because model completions and host-executed tool receipts come from the journal.

    An unmediated harness such as the Claude Code integration makes provider calls and runs tools from its own compute. Before this change, the class existed only in documentation. Pointing controller.Replay at a fresh Claude Code harness could therefore launch a real billed turn and repeat real tools before replay eventually diverged.

    The initial descriptor check alone is not enough for a remote harness: a load balancer can route Describe to a mediated replica and the later Connect to an unmediated one. The refusal must be bound to the exact stream that receives Start.

    Closes #248.

    Contract

    HarnessDescriptor.harness_class and api.Descriptor.HarnessClass now declare one of:

  • MEDIATED: every model call goes through the host model operation

  • UNMEDIATED: one or more model calls originate in harness compute

  • unspecified: compatibility behavior for harnesses built before this field, read as mediated
  • The declaration is trusted metadata, not attestation. A harness that claims mediated while calling a provider directly is still unmediated in fact. New harnesses should declare the class explicitly.

    An explicit unmediated class must also declare REQUIRES_MEMORY_SNAPSHOT. The host refuses any contradictory class/tier combination during admission, before provisioning compute, writing execution records, or invoking the harness.

    Reconstruction admission

    Controller.Replay now:

    1. verifies and projects the journal as before
    2. describes the supplied harness whenever at least one execution is selected
    3. checks every selected execution identity/version before the first run
    4. rejects UNMEDIATED and unknown classes before Harness.Run
    5. marks each replay invocation as reconstruction in an internal context value

    The context marker survives ordinary harness decorators that forward or derive from the supplied Run context. This avoids making the safety property depend on an optional interface exposed by the outermost wrapper.

    Raw Sessions.Replay remains a journal-only read and does not resolve or invoke a harness. Resume remains recovery, not reconstruction, and retains the existing unmediated interrupted-turn contract.

    Exact-stream wire check

    For reconstruction over Harness.Connect:

    1. the client opens the actual stream and sends an explicit ControllerFrame.reconstruction_probe with an empty envelope
    2. the server performs side-effect-free Describe and replies with EVENT_RECONSTRUCTION_INFO
    3. the client accepts mediated or compatibility-unspecified, and refuses unmediated, unknown, missing, or malformed metadata
    4. only an accepted stream receives Start

    The exchange is bounded to 10 seconds without extending an earlier caller deadline. Caller cancellation and transient transport failures retain their classifications; old or incompatible peers fail with ErrReconstructionUnsupported. Send-phase EOF is resolved through the final receive status so a transient outage is not mistaken for permanent incompatibility.

    EVENT_RECONSTRUCTION_INFO is transport-only. SQLite and the in-memory reference store refuse to journal it, and an occurrence after Start is rejected as a control event.

    Compatibility

  • The protobuf field, enum, message, and event kind are additive.

  • An omitted descriptor class keeps legacy mediated reconstruction behavior.

  • Older hosts ignore the declaration and cannot enforce this refusal.

  • Upgrade remote harness servers before hosts that reconstruct over Harness.Connect. Older harness servers still support live turns and recovery, but reconstruction from a new host fails closed.

  • Identity-less legacy reconstruction now requires a successful Describe; omission is accepted after that check.

  • Adding HarnessClass to the Go Descriptor means downstream unkeyed struct literals must become keyed.

  • Identity/version mismatch precedence is preserved ahead of class validation.
  • Implementations

  • echoagent, chatagent, toolagent, counteragent, and the Substrate example declare MEDIATED.

  • integrations/claudecode declares UNMEDIATED.

  • The Claude Code integration test reconstructs through a fresh wire harness and proves that zero Claude processes start.
  • Tests

    Coverage includes:

  • in-process mediated, omitted, unmediated, and unknown class handling

  • no harness, provider, tool, compute, or journal effects on refusal

  • descriptor round trips and unknown wire enum preservation

  • exact-stream refusal when mediated Describe and unmediated Connect reach different peers

  • the same routed-peer case through a harness decorator

  • old peers, malformed metadata, unknown classes, timeout, cancellation, transient status, and send EOF

  • transport-only journal rejection in both reference stores

  • class/tier contradiction and identity-mismatch precedence across Exec, Resume, Fork, and replay

  • a fresh Claude Code process path over real harnesswire
  • Verification

  • go test -race -shuffle=on ./api ./eventlog ./controller ./harnesswire ./conformance ./wire ./sqlitelog ./placement ./session ./harness/...

  • go test -race -shuffle=on ./... in integrations/claudecode

  • go test -race -shuffle=on ./... in integrations/substrate

  • go test ./... -skip ^TestDocumentedPythonExecutorLogsStorageFailureWithoutPayload$

  • go vet ./...

  • go build ./...

  • buf lint

  • buf breaking --against .git#ref=v0.4.0

  • generated protobuf and API-reference reproducibility check

  • go run ./hack/doccheck

  • go test ./hack/changelog and the staged changelog gate

  • python3 hack/verify_chain.py --golden

  • git diff --check and gofmt -l .
  • A focused security review of the final flow found no remaining actionable issues.

    The excluded root test is an existing macOS Python 3.9.6 portability failure: sqlite3.OperationalError.sqlite_errorname is unavailable and the documented executor safely logs OperationalError unknown, while the test requires SQLITE_ERROR. It reproduces on the unmodified base and is unrelated to this change.

    Diff: 2248 lines (+1826 / -422) across 47 files Reviewer: aramase Review duration: 3035m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.77) × (1 − Review Confidence (0.72)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.77 · 2248 lines diff across 47 files
    0.77
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.54 · 5 substantive comment(s)
    0.54
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    72%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    Mass File Touch mass_file_touch
    0.080
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    33 items
    Copilot Copilot commented on code on Nov 19, 2026 22:31 UTC
    Code Review
    harnesswire/harnesswire.go:1
    @@ -62,6 +66,24 @@ func (s *Server) Connect(stream v1.Harness_ConnectServer) error {
     	if err != nil {
     		return err
     	}
    +	if first.GetFrame() == nil && first.GetSession() == "" && first.GetExecutionId() == "" {
    +		desc, err := s.harness.Describe(stream.Context())

    When this server wraps a ClientHarness, the reconstruction probe is consumed here but the delegated Run receives an unmarked context, so the inner client sends Start without its own class handshake. If the inner Describe reaches a mediated replica and Connect reaches an unmediated one, reconstruction can repeat billed provider calls or tools. Track whether the probe was received, apply replayctx.WithReconstruction to the delegated run context, and add a two-hop routed-peer regression test.

    Copilot Copilot commented on code on Nov 19, 2026 22:31 UTC
    Code Review
    placement/model_policy.go:1
    @@ -63,6 +63,10 @@ func (p *Placer) ValidateModelPolicy(ctx context.Context) error {
     				"method", v1.Harness_Describe_FullMethodName, "error_kind", placementErrorKind(p.policyError), "error_category", "external")
     			return
     		}
    +		if err := api.ValidateDescriptor(desc); err != nil {
    +			p.policyError = err
    +			return

    With model policy enabled, registering an UNMEDIATED + STATELESS_REPLAY harness now returns ErrInvalidHarnessClass, but the shared registration status mapper does not handle it and reports INTERNAL. Add this sentinel to the FailedPrecondition case in session/harness_registry.go:458–459, so RegisterHarness/CreateHarness report an actionable descriptor refusal rather than a host failure.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 19, 2026 22:31 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🟡 Changes recommended

    The reconstruction probe is not propagated to delegated runs, risking repeated billed provider calls or tool execution, and invalid harness registration is incorrectly reported as an internal error.

    <details open>
    <summary><strong>2 open issues</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> Propagate reconstruction probe state to the delegated Run · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Map invalid harness class errors to FailedPrecondition · New

  • </details>

    <details>
    <summary><strong>3 files not reviewed</strong></summary>

    <ul>
    <li><strong><code>api/genpb/common.pb.go</code></strong>: Generated file</li>
    <li><strong><code>api/genpb/harness.pb.go</code></strong>: Generated file</li>
    <li><strong><code>api/genpb/harness_grpc.pb.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <details>
    <summary><strong>What changed in this PR</strong></summary>

    This PR addresses #248 by adding harness-class declarations and refusing unsafe reconstruction replay. It adds controller admission checks and a remote stream handshake while preserving raw journal replay and interrupted-turn recovery.

    Changes:

  • Add mediated/unmediated metadata and validate class/capability combinations.

  • Check remote reconstruction eligibility on the exact stream before sending Start.

  • Update harness declarations, journal protections, tests, and compatibility documentation.
  • | File | Description |
    | ---- | ----------- |
    | wire/​convert.go | Convert the reconstruction metadata event kind. |
    | sqlitelog/​sqlitelog.go | Reject reconstruction metadata from journal appends. |
    | sqlitelog/​approval_test.go | Test transport-only event rejection without state changes. |
    | spec.md | Define class declarations and reconstruction admission rules. |
    | session/​service.go | Map invalid class declarations to failed preconditions. |
    | session/​error_fork_test.go | Test Fork refusal for contradictory declarations. |
    | placement/​placement.go | Validate descriptors and classify admission failures. |
    | placement/​placement_test.go | Test descriptor refusal and mismatch precedence. |
    | placement/​model_policy.go | Validate class declarations during policy admission. |
    | internal/​replayctx/​replayctx.go | Carry reconstruction intent through contexts. |
    | integrations/​claudecode/​integration_test.go | Test reconstruction refusal before process startup. |
    | integrations/​claudecode/​claudecode.go | Declare Claude Code unmediated and update documentation. |
    | integrations/​claudecode/​claudecode_test.go | Verify the unmediated descriptor. |
    | harnesswire/​prepare_test.go | Test handshake admission, timeouts, and error classification. |
    | harnesswire/​harnesswire.go | Implement stream-bound class negotiation and conversion. |
    | harnesswire/​descriptor_version_test.go | Test class round trips and unknown-value handling. |
    | harness/​toolagent/​toolagent.go | Declare the tool harness mediated. |
    | harness/​toolagent/​toolagent_test.go | Verify its class declaration. |
    | harness/​echoagent/​echoagent.go | Declare the echo harness mediated. |
    | harness/​counteragent/​counteragent.go | Declare the counter harness mediated. |
    | harness/​chatagent/​chatagent.go | Declare the chat harness mediated. |
    | harness/​chatagent/​chatagent_test.go | Verify its class declaration. |
    | examples/​agentsuite-substrate/​agent/​agent.go | Declare the example harness mediated. |
    | eventlog/​eventlog.go | Reject reconstruction metadata from the in-memory journal. |
    | eventlog/​eventlog_test.go | Test rejection preserves journal state. |
    | docs/​security.md | Explain trusted declarations and stream-bound protection. |
    | docs/​harness-authoring.md | Document class declarations and context forwarding. |
    | docs/​concepts.md | Explain class metadata and replay compatibility. |
    | docs/​api-reference.md | Update the generated protocol reference. |
    | controller/​resume.go | Select recovery-specific harness checks. |
    | controller/​harness_identity.go | Enforce reconstruction class checks after identity validation. |
    | controller/​harness_identity_test.go | Test class admission and mismatch precedence. |
    | controller/​controller.go | Validate descriptors and mark reconstruction invocations. |
    | controller/​approval_effects.go | Validate descriptors used for approval handling. |
    | conformance/​wire_test.go | Test remote refusal and routed-peer protection. |
    | changelog/​unreleased/​unmediated-replay.md | Describe the security protections. |
    | changelog/​unreleased/​unmediated-replay-compat.md | Describe compatibility impacts and migration requirements. |
    | api/​types.go | Add the transport-only reconstruction event kind. |
    | api/​harness.proto | Add descriptor class metadata and handshake documentation. |
    | api/​harness.go | Define class types, validation, and error sentinels. |
    | api/​genpb/​harness.pb.go | Generate descriptor class bindings. |
    | api/​genpb/​harness_grpc.pb.go | Update generated service comments. |
    | api/​genpb/​common.pb.go | Generate class and reconstruction-event bindings. |
    | api/​common.proto | Define harness classes and reconstruction metadata. |
    </details>

    <sub>Review effort: Balanced</sub>

    Tatsinnit Tatsinnit commented on code on Nov 20, 2026 04:05 UTC
    Code Review
    harnesswire/harnesswire.go:1
    @@ -62,6 +66,24 @@ func (s *Server) Connect(stream v1.Harness_ConnectServer) error {
     	if err != nil {
     		return err
     	}
    +	if first.GetFrame() == nil && first.GetSession() == "" && first.GetExecutionId() == "" {
    +		desc, err := s.harness.Describe(stream.Context())

    Fixed in 94911f8. harnesswire.Server.Connect now records whether it consumed the reconstruction probe and reapplies replayctx.WithReconstruction to the stream-derived context before delegating Run, so an inner ClientHarness performs its own exact-stream class handshake before sending inner Start. Added TestWireReplayPropagatesClassCheckThroughDelegatingServer, which routes outer Describe through mediated descriptors, inner Connect to an unmediated peer, and asserts one inner stream-bound Describe and zero inner runs. Verified with the focused test at -count=10, the affected race/shuffle suite, and the full root suite excluding the known Python 3.9 baseline failure.

    Tatsinnit Tatsinnit commented on code on Nov 20, 2026 04:05 UTC
    Code Review
    placement/model_policy.go:1
    @@ -63,6 +63,10 @@ func (p *Placer) ValidateModelPolicy(ctx context.Context) error {
     				"method", v1.Harness_Describe_FullMethodName, "error_kind", placementErrorKind(p.policyError), "error_category", "external")
     			return
     		}
    +		if err := api.ValidateDescriptor(desc); err != nil {
    +			p.policyError = err
    +			return

    Fixed in 94911f8. The shared registration mapper now classifies api.ErrInvalidHarnessClass as FAILED_PRECONDITION, preserving the wrapped sentinel through withStatusCause. The model-policy registration table now covers both RegisterHarness and CreateHarness, asserts errors.Is(err, api.ErrInvalidHarnessClass), and verifies no immutable row is stored. Existing privacy, unavailable-peer, and model-policy cases remain covered and passing.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 20, 2026 04:09 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🔵 Needs a closer look

    A single receive can consume buffered metadata without reaching the terminal RPC error, causing cancellation to lose the original gRPC classification; receives must drain to a terminal error under the handshake timer, with regression coverage for queued metadata.

    No open issues 🎉

    <details>
    <summary><strong>1 previously missed issue</strong></summary>

    In code that hasn't changed since last review

    <details>
    <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Drain buffered stream events to preserve terminal gRPC status</summary>

    harnesswire/​harnesswire.go:539

    A single receive does not necessarily reach the final RPC status: a stream can have a buffered metadata event followed by an Unavailable error. In that case this receive succeeds, err remains io.EOF, and the stream is canceled before its terminal status is read, so callers lose the original gRPC classification. Drain receives until a terminal error under the existing handshake timer, and extend the send-EOF regression case to include a queued metadata event before the error.
    </details>
    </details>

    <details>
    <summary><strong>2 resolved since last review</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> Propagate reconstruction probe state to the delegated Run

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Map invalid harness class errors to FailedPrecondition

  • </details>

    <details>
    <summary><strong>3 files not reviewed</strong></summary>

    <ul>
    <li><strong><code>api/genpb/common.pb.go</code></strong>: Generated file</li>
    <li><strong><code>api/genpb/harness.pb.go</code></strong>: Generated file</li>
    <li><strong><code>api/genpb/harness_grpc.pb.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <sub>Review effort: Balanced</sub>

    aramase aramase commented on code on Nov 20, 2026 05:31 UTC
    Code Review
    harnesswire/harnesswire.go:1
    @@ -62,6 +66,26 @@ func (s *Server) Connect(stream v1.Harness_ConnectServer) error {
     	if err != nil {
     		return err
     	}
    +	reconstruction := false
    +	if first.GetFrame() == nil && first.GetSession() == "" && first.GetExecutionId() == "" {
    +		reconstruction = true
    +		desc, err := s.harness.Describe(stream.Context())
    +		if err != nil {
    +			return err

    A plain error from the probe's Describe goes out as gRPC Unknown. The client maps Unknown to ErrReconstructionUnsupported (line 578), because an old server's "first frame must be Start" rejection is also Unknown. So a new server whose Describe fails transiently is reported as not supporting reconstruction, logged as error_kind=reconstruction_unsupported, and a caller branching on the sentinels won't retry.

    To reproduce: make the second Describe return errors.New("backend temporarily down"). Replay then returns harness does not support reconstruction replay: ... code = Unknown. With status.Error(codes.Unavailable, ...) it returns reconstruction handshake failed, as it should.

    Could this branch keep a status the harness already set and wrap a plain error as Unavailable, so Unknown keeps meaning "older server"? Please also add a row (in TestPrepareReconstructionPreservesFailureClassification or a wire test) asserting ErrReconstructionHandshake for a plain Describe error.

    aramase aramase commented on code on Nov 20, 2026 05:31 UTC
    Code Review
    api/harness.proto:1
    @@ -143,7 +147,13 @@ service Harness {
       // Describe returns the static contract; used to match the harness to a runtime.
       rpc Describe(DescribeRequest) returns (HarnessDescriptor);
     
    -  // Connect drives ONE execution. The host sends Start (and optional control frames). Normally
    +  // Connect drives ONE execution. The host normally sends Start first (and optional control
    +  // frames). For reconstruction replay it first sends an empty ControllerFrame; a supporting
    +  // server answers with an EVENT_RECONSTRUCTION_INFO carrying the class of the exact harness that
    +  // will receive Start. The host sends Start only for MEDIATED or compatibility UNSPECIFIED. Older
    +  // servers close that probe without invoking the harness, so reconstruction fails closed rather
    +  // than sending Start.
    +  // Normally

    Nit: // Normally sits alone on this line, and it is copied into api/genpb/harness_grpc.pb.go. Could you reflow it?

    aramase aramase commented on code on Nov 20, 2026 05:31 UTC
    Code Review
    spec.md:1
    @@ -1569,13 +1576,25 @@ Exec's terminal status details survive after the first session frame, including
     ### 12.1 Describe
     
     - `WIRE-1`: `Describe` returns a `HarnessDescriptor`: `id`, `models`, `tools` (with default
    -  mediation), `capabilities`, and an opaque `version`. The host MUST bound `Describe` (10 seconds
    -  in the reference host, never extending an earlier caller deadline); a failure appends nothing.
    +  mediation), `capabilities`, an opaque `version`, and `harness_class`. The host MUST bound
    +  `Describe` (10 seconds in the reference host, never extending an earlier caller deadline); a
    +  failure appends nothing.
     - `WIRE-2`: `version` is owned by the harness author and MUST change when deterministic execution
       or config interpretation changes. It round-trips verbatim, including empty.
     - `WIRE-3`: On the wire, the host reads `RESUMABILITY_REQUIRES_MEMORY_SNAPSHOT` as that tier and
       every other value as `STATELESS_REPLAY`: `RESUMABILITY_UNSPECIFIED`, a number this host does not
       know, and an absent `capabilities` message.
    +- `WIRE-3a`: The host reads `HARNESS_CLASS_UNMEDIATED` as unmediated and
    +  `HARNESS_CLASS_UNSPECIFIED` as mediated for compatibility. Reconstruction replay MUST refuse
    +  `UNMEDIATED` and an unknown `HarnessClass` number before the first `Harness.Run`; it does not
    +  refuse `Exec` or recovery, and raw journal replay is unaffected. On `Harness.Connect`, the host

    Nit: §12.2 below still says "There is no protocol-version handshake" (line 1604), and its sequence diagram shows start as the first ControllerFrame (line 1611). Could it mention the reconstruction probe, or point here?

    docs/harness-authoring.md:450-454 also tells raw peers to implement the PARKED exchange but says nothing about the probe. One sentence there would help a server in another language: how a probe is recognized (frame unset, session and execution_id empty) and what to answer.

    It may also be worth saying here what a server returns when it can't determine its class.

    aramase aramase commented on code on Nov 20, 2026 05:31 UTC
    Code Review
    changelog/unreleased/unmediated-replay-compat.md:1
    @@ -0,0 +1,13 @@
    +---
    +category: Compatibility
    +---
    +
    +- `HarnessDescriptor.harness_class` is additive. An omitted class retains the legacy mediated

    Nit: "existing harnesses keep replaying" is broader than the rest of this fragment, which says older remote servers can't reconstruct. Could you limit it to in-process harnesses and upgraded servers, and give the rollout order: upgrade remote harness servers before hosts that reconstruct over Connect? examples/agentsuite-substrate/cmd/replay against a harness image built before this change is one caller that would hit this.

    aramase aramase commented on code on Nov 20, 2026 05:31 UTC
    Code Review
    placement/placement.go:1
    @@ -657,6 +667,8 @@ func controllerError(ctx context.Context, err error) error {
     		return describeError(ctx, err, errors.Is(err, context.DeadlineExceeded))
     	case errors.Is(err, controller.ErrHarnessPrepareFailed):
     		return prepareHarnessError(ctx, err)
    +	case errors.Is(err, api.ErrReconstructionHandshake):

    Nit: is this mapping reachable? Placement never calls controller.Replay, and the probe runs only under replayctx.WithReconstruction. I'd drop it, or add a test that reaches it.

    aramase aramase commented on code on Nov 20, 2026 05:31 UTC
    Code Review
    placement/placement_test.go:1
    @@ -260,6 +260,59 @@ func (memSnapshotHarness) Describe(context.Context) (api.Descriptor, error) {
     }
     func (memSnapshotHarness) Run(context.Context, *api.Start, api.EventSink) error { return nil }
     
    +type contradictoryClassHarness struct {
    +	runs *atomic.Int32
    +}
    +
    +func (h contradictoryClassHarness) Describe(context.Context) (api.Descriptor, error) {
    +	return api.Descriptor{ID: "invalid", HarnessClass: api.HarnessClassUnmediated,
    +		Capabilities: api.Capabilities{Resumability: api.ResumabilityStatelessReplay}}, nil
    +}
    +
    +func (h contradictoryClassHarness) Run(context.Context, *api.Start, api.EventSink) error {
    +	h.runs.Add(1)
    +	return nil
    +}
    +
    +func TestPlacerRejectsContradictoryUnmediatedDescriptorBeforeCompute(t *testing.T) {

    Nit: the name says "BeforeCompute", but the test checks head and runs, not that the backend never saw Create. The code is right (admit runs before Create). Asserting no Create would catch someone moving the check later.

    aramase aramase commented on code on Nov 20, 2026 05:31 UTC
    Code Review
    conformance/wire_test.go:1
    @@ -233,6 +237,151 @@ func TestWireNondeterministicReplay(t *testing.T) {
     	}
     }
     
    +type unmediatedReplayHarness struct {
    +	describes int
    +	runs      int
    +}
    +
    +func (h *unmediatedReplayHarness) Describe(context.Context) (api.Descriptor, error) {
    +	h.describes++
    +	return api.Descriptor{ID: "unmediated", Version: "1", HarnessClass: api.HarnessClassUnmediated,
    +		Capabilities: api.Capabilities{Resumability: api.ResumabilityRequiresMemorySnapshot}}, nil
    +}
    +
    +func (h *unmediatedReplayHarness) Run(ctx context.Context, _ *api.Start, sink api.EventSink) error {
    +	h.runs++
    +	return sink.Output(ctx, "reported output")
    +}
    +
    +func TestWireReplayRefusesUnmediatedHarnessBeforeConnect(t *testing.T) {
    +	s, _ := openFile(t)
    +	defer s.Close()
    +	log := s.Session("s")
    +	fence, err := log.NewFence()
    +	if err != nil {
    +		t.Fatal(err)
    +	}
    +	for i, event := range []api.Event{
    +		{ExecutionID: "turn", Kind: api.EventExecutionStart, ExecutionStart: &api.ExecutionStart{Harness: "unmediated", HarnessVersion: "1", InputCount: new(int64)}},
    +		{ExecutionID: "turn", Kind: api.EventOutput, Message: api.TextMessage("assistant", "reported output")},
    +		{ExecutionID: "turn", Kind: api.EventEnd, End: &api.HarnessEnd{State: "COMPLETED"}},
    +	} {
    +		if _, err := log.Append(int64(i), fence, event); err != nil {
    +			t.Fatal(err)
    +		}
    +	}
    +	h := &unmediatedReplayHarness{}
    +	remote := wireHarnessFrom(t, h)
    +	c, err := controller.New(log, nil)
    +	if err != nil {
    +		t.Fatal(err)
    +	}
    +	if _, err := c.Replay(t.Context(), remote); !errors.Is(err, controller.ErrReconstructionUnsupported) {
    +		t.Fatalf("wire Replay = %v; want ErrReconstructionUnsupported", err)
    +	}
    +	if h.runs != 0 {
    +		t.Fatalf("wire Replay opened Connect and ran the unmediated harness %d times", h.runs)
    +	}
    +	if h.describes != 1 {
    +		t.Fatalf("wire Replay Describe calls = %d, want preflight refusal before Connect", h.describes)
    +	}
    +}
    +
    +type routedClassClient struct {
    +	describe *v1.HarnessDescriptor
    +	connect  v1.HarnessClient
    +}
    +
    +type harnessDecorator struct {
    +	api.Harness
    +}
    +
    +func (h harnessDecorator) Describe(ctx context.Context) (api.Descriptor, error) {
    +	return h.Harness.Describe(ctx)
    +}
    +
    +func (h harnessDecorator) Run(ctx context.Context, start *api.Start, sink api.EventSink) error {
    +	return h.Harness.Run(ctx, start, sink)
    +}
    +
    +func (c routedClassClient) Describe(context.Context, *v1.DescribeRequest, ...grpc.CallOption) (*v1.HarnessDescriptor, error) {
    +	return c.describe, nil
    +}
    +
    +func (c routedClassClient) Connect(ctx context.Context, opts ...grpc.CallOption) (v1.Harness_ConnectClient, error) {
    +	return c.connect.Connect(ctx, opts...)
    +}
    +
    +func TestWireReplayBindsClassToConnectPeer(t *testing.T) {
    +	s, _ := openFile(t)
    +	defer s.Close()
    +	log := s.Session("s")
    +	fence, err := log.NewFence()
    +	if err != nil {
    +		t.Fatal(err)
    +	}
    +	for i, event := range []api.Event{
    +		{ExecutionID: "turn", Kind: api.EventExecutionStart, ExecutionStart: &api.ExecutionStart{Harness: "routed", HarnessVersion: "1", InputCount: new(int64)}},
    +		{ExecutionID: "turn", Kind: api.EventOutput, Message: api.TextMessage("assistant", "reported output")},
    +		{ExecutionID: "turn", Kind: api.EventEnd, End: &api.HarnessEnd{State: "COMPLETED"}},
    +	} {
    +		if _, err := log.Append(int64(i), fence, event); err != nil {
    +			t.Fatal(err)
    +		}
    +	}
    +
    +	unmediated := &unmediatedReplayHarness{}
    +	mediated := harnesswire.DescriptorToProto(api.Descriptor{ID: "routed", Version: "1", HarnessClass: api.HarnessClassMediated})
    +	remote := harnessDecorator{Harness: harnesswire.NewClientHarness(routedClassClient{describe: mediated, connect: wireHarnessClientFrom(t, unmediated)})}
    +	c, err := controller.New(log, nil)
    +	if err != nil {
    +		t.Fatal(err)
    +	}
    +	if _, err := c.Replay(t.Context(), remote); !errors.Is(err, controller.ErrReconstructionUnsupported) {
    +		t.Fatalf("routed Replay = %v; want stream-bound refusal", err)
    +	}
    +	if unmediated.runs != 0 {
    +		t.Fatalf("routed Replay ran unmediated Connect peer %d times", unmediated.runs)
    +	}
    +}
    +
    +func TestWireReplayPropagatesClassCheckThroughDelegatingServer(t *testing.T) {
    +	s, _ := openFile(t)
    +	defer s.Close()
    +	log := s.Session("s")
    +	fence, err := log.NewFence()
    +	if err != nil {
    +		t.Fatal(err)
    +	}
    +	for i, event := range []api.Event{
    +		{ExecutionID: "turn", Kind: api.EventExecutionStart, ExecutionStart: &api.ExecutionStart{Harness: "routed", HarnessVersion: "1", InputCount: new(int64)}},
    +		{ExecutionID: "turn", Kind: api.EventOutput, Message: api.TextMessage("assistant", "reported output")},
    +		{ExecutionID: "turn", Kind: api.EventEnd, End: &api.HarnessEnd{State: "COMPLETED"}},
    +	} {
    +		if _, err := log.Append(int64(i), fence, event); err != nil {
    +			t.Fatal(err)
    +		}
    +	}
    +
    +	unmediated := &unmediatedReplayHarness{}
    +	mediated := harnesswire.DescriptorToProto(api.Descriptor{ID: "routed", Version: "1", HarnessClass: api.HarnessClassMediated})
    +	inner := harnesswire.NewClientHarness(routedClassClient{describe: mediated, connect: wireHarnessClientFrom(t, unmediated)})
    +	outer := wireHarnessFrom(t, inner)
    +	c, err := controller.New(log, nil)
    +	if err != nil {
    +		t.Fatal(err)
    +	}
    +	if _, err := c.Replay(t.Context(), outer); err == nil {

    Nit: the describes and runs counts pin the inner probe, but err is only checked for non-nil. Could you assert errors.Is(err, api.ErrReconstructionUnsupported), or the status text, so the test shows the class check is what refused?

    aramase aramase requested changes on Nov 20, 2026 05:31 UTC
    Changes Requested Reviewer

    Thanks @Tatsinnit, this answers #248 well. The class on the descriptor, unset read as mediated, and binding the check to the exact Connect stream are all the right calls. I checked that buf breaking is clean against v0.4.0, that journals replay in both directions between main and this branch, that an old host works with a new server, and that a new host against an old server fails closed without sending Start.

    One must-fix: a supporting server whose Describe fails during the probe is reported as permanently unsupported (inline on harnesswire.go:74). The rest are small.

    A design question: the probe is an all-empty ControllerFrame, recognized by the absence of fields. Did you consider an explicit oneof member such as ReconstructionProbe probe = N in ControllerFrame.frame? It would describe itself and let a server tell a probe from a malformed empty frame. Once this is tagged, buf breaking and third-party servers lock in the meaning of the empty frame. Your choice is defensible, since an old server fails closed either way, but please say why in the spec.

    Tatsinnit Tatsinnit commented on code on Nov 20, 2026 06:49 UTC
    Code Review
    api/harness.proto:1
    @@ -143,7 +147,13 @@ service Harness {
       // Describe returns the static contract; used to match the harness to a runtime.
       rpc Describe(DescribeRequest) returns (HarnessDescriptor);
     
    -  // Connect drives ONE execution. The host sends Start (and optional control frames). Normally
    +  // Connect drives ONE execution. The host normally sends Start first (and optional control
    +  // frames). For reconstruction replay it first sends an empty ControllerFrame; a supporting
    +  // server answers with an EVENT_RECONSTRUCTION_INFO carrying the class of the exact harness that
    +  // will receive Start. The host sends Start only for MEDIATED or compatibility UNSPECIFIED. Older
    +  // servers close that probe without invoking the harness, so reconstruction fails closed rather
    +  // than sending Start.
    +  // Normally

    Fixed in fc02600. Reflowed the Harness.Connect comment and regenerated harness_grpc.pb.go plus the API reference; Normally no longer sits on its own line.

    Tatsinnit Tatsinnit commented on code on Nov 20, 2026 06:49 UTC
    Code Review
    conformance/wire_test.go:1
    @@ -233,6 +237,151 @@ func TestWireNondeterministicReplay(t *testing.T) {
     	}
     }
     
    +type unmediatedReplayHarness struct {
    +	describes int
    +	runs      int
    +}
    +
    +func (h *unmediatedReplayHarness) Describe(context.Context) (api.Descriptor, error) {
    +	h.describes++
    +	return api.Descriptor{ID: "unmediated", Version: "1", HarnessClass: api.HarnessClassUnmediated,
    +		Capabilities: api.Capabilities{Resumability: api.ResumabilityRequiresMemorySnapshot}}, nil
    +}
    +
    +func (h *unmediatedReplayHarness) Run(ctx context.Context, _ *api.Start, sink api.EventSink) error {
    +	h.runs++
    +	return sink.Output(ctx, "reported output")
    +}
    +
    +func TestWireReplayRefusesUnmediatedHarnessBeforeConnect(t *testing.T) {
    +	s, _ := openFile(t)
    +	defer s.Close()
    +	log := s.Session("s")
    +	fence, err := log.NewFence()
    +	if err != nil {
    +		t.Fatal(err)
    +	}
    +	for i, event := range []api.Event{
    +		{ExecutionID: "turn", Kind: api.EventExecutionStart, ExecutionStart: &api.ExecutionStart{Harness: "unmediated", HarnessVersion: "1", InputCount: new(int64)}},
    +		{ExecutionID: "turn", Kind: api.EventOutput, Message: api.TextMessage("assistant", "reported output")},
    +		{ExecutionID: "turn", Kind: api.EventEnd, End: &api.HarnessEnd{State: "COMPLETED"}},
    +	} {
    +		if _, err := log.Append(int64(i), fence, event); err != nil {
    +			t.Fatal(err)
    +		}
    +	}
    +	h := &unmediatedReplayHarness{}
    +	remote := wireHarnessFrom(t, h)
    +	c, err := controller.New(log, nil)
    +	if err != nil {
    +		t.Fatal(err)
    +	}
    +	if _, err := c.Replay(t.Context(), remote); !errors.Is(err, controller.ErrReconstructionUnsupported) {
    +		t.Fatalf("wire Replay = %v; want ErrReconstructionUnsupported", err)
    +	}
    +	if h.runs != 0 {
    +		t.Fatalf("wire Replay opened Connect and ran the unmediated harness %d times", h.runs)
    +	}
    +	if h.describes != 1 {
    +		t.Fatalf("wire Replay Describe calls = %d, want preflight refusal before Connect", h.describes)
    +	}
    +}
    +
    +type routedClassClient struct {
    +	describe *v1.HarnessDescriptor
    +	connect  v1.HarnessClient
    +}
    +
    +type harnessDecorator struct {
    +	api.Harness
    +}
    +
    +func (h harnessDecorator) Describe(ctx context.Context) (api.Descriptor, error) {
    +	return h.Harness.Describe(ctx)
    +}
    +
    +func (h harnessDecorator) Run(ctx context.Context, start *api.Start, sink api.EventSink) error {
    +	return h.Harness.Run(ctx, start, sink)
    +}
    +
    +func (c routedClassClient) Describe(context.Context, *v1.DescribeRequest, ...grpc.CallOption) (*v1.HarnessDescriptor, error) {
    +	return c.describe, nil
    +}
    +
    +func (c routedClassClient) Connect(ctx context.Context, opts ...grpc.CallOption) (v1.Harness_ConnectClient, error) {
    +	return c.connect.Connect(ctx, opts...)
    +}
    +
    +func TestWireReplayBindsClassToConnectPeer(t *testing.T) {
    +	s, _ := openFile(t)
    +	defer s.Close()
    +	log := s.Session("s")
    +	fence, err := log.NewFence()
    +	if err != nil {
    +		t.Fatal(err)
    +	}
    +	for i, event := range []api.Event{
    +		{ExecutionID: "turn", Kind: api.EventExecutionStart, ExecutionStart: &api.ExecutionStart{Harness: "routed", HarnessVersion: "1", InputCount: new(int64)}},
    +		{ExecutionID: "turn", Kind: api.EventOutput, Message: api.TextMessage("assistant", "reported output")},
    +		{ExecutionID: "turn", Kind: api.EventEnd, End: &api.HarnessEnd{State: "COMPLETED"}},
    +	} {
    +		if _, err := log.Append(int64(i), fence, event); err != nil {
    +			t.Fatal(err)
    +		}
    +	}
    +
    +	unmediated := &unmediatedReplayHarness{}
    +	mediated := harnesswire.DescriptorToProto(api.Descriptor{ID: "routed", Version: "1", HarnessClass: api.HarnessClassMediated})
    +	remote := harnessDecorator{Harness: harnesswire.NewClientHarness(routedClassClient{describe: mediated, connect: wireHarnessClientFrom(t, unmediated)})}
    +	c, err := controller.New(log, nil)
    +	if err != nil {
    +		t.Fatal(err)
    +	}
    +	if _, err := c.Replay(t.Context(), remote); !errors.Is(err, controller.ErrReconstructionUnsupported) {
    +		t.Fatalf("routed Replay = %v; want stream-bound refusal", err)
    +	}
    +	if unmediated.runs != 0 {
    +		t.Fatalf("routed Replay ran unmediated Connect peer %d times", unmediated.runs)
    +	}
    +}
    +
    +func TestWireReplayPropagatesClassCheckThroughDelegatingServer(t *testing.T) {
    +	s, _ := openFile(t)
    +	defer s.Close()
    +	log := s.Session("s")
    +	fence, err := log.NewFence()
    +	if err != nil {
    +		t.Fatal(err)
    +	}
    +	for i, event := range []api.Event{
    +		{ExecutionID: "turn", Kind: api.EventExecutionStart, ExecutionStart: &api.ExecutionStart{Harness: "routed", HarnessVersion: "1", InputCount: new(int64)}},
    +		{ExecutionID: "turn", Kind: api.EventOutput, Message: api.TextMessage("assistant", "reported output")},
    +		{ExecutionID: "turn", Kind: api.EventEnd, End: &api.HarnessEnd{State: "COMPLETED"}},
    +	} {
    +		if _, err := log.Append(int64(i), fence, event); err != nil {
    +			t.Fatal(err)
    +		}
    +	}
    +
    +	unmediated := &unmediatedReplayHarness{}
    +	mediated := harnesswire.DescriptorToProto(api.Descriptor{ID: "routed", Version: "1", HarnessClass: api.HarnessClassMediated})
    +	inner := harnesswire.NewClientHarness(routedClassClient{describe: mediated, connect: wireHarnessClientFrom(t, unmediated)})
    +	outer := wireHarnessFrom(t, inner)
    +	c, err := controller.New(log, nil)
    +	if err != nil {
    +		t.Fatal(err)
    +	}
    +	if _, err := c.Replay(t.Context(), outer); err == nil {

    Fixed in fc02600 using the wire-visible alternative you suggested. The outer hop intentionally does not serialize Go sentinels, so the two-hop test now requires the remote error text to contain both the ErrReconstructionUnsupported message and UNMEDIATED, plus exactly one inner Describe and zero inner Runs.

    Tatsinnit Tatsinnit commented on code on Nov 20, 2026 06:49 UTC
    Code Review
    placement/placement.go:1
    @@ -657,6 +667,8 @@ func controllerError(ctx context.Context, err error) error {
     		return describeError(ctx, err, errors.Is(err, context.DeadlineExceeded))
     	case errors.Is(err, controller.ErrHarnessPrepareFailed):
     		return prepareHarnessError(ctx, err)
    +	case errors.Is(err, api.ErrReconstructionHandshake):

    Agreed; this mapping was unreachable because placement drives only Exec/Resume and reconstruction handshakes are selected only from the replay context. Removed it in fc02600. Existing placement Describe/Prepare mappings remain unchanged and covered.

    Tatsinnit Tatsinnit commented on code on Nov 20, 2026 06:49 UTC
    Code Review
    changelog/unreleased/unmediated-replay-compat.md:1
    @@ -0,0 +1,13 @@
    +---
    +category: Compatibility
    +---
    +
    +- `HarnessDescriptor.harness_class` is additive. An omitted class retains the legacy mediated

    Fixed in fc02600. The compatibility fragment now limits legacy omission behavior to in-process harnesses and upgraded remote servers, and states the rollout order explicitly: upgrade remote harness servers before hosts that reconstruct over Harness.Connect. Older servers remain usable for live turns and recovery but fail closed for reconstruction from a new host.

    Tatsinnit Tatsinnit commented on code on Nov 20, 2026 06:49 UTC
    Code Review
    harnesswire/harnesswire.go:1
    @@ -62,6 +66,26 @@ func (s *Server) Connect(stream v1.Harness_ConnectServer) error {
     	if err != nil {
     		return err
     	}
    +	reconstruction := false
    +	if first.GetFrame() == nil && first.GetSession() == "" && first.GetExecutionId() == "" {
    +		reconstruction = true
    +		desc, err := s.harness.Describe(stream.Context())
    +		if err != nil {
    +			return err

    Legitimate and fixed in fc02600. A supporting server now preserves any explicit gRPC status from probe-time Describe, but converts a plain Go error to fixed-text UNAVAILABLE so it cannot collide with the old-server UNKNOWN unsupported signal or leak backend details. TestWireReplayProbeDescribeFailureIsTransient covers both a redacted plain error and preservation of an explicit RESOURCE_EXHAUSTED status, with two Describes and zero Runs.

    Tatsinnit Tatsinnit commented on code on Nov 20, 2026 06:49 UTC
    Code Review
    spec.md:1
    @@ -1569,13 +1576,25 @@ Exec's terminal status details survive after the first session frame, including
     ### 12.1 Describe
     
     - `WIRE-1`: `Describe` returns a `HarnessDescriptor`: `id`, `models`, `tools` (with default
    -  mediation), `capabilities`, and an opaque `version`. The host MUST bound `Describe` (10 seconds
    -  in the reference host, never extending an earlier caller deadline); a failure appends nothing.
    +  mediation), `capabilities`, an opaque `version`, and `harness_class`. The host MUST bound
    +  `Describe` (10 seconds in the reference host, never extending an earlier caller deadline); a
    +  failure appends nothing.
     - `WIRE-2`: `version` is owned by the harness author and MUST change when deterministic execution
       or config interpretation changes. It round-trips verbatim, including empty.
     - `WIRE-3`: On the wire, the host reads `RESUMABILITY_REQUIRES_MEMORY_SNAPSHOT` as that tier and
       every other value as `STATELESS_REPLAY`: `RESUMABILITY_UNSPECIFIED`, a number this host does not
       know, and an absent `capabilities` message.
    +- `WIRE-3a`: The host reads `HARNESS_CLASS_UNMEDIATED` as unmediated and
    +  `HARNESS_CLASS_UNSPECIFIED` as mediated for compatibility. Reconstruction replay MUST refuse
    +  `UNMEDIATED` and an unknown `HarnessClass` number before the first `Harness.Run`; it does not
    +  refuse `Exec` or recovery, and raw journal replay is unaffected. On `Harness.Connect`, the host

    Legitimate and fixed in fc02600. §12.2 now points to the reconstruction-only probe and the sequence diagram shows probe/metadata before Start. The raw-peer guide documents the explicit ControllerFrame.reconstruction_probe, empty envelope, required EVENT_RECONSTRUCTION_INFO, waiting for Start, and non-OK behavior when class cannot be determined. I also adopted the explicit oneof design: it distinguishes a probe from a malformed empty frame and gives non-Go servers a stable discriminator; TestEmptyFrameIsNotAReconstructionProbe pins that decision.

    Tatsinnit Tatsinnit commented on code on Nov 20, 2026 06:49 UTC
    Code Review
    placement/placement_test.go:1
    @@ -260,6 +260,59 @@ func (memSnapshotHarness) Describe(context.Context) (api.Descriptor, error) {
     }
     func (memSnapshotHarness) Run(context.Context, *api.Start, api.EventSink) error { return nil }
     
    +type contradictoryClassHarness struct {
    +	runs *atomic.Int32
    +}
    +
    +func (h contradictoryClassHarness) Describe(context.Context) (api.Descriptor, error) {
    +	return api.Descriptor{ID: "invalid", HarnessClass: api.HarnessClassUnmediated,
    +		Capabilities: api.Capabilities{Resumability: api.ResumabilityStatelessReplay}}, nil
    +}
    +
    +func (h contradictoryClassHarness) Run(context.Context, *api.Start, api.EventSink) error {
    +	h.runs.Add(1)
    +	return nil
    +}
    +
    +func TestPlacerRejectsContradictoryUnmediatedDescriptorBeforeCompute(t *testing.T) {

    Fixed in fc02600. The test now wraps the real local backend with a Create counter and asserts creates == 0 alongside an unchanged journal and zero harness runs, so moving descriptor validation after allocation will fail the test.

    Tatsinnit Tatsinnit commented on Nov 20, 2026 06:50 UTC
    Author

    Follow-up fc02600 also addresses Copilot's non-inline buffered-status finding: when probe Send returns io.EOF, the client now drains all queued events until the terminal RPC status under the existing handshake timeout. The regression queues EVENT_RECONSTRUCTION_INFO before terminal UNAVAILABLE, and a second case proves a buffered drain that never terminates is canceled with ErrReconstructionHandshake/DeadlineExceeded.

    The protocol probe is now an explicit additive ControllerFrame.reconstruction_probe oneof member rather than an all-empty frame. An empty frame remains malformed; old servers discard the unknown field and fail closed before Run.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 20, 2026 06:55 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🔵 Needs a closer look

    The prepared-run API bypasses the reconstruction handshake, allowing routed-peer mismatches to send Start without a probe and potentially repeat billed calls or tool executions.

    No open issues 🎉

    <details>
    <summary><strong>1 previously missed issue</strong></summary>

    In code that hasn't changed since last review

    <details>
    <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> Prepared runs bypass reconstruction handshake for marked contexts</summary>

    harnesswire/​harnesswire.go:515

    A decorator that forwards the reconstruction context through PrepareRun(ctx) and then prepared.Run(ctx, ...) bypasses this handshake, because neither prepared-run method checks the marker. If Describe reaches a mediated replica but Connect reaches an unmediated one, the prepared run sends Start without a probe and can repeat billed calls or tools. Make PrepareRun route marked contexts through prepareReconstruction, and add a routed-peer regression test using a decorator that delegates through the prepared-run API.
    </details>
    </details>

    <details>
    <summary><strong>3 files not reviewed</strong></summary>

    <ul>
    <li><strong><code>api/genpb/common.pb.go</code></strong>: Generated file</li>
    <li><strong><code>api/genpb/harness.pb.go</code></strong>: Generated file</li>
    <li><strong><code>api/genpb/harness_grpc.pb.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <sub>Review effort: Balanced</sub>

    Tatsinnit Tatsinnit commented on Nov 20, 2026 07:22 UTC
    Author

    @aramase, re: the design question in your review:

    Thanks, I considered both forms. I initially used the empty frame because an old server fails closed either way, but I agree that giving an otherwise malformed frame implicit protocol meaning would create an ambiguous contract for third-party implementations.

    I changed this in fc02600 to an explicit additive oneof member:

    ReconstructionProbe reconstruction_probe = 9;
    

    A supporting server now recognizes only that member, requires an empty session and execution_id, returns EVENT_RECONSTRUCTION_INFO, and waits for Start. An all-empty ControllerFrame remains malformed.

    This retains the rolling-upgrade behavior: an old server ignores the unknown field, sees no Start, and fails closed without invoking the harness. It also gives non-Go implementations a stable, self-describing discriminator before Buf and third-party implementations lock in the contract.

    The rationale and exchange are documented in WIRE-3a and WIRE-4, including the sequence diagram and raw-peer guidance. TestEmptyFrameIsNotAReconstructionProbe pins the malformed-empty-frame behavior. buf breaking remains clean against v0.4.0.

    I also addressed the must-fix: probe-time Describe now preserves explicit gRPC statuses and maps plain errors to fixed-text UNAVAILABLE, so a transient supporting-server failure is not misclassified as permanently unsupported. The regression covers redaction of plain backend details, preservation of explicit status, and zero harness runs.

    aramase aramase commented on code on Nov 20, 2026 07:36 UTC
    Code Review
    spec.md:1
    @@ -868,7 +871,8 @@ cannot observe a model call that does not reach it. The class concerns model cal
       egress. An agent CLI that calls its provider itself, such as Claude Code, is an example.
     - `EXE-38`: An unmediated harness MUST declare `REQUIRES_MEMORY_SNAPSHOT` (§13.1). Its conversation
       state lives in its compute, and the log, which holds no record of the model calls it makes outside
    -  the model call operation, cannot rebuild that state.
    +  the model call operation, cannot rebuild that state. The reference host rejects an explicitly
    +  `UNMEDIATED` descriptor with any other tier before compute, journal writes or `Harness.Run`.

    This says the reference host refuses an explicitly UNMEDIATED descriptor with any other tier before journal writes, but APR-13's call-only repair still writes first.

    To reproduce: seed EXECUTION_START and a REQUIRES_APPROVAL TOOL_CALL (no APPROVAL_REQUEST) on a harness that now describes itself as UNMEDIATED + STATELESS_REPLAY, then call Resume. It returns ErrApprovalParked, appends one APPROVAL_REQUEST, and makes no Describe call (placement/placement.go:1208-1218, reached from :1264-1271). Only the Resume after a decision goes through admission and returns ErrInvalidHarnessClass, still without compute or Run.

    APR-13 requires that repair to run without runtime IO (and TestApprovalRepairCASAndSharedGuard pins zero Describes), so the code is right and the sentence is too broad. Could you narrow it? Something like: "...before compute or Harness.Run, and before any record of an execution it would start. An APR-13 call-only repair, which runs without admission, can still append APPROVAL_REQUEST; admission after the decision refuses the descriptor." A placement test of that sequence would pin it, but that's optional.

    aramase aramase requested changes on Nov 20, 2026 07:36 UTC
    Changes Requested Reviewer

    Thanks @Tatsinnit. Switching the probe to an explicit ReconstructionProbe member answers the design question, and keeping the all-empty frame malformed (with TestEmptyFrameIsNotAReconstructionProbe pinning it) is the right contract for other implementations. The round-one must-fix and nits are resolved too: a failed Describe during the probe now comes back as Unavailable and is classified as a handshake error. I re-checked buf breaking against v0.4.0, the schema-v4 fixture on base, main and head, and that it still merges cleanly with main.

    One must-fix, inline on spec.md: the new EXE-38 sentence promises more than the host does on the APR-13 call-only repair path. I don't think the code should change there; narrowing the sentence is enough.

    Tatsinnit Tatsinnit commented on code on Nov 20, 2026 10:08 UTC
    Code Review
    spec.md:1
    @@ -868,7 +871,8 @@ cannot observe a model call that does not reach it. The class concerns model cal
       egress. An agent CLI that calls its provider itself, such as Claude Code, is an example.
     - `EXE-38`: An unmediated harness MUST declare `REQUIRES_MEMORY_SNAPSHOT` (§13.1). Its conversation
       state lives in its compute, and the log, which holds no record of the model calls it makes outside
    -  the model call operation, cannot rebuild that state.
    +  the model call operation, cannot rebuild that state. The reference host rejects an explicitly
    +  `UNMEDIATED` descriptor with any other tier before compute, journal writes or `Harness.Run`.

    Legitimate and fixed in 0fe0504. I narrowed EXE-38 rather than changing the correct APR-13 sequencing: the host refuses the contradictory descriptor before compute/Run and before records for an execution it would start; an ordinary call-only repair may append APPROVAL_REQUEST without admission, while a memory-capable override performs its override admission before repair. The existing TestRegistryResumeRefusesAMemoryOverrideTurn and TestApprovalRepairCASAndSharedGuard pin those two paths.

    Tatsinnit Tatsinnit commented on Nov 20, 2026 10:08 UTC
    Author

    Thank you for this!! The copilot's prepared-run bypass finding was legitimate and is fixed in 0fe0504. ClientHarness.PrepareRun now checks the reconstruction context itself and routes marked calls through prepareReconstruction; ClientHarness.Run uses that single preparation path. This covers decorators that forward HarnessRunPreparer and call prepared.Run directly, not just decorators that delegate ordinary Run.

    TestWireReplayBindsClassThroughPreparedRunDecorator reproduces the routed-peer mismatch through the prepared-run API and requires ErrReconstructionUnsupported, exactly one inner class Describe, and zero inner Runs. The authoring guide now explicitly requires wrappers to pass the supplied context to PrepareRun as well as Run. ❤️

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 20, 2026 10:14 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🔵 Needs a closer look

    Human assessment is needed because an unpublished critical finding indicates the server can execute a harness with an unknown class, violating WIRE-3a.

    No open issues 🎉

    <details>
    <summary><strong>3 files not reviewed</strong></summary>

    <ul>
    <li><strong><code>api/genpb/common.pb.go</code></strong>: Generated file</li>
    <li><strong><code>api/genpb/harness.pb.go</code></strong>: Generated file</li>
    <li><strong><code>api/genpb/harness_grpc.pb.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <sub>Review effort: Balanced</sub>

    aramase aramase commented on code on Nov 22, 2026 00:59 UTC
    Code Review
    harnesswire/harnesswire.go:1
    @@ -62,6 +66,31 @@ func (s *Server) Connect(stream v1.Harness_ConnectServer) error {
     	if err != nil {
     		return err
     	}
    +	reconstruction := first.GetReconstructionProbe() != nil
    +	if reconstruction {
    +		if first.GetSession() != "" || first.GetExecutionId() != "" {
    +			return status.Error(grpccodes.InvalidArgument, "harnesswire: reconstruction probe must have an empty envelope")
    +		}
    +		desc, err := s.harness.Describe(stream.Context())
    +		if err != nil {
    +			if _, ok := status.FromError(err); !ok {
    +				return status.Error(grpccodes.Unavailable, "harnesswire: describe harness for reconstruction failed")
    +			}
    +			return err
    +		}
    +		if err := stream.Send(&v1.Event{
    +			Kind: v1.EventKind_EVENT_RECONSTRUCTION_INFO,
    +			Body: &v1.Event_ReconstructionInfo{ReconstructionInfo: &v1.ReconstructionInfo{
    +				HarnessClass: harnessClassToProto(desc.HarnessClass),

    nit: When desc.HarnessClass has no wire mapping, this sends -1 and then accepts Start, so the server only meets WIRE-3a's "cannot determine its class ... MUST NOT accept Start" if the host behaves. Could this return status.Error(codes.FailedPrecondition, ...) before sending INFO? The client already maps that to ErrReconstructionUnsupported. A raw-stream test asserting a non-OK status and zero Run calls would pin it. The bundled host already refuses here, so this isn't blocking.

    aramase aramase commented on Nov 22, 2026 00:59 UTC
    Reviewer

    One non-blocking nit inline; approving separately.

    aramase aramase approved these changes on Nov 22, 2026 01:00 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    Tatsinnit Tatsinnit
    Labels
    risk: low confidence: 72.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 76.5% (HIGH) · Higher = larger blast radius
    76.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 72.5% · Lower = rushed or shallow review
    72.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 21.1% · Safe to merge
    21.1%