01huadalang on Discord (11-01): three ZCode accounts, three requests at
once each. The first two got a 405 and rested, so every request went to
the third, and those over its three waited in its lane. Once the first two
were back, the waiting ones stayed on the third, behind its long turns,
until its requests were cut by hand. Same under Smart, In turn and Stays
off.
Cause: a request that queued in a lane (lanes.take) waited only for that
lane's turn. Nothing looked again when another lane gave a slot back or a
rest ended. With ZCode's maxAccounts 2, the third took a seat while the
first two rested and was a reserve again once they were back, but the
requests already waiting for it stayed. laneMate also gave way to a mate
resting, because ready() checks only lane and RPM room.
Change:
- lanes.take takes a move func. While waiting (lanes.await), it looks
again when any lane gives a slot back, when a rest is lifted (Unrest,
UnrestAll signal lanes.freed), when the soonest rest among the others
ends, and at least every 5s (laneRecheck). waitMate finds the first
candidate after it in the planned order (then those probeOne left out
for resting) of the same provider, or any member of a group, that has
a free slot with no queue (tryTake), minute room, isn't resting, didn't
give way, and isn't a reserve as keepAtOnce stands now. The request
then leaves its queue (errMoved) and serve runs that candidate with the
slot already taken for it. A fallback provider is never one. Strict
stays leave no other candidate, so nothing changes there.
- laneMate skips resting mates.
- docs/subsystems/gateway-routing.md Limits row says so.
Tests:
- TestWaitingRequestGoesToAccountBackFromRest: 3 keys, cap 3, MaxAccounts
2, k1 and k2 resting (405), 9 requests. 3 go to k3, 6 wait for it, and
none reach the resting two. Then the rests are lifted (Unrest) or run
out (300ms), and the six go to k1 and k2 while k3's three are still
out (9 at once). Run under Smart and Rotate, with Stays default and
off.
- TestWaitingRequestTakesSlotGivenBackElsewhere: 2 keys, cap 1. A third
request waiting for one key goes to the other when that one's request
ends, under default, order, rotate and usage routing.
- TestFullMemberGivesWay updated. c, waiting for first, now goes to second
once second's b ends. d (first's fallback is second) still waits for
first.
Run on mote (mote-run), rebased on e65bc8473:
- go test -count=1 -timeout 45m ./internal/gateway: every test ok
except TestCodexPoolSaysTheClientsVersion (608s; #4807, below)
- go vet ./internal/gateway, GOOS=linux (-tags nogui), GOOS=windows: ok
- gofmt -l: clean
- go test -race -count=10 on the three tests above: ok
- That red is #4807, also the only red in an earlier full run (it passes alone,
here and on origin/main e65bc8473; another test's Codex version reaches
it).
Rebased again on 6b3a6d42c (VS Code agent host, gateway.go): at this
head, vet for darwin, linux and windows ok, gofmt clean, and go test -run
'Lane|Waiting|FullMember|AtOnce|VSCode|Vscode|AgentHost|Concurrency|
Queue|Rest|Probe|Affinity' ./internal/gateway ok (44s).
Broken by hand:
- On origin/main's code, the new tests and the updated
TestFullMemberGivesWay are red. The rest test fails at "six waiting for
k3" because laneMate handed requests to the resting keys.
- With waitMate's move ignored (if ok && false), every case is red at
"the waiting ones at k1 and k2", and so is TestWaitingRequestTakesSlot-
GivenBackElsewhere.
- With the rest's end ignored for the recheck timer (only laneRecheck),
the four "ran out" cases are red.
- Two test races were found under -race and fixed in the test: the rest
was timed from before the nine were sent, and the concurrency count was
read before the ninth reached the fake vendor.
Not tried: real ZCode accounts or the ZCode plugin. The plugin's own 405
handling and maxAccounts are as before. Not run on Windows or Linux
machines; vet only.