Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions reviewer/EXHAUSTION-FIXTURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,40 @@ 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.

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

- **Deadline fences auth.** A stall or a hung client always ends with auth fenced
Expand All @@ -251,11 +285,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
Expand Down
14 changes: 14 additions & 0 deletions reviewer/HOSTILE-FIXTURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ 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. 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
could not attest stop within its cleanup window. It kept the auth lease for
Expand Down
6 changes: 5 additions & 1 deletion reviewer/NATIVE-VM.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
92 changes: 92 additions & 0 deletions reviewer/native_vm_guest_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 16 additions & 2 deletions reviewer/native_vm_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions reviewer/native_vm_reviewer_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down