magpie icon indicating copy to clipboard operation
magpie copied to clipboard

test: TestIntentClassifierGroup's 3s bound on the classifier loop fails under load (3.17s, reply right)

Open yetone opened this issue 1 month ago • 3 comments

Seen in a full go test -timeout 40m ./... on a machine at load average 66-100 (several sessions running suites), at 4877a9ecc (origin/main 23e764d0e + #1801/#1798, neither touches classify).

--- FAIL: TestIntentClassifierGroup (18.56s)
    classify_test.go:425: loop: {..."content":"from kb"...} ... Classified:{By:group/cls Intents:[refactoring] ... Ms:1890 Error:} 2 3.174249417s

Everything else in the check holds (the reply, N=1, no classify error, c asked twice). Only time.Since(t0) > 3*time.Second fails. The classifier call alone took 1890ms. Run alone on the same head, it passes (go test ./internal/gateway -run TestIntentClassifierGroup, ok).

The bound is there to show the cls↔r loop asks nobody, rather than to time the turn. A count of upstream requests (already c.n() == 2) or a much wider bound would test that without wall-clock. Same shape as #1800.

In the same run, internal/gateway and internal/agent each hit the 40m package timeout (stacks: gateway in TestPluginStreamLargeReplies/JSON_fast, agent in TestPrimeAgent at 0s, so no test was hung, the packages just ran out of time). Both tests pass alone (gateway 55s for the failing set, agent 10s). Noted here so it is on file, not as a separate bug.

yetone avatar Oct 12 '26 13:10 yetone

Took this one (state was OPEN with no claim; git log --grep=1813 shows no fix on main as of b1d02fa6). Since the repo doesn't take pull requests, the fix is on a branch of my fork for cherry-picking — one commit (aeaf6703) covers this, #1829, #1812 and #1791:

git fetch https://github.com/Niko-Wu/magpie fix/timing && git cherry-pick aeaf6703

(based on current b1d02fa6, single commit, test files only)

Root cause — the turn was bounded by wall-clock instead of the count the test is about:

  • internal/gateway/classify_test.go:472-476 (old) bounded the g2 turn at time.Since(t0) > 3*time.Second. The bound was there to show the cls ↔ r pair (each is the other's classifier) asks nobody from inside its own call — but that is already counted: the same check asserts c.n() != 2 fails the test. On a busy machine the turn spent 3.17s with the reply right and nobody asked again.

The fix (the count is the guard, the bound added nothing it doesn't catch):

  • classify_test.go:485-495 — the 3s bound and its t0 are gone. If the loop guard broke, c would see more than its two asks and the count check goes red on its own.
  • Broken by hand to prove a real violation is still caught: turning the loop guard off (internal/gateway/gateway.go:1762, the RouterAgent → ask = nil branch) makes the turn recurse, c.n() climbs past 2, and the fixed test fails.

Red → green

  • On origin/main 707fbb24, injecting 3.4s into ruleUp.ServeHTTP reproduces your red: loop: at classify_test.go:475, turn 3.449s > 3s with c.n() == 2 — the bound red, the count fine, exactly your report. With the fix, the same injected load passes -count=3.

Verification

  • The four changed tests, go test -tags nogui -count=3: internal/gateway 21 passed (classifier + TestMaxRPM set).
  • Full packages go test -tags nogui: internal/gateway 4192 passed on the final tree.
  • gofmt -l clean; go vet -tags nogui clean for GOOS=linux and GOOS=windows.
  • Not run: -race; CI's machines.

Niko-Wu avatar Oct 15 '26 03:10 Niko-Wu

Seen again on e72b6a332, in a full go test -tags nogui -timeout 45m ./... at a load average of about 190: loop: … 2 3.632694584s. The reply was right and the classifier was asked twice, as the test expects. Only the 3 s bound failed. I'm not taking this issue: I'm on plugins #149.

yetone avatar Oct 16 '26 08:10 yetone

Seen again on 10-16, full go test -timeout 45m ./... on d4e7f56d2 (origin/main 63be47717 + #2489, which touches no classifier or gateway code), load ~290:

--- FAIL: TestIntentClassifierGroup (16.57s)
    classify_test.go:475: loop: {... "content":"from kb" ...} ... Classified:... {By:group/cls Intents:[refactoring] Intent:refactoring ... Ms:1796 ...} 2 5.8119165s

The reply was right, but the loop took 5.81s against the 3s bound. Alone on the same head it passes. This is still the bound measuring time, not state.

yetone avatar Oct 16 '26 09:10 yetone