# inspect: reserve fan-in capacity for start-failure terminals

`fa22e12`→[main](/content/gh/entireio/cli/commits/main/index.html)·

dipree·4w ago·2 files·+40 added/-3 removed

Keep the start-failure terminal-marker protocol but reserve channel capacity for
all possible Start-failure terminal markers in addition to event-burst slack.
The fanIn buffer is now 17*N: 16*N for event jitter plus N terminal slots, so
queued start terminals cannot consume the event-burst budget before dispatch
starts.

Add a regression with a noisy started agent plus many Start failures to prove
RunMulti drains and finishes.

## Sessions

2f05f06fd7f8View transcript

[?\
Checkout the hand off doc that I just added.Pi·Opus 4.8·1 step](/content/gh/entireio/cli/session/019eca64-8c2c-7b00-90c6-3aa49738c497#timeline-2f05f06fd7f8/index.html)

## Changes

2

- cmd/entire/cli/review

- Mrun_multi.go+4/-3

- Mrun_multi_test.go+36

```
130 unmodified lines

131
132
133
134
135
136
134
135
136
137
138
139
140

130 unmodified lines

}

// fanIn carries tagged events from N agent goroutines into the single
	// dispatch loop. Buffer of len(reviewers)*16 amortises goroutine
	// scheduling jitter without holding an unbounded queue.
	fanIn := make(chan taggedEvent, len(reviewers)*16)
	// dispatch loop. Reserve len(reviewers)*16 slots for event-burst jitter plus
	// one terminal-marker slot per reviewer, so queued Start-failure terminals
	// cannot consume the event-burst slack before the dispatch loop starts.
	fanIn := make(chan taggedEvent, len(reviewers)*17)

// Each inspector runs under its own deadline (unless inspectorTimeout returns
	// 0, meaning disabled) so a stuck agent is cancelled without hanging the run;
```

Mcmd/entire/cli/review/run_multi.go+4/-3

```
2 unmodified lines

3
4
5
6
7
8
9
137 unmodified lines

147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187

2 unmodified lines

import (
	"context"
	"errors"
	"fmt"
	"sync/atomic"
	"testing"
	"time"
137 unmodified lines

}
}

func TestRunMulti_StartErrorsAndEventBurstStillDrain(t *testing.T) {
	t.Parallel()
	events := make([]reviewtypes.Event, 0, 400)
	for range 399 {
		events = append(events, reviewtypes.AssistantText{Text: "event"})
	}
	events = append(events, reviewtypes.Finished{Success: true})
	reviewers := []reviewtypes.AgentReviewer{&stubReviewer{name: "noisy", events: events}}
	for i := range 40 {
		reviewers = append(reviewers, &stubReviewer{name: fmt.Sprintf("bad-%02d", i), startErr: errors.New("start failed")})
	}
	type result struct {
		summary reviewtypes.RunSummary
		err     error
	}
	done := make(chan result, 1)
	go func() {
		summary, err := RunMulti(context.Background(), reviewers, reviewtypes.RunConfig{}, nil)
		done <- result{summary: summary, err: err}
	}()

select {
	case res := <-done:
		if res.err == nil {
			t.Fatal("RunMulti error = nil, want one of the start errors")
		}
		summary := res.summary
		if len(summary.AgentRuns) != len(reviewers) {
			t.Fatalf("AgentRuns = %d, want %d", len(summary.AgentRuns), len(reviewers))
		}
	case <-time.After(2 * time.Second):
		t.Fatal("RunMulti deadlocked with start-failure terminals plus event burst")
	}
}

func TestRunMulti_AllStartErrorsStillFinish(t *testing.T) {
	t.Parallel()
	firstErr := errors.New("first start failed")
