Commit Graph
23 Commits
Author SHA1 Message Date
yetone 59d9f5c7d9 gateway, redact: compile their 275 package-level regexps on first use, not at every start
magpie is one binary, so every package's init runs on every launch,
including `magpie statusline`, which Claude Code runs on every message.
internal/gateway and internal/redact compiled 275 patterns at init:
3.7 MB + 2.3 MB and ~38k allocations per launch, most of them for
vendors and rules that launch never reaches.

New internal/lazyre: RE holds the source and compiles it through a
sync.Once on first use, with the *regexp.Regexp methods magpie calls
delegating to it (Of wraps one already compiled, for the user's own
privacy rules). A one-off Go AST rewrite turned every regexp.MustCompile
in a package-level var (outside func literals) into lazyre.New; the
struct fields, map and parameter that hold them took the new type. A
bad pattern now panics on first use instead of at start, so
TestAllCompile in gateway and redact compiles every registered one.

Measured on mote (M5 Pro), sandbox HOME with a copy of real accounts,
v0.1.3515 (273b9f5a9) vs this change:
- GODEBUG=inittrace=1: all init 13.0 MB / 106k allocs -> 7.4 MB / 70k;
  gateway 3.68 MB -> 70 KB, redact 2.31 MB -> 261 KB.
- `echo {} | magpie statusline`, /usr/bin/time -l, 3 runs each:
  instructions retired 260-265M -> 212-215M (-18%), peak footprint
  22.1-22.3 MB -> 18.6-19.2 MB.

Run: go vet ./... (mote); GOOS=linux and GOOS=windows go vet of
gateway, redact, lazyre; go test -race ./internal/lazyre (incl. a
bad-pattern test that MustAll panics); go test ./internal/redact (all);
go test ./internal/gateway -run 'TestAllCompile|OtherOff|WorkDir|
WorkPlace|RunNoise': ok. Broken by hand: TestBadPatternPanicsInMustAll
registers `(` and fails if MustAll does not panic.
Not run before the push: the whole internal/gateway package and the
full suite (a full suite of 273b9f5a9 was running on mote).
2026-11-10 12:34:14 +08:00
yetoneandggbdpq 7e5a54147f gateway: a routing group's intent sureness is its own, intent-sure= (#5101)
Jev's sure of an intent had to reach jevSure, a fixed 0.4, for every
group. zminds measured 39 of 237 turns in one day (16.5%) refused at sure
0.153 to 0.395, and those turns went by the group's routing as if it had
no intent rules. A group can now set its own threshold: intentSure, from
0 (take Jev's likeliest intent however unsure) to 1. Missing keeps 0.4.

readJev keeps Jev's likeliest intent, its sure and Topic (an answer of
intents rather than levels). ruleFor applies the group's own sure through
intentOf, so two groups sharing one classifier and its cached answer each
judge it at their own. "none of these" is never an intent, at 0 too.
Levels and effort are as before.

Set from a terminal: magpie group set <group> intent-sure=0.25, empty to
unset. SaveGroup and the CLI refuse a value outside 0 to 1, NaN too: the
patch's `v < 0 || v > 1` let intent-sure=NaN through the CLI, which
SaveGroup then failed on as "json: unsupported value". cloneGroups copies
the new pointer, since TestCloneGroupsSharesNothing went red on it.

Changed from ggbdpq's patch on #5101:
- The group editor's "Intent sure" row is left out. Its hints were long
  secondary text, it showed for every classifier when only Jev answers
  with a sure, and it had no GUI test. The Routing page instead carries
  intentSure through each save it makes of a group (the editor's Save,
  the routing menu, the manual pick), so a value set from the CLI isn't
  wiped by the next GUI save.
- Its i18n strings and site/public/docs/intent.html are left out. A
  site/ change waits for the maintainer (docs/contributors.md). The site
  diff was documentation text only: a paragraph id="sure", a sentence
  in "Match the rules" and one table row. It had no links or scripts.
- docs/subsystems/gateway-routing.md has a bullet for IntentSure.

Run on mote (mote-run):
- gofmt -l internal/: clean.
- go vet -tags nogui, also with GOOS=linux and GOOS=windows, on
  internal/gateway, internal/cli and internal/provider: clean.
- go test -tags nogui -run 'TestGroupIntentSure|TestJev|Rule|Classif|Decide'
  ./internal/gateway: ok.
- -run 'Group|Apply' ./internal/cli: ok.
- -run 'Group|Save|Clone' ./internal/provider: ok.
- go test -run Budget ./internal/gui: ok.
- node --test group-intent-sure (new), routing-group-strategy and
  group-first-token, in Chromium and WebKit: 42 pass, 0 fail.
- i18n-keys has one red, "a plugin's words are its own". It fails the
  same on origin/main b712adb84 and is filed as #5327, #5332 and #5426.
  i18n-en-no-cjk: ok.

Broken by hand, each red, then restored:
- sureNeeded always returns 0.4: TestGroupIntentSureThreshold,
  ZeroTakesTheArgmax and IsPerGroup FAIL.
- The patch's `< 0 || > 1` checks put back: TestGroupIntentSurePairs
  FAILs on "NaN" and "nan"; TestGroupIntentSureRange FAILs on NaN.
- The cloneGroups copy removed: TestCloneGroupsSharesNothing FAILs.
- The editor's Save sending intentSure null: group-intent-sure FAILs 4/4
  ("the editor's Save keeps it").
- The routing menu's pick sending null: it FAILs 4/4 ("a routing pick
  keeps it").

Not tried: a real Jev account with a group at 0.25; the full suite.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-06 10:44:24 +08:00
ggbdpq f73b780422 gateway: a group's trace says what its classifier said, as it said it (#4598)
What changed: Classified keeps the classifier's answer as it said it
(said): the number a chat model answered with, 0 for none, or the choice
a decision model named, "none of these" included. readIntent gives the
number back, readJev keeps the choice, and the trace's rule.classified
carries the said on. An answer that named no rule's intent — a chat
classifier's 0, a decision model's own none-of-the-kinds option, a kind
named under the sure-enough bar — all read "said none" in the trace
before, so a group's fallback kind ("not any of the above") that never
matched looked the same as an answer no rule could take.

The matching itself is as it was: a classifier that answers the
fallback kind's number still routes by that rule, which a test now
holds (it passes unchanged); the said is only what the trace tells.

Run: go test -tags nogui ./internal/gateway (pass; without the change
TestClassifiedSaysTheClassifiersAnswer fails "the classifier said 0,
the trace says \"\"" and TestClassifiedSaysWhatJevChose fails "Jev
chose \"none of these\", the trace says \"\""); gofmt -l prints
nothing; go vet and GOOS=linux/windows go vet on the package pass;
go build on darwin, linux (-tags nogui) and windows pass.

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-02 05:38:10 +08:00
yetone b1a1b950fe routing: the classifier asks its model not to think (tangtang969 on X)
"classifier的模型调用可以加上不带思考的参数么?提速效果比较好". A routing
group's classifier (and its effort question) asked its model for the
least level on its list, and nothing at all when the list was unknown,
so a relay's reasoning model thought at its vendor's default before
answering a number.

Now classifyEffort asks for none, reasoning off, and each wire fits it
with the code that already fits a client's none:
- Chat/Responses: a model with none gets none; one without gets its
  lowest (fitFor: low, minimal), as before; one whose levels aren't
  known gets none (as auto mode's classifier does, fitAutoModeClassifier).
- Anthropic: thinking {"type":"disabled"}; Opus 5.5, which refuses it,
  still has it left out (thinkingOffAsTaken).
- Gemini API / Code Assist 2.5: thinkingConfig.thinkingBudget is the
  off budget (0 for Flash and Flash-Lite, 128 for Pro, as Vertex already
  did) where a Chat none went as low's 4096. Gemini 3 is unchanged (low).
- A model the user marked as taking no reasoning ask (Reasonless) is
  sent none at all; a routing group as classifier is left as before.
- An upstream that turns the effort away (unknown reasoning_effort
  field, or the level) is asked again without it and remembered
  (askLeast), so the classifier keeps answering.
The Image recognition model keeps its old least-level rule
(leastEffort); only the classifier changed.

Run (mote-run, this tree on origin/main 90518de26, rebased onto
d83823d26, which touches internal/agent only):
- go test ./internal/gateway -run 'TestClassifierAsksThinkingOff|
  TestClassifierThinkingAsEachVendorTakes|TestVisionEffortUnchangedByClassifier|
  TestIntent|Classif|TestAdaptiveOnly|Vertex|Gemini|Think|Decide|Effort': ok
- go test ./internal/gateway -run 'CodeAssist|Codeassist|Antigravity|
  GeminiCLI|Gemini|AIStudio|Auto|Rule|Group|Vision|Search|Reason|Off': ok
- go vet ./internal/gateway on darwin, linux, windows; gofmt -l clean.
Broken by hand: classifyEffort back to the least level and the 2.5
off budget turned off: TestClassifierAsksThinkingOff (anthropic, gemini
2.5 flash, unknown chat), TestIntentClassifierEffort and the 2.5 Pro case
go red. Before askLeast, the "effort turned away" case was red (the
classifier failed on a relay refusing reasoning_effort).
Not tried: a real vendor account; the whole internal/gateway package
and full suite (running after the push). On Anthropic, the old body for
claude-sonnet-4-5 had no thinking at max_tokens 2048, so that model
wasn't thinking before either; the change there is the explicit
disabled.
2026-10-31 16:38:58 +08:00
yetone f7f2d75f2c gateway: nested routing groups share one classifier wait, not one each (heatonz)
heatonz on Discord (v0.1.2215): requests through nested routing groups
often failed after 120s with 504 "magpie held this request for 2m0s
without routing it to any provider". The 2m is the unrouted watch's
bar for known waits, and the wait was the decision model: the top
group's ruleFor and each ruled nested group's (nestedRules) asked its
classifier with a whole classifyTimeout() of its own, one after
another, before the route was begun. With classifiers that don't
answer, N ruled levels held a request N waits (60s x 2 is exactly the
2m). Jason's fix shared one wait across a decision model's key
failover (askDecideTries); the levels were the sibling it missed.

Now a request has one classifier wait, from the first classifier
asked (Server.askWaited), shared by every group it goes through:
- a level asked with time left gets only what's left (askClassifierIn,
  askChat, askDecider/askDecisionGroup/askDecideTries take the wait);
- a level asked once it is spent isn't asked: it goes by its group's
  order at once, as for a classifier that didn't answer, and its
  Classified.Error says "spent by the routing group above";
- a classifier or decision key cut short by the shared wait (waitSpent,
  cutShort) is not rested (classifyRest, decideFailed): it had less
  than its own wait, and nothing says it is down.
docs/subsystems/gateway-routing.md says so.

Nothing from v0.1.2215 to origin/main 2df46e3c8 touched this path.

Tests (new, internal/gateway/nested_classify_wait_test.go):
- TestNestedGroupsShareTheClassifierWait: outer > mid > inner, each
  ruled on intent with its own classifier that never answers,
  classifyUnit 60ms (8s -> 480ms), unrouted most 1.1s. Red on
  origin/main 2df46e3c8: 504 "held this request for 1s without routing
  it" after 1.45s. Green: 200 from a/m, nested levels say "spent",
  only cls1 rests. -count=5 green.
- TestDecisionKeyCutShortIsNotRested: a decision provider's key cut off
  at 50ms of a 200ms wait is asked first again.

Broken by hand, each red then put back:
- askWaited giving each level a whole classifyTimeout(): the 504 again;
- classify resting waitSpent errors: cls2 and cls3 rest;
- askDecideTries without the cut-short case: the key's error is the
  plain "no answer in 50ms", and it is rested.

Run on mote (mote-run), at this tree except a comment moved back onto
askClassifier afterwards:
- go test -timeout 45m ./... : every package ok but internal/gui, whose
  10 real-window AppKit tests (TestMainWindowCorners,
  TestPanelCloseHidesIt, TestDockJoinLeadsCommandTab, ...) were killed
  at their deadlines: mote's AppKit hang, #4125 / #2645. internal/gui
  is not touched here. internal/gateway ok (745s).
- at the final tree: GOOS=linux, GOOS=windows and darwin go vet
  ./internal/gateway, and the Classif|Decide|Decision|Rule|Unrouted
  tests plus the two new ones: ok. gofmt -l clean.

Rebased onto origin/main 59109044c (no internal/gateway change between):
go vet ./internal/gateway and the same targeted tests ok there.

Not tried: heatonz's own groups and settings (their Classifier timeout
and classifiers aren't known; 60s with two ruled levels fits the 2m0s,
and the 30s between rows matches classifyRest), and a real slow
decision model; only fake upstreams. GUI not touched, GUI suite not run.
2026-10-30 23:28:16 +08:00
yetone c46829e0b4 routing: a group's card says its classifier's failure only when that group asked it
jjt on Discord: the Routing card of "claude难易" (group/claude-ny), which
no turn of theirs was sent to, said "分类器3分钟前失败:claude/claude-haiku-5-5:
Claude Code: You've hit your weekly limit", read as magpie asking its
classifier at every turn. The card read the failure by classifier model
(ClassifierFailure), so every group sharing a classifier showed the
failure of whichever group had last asked it.

What runs the classifier was not changed: ruleFor asks it only for a
request whose model is the group (group/<id>, its name, or a stand-in an
agent's config names it by: Claude Code's tiers, Codex's bare name), or
for a group in it its rules or order put first (nestedRules). A request
for another model or group asks nothing. Out of quota, the classifier's
account rests until the reset (restAfter), so later classifier calls get
magpie's held refusal back, at most once each classifyRest (30s), and
do not reach the vendor.

Now ruleFor notes the outcome per group (classifiedFor) and the card
reads GroupClassifierFailure(group, classifier): the classifier's own
words and time (resting or not) from that group's last ask, cleared when
it answers that group, and nothing once the group's classifier changed.

Run (mote, macOS 27, Go 1.26.8), at base 4586307de:
- gofmt -l internal: clean; go vet darwin, GOOS=linux -tags nogui,
  GOOS=windows for ./internal/gateway ./internal/gui: ok
- go test -count=1 -timeout 45m ./internal/gateway ./internal/gui:
  two reds, neither in this change. TestUnroutedHeldReportSaved passed
  5 of 5 alone after; filed #4300. TestMainWindowCorners/macOS_26_SDK
  is #3949.
- -run 'TestClassifierFailure|TestGroupsSayAClassifier': ok
- node --test internal/gui/tests/group-classifier-failed.test.cjs: 20 of
  20 (Chromium and WebKit, both widths, every language)
- Broken by hand: GroupClassifierFailure read by model as before, and
  TestClassifierFailureIsTheGroupsOwn went red ("idle, which nothing
  asked: c/cls: C: classifier down").
Not tried: a real Claude Code account at its weekly limit.
2026-10-29 23:36:58 +08:00
yetone 29185e3bbc gateway: a request held too long before routing leaves a report its user can copy
Jason on Discord (#general, v0.1.1995, AirbuildEnvironment over Codex's
/backend-api/codex/responses) got the 2m 504: "magpie held this request
for 2m0s without routing it to any provider ... report it with magpie's
log". The desktop app runs the gateway in-process and logs only to
stderr, so there is no log for him to send.

giveUp now writes a report of the held request to a small file in
magpie's cache (held/, folder 0700, temp file renamed into place, the
newest 5 kept). It holds the time, version, OS, the method and path, the
model and agent, how long it was held, each named wait with its time and
whether it was still under way (noteWait now takes a kind: body, body
room, decision model, image description, plugin hooks, JS middleware,
Codex reset, masking), the body room's state, the requests in flight,
and a goroutine profile (function names and lines only, cut at 128KB).
It holds no body and no headers. Route.Held names the file. On the
Routing page, the request's story then says a report was saved, with
Copy Report and Open Folder (Open Folder is left out in magpie web).
GET /api/gateway/held/{name} reads only a report's own name. The 504's
text no longer points to a log: it names Copy Report on the Routing page
and the folder. The log line names the waits too. i18n is in zh, zh-TW,
ja and de, and docs/subsystems/gateway-routing.md has the section.

What held Jason's request is not known from what he sent. The waits that
count before routing are: the body arriving (idle deadline only), body
room (up to 100s, then 503), the decision model (see the next commit),
plugin hooks (11s), JS middleware (250ms a hook), image description
(bounded by the request) and the Codex reset (20s). Slots, RPM and
upstream come after the route begins. A WebSocket upgrade gets a 426.
The report names the wait, so the next one says which.

Run:
- mote, at 57b21abd9 before the rebase: go test ./internal/gateway
  -run 'Unrouted|Held|...' passed. The full go test ./... -timeout 45m
  was cut off when mote dropped off the network (2 packages ok). The
  full suite then went to the Windows box (see the next commit).
- xiaomi-gpu (Windows), node --test: routing-held-report 50/50 in
  chromium and webkit, 5 languages, 1100/420px, app and web.
  routing-held-request and i18n-keys pass. All routing-* and i18n*:
  1742 tests, 94 reds, none in i18n*. The same files are red alone at
  origin/main 033b17baf (22 of 46 in WebKit), recorded on #4124.
- GOOS=windows/darwin go vet ./internal/gateway ./internal/gui,
  GOOS=linux go vet ./internal/gateway, go build ./... : ok.
Broken by hand: leaving Route.Held unset turned
TestUnroutedHeldReportSaved red ("names no report"). Dropping the
story's report line in client.js turned routing-held-report red in both
engines.
Not tried: a real held request in the real app. Linux vet of
internal/gui (cgo for Wails, cross-compiled). The GUI test on macOS
WebKit, since mote was unreachable.
2026-10-29 15:10:34 +08:00
yetone 5a94eec3ae gateway: a request held 30s before routing in no known wait is answered then
sharwowwow on X: "转圈两分钟才报 504,这个超时阈值本身就很折磨人。网关要是能
早点失败、早点给明确错误,排查能省不少时间。" A request held before any
route was answered 504 only after unroutedMost (2m), whatever held it.

Now the time a request spends in a wait magpie knows of is added up as it
happens (noteWait/waited, the union of overlapping waits), and a request
held unroutedUnknown (30s) outside them gets the same 504 and message
then. unroutedMost (2m) stays the cap for one in known waits. Known waits,
each read from the code between counted and noteRoute:
- the request's body arriving: r.Body is wrapped (waitedBody), so every
  read of it (keyLimited, requestBody, readRequestBody) counts;
- masking (noteMasking);
- System One's or the decision model's classifier (askWaited);
- an image's description (seenBody);
- Codex's auto reset before the route (autoReset);
- plugins' gateway hooks / plugin host start (GatewayBegin) and JS
  gateway middleware (Begin, Request);
- every notePhase (slot, rpm, upstream); these come after the route for
  watched requests today, so it only guards a future change.
What is left is magpie's own work (catalog build, parsing, planning,
affine, reading the usage log), ~8.5s at its slowest (a cold catalog
sync); 30s is about three times that, with room for a loaded machine.
The log says "30s of it in no wait magpie knows of".

Run at this tree (rebased on origin/main 9120acaff):
- gofmt -l internal/gateway: clean.
- go vet ./internal/gateway/... on darwin, GOOS=linux, GOOS=windows: ok.
- go test -timeout 45m ./internal/gateway/...: ok (478.0s).
  Also ok on the earlier bases a5ce158e5 (655.8s) and 7d075df9d (448.1s).
Not run: the full go test ./... and go vet ./..., because the machine's
disk was full (under 1GB free for over 20 minutes; a build and one
gateway run failed with "no space left on device", every red naming it). No -race run.

Broken by hand, each test red, then restored:
- without the 30s answer (u.giveUp(true)),
  TestUnroutedUnknownHoldAnsweredSooner: not answered before unroutedMost;
- without the body wrap, TestUnroutedSlowBodyNotCutOff: answered 504
  while its body was still arriving;
- without masking's excuse, TestUnroutedMaskingNotCutOff: answered 504
  while it was masked.
TestUnroutedSlotWaitNotCutOff stays green without notePhase's excuse (the
slot wait is after the route); it guards that a slot wait is never cut.

Not tried: no test of its own for the classifier, auto reset, gateway
hook, JS middleware or image-description excuses; no run in the real app
or against a real provider.
2026-10-26 19:04:27 +08:00
Yang Yu a1cce7faa1 gateway: the decision model's timeout is a setting (#2934, reyoung)
A routing group's intent classifier (askChat) and System One (askJev)
were each given a fixed 8s. A slow subscription classifier can now be
given longer in Settings > Models > Replies > Intent classifier timeout.
settings.json's classifyTimeout takes 1..60 seconds; 0 or missing keeps
8s. save() refuses below 0 or above 60, and ClassifyWait clamps a value
edited by hand (below 1 gives 8s, above 60 gives 60s). A settings file
that can't be read gives Shared()'s defaults, so 8s, never no timeout.
Both askChat and askJev read it per call. The GUI row is the app's own
segmented control (8, 15, 30, 60, plus a value set by hand), and other
saves carry the value on (prefsKeep, api.go). zh, zh-TW, ja and de
strings; the routing reference and the en, zh, ja docs say it.

Ported from reyoung's classify-timeout-2934 (author kept). On top:
- askJev's defer reworded any error once ctx had expired, so a refusal
  (decideRefused) or an answerError read as the wait ran out lost the
  type askDecideTries rests an account by. Now only errNoAnswer, which
  systemOne returns when postDecide failed with ctx done, is reworded
  to "<provider> gave no answer in <wait>".
- ja intent.html: a stray space in "遅いモデルだと 設定した".
- app.js: the Image generation timeout row and the new row share
  waitRow (~350 bytes less). TestCoreScriptBudget was red (app.js
  1,337,982 > 1,337,000); budgets raised to the exact sizes, app.js
  1,337,633 and core 1,529,393, no room added.

Run (macOS, Go env pinned, sandbox HOME):
- Full go test -tags nogui -timeout 45m ./... at 766cf1cf9: 68 packages
  ok; internal/gui red on TestCoreScriptBudget only, fixed above.
- At ed008ca9f and again after rebasing on 65e80405b: internal/gateway,
  internal/settings, internal/gui ok; gofmt -l clean; go vet (darwin),
  GOOS=linux go vet -tags nogui, GOOS=windows go vet all ok.
- Whole GUI suite at ed008ca9f, chromium and webkit, 4 wide at load
  ~30: 11,930 tests, 52 red, none in the files this change reaches
  (classify-timeout-setting, image-timeout, i18n-keys all pass). The
  red files rerun alone: 44 red in 10 files, the same 44 on origin/main
  65e80405b. All have issues (#2228, #2399, #2150, #2448, #2276, #3091,
  #2549, #2163, #3099, #3104) except library-mcp-health-wsl's ja case,
  filed as #3350.

Broken by hand, each red then restored:
- classifyTimeout fixed at 8: TestClassifierTimeoutSetting and
  TestJevGivenTheClassifierTimeout red.
- askJev fixed at 8: TestJevGivenTheClassifierTimeout red.
- save()'s bound removed: TestClassifyTimeoutKeptAndBounded (-1
  accepted) and TestSettingsClassifyTimeout (61 gives 200) red.
- ClassifyWait's clamp removed: red (600 waits 10m0s).
- api.go's keep removed: TestSettingsClassifyTimeout red.
- prefsKeep's classifyTimeout removed: the GUI test's "sent on with
  other saves" red in chromium and webkit.

Not tried: a real slow classifier or account; Linux and Windows at
run time; the native Linux desktop build; a test that pins the askJev
refusal-at-deadline race (it is timing-only, so no deterministic red
was written for it).
2026-10-23 15:03:08 +08:00
yetone 6b5501027d gateway: Jev is told the user's message before and the reply to it, so a short follow-up routes like its turn (@HirotaNagai on X)
A follow-up like "继续", "yes" or "fix that" was classified alone, so it routed
as a trivial turn. The decision classifier (Jev's state and the chat-model
classifier's prompt) now also gets previous_user_message and
previous_assistant_reply, when present.

- Taken from the same parsed request as the classified message, after the
  gateway masks it, so the new fields are masked the same way. The answer
  cache key includes them.
- The reply is the text of the latest assistant message after the previous
  user message. Never thinking, tool calls, tool results or system prompts;
  a tool-only reply gives nothing.
- Caps: the message keeps 3000+1000. The previous user message is cut to
  its first 750 and last 250; the reply keeps its last 1000. Together at
  most half the message's cap.
- The intent, level and effort instructions name the keys only when they
  are present, as context, not the thing being judged.

Tests: TestTurnBeforeEachProtocol, TestTurnBeforeCuts,
TestJevIsToldWhatCameBefore, TestChatClassifierIsToldWhatCameBefore,
TestClassifyKeepsAnAnswerPerTurnBefore, TestJevSeesTheTurnBefore. Each was
broken by hand and went red (10 breaks: reply taking thinking or tool
arguments or a tool result, searched past the user message, no caps,
jevState dropping the keys, priorAsk naming both always, writePrior not
called, rules.go not setting prev, a cache key without the turn before,
privacy off in the end-to-end test).

Run at 85eef5d87 + this: gofmt -l clean; go vet ./..., GOOS=windows go vet
./..., GOOS=linux go vet -tags nogui ./... ok; go test -p 3 -tags nogui
-timeout 45m ./... 65 packages ok; internal/agent timed out at 45m under
load ~350 (origin/main alone: 2305s), alone with -timeout 90m ok, 936s
(#2544). Rebased on 89521b03d; full suite at bf2018807 (89521b03d + both commits): go test -p 3 -tags nogui -timeout 45m ./... under a sandbox HOME: 65 packages ok, gateway among them; internal/agent hit the 45m timeout (#2544, as on main under load ~330). gofmt -l clean; go vet -tags nogui, GOOS=windows go vet of internal/gateway ok.

When every group member skips redaction, unredactedRoute handed Jev the
unmasked body, now with the turn before as well; the next commit masks
what Jev is told.
2026-10-17 22:45:57 +08:00
yetone ecaa7e7dd7 gateway: a decision provider of several keys asks the next when one is out of quota, at /v1/systemone and as a classifier, in its routing's order (fflake33 on Discord)
A TypeSafe Jev provider with several keys never left its first key when that
one's quota ran out. serveSystemOne and the classifier (askClassifier → askJev)
always sent to p.Key, with no rest and no rotation. Only a decision group
failed over (serveDecisionGroup, askDecisionGroup).

Now the single provider goes the same way as a group:
- decideKeys plans its keys and accounts with s.plan, so Smart or In order,
  rests and barred keys apply. probeOne keeps only the resting one back
  soonest.
- serveDecideTries and askDecideTries (the group's loops, pulled out) ask
  each in turn. A retryable failure that isn't the request's own rests it and
  the next is asked.
- serveSystemOne keeps #905's limits. A gateway key held to some accounts is
  asked only on those (allowedCandidates), and gets 403 keyAccountsError when
  none serves the model.
- A provider whose every key is set not to serve the model is refused 403
  (barredError) instead of being sent on its first key.
- decideSeat is gone; the trace lists every key tried.
- docs/subsystems/gateway-routing.md says so.

Run: go test -p 1 -tags nogui -run 'SystemOne|Decid|Decide|Jev|Classif|
KeyAccount|KeyModel|Disabled|RemoteMagpie|Caller|Usage|Plugin.*Decide|
Barred|Rest|Probe' ./internal/gateway (ok, 124s).
TestDecisionProviderKeysFailOver (Smart and In order) refuses the first key
429 and checks:
- /v1/systemone answers 200 from the second, the trace has two tries and the
  first rests, and one usage row goes to the provider;
- the next request asks only the second;
- the same holds through askClassifier.
Broken by hand: with the old decide.go, decide_group.go and classify.go it
fails "systemone: 429 no capacity for k1" in both. The first version of the
reordering ran the barred check before the held-key one, and
TestGatewayKeyAccountsSystemOne caught the changed 403 message. The held
check now runs first.
gofmt -l clean; GOOS=darwin/linux/windows go vet -tags nogui
./internal/gateway ok.
Not tried against the real TypeSafe API.

Full suite: SUITE_LINE
2026-10-15 23:08:02 +08:00
yetone 08b1a60c03 gateway, gui: a routing group whose classifier fails says so on its card, and the log says why (#1929, versun)
What changed: the gateway keeps, per classifier model, why it couldn't
say the last time it was asked (an error from the request, or an answer
that was no number of the list) and when, until it answers again
(gateway.ClassifierFailure). The first failure, and each one that says
something new, is written to the log once ("routing: the classifier X
couldn't say: ..."). /api/groups sends it as a group's classifierFailed,
and the group's card on Routing shows a line "Classifier failed 3 min
ago: <why>" with an amber dot (no stripe); its title says that until the
classifier answers, no rule with an intent matches and turns reason as
the agent asked. Strings in en, zh, zh-TW, ja and de.

Why: versun's MLX-Serve answered its Clef decision model, asked as a
chat model, with a 400. The only place that said so was each request's
own details; the group's rules with an intent quietly never matched,
which read as the routing working. The preset itself is fixed in the
commit before this one (versun's, cherry-picked).

Run:
- go test: TestClassifierFailureIsKept (gateway: a 400, kept while
  resting, "not a number", cleared by an answer) and
  TestGroupsSayAClassifierThatFailed (gui: only the failing group's JSON
  has classifierFailed). Each went red with its line removed by hand
  (the record in classify(), the fill in groupsState).
- group-classifier-failed.test.cjs: chromium and webkit, en zh zh-TW ja
  de, at 1100 and 420: 20/20; with classifierFailed dropped from the
  fixture's reading in groupRow, 10/10 of one engine red. i18n-keys
  passes.
- go test -tags nogui ./internal/provider ./internal/usage ./internal/cli:
  ok. ./internal/gateway hit the 10m default timeout at load ~150-190
  (other sessions); rerun with a longer timeout before the push, below.
- go test ./internal/gui: TestDockJoinLeadsCommandTab (Command-Tab order
  had kitty in front) and TestMainWindowCorners (measuring killed under
  load) failed; both are desktop-window tests this change doesn't touch.

Not verified: a real MLX-Serve; versun ran his own.
2026-10-13 16:34:59 +08:00
yetone a1c30b5be9 gateway: a user message the agent wrote alone is no new turn, and routing asks about and keys on the user's own words (#1826)
What: one helper, userWords/userSaid in prompt.go, says what the user
said in a text: it drops <system-reminder …> blocks (now with a source=
attribute too, as ZCode sends) and any text that begins as an agent
writes for the model alone, and keeps only what follows the Codex app's
"## My request (for Codex):". The leads, beside agentsFor: Codex's
<environment_context>, <user_instructions>, <turn_aborted>,
<user_shell_command>, <subagent_notification>; Claude Code's and
ZCode's <task-notification>, <subagent-notification>, agent lists
("Available agent types …", "New agent types are now available …"),
TodoWrite and task-tool nudges, rewind notices; ZCode's
<plugin_reference>; the Codex app's <in-app-browser-context …>. Each
was taken from the clients' own code or a real transcript (Claude Code
2.1.296, ZCode.app's zcode.cjs, Codex CLI 0.162.1, ChatGPT.app).

Everything that asks "did the user say something" now goes by it:
- turnIn: a user message with nothing of the user's (and no image or
  file) begins no turn. After an answer or a tool round it carries the
  turn on (within), so the turn's rule and stick hold and the classifier
  isn't asked; right after the user's own message it leaves that turn as
  it began.
- userText: the classifier is asked about the last user message with
  words of the user's, only those words (it was the last user message,
  ZCode's agent list after the user's plugin question).
- firstWords (ruleKey and the affinity scope): the words of the first
  user message that has any, so an instruction file or notice the agent
  changes beside them no longer moves a conversation to a new key
  mid-turn. A conversation with no words yet keys on its first message
  as before.
- lastUserText (Copilot's Auto, a sibling): the same.
- userSays (the prompt breakdown's turns) is userWords != "".

Why: #1826 (ZCode) and @321sssrt-bit's comment (Codex): a TodoWrite
nudge was classified as a new, harder turn and sent a 常规 turn to the
复杂 member; a task notification or agent list re-classified the turn;
one ZCode session had three firstWords keys, and the turn that lost its
key fell to the group's first member.

Upgrade: a conversation whose first user message held injected text
gets a new key once (its words only), so its stick and turn rule are
looked up afresh on the first request after the upgrade.

Run: user_said_test.go (TestTurnInSkipsWhatTheAgentPutIn,
TestUserTextSkipsWhatTheAgentPutIn, TestFirstWordsAreWhatTheUserSaid,
TestLastUserTextSkipsWhatTheAgentPutIn,
TestIntentHoldsPastWhatTheAgentPutIn end to end through the server,
TestUserSaysPastAReminderWithASource) fails on the old code (all six
red with the five source files put back) and passes now; go test
./internal/gateway -count=1 green (323s); gofmt -l clean; go vet ./...
on darwin, GOOS=linux -tags nogui and GOOS=windows clean.
Not tried: a live ZCode, Claude Code or Codex session against a
group with intent rules; fixtures are the clients' literal strings.
Not done here: persisting turnRules beside the sticks (the issue's
idea 3); the classifier-failure fallback is the next commit.
2026-10-13 00:19:50 +08:00
yetone b1396d2360 gateway, provider, gui: a routing group of decision models answers /v1/systemone, failing over between them (ARNO on Discord)
ARNO asked for decision models to get the group feature too: /v1/systemone
took only "<provider>/<model>" (xxx/jev-latest), so one refusing key or
vendor failed the call with nothing to fall back on.

A routing group may now be of decision models alone (provider.Group.Decides,
provider/decide_group.go). SaveGroup refuses one mixed with models that hold
a conversation, a decision group inside a chat group, and patterns, rules,
classifier, effort, levels, fast mode or a member effort on it. It is kept
out of the agents' catalog (groupEntries), and a chat request to it gets a
400 pointing at /v1/systemone.

POST /v1/systemone with "model":"group/<id>" (or the group's id or name, as
GroupFor reads them) goes to serveDecisionGroup (gateway/decide_group.go):
- the members' keys and accounts are planned with planGroup in the group's
  routing order, resting ones last; perKeyBarred no longer drops a
  decision-only provider's keys (it speaks no chat protocol), so each key
  is a try of its own;
- a gateway key's model and account limits and pause rules hold as for chat;
- a retryable failure that isn't the request's own (shape/prompt/protection)
  rests the candidate via restAfter and the next is asked; a transport error
  rests it as a 502; the last one's answer and Retry-After are passed on;
- every try is a Try of one route in the routing log; one usage row for the
  answer.
A group classifier naming a decision group fails over the same way
(askDecisionGroup; systemOne now returns decideRefused with the vendor's
status, headers and body, and postDecide returns the headers).

The GUI group editor offers a group of decision models only decision models
(groups.deciders), a chat group no decision model or decision group, a new
one both, and a decision model's row has no reasoning picker (groupJSON
.decides). The TUI member picker and `magpie group add` follow the same rule.
#1514's plugin_decide_test and TestMixedDecisionProvider now assert a mixed group is refused and a group
of decision models saves. Docs: reference.md (routing groups),
gateway-routing.md, provider-plugins.md.

Run:
- go test -tags nogui -timeout 40m . ./internal/provider ./internal/gateway
  ./internal/gui ./internal/tui: ok
- new: TestSystemOneDecisionGroupFailsOver (httptest System One fakes: a
  provider with two keys answering 429 and 503, then a second provider
  answering 200: tries ka1,ka2,kb, both failures rested and ask by name
  goes to kb first; all failing passes the last answer on; chat to the
  group is 400), TestDecisionGroupClassifierFailsOver, TestDecisionGroup,
  TestGroupAddDecisionModels, TestMemberOptionsDecisionGroup,
  group-decide-members.test.cjs (Chromium and WebKit, en and zh; no new
  strings)
- each broken by hand and seen red: no dispatch (404), no perKeyBarred
  change (ka2 skipped), no classifier failover, no rest, decision group in
  the catalog, CLI resolver, TUI and GUI picker filters
- GUI: group-*, routing-effort*, routing-levels, routing-save*,
  routing-intent-entry, routing-manual, i18n-keys in both engines: 169 pass
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui on the
  touched packages
- after rebasing on bc2496dca, the five packages again: ok. The first run
  had TestMaxRPMWaitsForRoomInTheMinute red once under load; it passed
  -count=3 alone and in the rerun, and nothing here touches rpm.go.
Not tried against a real TypeSafe or Bailian account.
2026-10-11 01:37:18 +08:00
Snowyy 280797ecf6 perf: reuse model settings and coalesce classifier calls (#622) 2026-10-03 10:39:44 +08:00
XYenonandAmp 564f8782c7 provider: keep conversation models on mixed decision providers (#609)
Distinguish decision-only providers from gateways that also serve conversations. Only Jev models use the decision API; ordinary models remain in the catalog, automatic groups and conversation routes. Keep the full model cache when probing a mixed provider’s decision endpoint, and allow conversation model tests in its editor.

Verified with go vet -tags gtk3 ./..., go test -tags gtk3 ./..., node --check internal/gui/assets/app.js, and an isolated browser fixture.

Amp-Thread-ID: https://ampcode.com/threads/T-01a0fe05-afd7-70df-97cf-fdb69c4f4680

Co-authored-by: Amp <amp@ampcode.com>
2026-10-03 04:06:02 +08:00
yetone 154d071699 routing: a group's effort can be picked per turn by any classifier, not only TypeSafe's Jev — a model that isn't a decision API (Jev Router on OpenRouter, Jev on OpenCode Zen, or any small fast model) is asked in words which of low, medium, high or xhigh the turn needs, in a call of its own beside the intent's, and told what the turn before needed; the routing editor offers every model for it 2026-09-27 16:11:23 +08:00
yetone f2b88ad5b4 jev: a group whose intents are levels has every message in one of them — Jev is asked once per set whether the kinds are levels (a noul, kept), and for such a set each turn is read from a choice among the kinds alone, as with a "none of these" option it put 你好 in none; Jev is also told the kind and the reasoning of the turn before, so 继续 after a 复杂任务 stays complex at its effort. Tested live against System One and OpenRouter: 你好 → nano/low, a deadlock analysis → mini/high (xhigh capped), 继续 → mini, 你是谁 after it → nano/low, Claude Code and Responses requests → the effort picked is what is sent 2026-09-27 01:53:04 +08:00
yetone 6fd85894ea routing: Jev (TypeSafe's System One) as a group's classifier — asked once as a turn begins which of the rules' intents the message is, with how sure it is, and, for a group with effort auto, how hard the turn is to think about; the turn's requests then ask their model for that reasoning, where the agent asked for any. TypeSafe is a decision provider: it serves no conversation and is no group's member 2026-09-27 01:53:04 +08:00
yetone cd3222d213 intent: a turn that only carries on from the one before — 继续, 好的就这么做, fix that — is of the kind that one was; the classifier is told what it said of the conversation's turn before, as it only saw the new message and put 继续 after a 复杂任务 among the simple ones. A message that asks for something of its own is still classed by itself (你是谁 after a 复杂任务 is 简单任务), and the Routing view says what it was told 2026-09-26 22:51:17 +08:00
yetone 13aa2049a4 intent: a group whose intents are levels — 简单任务 and 复杂任务, how hard a request is — has every message in one of them; the classifier was asked which kind of request a message is, with 0 for none, and put 你是谁 and 你好 in neither, so those turns matched no rule and went to the group's usual route (Claude Opus) rather than the simple one. It now picks the kind that fits best, answering 0 only when a message is plainly none of them: groups by topic still get 0 for a greeting or a poem 2026-09-26 22:39:30 +08:00
yetone f64d2fbaf0 intent: a reasoning classifier answered nothing now and then, and the turn after it wasn't classified — tested for real (20 coding messages, real models through magpie), deepseek-flash spent its 512 tokens thinking and answered "", and that 30 s rest skipped the next turn too; the classifier is now asked for its least reasoning (none, else its lowest level) with 2048 tokens, and an answer that isn't a number no longer rests it. DeepSeek V4 Flash, GLM-5.3 Flash and MiMo v2.6 Flash now get 20/20. The site's routing demo opens on By intent: a turn is classified once, goes to its rule's model, and its tool rounds stay there 2026-09-26 12:34:55 +08:00
yetone bc720c8d87 group: a rule can be for a kind of message — intent="writing or fixing tests": as a user's turn begins, the group's classifier (any model magpie has, best a small fast one) is asked once which of the intents that may match the message is, and the turn stays with the answer through its tool rounds; it isn't asked when no intent rule could decide, the same message isn't asked about twice, and when it fails or is slow (8s) no intent matches and it rests 30s. The trace says what it was asked and said; Routing's rule editor has "asks for" and the classifier picker, and magpie group rule add … intent=… classifier=… / magpie group rule classifier from the terminal. A sub-millisecond reply no longer shows as NaN s in the trace 2026-09-26 11:09:13 +08:00