Commit Graph
2 Commits
Author SHA1 Message Date
yetone 6e0b8113dd gateway tests: a rest one test records is let go when it ends (#6717)
restingUntil is package-global. Six tests leave a Codex usage-limit rest
behind (TestAccountProxy, TestCodexOwnModelMovesToNextAccount,
TestCodexSwitchedAccountRestsAsItself, TestCodexPausedOwnAccountPassedOver,
TestCodexPoolForwardsCodexHeaders, TestCodexSocketErrorIsItsStatus), and
TestEffortChangeKeepsTheCache, whose effortCodexAccount sets its home
without fresh(t), started held by it whenever the chunking put them in one
process: its first turn was refused in 15ms with "The usage limit has been
reached". Red in Race at 6e6a18eda and in Test at 0dbdc7481.

The class, both sides:
- fresh(t) clears the rests through noRests() and again when the test
  ends (t.Cleanup), so a test that comes through fresh leaves none.
- noRests() clears restingUntil.lifted too, not only m and note.
- The helpers that set a home without fresh (effortCodexAccount,
  leadSignIn, claudeMadeFirst, piTwoTurns) call noRests first and when
  they end, as b64Home already did.

Run on mote, at 6af327e2b plus this change:
- Broken by hand: each test of the eleven files whose fakes answer a
  usage limit, run with TestEffortChangeKeepsTheCache in one process
  (-test.run '^(T|TestEffortChangeKeepsTheCache)$'). Before: red with the
  six tests above. After: none red.
- internal/gateway plain, sharded as CI does (build/race-shards.sh, 12
  workers): 4300 tests, shards_rc=0.
- internal/gateway -race, sharded: one red, TestBurstTellsNoSpeed/
  responses_from_chat_burst (839ms burst read as 5959 tok/s), a timing
  red with its issue, #2719 (output recorded there); every other test ok.
- gofmt -l internal/gateway: clean.

Not run: the other packages (test files of internal/gateway only).

Fixes #6717
2026-11-15 08:45:42 +08:00
yetoneandcrayon b68218f43e gateway: a Responses reply to a client that isn't Codex carries only the Responses enum's events (#4482)
Grok Build, reading /v1/responses through async-openai's typed
ResponseStreamEvent, lost whole turns on a ChatGPT account: the backend
speaks part of the Codex protocol (codex.rate_limits,
codex.response.metadata, response.metadata, a keepalive event), and the
client read each as `unknown variant` and ended the turn.

passthrough now runs responsesEnumTidy (responses_enum.go) last in its
chain for a Responses stream to a client that isn't Codex (the
fromCodex / agentOf pair codex_own_v1.go uses): every event whose
`event:` name, or data `type` where it names none, is outside the OpenAI
Responses enum is dropped; a keepalive goes on as an SSE comment so a
quiet upstream still keeps the client's idle timer alive. sniff and
codexLimitsTap read the upstream bytes before it, so failover and the
account's windows are unchanged. Codex itself gets every event as it
came. A plugin's Responses reply goes through the same passthrough, so
it is covered too. The WebSocket route's synthesized header frames
(socketTurnWriter.headerFrames) go to Codex alone too.

The response.failed shape from the report (missing created_at /
sequence_number) was already fixed on main by 29bfd5dc8 (plugins#852);
crayonlu's test for it is kept.

Ported from crayonlu's codex-lead-events branch (917878484, four
commits), with the keepalive comment and OpenAI's audio events added to
the enum.

Run (mote, macOS arm64, Go 1.26.8):
- focused: TestResponsesEventsOutsideTheEnumStayWithCodex,
  TestResponsesEnumAllowed, TestPassthroughResponsesEndsShort,
  TestSocketHeaderFramesOnlyForCodex, TestCodexSocketServed,
  TestResponsesEventsAreClientShaped: ok.
- broken by hand: gateway.go and responses_ws.go back to origin/main
  with the tests kept: both foreign clients red (codex.rate_limits,
  codex.response.metadata, response.metadata, keepalive there=true, no
  keepalive comment) and the socket test red with the leaked frames;
  the Codex cases stay green.
- gofmt -l clean; go vet -tags nogui ./internal/gateway on darwin,
  GOOS=linux and GOOS=windows ok.
- go test -tags nogui -timeout 45m -count=1 ./internal/gateway: ok
  (2186s), at this tree on origin/main c9d253e4a.
- rebased on 44d6dd75d (gateway.go changed upstream): the focused
  tests above with the new cap/group tests (TestCapGroup*,
  TestCodexOneAccountSpent*, TestPluginCapPool*) ok; vet ok.
Not tried: a real ChatGPT account with Grok Build (a second sign-in can
rotate the live refresh token); the full ./... suite (mote at load ~760
with a long suite-lock queue).

Reported-by: crayonlu
Reported-by: Jeo-Meek
Co-authored-by: crayon <hicrayon@outlook.com>
2026-11-09 12:36:18 +08:00