You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(controller): correlate model results by call ID - #299
MODEL_CALL already had an ID, but its durable completion was an ordinary OUTPUT correlated only by position. Direct EventSink.Output produced the same shape.
An in-process harness could therefore handle a provider error, emit fallback output, and crash before END. Replay or Resume would consume that fallback as the successful model response and enter a control-flow branch the original execution never took.
Direct harness output leaves Event.model_call_id absent. The field is proto-optional so absent and explicitly empty remain distinguishable; present-empty is malformed evidence.
ModelCall.result_correlation is the compatibility discriminator. Markerless calls retain legacy positional behavior, because old calls already had nonempty IDs and absence of an output ID alone cannot distinguish an old completion from new direct output.
Replay and recovery
A shared matcher enforces:
BY_ID calls consume only an immediately adjacent OUTPUT with the exact nonempty ID
absent output ID after BY_ID is direct output and remains unconsumed
wrong, empty, or unknown correlation evidence is sticky ErrReplayDiverged
direct Output cannot consume a correlated model result
a trailing unanswered call is re-driven once and its completion reuses the original durable ID
markerless calls accept an old ID-less positional completion or an exact upgraded result
A failed re-drive of a pre-v11 positional call cannot immediately append direct fallback output: that would create a newly ambiguous journal. The host fails closed before the fallback append. A fresh model-call retry is still allowed because it records a new BY_ID call first.
Compatibility
SQLite schema v11 is stamp-only:
no table or event is rewritten
old records preserve bytes, hashes, and positional behavior
old binaries reject v11 cleanly at Open instead of dropping the new hash-bound fields
operators must stop older writers/embedded clients and back up the database and WAL before first v11 open
rollback requires restoring the backup
Tests
Coverage includes:
provider failure + direct fallback + crash, with zero provider calls during Resume/Replay
exact, empty, wrong, and unknown correlation evidence in Replay and Resume
sticky divergence after a harness swallows the first error
direct output refusing correlated result evidence
trailing re-drive retaining the original call ID
same-run retry producing a distinct BY_ID call and result
pre-v11 positional replay
failed pre-v11 re-drive refusing immediate fallback while permitting a fresh correlated retry
optional-field wire presence and hash binding
Go/Python canonical interop vectors for correlated calls and results
v10-to-v11 stamp-only migration preserving raw event rows and schema
Verification
go test -race -shuffle=on ./controller ./wire ./canon ./sqlitelog
go test -race -shuffle=on ./session ./placement ./conformance ./harnesswire
go test -race -shuffle=on ./... in integrations/substrate
go test -race -shuffle=on ./... in integrations/claudecode
The repository-wide root test command still reaches the pre-existing Python 3.9 portability failure in internal/agentsessionsd.TestDocumentedPythonExecutorLogsStorageFailureWithoutPayload; all changed and dependent packages pass, including race-enabled tests.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Legacy recovery returns before flagging a trailing markerless model call as ambiguous, allowing fallback harness output to be replayed as a successful model result.
This PR addresses #93 by linking durable model results to their call IDs, preventing direct harness fallback output from being replayed as provider success.
Changes:
Adds explicit result-correlation fields and shared matching rules for replay and recovery.
Preserves legacy positional matching and introduces a stamp-only SQLite schema v11 migration.
Adds regression tests, canonical hash vectors, and compatibility documentation.
File
Description
wire/convert.go
Preserves correlation fields during conversion.
wire/convert_test.go
Tests correlation round-trips and hash stability.
sqlitelog/sqlitelog.go
Adds the stamp-only v11 migration.
sqlitelog/model_correlation_schema_test.go
Checks migration preserves schema and event rows.
sqlitelog/cleanup_resources_test.go
Updates migration expectations to the current schema.
spec.md
Defines correlation, recovery, and upgrade rules.
hack/verify_chain.py
Adds Python correlation hash vectors.
docs/session-data-model.md
Explains correlated results and legacy matching.
docs/harness-authoring.md
Documents fallback and recovery behavior.
docs/concepts.md
Clarifies model-call and output event semantics.
docs/api-reference.md
Documents the new protobuf fields and enum.
controller/resume.go
Matches results by ID and guards ambiguous fallback.
controller/resume_model_cut_test.go
Tests correlation, fallback, divergence, and legacy recovery.
controller/model_result.go
Centralizes recorded-result matching.
controller/legacy.go
Counts successful durable sink writes.
controller/executions.go
Rejects correlation fields on non-output events.
controller/effects.go
Writes correlated results and validates replay matching.
The reason will be displayed to describe this comment to others. Learn more.
The v11 correlation looks good for new calls; the legacy path still has the bug #93 describes (same as the open Copilot thread).
Nits:
changelog/unreleased/model-result-correlation.md:5-6: "no longer reinterpret direct fallback output" holds only for v11+ calls (EXE-10 says no retroactive repair); scope it to new calls.
docs/harness-authoring.md:285, spec.md:743, spec.md:790: the edited paragraphs leave short lines; rewrap each to 100 columns.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
A regression test is missing for markerless-call re-drive and replay, including ID and journal integrity checks and fail-closed cases, and the specification conflates model IDs with call IDs.
No open issues 🎉
2 previously missed issues
In code that hasn't changed since last review
Test legacy-call re-drive and replay with ID validation
controller/model_result.go:39
The compatibility tests do not cover a successful re-drive of a markerless call followed by replay of its new ID-bearing completion. Add a regression in controller/resume_model_cut_test.go that verifies the original call ID and journal prefix/hashes are preserved, then replays with zero provider calls. Include empty and wrong result IDs for this upgraded legacy shape to verify that it fails closed.
Distinguish model IDs from ModelCall.id call-correlation tokens
spec.md:730
The per-call IDs discussed in EXE-34/35 are model identifiers, but this sentence now places them in ModelCall.id, which is the independently generated call-correlation token. liveSink.model still records the selected model in ModelCall.model. Please distinguish model IDs from call IDs so the model-policy contract does not point consumers at the wrong field.
Thank you for the careful follow-up, and apologies for the missed coverage. I addressed both points in 5f07f2b:
Added a markerless-call re-drive and replay regression that preserves the original call ID and full journal prefix/hashes, proves both regular and streaming provider callbacks remain unused on replay, and checks empty and wrong result IDs fail closed.
Corrected EXE-34/35 so selected model IDs remain in ModelCall.model, while ModelCall.id is clearly the independently generated call-correlation token.
The focused controller race suite, build, vet, doccheck, formatting, changelog, and cross-language chain checks pass. Thank you again for catching these gaps.
Anish Ramasekar (@aramase), when convenient, would you mind taking another look? GitHub would not let me formally re-request review from the fork. Oh, wait I can!! 🧙 = )
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed to evaluate the operational impact of compatibility guidance that omits the release introducing a one-way journal migration and stricter recovery behavior.
No open issues 🎉
1 file not reviewed
api/genpb/common.pb.go: Generated file
Review effort: Balanced
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OUTPUTrecords with theirMODEL_CALLIDsFixes #93.
Problem
MODEL_CALLalready had an ID, but its durable completion was an ordinaryOUTPUTcorrelated only by position. DirectEventSink.Outputproduced the same shape.An in-process harness could therefore handle a provider error, emit fallback output, and crash before
END. Replay or Resume would consume that fallback as the successful model response and enter a control-flow branch the original execution never took.Durable format
New journaled calls carry:
Direct harness output leaves
Event.model_call_idabsent. The field is proto-optional so absent and explicitly empty remain distinguishable; present-empty is malformed evidence.ModelCall.result_correlationis the compatibility discriminator. Markerless calls retain legacy positional behavior, because old calls already had nonempty IDs and absence of an output ID alone cannot distinguish an old completion from new direct output.Replay and recovery
A shared matcher enforces:
BY_IDcalls consume only an immediately adjacentOUTPUTwith the exact nonempty IDBY_IDis direct output and remains unconsumedErrReplayDivergedOutputcannot consume a correlated model resultA failed re-drive of a pre-v11 positional call cannot immediately append direct fallback output: that would create a newly ambiguous journal. The host fails closed before the fallback append. A fresh model-call retry is still allowed because it records a new
BY_IDcall first.Compatibility
SQLite schema v11 is stamp-only:
Tests
Coverage includes:
BY_IDcall and resultVerification
go test -race -shuffle=on ./controller ./wire ./canon ./sqliteloggo test -race -shuffle=on ./session ./placement ./conformance ./harnesswirego test -race -shuffle=on ./...inintegrations/substratego test -race -shuffle=on ./...inintegrations/claudecodego build ./...go vet ./...buf lintbuf breaking --against ".git#tag=v0.4.0,subdir=api"go run ./hack/doccheck./hack/verify_chain.shgofmt -l .git diff --checkThe repository-wide root test command still reaches the pre-existing Python 3.9 portability failure in
internal/agentsessionsd.TestDocumentedPythonExecutorLogsStorageFailureWithoutPayload; all changed and dependent packages pass, including race-enabled tests.