TestOverflowRefusedOnceIsAskedLast's "compacted" request changed the
conversation's only user message. A ruled group keeps a conversation by
its first user message (firstWords in the stick key), so that request
was another conversation, and passed with behindOverflow's size check
taken out. Nothing asked that what a member answered is forgotten.
The conversation now has turns after its first user message, and the
compacted request keeps that message and drops the rest: the same key,
a smaller body. a answers it, and the conversation grown back to the
size a once refused begins with a again.
Run on mote, -tags nogui ./internal/gateway/:
- -run TestOverflowRefusedOnceIsAskedLast: ok.
- size check taken out (size >= r.bytes always true): FAIL at
overflow_learn_test.go:71 "compacted: ... (a 0, b 1)".
- forgetOverflow call taken out: FAIL at :81 "after a answered: ...
(a 0, b 1)".
- -race -count=20 of this test, TestOverflowMemoryReadWhileNoted and
TestRelayInputCapGoesToTheNextMember: ok.
Review follow-up to ggbdpq's 075aaef62. behindOverflow took the
conversation's inner map under overflowLearned's lock, let go, and then
read it, while noteOverflow and forgetOverflow write that same map under
the lock. Two requests of one conversation at once (a turn beside its
title ask, a client's retry) read and wrote one Go map together, which
is a fatal "concurrent map read and map write", the whole gateway gone.
The loop now runs under the lock.
TestOverflowMemoryReadWhileNoted notes and forgets on one goroutine while
another orders members by the memory. Before this commit, on mote:
go test -tags nogui -race -count=1 -run TestOverflowMemoryReadWhileNoted
./internal/gateway/ -> "--- FAIL: TestOverflowMemoryReadWhileNoted ...
race detected during execution of test". With it, -race -count=20 of
that test, TestOverflowRefusedOnceIsAskedLast and
TestRelayInputCapGoesToTheNextMember: ok.
Also: behindOverflow's comment said resting members keep their order;
the code moves a refused member behind every other one, resting or not,
so the sentence is dropped. gateway-routing.md now describes the memory
beside withRoom's overflow paragraph.
What changed: an overflow (400, "prompt is too long") is the request's
length, not the account's, so it rests nobody — and left no trace: the
next request of the same conversation tried the member again, failed the
same way, and fell back again, for every request (#3453: a rule sent
every turn to a Claude subscription bridge that answered "Prompt is too
long" and DeepSeek answered; two consecutive requests of one turn each
paid the refused try first). Now the conversation remembers, per
provider's model, how large the request was when it was refused, and the
member is put behind the others — behind, not out: it is still asked
when every other member has failed, a rule that names it is still
heard (ruleOver has run), and what it answers makes magpie forget the
refusal. A request smaller than what was refused — the agent has
compacted the conversation — finds the member where the rule put it.
Another conversation is unaffected, and a byte cap (413) is not
remembered: it is not the conversation too long for the model.
TestRelayInputCapGoesToTheNextMember's second phase shares its server
with the first, whose overflow left this conversation's memory of a's
refusal behind; as that phase says how a plain bad request is classed,
its memory starts empty.
Run: go test -tags nogui -count=1 -run
'TestOverflowRefusedOnceIsAskedLast' ./internal/gateway/ (red on
c688211d1 with the test alone, green here); go test -tags nogui
-count=1 ./internal/gateway/; go vet -tags nogui ./internal/gateway/;
gofmt -l internal/gateway clean. Broken by hand: the product half of
the commit dropped (affinity.go, gateway.go hooks), the test red at
"second: (a 1, b 1)"; restored, green.
Generated-by: GLM-5.3-Flash (ZCode)