fix(harnesswire): prepare Connect before journaling #282
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
aramase
Summary
Harness.Connectstream before recording a new execution, without sendingStartSend(Start)is attempted: send/receive failures remain durable and visible in later historyEVENT_END, unsupported events, and frames after END fail the executionProblem
controller.ExecrecordsEXECUTION_STARTand everyINPUTbefore callingHarness.Run. Forharnesswire.ClientHarness,Runpreviously openedHarness.Connectonly after those records committed.If the first Connect failed, no
Startreached the harness, but the next Exec still received the failed execution inStart.History. Claude Code conservatively treats any priorEXECUTION_STARTorINPUTas evidence that it may already have run, so a transient first-turn Connect failure permanently wedged the session witherrStateLost.Design
This PR adds an optional Go SPI extension:
api.HarnessRunPreparerprepares one Run without invoking the harness or sendingStart.api.PreparedHarnessRunis one-shot. It is either run once or closed; concurrent Close prevents or cancels Run.harnesswire.ClientHarnessimplements the extension by opening the actual Connect stream and retaining that exact stream for Run.controller.Execinvokes 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_STARTand all inputs still commit beforeStartis 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 |
|---|---|---|
|
Connectpreparation 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 ||
Recvfails after Start | Attempted execution remains durable | Delivery uncertain; fail closed || EOF before
EVENT_ENDor unsupported frame | Durable failed execution | Protocol failure, never implicit success |Error and privacy behavior
A live-caller Connect outage maps to
UNAVAILABLEwith host-owned reasonHARNESS_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
placement.Dialerclosers are now documented to interrupt blocked PrepareRun/Run calls and return promptly.EVENT_PARKED+ EOF path.Additional protocol hardening
While validating the certainty boundary, the existing client was found to accept clean EOF without
EVENT_ENDas success and ignore unsupported event kinds. That contradictedWIRE-12and 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 ./sessiongo test -race ./internal/harnessnode ./harnesswire ./conformancego test ./... -skip '^TestDocumentedPythonExecutorLogsStorageFailureWithoutPayload$'go test ./...inintegrations/claudecodego test ./...inintegrations/substratego vet ./...go build ./...go run ./hack/doccheckgo test ./hack/changeloggo run ./hack/changelog check -base upstream-agentsession/main -head HEAD -skip=falsepython3 hack/check-doc-links.py: 660 links across 76 Markdown filesnpm run build && node hack/check-links.mjsinsite: 19 pages and 18 routesgit diff --checkgofmt -lon all changed Go filesThe excluded root test is an existing macOS Python 3.9.6 portability failure:
sqlite3.OperationalErrorreportssqlite_errornameasunknownwhere the test requiresSQLITE_ERROR. It reproduces on the unmodified base and is unrelated to these changes.