yyhhyyyyyy (Discord, 10-28) saw an agent's parallel requests queue behind
Guard's one turn and asked for a concurrency setting (16). The turn now has
guard.Cores() places (half GOMAXPROCS, 4 at most). The cores are shared: a
process-wide pool of Cores() tokens, each window takes one before it reads
and more only while they are free (guard.take), so requests together never
use more cores than one did (the 4-core cap of 10-28, xinvxueyuan and
shensmart). The model loads once (guardLoading), the idle unload waits for
every place (guardIdle), and a text one request is reading another waits
for instead of reading it too (backend.reading). On CoreML windows are read
one at a time; only windows under coremlMin or after a failure take CPU
tokens.
No setting: measured, the bound is cores, not the request count.
Bench (zz bench, not committed): requests/s at 1/2/4/8 concurrent.
- Linux (WSL magpie-desktop, Ryzen AI Max+ 395, Cores()=4):
512 B shared 4.2/6.1/8.1/8.4 on 1.9-3.9 cores, rss ~150 MB
one turn (before) 4.2 whatever came
unshared 4.4/8.8/14.1/20.4, on 12 cores at 8
4 KB shared 0.6/0.5/0.6/0.7 (one 4 KB already reads 3 windows on 3.6 cores)
unshared 0.6/1.1/1.7/2.2, 20 cores and 521 MB at 8
- Windows (xiaomi-gpu, same box, busy with other runs):
512 B shared 7.5/9.2/11.3/12.1 on <=3.8 cores; unshared 5.1/9.6/15.9/24.1 on 13 cores
4 KB shared 0.7/0.8/0.8/0.8; unshared 0.9/1.2/1.8/2.4, 18 cores, 519 MB
- mote (M5 Pro, load 25-45): CoreML 4 KB 23.0/19.6/25.1/24.9, a model a
worker 15.7/25.6/25.5/23.4, rss ~190 MB flat: the GPU is the bound.
CPU unshared 4 KB at 8: 953 MB.
Tests: turns_test.go (TestGuardReadsRequestsAtOnce, TestGuardIdleWaitsForEveryTurn,
TestOneTextReadOnceAtOnce), guard/cores_test.go (TestTakeHoldsOnlyWhatIsFree,
TestFindsAtOnceReadAsOneAtATime: concurrent finds equal serial ones).
Broken by hand, each red: one turn ("1 turns, 4 cores"), no load lock
("4 loads"), idle taking one place ("let go while a request read it"), no
in-flight check (TestOneTextReadOnceAtOnce), take waiting for more (10s
timeout fail).
Run:
- wsl-run: go test ./internal/pii/... ok; -race -count=3 ./internal/pii ok;
-race guard TakeHolds/FindsAtOnce ok.
- mote-run: gofmt -l internal clean; GOOS=darwin/linux/windows go vet
./internal/pii/... ./internal/masking/ ok; MAGPIE_GUARD_DIR=real model
go test ./internal/pii/... ./internal/masking/ ok (CoreML).
- win-run: go test ./internal/pii/... ./internal/masking/ with the real model ok.
- mote-run full go test -timeout 45m ./... of this and the commit before
(at c3462d5fe): red only in TestClaudeAccountsSpentFallBackToCodex
(#2858, #2859), TestGatewayHookWaitsForStartingHost (#2871), both ok
alone after, and AppKit window tests in internal/gui (#2645, #4125), red
the same alone at origin/main e15b2277c on mote.
Not tried: a real agent's parallel requests through the gateway.