From e5592952473d0401a4a7c3fddfc0a0c7a494b582 Mon Sep 17 00:00:00 2001 From: Franz Hemmer <8227352+HemSoft@users.noreply.github.com> Date: Fri, 23 Oct 2026 20:53:12 -0400 Subject: [PATCH 1/3] Deliver typed guest failures to the host (#255) The guest left Report nil on every non-complete finished record. As a json.RawMessage, nil encodes as the literal null, which decodes back to four bytes, so the host's valid() refused every typed guest failure (auth_failed, provider_unavailable, cancelled, ...) and classified the phase as invalid_output. The same decoding let a complete record carry a null report past valid(). Report is now omitted when absent. The host's exact re-encoding keeps that canonical: an explicit null is a carried value, which valid() refuses for every state. The host's classification of a decoded record is extracted as nativeVMFinished.failure. The guest and host binaries must both be rebuilt; a mixed pair fails closed. Tests encode records through the guest's own finish producer and the host's readVMRecord/failure path. Co-Authored-By: Claude Opus 5.5 --- reviewer/native_vm_guest_linux_test.go | 92 ++++++++++++++++++++++++++ reviewer/native_vm_protocol.go | 18 ++++- reviewer/native_vm_reviewer_linux.go | 7 +- 3 files changed, 110 insertions(+), 7 deletions(-) diff --git a/reviewer/native_vm_guest_linux_test.go b/reviewer/native_vm_guest_linux_test.go index c36be200..698c2795 100644 --- a/reviewer/native_vm_guest_linux_test.go +++ b/reviewer/native_vm_guest_linux_test.go @@ -284,6 +284,98 @@ func TestNativeGuestInvocationBothProvidersRetainSourceAndFixedProxy(t *testing. } } +// guestFinishedWire runs the guest's own finish producer over a pipe and +// returns the exact control record bytes the host reads. +func guestFinishedWire(t *testing.T, q nativeVMRequest, state string, report []byte) []byte { + t.Helper() + read, write, err := os.Pipe() + if err != nil { + t.Fatal(err) + } + defer read.Close() + wire := make(chan []byte, 1) + go func() { raw, _ := io.ReadAll(read); wire <- raw }() + phase := &nativeGuestPhase{request: q, control: write, state: state, stage: "native-execute", report: report} + phase.finish(context.Background()) + write.Close() + return <-wire +} + +func TestNativeVMHostReceivesTypedGuestFailureAsEncodedByTheGuest(t *testing.T) { + for _, provider := range []Provider{Codex, Claude} { + q := nativeRequestFixture(t, provider) + report, _ := json.Marshal(fakeReport(q.Session)) + cases := map[string]string{"auth_failed": "auth_failed", "provider_unavailable": "provider_unavailable", "quota_wait": "quota_wait", "incomplete_expired": "incomplete_expired", "invalid_output": "invalid_output", "cancelled": "cancelled", "": "blocked"} + // A complete phase without a stopped auth return is downgraded by the + // guest itself; the host must still see that typed state. + cases["complete"] = "invalid_output" + for state, want := range cases { + raw := report + if state != "complete" { + raw = nil + } + wire := guestFinishedWire(t, q, state, append([]byte{}, raw...)) + finished, err := readVMRecord[nativeVMFinished](bytes.NewReader(wire), 4<<20) + var phase PhaseError + failure := finished.failure(q) + if err != nil || !errors.As(failure, &phase) || phase.State != want || errors.Is(failure, ErrVMBoot) || len(finished.Report) != 0 { + t.Error("typed guest failure did not reach the host", provider, state, finished.State, string(finished.Report), err, failure) + } + if bytes.Contains(wire, []byte(`"Report"`)) { + t.Error("guest encoded an absent report", provider, state) + } + } + } +} + +func TestNativeVMFinishedRefusesReportsOutsideCompleteOverTheWire(t *testing.T) { + q := nativeRequestFixture(t, Codex) + report, _ := json.Marshal(fakeReport(q.Session)) + code := &nativeVMCodeHostAccess{Version: 2, SessionHash: Digest(q.Session), UID: nativeVMCodeHostUID, InputHash: Digest("input"), OutputHash: Digest("output"), Stopped: true, RelayComplete: true} + complete := nativeVMFinished{Version: 1, Binding: q.Binding, RequestHash: Digest(q), State: "complete", Report: report, SourceAudit: []byte("private-audit-placeholder"), AuthReturn: []byte("private-return-placeholder"), CodeHost: code} + roundTrip := func(value any) (nativeVMFinished, error) { + var wire bytes.Buffer + if err := writeVMRecord(&wire, value, 4<<20); err != nil { + t.Fatal(err) + } + return readVMRecord[nativeVMFinished](&wire, 4<<20) + } + refused := func(got nativeVMFinished) bool { + var phase PhaseError + failure := got.failure(q) + return !got.valid(q) && errors.As(failure, &phase) && phase.State == "invalid_output" && errors.Is(failure, ErrVMBoot) + } + if got, err := roundTrip(complete); err != nil || got.failure(q) != nil || !bytes.Equal(got.Report, report) { + t.Fatal("complete record with a report refused", err) + } + missing := complete + missing.Report = nil + if got, err := roundTrip(missing); err != nil || !refused(got) { + t.Fatal("complete record without a report accepted", err) + } + failed := complete + failed.State = "auth_failed" + if got, err := roundTrip(failed); err != nil || !refused(got) { + t.Fatal("typed failure carrying a report accepted", err) + } + // The guest omits an absent report. An explicit null is not its encoding + // and stays a carried value that a typed failure cannot hold. + raw, _ := json.Marshal(nativeVMFinished{Version: 1, Binding: q.Binding, RequestHash: Digest(q), State: "auth_failed"}) + if !bytes.Contains(raw, []byte(`"Report":null`)) { + raw = bytes.Replace(raw, []byte(`"State":"auth_failed",`), []byte(`"State":"auth_failed","Report":null,`), 1) + } + if got, err := roundTrip(json.RawMessage(raw)); err != nil || !refused(got) || string(got.Report) != "null" { + t.Fatal("typed failure with an explicit null report accepted", err) + } + raw, _ = json.Marshal(missing) + if !bytes.Contains(raw, []byte(`"Report":null`)) { + raw = bytes.Replace(raw, []byte(`"State":"complete",`), []byte(`"State":"complete","Report":null,`), 1) + } + if got, err := roundTrip(json.RawMessage(raw)); err != nil || !refused(got) || string(got.Report) != "null" { + t.Fatal("complete record with an explicit null report accepted", err) + } +} + func TestNativeGuestReturnedFileRequiresBoundedSingleOwnedRegularFile(t *testing.T) { for _, kind := range []string{"valid", "symlink", "parent-escape", "hardlink", "permissions", "oversize", "fifo", "owner"} { t.Run(kind, func(t *testing.T) { diff --git a/reviewer/native_vm_protocol.go b/reviewer/native_vm_protocol.go index d287f82b..6519ea8d 100644 --- a/reviewer/native_vm_protocol.go +++ b/reviewer/native_vm_protocol.go @@ -165,12 +165,14 @@ func (r nativeVMReady) valid(q nativeVMRequest) bool { // The guest's privileged supervisor writes this receipt over the control port. // It never accepts this structure from client stdout or a source tool. The host // must separately prove whole-VM stop and validate its own provider receipt. +// A record without a report omits Report. An explicit null is a carried value, +// so only a complete record can hold a report and none may hold null. type nativeVMFinished struct { Version int Binding AuthBinding RequestHash string State string - Report json.RawMessage + Report json.RawMessage `json:",omitempty"` SourceAudit []byte AuthReturn []byte CodeHost *nativeVMCodeHostAccess @@ -208,7 +210,7 @@ func (f nativeVMFinished) valid(q nativeVMRequest) bool { default: return false } - if f.State != "complete" && len(f.Report) != 0 { + if f.State != "complete" && len(f.Report) != 0 || string(f.Report) == "null" { return false } if q.Session.Identity.Provider == Claude && f.CodeHost != nil { @@ -229,6 +231,18 @@ func (f nativeVMFinished) valid(q nativeVMRequest) bool { return true } +// failure classifies a decoded finished record on the host. A valid typed +// guest failure keeps its state; an invalid record is invalid output. +func (f nativeVMFinished) failure(q nativeVMRequest) error { + if !f.valid(q) { + return adapterValidation(ErrVMBoot, false) + } + if f.State != "complete" { + return PhaseError{State: f.State} + } + return nil +} + func nativeVMSeedRecord(seed AuthTransfer) ([]byte, error) { var wire bytes.Buffer if _, err := seed.WriteTo(&wire); err != nil { diff --git a/reviewer/native_vm_reviewer_linux.go b/reviewer/native_vm_reviewer_linux.go index 7e1b8e74..6d0f688b 100644 --- a/reviewer/native_vm_reviewer_linux.go +++ b/reviewer/native_vm_reviewer_linux.go @@ -272,11 +272,8 @@ func (r *NativeVMReviewer) reviewTaskAudited(ctx context.Context, s Session, con } phase.finished = &finished phase.stage = "result-validation" - if !finished.valid(request) { - return nativeVMTaskReport{}, nil, nil, adapterValidation(ErrVMBoot, false) - } - if finished.State != "complete" { - return nativeVMTaskReport{}, nil, nil, PhaseError{State: finished.State} + if err := finished.failure(request); err != nil { + return nativeVMTaskReport{}, nil, nil, err } report, err = decodeNativeVMTaskReport(request, finished.Report) if err != nil { From a3c8dbd8fc2c6152d61a90f32d8c194673bf0e6d Mon Sep 17 00:00:00 2001 From: Franz Hemmer <8227352+HemSoft@users.noreply.github.com> Date: Fri, 23 Oct 2026 20:54:05 -0400 Subject: [PATCH 2/3] Document typed guest failure states in the fixture matrices (#255) Record that the measured phase-invalid_output classes were the host's refusal of the guest's null report, which classes each refused case is expected to record after the fix, and that they still need a rebuilt guest image and runner to be measured. Co-Authored-By: Claude Opus 5.5 --- reviewer/EXHAUSTION-FIXTURES.md | 39 ++++++++++++++++++++++++++++----- reviewer/HOSTILE-FIXTURES.md | 10 +++++++++ reviewer/NATIVE-VM.md | 6 ++++- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/reviewer/EXHAUSTION-FIXTURES.md b/reviewer/EXHAUSTION-FIXTURES.md index 5898fb46..bd1c960b 100644 --- a/reviewer/EXHAUSTION-FIXTURES.md +++ b/reviewer/EXHAUSTION-FIXTURES.md @@ -240,6 +240,34 @@ passes and the contained `codex-metadata` client failure; and every E2E case, including `close-provider-recover`, passed. The E2E source acquisitions also ran with the capped `git fetch` output enforced. +## Typed guest failure states + +Through `a3f665b`, every `phase-invalid_output` above was the host's class, +not the guest's. The guest encoded an absent report as `"Report":null`, and +the host refused every non-complete finished record and classified the phase +as invalid output +([#255](https://github.com/hemsoft-dev/set-it-free-loop/issues/255)). The +guest now omits an absent report, and the host returns a valid typed guest +failure with its own state. `ErrorText` no longer carries the VM boot error +for such a case. + +`typed-failure` accepts any `phase-*` class, so no check or verdict changes. +The recorded class changes only for cases whose guest record arrives with a +state other than `invalid_output`: + +- The response and turn floods record the state the guest classified from the + client's output, such as `provider_unavailable` for a Codex failure event + or `incomplete_expired` for Claude's `error_max_turns`. Output the guest + cannot classify stays `invalid_output`. +- `codex-code-output-flood` stays `phase-invalid_output`. The guest itself + downgrades the report because the code-host exchange failed. +- The stalls and `codex-code-memory` stay `auth-recovery`. The host stops the + unit before the guest's record arrives. +- The complete cases are unchanged. + +These are expectations from the code, not measurements. They need a guest +image and runner built after the fix. + ## Remaining limitations - **Deadline fences auth.** A stall or a hung client always ends with auth fenced @@ -251,11 +279,12 @@ ran with the capped `git fetch` output enforced. - **Claude max-turns classification.** The pinned client emits `error_max_turns` with `is_error: true`, which the normalizer maps to `incomplete_expired`. The native run reported `invalid_output` with - `client-error-silent-exit`, so the exchange failed after or around the result - frame. One likely cause is the post-result `mcp_status` control request - meeting an exited client, but that is not confirmed. The guest records no - frame-level observation on the Claude path. It is still a typed failure, not - success. + `client-error-silent-exit`. That run predates the typed-state fix above, so + its class does not show what the guest classified. If a rerun still records + `invalid_output`, the exchange failed after or around the result frame. One + likely cause is the post-result `mcp_status` control request meeting an + exited client, but that is not confirmed. The guest records no frame-level + observation on the Claude path. It is still a typed failure, not success. - **Request floods.** More than `ReaderCalls + 32` MCP requests still close the source connection, with the pre-fix effect: lost audit and fenced auth. - **Unreachable pressure.** Guest task pressure cannot be induced through diff --git a/reviewer/HOSTILE-FIXTURES.md b/reviewer/HOSTILE-FIXTURES.md index cd5b997f..471989e7 100644 --- a/reviewer/HOSTILE-FIXTURES.md +++ b/reviewer/HOSTILE-FIXTURES.md @@ -138,6 +138,16 @@ injection text came back as data. The next request had the same tool inventory, with no tool or MCP handle added. The store never saw a path outside the allowlist. +The `phase-invalid_output` class in these runs is the host's, not the guest's. +Through `a3f665b` the guest encoded an absent report as `"Report":null`, and +the host refused every non-complete finished record as invalid output +([#255](https://github.com/hemsoft-dev/set-it-free-loop/issues/255)). A +refused case now records the guest's typed state, for example +`phase-provider_unavailable` when the client ends its turn with a provider +failure, and its `ErrorText` no longer carries the VM boot error. No check +or verdict depends on the class. The new classes need a guest image and +runner built after the fix and have not been measured yet. + An earlier full run, `matrix-r1` at `24ccb25`, matched these verdicts except for one `claude-foreign-mcp` run. That run ended `stop-pending`: the host could not attest stop within its cleanup window. It kept the auth lease for diff --git a/reviewer/NATIVE-VM.md b/reviewer/NATIVE-VM.md index 0dd27815..1305440c 100644 --- a/reviewer/NATIVE-VM.md +++ b/reviewer/NATIVE-VM.md @@ -85,7 +85,11 @@ active response intact. It requires the captured model and strict source-tool response policy, and retains a stopped host-side provider receipt. Control request/ready/finished envelopes bind the full launch, session and request digest; the host must still validate -their actual source audit/auth return before accepting a report. +their actual source audit/auth return before accepting a report. A finished +envelope without a report omits `Report`. Only a `complete` envelope may carry +one, and an explicit `null` is refused in every state. A valid typed guest +failure, such as `auth_failed` or `provider_unavailable`, reaches the host with +its own state. The host waits for the first private byte within the job's timeout before starting its five-second HTTP header timer. VM boot and client initialization From ac825e7bdb36651a6845400b1b338e864962a4e8 Mon Sep 17 00:00:00 2001 From: Franz Hemmer <8227352+HemSoft@users.noreply.github.com> Date: Fri, 23 Oct 2026 21:58:53 -0400 Subject: [PATCH 3/3] Record the typed guest failure classes measured at a3c8dbd Co-Authored-By: Claude Opus 5.5 --- reviewer/EXHAUSTION-FIXTURES.md | 10 ++++++++-- reviewer/HOSTILE-FIXTURES.md | 8 ++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/reviewer/EXHAUSTION-FIXTURES.md b/reviewer/EXHAUSTION-FIXTURES.md index bd1c960b..04d8d583 100644 --- a/reviewer/EXHAUSTION-FIXTURES.md +++ b/reviewer/EXHAUSTION-FIXTURES.md @@ -265,8 +265,14 @@ state other than `invalid_output`: unit before the guest's record arrives. - The complete cases are unchanged. -These are expectations from the code, not measurements. They need a guest -image and runner built after the fix. +Measured on October 23, 2026 at `a3c8dbd` on mini, with a native image and +runner built from that commit: the exhaustion matrix passed 12 of 12. +`claude-turn-flood` now records `phase-incomplete_expired` (Claude's +`error_max_turns`), where it previously recorded the host's +`phase-invalid_output`. The response floods, `codex-turn-flood` and +`codex-code-output-flood` record `phase-invalid_output` as the guest's own +classification. The stalls and `codex-code-memory` stay `auth-recovery`, and +the complete cases are unchanged. ## Remaining limitations diff --git a/reviewer/HOSTILE-FIXTURES.md b/reviewer/HOSTILE-FIXTURES.md index 471989e7..a0a9c4fd 100644 --- a/reviewer/HOSTILE-FIXTURES.md +++ b/reviewer/HOSTILE-FIXTURES.md @@ -145,8 +145,12 @@ the host refused every non-complete finished record as invalid output refused case now records the guest's typed state, for example `phase-provider_unavailable` when the client ends its turn with a provider failure, and its `ErrorText` no longer carries the VM boot error. No check -or verdict depends on the class. The new classes need a guest image and -runner built after the fix and have not been measured yet. +or verdict depends on the class. Measured at `a3c8dbd` with a guest image and +runner built from that commit, the hostile matrix gave the same verdicts (19 +pass and the contained `codex-metadata` client failure). Every refused case, +including `codex-metadata`, still records `phase-invalid_output`, now as the +guest's own classification of the refused response rather than the host's +rejection of the finished record. An earlier full run, `matrix-r1` at `24ccb25`, matched these verdicts except for one `claude-foreign-mcp` run. That run ended `stop-pending`: the host