← Back to Pull requests

fix(harnesswire): prepare Connect before journaling #282

Open
unknown opened this pull request with 620 lines diff across 7 files
View on GitHub
unknown unknown commented on Nov 17, 2026 05:40 UTC
Author

Summary

  • open the actual Harness.Connect stream before recording a new execution, without sending Start

  • leave no execution records when Connect setup fails, so the same session can retry its first turn

  • preserve fail-closed behavior once Send(Start) is attempted: send/receive failures remain durable and visible in later history

  • make terminal wire handling strict: clean EOF before EVENT_END, unsupported events, and frames after END fail the execution
  • Problem

    controller.Exec records EXECUTION_START and every INPUT before calling Harness.Run. For harnesswire.ClientHarness, Run previously opened Harness.Connect only after those records committed.

    If the first Connect failed, no Start reached the harness, but the next Exec still received the failed execution in Start.History. Claude Code conservatively treats any prior EXECUTION_START or INPUT as evidence that it may already have run, so a transient first-turn Connect failure permanently wedged the session with errStateLost.

    Design

    This PR adds an optional Go SPI extension:

  • api.HarnessRunPreparer prepares one Run without invoking the harness or sending Start.

  • api.PreparedHarnessRun is one-shot. It is either run once or closed; concurrent Close prevents or cancels Run.

  • harnesswire.ClientHarness implements the extension by opening the actual Connect stream and retaining that exact stream for Run.
  • controller.Exec invokes preparation only after journal/descriptor/model-policy prechecks and before its first append. A preparation failure therefore proves non-delivery and appends nothing. After successful preparation, EXECUTION_START and all inputs still commit before Start is sent.

    Resume and reconstruction Replay are unchanged. They operate on already-durable executions and continue through ordinary Harness.Run.

    Delivery boundary

    | Failure point | Journal result | Interpretation |
    |---|---|---|
    | Connect preparation fails | No new execution records | Positive non-delivery; retry the same cursor/session |
    | Start or input append fails | No Start send | Existing CAS/incomplete-invocation behavior |
    | Send(Start) fails | Attempted execution remains durable | Delivery uncertain; fail closed |
    | Recv fails after Start | Attempted execution remains durable | Delivery uncertain; fail closed |
    | EOF before EVENT_END or unsupported frame | Durable failed execution | Protocol failure, never implicit success |

    Error and privacy behavior

    A live-caller Connect outage maps to UNAVAILABLE with host-owned reason HARNESS_UNAVAILABLE. The public message is fixed (placement: harness unavailable); private endpoint or credential-provider text stays only in the Go cause chain. Caller cancellation/deadline retains its own code with no reason.

    Errors after Start sending are not classified as preparation outages, even if they carry the same gRPC code.

    Concurrency and cleanup

  • The placement connection is registered before preparation, so a stateful Fork can mark it superseded, cancel the idle Connect stream, and wait for fence settlement before snapshotting.

  • A prepared stream is closed on append refusal, partial input persistence, cancellation, checkpoint supersession, or normal Run completion.

  • Custom placement.Dialer closers are now documented to interrupt blocked PrepareRun/Run calls and return promptly.

  • Approval park keeps its separate correlated EVENT_PARKED + EOF path.

  • Host-side sink failures retain their bounded drain so harness spans flush before the turn returns.
  • Additional protocol hardening

    While validating the certainty boundary, the existing client was found to accept clean EOF without EVENT_END as success and ignore unsupported event kinds. That contradicted WIRE-12 and could journal a false successful END. The client now requires exactly one terminal END and rejects surplus frames after it.

    Closes #276.

    Verification

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

  • go test -race ./internal/harnessnode ./harnesswire ./conformance

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

  • go test ./... in integrations/claudecode

  • go test ./... in integrations/substrate

  • go vet ./...

  • go build ./...

  • go run ./hack/doccheck

  • go test ./hack/changelog

  • go run ./hack/changelog check -base upstream-agentsession/main -head HEAD -skip=false

  • clean-checkout python3 hack/check-doc-links.py: 660 links across 76 Markdown files

  • npm run build && node hack/check-links.mjs in site: 19 pages and 18 routes

  • git diff --check

  • gofmt -l on all changed Go files
  • The excluded root test is an existing macOS Python 3.9.6 portability failure: sqlite3.OperationalError reports sqlite_errorname as unknown where the test requires SQLITE_ERROR. It reproduces on the unmodified base and is unrelated to these changes.

    Diff: 620 lines (+465 / -155) across 7 files Reviewer: aramase Review duration: 557m
    All Vouch review confidence checks passed
    Residual risk 0.32 = Change Risk (0.55) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.55 · 620 lines diff across 7 files
    0.55
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    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.385
    Shallow Review Depth shallow_review_depth
    0.344
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #282"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% 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: 55.3% (MEDIUM) · Higher = larger blast radius
    55.3%
    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: 43.0% · Lower = rushed or shallow review
    43.0%
    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: 31.5% · Safe to merge
    31.5%