gateway tests: TestCodexHeardWithinItsIdleTimeout leaves over a second of room on both sides, where a busy machine's lag carried member a's failure past Codex's quiet limit (#1800)

#1800 has the test failing two ways on busy machines. The body check:
member a failed at 0.7s and Codex's quiet limit was 1s, so 300ms of the
gateway's lag put a's failure past the limit, and it went to Codex as
it was. The bound on the second half: 3s, against 1.2s expected and
3.2s for the pause waited.

Now the quiet limit is 2s (a fails 1.3s before it), b's reply comes at
4.7s with the first event bounded at 3.5s, and the second half's pause
is 10s with a 6s bound (1.2s expected, 11.2s waited).

Run:
- Reproduced the body failure on origin/main 7d15df78a by injecting
  350ms into a's wait (1050ms): overload_test.go:269 got a's
  server_is_overloaded, as in #1800's comments.
- With the change: passes 3/3; with 1s injected into a's wait (1.7s);
  with 1.3s injected into each member's wait in the second half; 8/8
  under 24 busy loops on top of other sessions' load (load average
  38 to 69).
- Broken by hand: tooQuiet returning false fails the first bound
  (4.72s); the replan and passing pauses no longer skipped when too
  quiet fails the second (21.8s, a 2, b 1).
- gofmt -l clean; go vet darwin, linux -tags nogui, windows.

Not tried: the whole gateway package after the change (only this
test); CI's machines. The test takes about 6.3s, up from 4.5s.
This commit is contained in:
yetone
2026-10-14 08:47:30 +08:00
parent 40df6dbd38
commit 10f3877071
+14 -7
View File
@@ -218,12 +218,17 @@ func (s *slowFrames) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// past its 300s with no event. Now, once Codex has gone agentQuietMost
// with none, the try held goes to it as it is, and the next one's reply
// follows; a group's pause that would run past it isn't waited.
//
// Room on both sides (#1800): a fails 1.3s before Codex's quiet limit
// here, so a busy machine's lag doesn't carry a's failure past it to go
// as it is; the bounds sit over a second from both what is expected and
// what the old waits would take.
func TestCodexHeardWithinItsIdleTimeout(t *testing.T) {
k, w, q := keepHeldAfter, watchEvery, agentQuietMost
keepHeldAfter, watchEvery, agentQuietMost = 50*time.Millisecond, 10*time.Millisecond, time.Second
keepHeldAfter, watchEvery, agentQuietMost = 50*time.Millisecond, 10*time.Millisecond, 2*time.Second
t.Cleanup(func() { keepHeldAfter, watchEvery, agentQuietMost = k, w, q })
fresh(t)
const wait = 1500 * time.Millisecond
const wait = 4 * time.Second
a := &slowFrames{wait: 700 * time.Millisecond, then: func(int) string { return sse(overloadedFailed) }}
b := &slowFrames{wait: wait, then: func(int) string {
return sse(`event: response.output_text.delta`+"\n"+`data: {"type":"response.output_text.delta","delta":"hello"}`,
@@ -260,9 +265,9 @@ func TestCodexHeardWithinItsIdleTimeout(t *testing.T) {
break
}
}
// a failed at 0.7s and b, held, would have gone at 2.2s: b's frames
// go at 1s, Codex's idle timeout here, and its reply after them
if first == 0 || first > 1600*time.Millisecond {
// a failed at 0.7s and b, held, would have gone at 4.7s: b's frames
// go at 2s, Codex's idle timeout here, and its reply after them
if first == 0 || first > 3500*time.Millisecond {
t.Fatalf("Codex's first event came after %s:\n%s", first, got.String())
}
if !strings.Contains(got.String(), "hello") || strings.Contains(got.String(), "server_is_overloaded") {
@@ -275,7 +280,7 @@ func TestCodexHeardWithinItsIdleTimeout(t *testing.T) {
a.wait, b.wait = 600*time.Millisecond, 600*time.Millisecond
b.then = a.then
k2 := retryPause
retryPause = 2 * time.Second
retryPause = 10 * time.Second
t.Cleanup(func() { retryPause = k2 })
for id, up := range map[string]http.Handler{"a": a, "b": b} {
srv := httptest.NewServer(up)
@@ -296,7 +301,9 @@ func TestCodexHeardWithinItsIdleTimeout(t *testing.T) {
}
body, _ := io.ReadAll(res2.Body)
res2.Body.Close()
if took := time.Since(start); took > 3*time.Second || !strings.Contains(string(body), "server_is_overloaded") {
// a's failure at 0.6s and b's at 1.2s; the pause waited would make it
// 11.2s
if took := time.Since(start); took > 6*time.Second || !strings.Contains(string(body), "server_is_overloaded") {
t.Fatalf("after %s (a %d, b %d):\n%s", took, a.n, b.n, body)
}
}