magpie icon indicating copy to clipboard operation
magpie copied to clipboard

Claude Code 的 Anthropic 端点测试,默认不应该使用 Fable 5.2 模型

Open vibbow opened this issue 2 weeks ago • 1 comments

magpie version

v0.1.4493

Where

Gateway only

OS

Ubuntu 26.04

Agent, provider and model

Claude Code - Pro

Steps to reproduce

Claude Code 的 Anthropic 端点测试,默认不应该使用 Fable 5.2 模型 应该使用比如 Haiku 5.5 这种便宜,所有账号又都能用的模型

图片

What happened, and what you expected

端点测试应该用最便宜的模型测试,现在默认是选了个最贵的,并且不是所有订阅都可用的模型。

Error text or logs


vibbow avatar Nov 18 '26 17:11 vibbow

针对默认端点测试选到 Fable 的候选修复,基于 d01e0a465aaf06976d8c8a547bf07b7f9513c8b1,按贡献规则在 issue 提供完整补丁供评审。

根因:testModel 取当前候选池的第一个合法模型,而 Claude 目录把新模型排前面,所以新出现的 Fable 成为默认探测模型。不是显式测试某个模型时选错。

改动只针对 Claude 订阅的 Anthropic 端点默认探测:

  • 在原有每个候选池内优先 claude-haiku-*,仍先考虑 Exposed,再考虑 Available;不会越过用户只暴露 Fable 的选择。
  • 沿用协议、disabled 等过滤,额外要求 accountFor 找到路由允许的账号才给予 Haiku 优先。
  • 没有可优先的 Haiku 时,保留原池首选;非订阅 API-key provider、显式 TestModels、实际聊天请求不改。
  • 同步 providers/accounts 设计文档。

这只是默认探测偏好,不是“每个账号保证可用”或价格最优保证。 既有账号路由在所有账号的模型列表均不含某模型时仍可能尝试;本补丁不新增厂商权限判断、失败重试或硬编码模型版本。原有 fallback 可能选到账号限制模型的问题也不在本次修复内,新增 Haiku 偏好不会绕过该限制。

验证

Linux amd64,Go 1.26.8,临时 HOME、隔离缓存、本地 fixture,无真实 Claude/Anthropic 请求。

  • 旧代码加回归:TestClaudeEndpointProbePrefersHaiku 真实 FAIL:endpoint probe chose "claude-fable-5-2", want available Haiku(0.364s)。
  • 最终 go test -p 1 -tags nogui ./internal/provider -run '^(TestClaudeEndpointProbePrefersHaiku|TestClaudeTestRunsThroughClaudeCode|TestClaudeAccount.*|TestModelTest.*|TestProviderTest.*)$' -count=10 通过(3.986s)。
  • 新测试涵盖默认 Haiku、Exposed 仅 Fable、不改变非订阅顺序、disabled 后确切回退 Fable、实际路由账号全部限制 Haiku 时确切回退 Fable。限制 fixture 使用规范化账号键,并先确认限制生效;开发中不正确的 fixture 失败未计作通过。
  • 最后一次 go vet -p 1 -tags nogui ./internal/provider、gofmt、git diff --check 通过。独立只读审查无生产阻断。
  • 未跑整个 provider/仓库 suite、race、跨平台 build/vet、GUI 或真实 Pro 账号。尚未创建 PR、未合入,不是 release-ready 声明。

感谢 @vibbow 报告。AI 辅助实现及验证;采用时请按项目规则保留补丁作者 credit。

完整候选补丁(3 个文件)
diff --git a/docs/subsystems/providers-accounts.md b/docs/subsystems/providers-accounts.md
index 66accdf..49bf4e8 100644
--- a/docs/subsystems/providers-accounts.md
+++ b/docs/subsystems/providers-accounts.md
@@ -89,7 +89,7 @@ keys and accounts per request is in [Gateway routing and fallback](gateway-routi
 | Last served | `served.json` records when each account, plan or key last answered, shown as `lastServedAt` (#570) on `/v1/magpie/quotas` and on the Usage page's own cards (`Quotas` → `cardsServed`, this computer's cards only, the caches left alone). The Usage page and the tray panel show the last-answered account in full, and a menu bar card that follows the account in use (`codex|*`) takes the one that answered within the last hour, else `InUseLogin`'s guess, else the one that answered last at all (a plugin's accounts, #1516) (`trayInUseCard`; okingkee on X: A spent, B answering, the menu bar stayed on A). `NoteServed` calls `OnServedMoved` when a provider's answers move to another account or key, and `SwitchLogin` after a switch, so the menu bar reads its cards again at once. | [`served.go`](../../internal/provider/served.go), [`trayusage.go`](../../internal/gui/trayusage.go) |
 | Partners | Services that pay to be listed first in the add sheet, under a heading of their own ("Partners · magpie's sponsors"). The list is `site/partners.js`, served at `usemagpie.ai/api/partners`: a change reaches users with a deploy, not a release. `Partners` never waits: it returns what was fetched last and fetches again behind the call on a process's first ask, whatever the kept list's age, and hourly after (10 minutes after a failure), keeping the list in `partners.json` in the cache folder. The magpie serving the gateway fetches it when it starts and whenever it is due, asked for or not (`KeepPartnersFresh`), so an app left open on another page still learns of a partner added. The file also says when the last fetch started (`tried`) and, when it failed, why (`error`, logged once until a fetch gets the list again), so a list that stops changing tells a fetch that fails from one that never came back (`tried` after `at`, no error) and from none asked (#3362). Each entry is checked again on every read (`validPartners`): its own id, never a built-in preset's, a name, an endpoint, https only, at most 12; what only magpie's presets may set (a decision API, no key, a user endpoint) is cleared. Its logo is fetched through `FetchIcon` and kept as an uploaded icon, used as it is while its `iconUrl` stays the same; the prune after a save of `providers.json` (`pruneIcons`) leaves the logos of the partners listed now (`keptPartnerIcons`), as it leaves a plugin's. A partner is a preset to the rest of magpie (`Preset`, `FromPreset`, the editor), and one no longer listed still is to the providers added from it (`Seen`), without the sponsored mark. The window lists a partner in the languages it names (`langs`) only and shows its tagline in the page's language (`notes`, else `en`). `MAGPIE_PARTNERS` points it elsewhere, `off` lists none; tests list none unless they name a list. How often each listed partner was shown, opened (its row, its key page) and added is counted per UTC day (`CountPartner`, capped at 20 of each and 5 adds, kept in `partner-counts.json` in the cache folder) and sent with the next day's stats event as `magpie partner` events (`internal/stats`); nothing is counted with the stats or their usage part off. A listed partner the add sheet (or the TUI's, or `magpie providers presets`) hasn't shown yet is new (`NoticePartners` keeps those shown, as `noticed` in `partners.json`, whatever the stats); the window's add button carries a small dot for it, with its name in the title, until the sheet shows it. | [`partners.go`](../../internal/provider/partners.go), [`partner_events.go`](../../internal/provider/partner_events.go), [`site/partners.js`](../../site/partners.js) |
 | Local servers | A preset of `KindLocal` (Ollama, LM Studio, oMLX, MLX-Serve) is at its server's default port on this machine. Another address — a port, or another computer — is given in the window's editor, in its Server address field, shown first above the key and never folded (a folded one read as an LM Studio whose base URL can't be changed, mengxiangziyou on X), or in the TUI (asked on adding, `w` after); on the command line with `address=` (`atAddress` in `providers_cli.go`: every URL moves, from the preset's when the provider was saved with none, and `address=` alone puts a local server back at its preset's), or the URLs themselves (`url=`, `anthropic=`, `responses=`). `AtAddress` replaces only each URL's scheme, host and port, each API keeping its path; `AddressOf` is the address an editor starts from. The window sends the URLs moved only when the address was changed, so a Save doesn't move URLs set apart (another app's import). A provider of the user's own (no preset) has `w` in the TUI too: each base URL it has is asked in turn, typed in as it is, Enter alone keeping one (`customURLsAsk`). | [`local_address.go`](../../internal/provider/local_address.go), [`providers_cli.go`](../../internal/cli/providers_cli.go) |
-| Protocol detection | Works out which of Chat, Responses, Anthropic Messages and Gemini generateContent a base URL speaks when a provider is added. Each is asked at the URL as it takes it (`DetectBase`); Gemini's at the `…/v1beta` beside a typed `…/v1` or bare host, a Gemini model from the list picked for it, with the key in `x-goog-api-key` (#1346). Each API is asked with a model that chats, if the list has one; an embedding or rerank model (`catalog.ServesOf`) is asked only on Chat's URL, at its `/embeddings` or `/rerank` with the smallest body and no extra body, as the gateway's `retrieve` asks it, and the other APIs say why they weren't asked (heatonz on Discord: a vendor of only those detected nothing, asked to chat; `TestDetectEmbeddingOnly`). A saved provider whose list has nothing to chat with tests on such a model (`testModel`, `TestTestEmbeddingOnly`), and its editor and the add form's Fetch models say the models need no pick (`retrieval` in the list's answer and the provider's JSON, `provider-retrieval-only.test.cjs`). A model's test (Test models, a model's right-click, `magpie provider test`) asks the account or key a request for it goes to: `provider.AccountsFor` and `provider.KeysFor` ([`route_accounts.go`](../../internal/provider/route_accounts.go)), which the gateway's `perKeyEvery` routes by too, its usage and spend caps aside (one the user lets serve it, `AccountModels`; whose own list or plan has it, `Account.Lists`, `PlanServing`, `Serving`; in the user's order, `AccountsOn`), so a pool whose accounts list different models (a newapi plugin's) asks the one whose list has it, and one every account is barred from isn't asked. The provider's Test picks each endpoint's model from every account's and asks it of the account that serves it (`routedTo`), and with keys the first key with a model of its own to test (`testWith`). The request log's row names the account asked (`loggedAs`; #4992, `TestModelTestAsksTheAccountThatServesIt`). A model's right-click *Test on account…* (tmr11235 on X; a provider with two or more accounts or keys that are on, `TestPicks`) pins its test to one of them (`TestOn`, `accountNamed`, `keyNamed`, the GUI's `account`; `TestModelTestPinnedToAKey`, `TestModelTestPinnedToAnAccount`, `model-test-account.test.cjs`), and every result names the account or key it went to (`Result.Account`, `testedAccount`), so the status line says which one answered. Test models and `magpie providers` still test with routing's pick. Detection, endpoint tests and model tests share `probe`, which adds `anthropic-version` only for Anthropic Messages; OpenAI probes omit that default so a relay that refuses it can answer. A Chat or Responses URL typed without its version (CRS's `…/openai`, Cyrus_4433 on X: CRS serves `/openai/v1/chat/completions` and `/openai/responses`, and answers anything else 404 `Not Found`) that is answered 404 is asked once more under `/v1` (`missingV1`, not for an account, Azure, Bedrock or Vertex); answered there, the saved provider's URL takes the `/v1` (`setV1`), the result carries it (`Result.V1`), Detect hands it on as the base, and the editor's URL field follows (`draft.onV1`), so Save doesn't put it back. A model's own 404 at both stays a 404 and changes nothing. CRS lists at `/api/v1/models`, which `catalog.RelayOpenAIList` adds to an unversioned `…/openai` base's list URLs, and a list answered there adds `/v1` as `fixV1` does (`TestCRSOpenAIBaseTestsUnderV1`, `TestCRSOpenAIBaseListsAtAPI`, `TestCRSOpenAIBaseDetectsV1`, `TestModel404KeepsBase`, `provider-test-v1.test.cjs`). A model's test that the vendor turns away with its word that the model is served on another API (`catalog.WrongEndpoint`, the gateway's words) asks the next API the provider has a URL for, as the gateway's `usable` takes it (the model's picked or listed API, else each API it isn't named-only on), with a key that sees the model there (`keySeeing`); that API's answer is the model's, and with none left, or every one saying it, the first stays. As Codex the next API is asked with Codex's headers, as the gateway sends them on Responses and Chat; as Claude Code it isn't, since the gateway sends Claude Code's on Messages alone (#3766, `TestTestModelsMovesToTheAPIServingIt`, `TestTestModelsKeepsAModelOnItsAPI`, `TestTestModelsAsAClientMovesAsTheGatewayDoes`). User-supplied headers still apply through `Sign`. The editor asks with the form as it stands, before any Save (#1545): the URL, key and models typed (`picked`, else the saved picks, else the vendor list); a key not typed again is the saved provider's, or for an unsaved copy the copied one's (`copyOf`). The probe writes nothing and adds no provider, and the route stays behind `magpie web`'s key. An endpoint or model test fails fast and can be stopped (RIck on Discord: 测试模型 took long to fail and couldn't be cancelled): a probe on magpie's own client that has no connection in `connectWait` (10s) fails then (`connecting`, an httptrace `GotConn`), and a host that couldn't be reached (no connection, DNS, refused, a bad certificate) fails the run's other models at once (`withUnreached`, `TestTestModelsUnreachedHostFailsOnce`); a stream that breaks off before an answer is a failure. While a test runs its Test models and endpoints' Test read Stop, which aborts the window's request and posts `provider/teststop` with the test's `run`, ending the vendor's request on the server too (`testRuns` in [`providers.go`](../../internal/gui/providers.go), since WebView2 doesn't end the request when a fetch is aborted; `TestProviderTestStops`, `model-test-stop.test.cjs`). | [`detect.go`](../../internal/provider/detect.go), [`test.go`](../../internal/provider/test.go) |
+| Protocol detection | Works out which of Chat, Responses, Anthropic Messages and Gemini generateContent a base URL speaks when a provider is added. Each is asked at the URL as it takes it (`DetectBase`); Gemini's at the `…/v1beta` beside a typed `…/v1` or bare host, a Gemini model from the list picked for it, with the key in `x-goog-api-key` (#1346). Each API is asked with a model that chats, if the list has one; an embedding or rerank model (`catalog.ServesOf`) is asked only on Chat's URL, at its `/embeddings` or `/rerank` with the smallest body and no extra body, as the gateway's `retrieve` asks it, and the other APIs say why they weren't asked (heatonz on Discord: a vendor of only those detected nothing, asked to chat; `TestDetectEmbeddingOnly`). A saved provider whose list has nothing to chat with tests on such a model (`testModel`, `TestTestEmbeddingOnly`), and its editor and the add form's Fetch models say the models need no pick (`retrieval` in the list's answer and the provider's JSON, `provider-retrieval-only.test.cjs`). A model's test (Test models, a model's right-click, `magpie provider test`) asks the account or key a request for it goes to: `provider.AccountsFor` and `provider.KeysFor` ([`route_accounts.go`](../../internal/provider/route_accounts.go)), which the gateway's `perKeyEvery` routes by too, its usage and spend caps aside (one the user lets serve it, `AccountModels`; whose own list or plan has it, `Account.Lists`, `PlanServing`, `Serving`; in the user's order, `AccountsOn`), so a pool whose accounts list different models (a newapi plugin's) asks the one whose list has it, and one every account is barred from isn't asked. The provider's Test picks each endpoint's model from every account's and asks it of the account that serves it (`routedTo`), and with keys the first key with a model of its own to test (`testWith`). The request log's row names the account asked (`loggedAs`; #4992, `TestModelTestAsksTheAccountThatServesIt`). A model's right-click *Test on account…* (tmr11235 on X; a provider with two or more accounts or keys that are on, `TestPicks`) pins its test to one of them (`TestOn`, `accountNamed`, `keyNamed`, the GUI's `account`; `TestModelTestPinnedToAKey`, `TestModelTestPinnedToAnAccount`, `model-test-account.test.cjs`), and every result names the account or key it went to (`Result.Account`, `testedAccount`), so the status line says which one answered. Test models and `magpie providers` still test with routing's pick. Detection, endpoint tests and model tests share `probe`, which adds `anthropic-version` only for Anthropic Messages; OpenAI probes omit that default so a relay that refuses it can answer. A Chat or Responses URL typed without its version (CRS's `…/openai`, Cyrus_4433 on X: CRS serves `/openai/v1/chat/completions` and `/openai/responses`, and answers anything else 404 `Not Found`) that is answered 404 is asked once more under `/v1` (`missingV1`, not for an account, Azure, Bedrock or Vertex); answered there, the saved provider's URL takes the `/v1` (`setV1`), the result carries it (`Result.V1`), Detect hands it on as the base, and the editor's URL field follows (`draft.onV1`), so Save doesn't put it back. A model's own 404 at both stays a 404 and changes nothing. CRS lists at `/api/v1/models`, which `catalog.RelayOpenAIList` adds to an unversioned `…/openai` base's list URLs, and a list answered there adds `/v1` as `fixV1` does (`TestCRSOpenAIBaseTestsUnderV1`, `TestCRSOpenAIBaseListsAtAPI`, `TestCRSOpenAIBaseDetectsV1`, `TestModel404KeepsBase`, `provider-test-v1.test.cjs`). A model's test that the vendor turns away with its word that the model is served on another API (`catalog.WrongEndpoint`, the gateway's words) asks the next API the provider has a URL for, as the gateway's `usable` takes it (the model's picked or listed API, else each API it isn't named-only on), with a key that sees the model there (`keySeeing`); that API's answer is the model's, and with none left, or every one saying it, the first stays. As Codex the next API is asked with Codex's headers, as the gateway sends them on Responses and Chat; as Claude Code it isn't, since the gateway sends Claude Code's on Messages alone (#3766, `TestTestModelsMovesToTheAPIServingIt`, `TestTestModelsKeepsAModelOnItsAPI`, `TestTestModelsAsAClientMovesAsTheGatewayDoes`). User-supplied headers still apply through `Sign`. The editor asks with the form as it stands, before any Save (#1545): the URL, key and models typed (`picked`, else the saved picks, else the vendor list); a key not typed again is the saved provider's, or for an unsaved copy the copied one's (`copyOf`). The probe writes nothing and adds no provider, and the route stays behind `magpie web`'s key. An endpoint or model test fails fast and can be stopped (RIck on Discord: 测试模型 took long to fail and couldn't be cancelled): a probe on magpie's own client that has no connection in `connectWait` (10s) fails then (`connecting`, an httptrace `GotConn`), and a host that couldn't be reached (no connection, DNS, refused, a bad certificate) fails the run's other models at once (`withUnreached`, `TestTestModelsUnreachedHostFailsOnce`); a stream that breaks off before an answer is a failure. While a test runs its Test models and endpoints' Test read Stop, which aborts the window's request and posts `provider/teststop` with the test's `run`, ending the vendor's request on the server too (`testRuns` in [`providers.go`](../../internal/gui/providers.go), since WebView2 doesn't end the request when a fetch is aborted; `TestProviderTestStops`, `model-test-stop.test.cjs`). Claude subscription endpoint tests prefer a permitted `claude-haiku-*` in the current exposed/available candidate pool (`testModel`, #7135), falling back to that pool's original first candidate. Disabled models and explicit exposure keep their priority, and Haiku is preferred only when `accountFor` finds an account routing allows. This is a default preference, not a guarantee the vendor will accept it; explicit model tests and API-key providers are unchanged (`TestClaudeEndpointProbePrefersHaiku`). | [`detect.go`](../../internal/provider/detect.go), [`test.go`](../../internal/provider/test.go) |
 | A pasted curl command | A curl command from a vendor's docs pasted into a custom provider's Base URL or API key fills the editor in (@mark_li21 on X). `curlOf` reads it as a shell would (lines joined by `\`, cmd's `^` or PowerShell's backtick; `curl.exe`; quotes and escapes), and takes: the API its URL's endpoint names (`…/chat/completions` Chat, `…/messages` Anthropic Messages, `…/responses` Responses) with the base URL before it, spelled as that API wants it (`respellURL`: Anthropic at its root, `/v1` after a bare host); the key from `Authorization: Bearer`, `x-api-key` or `api-key`, unless it only stands for one (`$OPENAI_API_KEY`, `${X}`, `%X%`, `<token>`, `YOUR_API_KEY`), when the key's box is left empty and focused; and the `model` of its JSON body, added to a new provider's models (a saved one's picks are left alone, since adding to none would narrow what it serves). A preset's editor takes only the key. A note (`editorError`, kind `note`) says what was taken, a placeholder like `{WorkspaceId}` left in the URL, and a URL with no known endpoint. Text that isn't a curl command pastes as before, several keys included. Tested on the docs' own examples (`fixtures/curl`). | [`app.js`](../../internal/gui/assets/app.js) (`curlOf`, `fromCurl`), [`provider-curl-paste.test.cjs`](../../internal/gui/tests/provider-curl-paste.test.cjs) |
 | Saved proxies | `settings.Proxies` holds named proxies (`NamedProxy`: id, name, address, optional login), kept in Settings › Network. Wherever a proxy is chosen (global, plugin downloads, app updates, a provider, a key, a Claude account) the value is "" (inherit), `direct`, an address as typed, or `@<id>` for a saved one (@tsingchao on X). Addresses as typed are untouched. App updates take a proxy of their own, Settings › Network › App updates (`settings.UpdateProxy`, `magpie settings set updateProxy <url|direct>`; moonlityu on X: models direct, updates through a proxy): "" follows the global proxy as before, a proxy given to one `magpie update --proxy` run comes first, and it covers the feed, the notes and the release's file (`updateProxy` in [`update.go`](../../internal/update/update.go); `TestUpdateTakesItsOwnProxy`, `settings-update-proxy.test.cjs`). Per-model proxies within one provider are not offered: a proxy belongs to a provider, an account or a key, and a model that needs the other route is a second provider on the same URL. `netproxy.Parse`, `Resolve`, `Redact`, `EnvWith` and `Dispatch` resolve an `@id` at the lowest layer, so an edit reaches every user at the next request; a Claude Code `settings.json` env is a snapshot and is rewritten after an edit (`provider.ProxyEdited`). An `@id` this computer lacks fails closed (`netproxy.DeadProxy`, the request error and the provider row say "Proxy missing: {name}", `provider.ProxyGone`); it never goes direct. The password is written to settings.json (0600) and never read back by the page (nor sent in `/api/state`'s settings, with the LAN key, Bark key and GitHub token: `stateSettings`, `TestStateSendsNoCredentials`), logged or put in `Settings` sync; the list rides with the providers part of a sync (`backup.Bundle.Proxies`, `settings.MergeProxies`, passwords only with keys). A proxy in use cannot be deleted (409). A saved proxy can be an SSH server (`ssh://host:port`, a user, a password and/or a private key; @laiuuui on X, whose VPS gives only SSH): magpie logs in itself with golang.org/x/crypto/ssh, no ssh command, and resolves the `@id` to a SOCKS5 server of its own on loopback (`socks5h://magpie:<random>@127.0.0.1:<port>`, which takes only that login), carrying each CONNECT as a direct-tcpip channel, as `ssh -D` does. It logs in on the first request, keeps the connection with [email protected] every 20s (15s with no answer ends it), and logs in again once when a channel finds it dead (`sshTunnel` in [`ssh.go`](../../internal/netproxy/ssh.go)). Save logs in first, so a refused login is said there and nothing is kept; the host key is trusted on first use and kept as `HostKey` (authorized_keys form, the page shows its SHA256 fingerprint), and a server showing another key is refused (`HostKeyChangedError`) until Advanced › Trust a new key. The key is a secret as the password is: `WithoutProxyPasswords`, `MergeProxies`, `KeepSecretsOf`. An `ssh://` typed as an address is refused: its login belongs to a saved proxy. Every request to the server needs it to allow forwarding: macOS 27's sshd hangs up on a forward (also with OpenSSH's own `ssh -W`), and that is said as "won't forward connections" (`SSHForwardWhy`). A failed proxy says why (`netproxy.Why`: an English template the page translates, its `{addr}`, `{was}`, `{now}` filled; `fail` in api.go sends it as `code: proxy_why`, a check as `why`/`addr`): `Explain` reads Go's error, and `ExplainServer`, for a check the user asked for only, reads the server's first bytes when the text can't tell, since Go reads a real OpenSSH banner ("SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13.20") as an HTTP status line with a bad code. Each save is tested at once. A Test (Settings, and the provider editor's Saved mode) asks Cloudflare's trace page through the proxy, only on a click: its latency runs from the request written to the answer's first byte, so a new connection's dial, tunnel and TLS don't count and a second Test reads like the first, and the exit's region is named in the reader's language (IcyLiqu1d on X). An editor opened before Settings was read draws its picker again once the saved proxies are in. `TestSavedProxyLatencyIsTheRoundTrip`, `provider-proxy-pick-test.test.cjs`, `TestSavedProxyChoice`, `TestDanglingProxyReferenceFailsClosed`, `TestSavedProxiesTravelWithProviders`, `TestSSHProxyCarriesRequests`, `TestSSHProxyRefusesAChangedHostKey`, `TestSSHProxySaysWhyItFailed`, `TestProxyFailureNamesAnSSHServer`, `TestSavedSSHProxyAPI`, `TestSavedSSHProxyThatWontForward` (an SSH server in the test, `netproxy/sshtest`, never the network), `saved-proxies.test.cjs`, `saved-ssh-proxy.test.cjs`, `provider-proxy-missing.test.cjs`. | [`proxies.go`](../../internal/settings/proxies.go), [`netproxy.go`](../../internal/netproxy/netproxy.go), [`ssh.go`](../../internal/netproxy/ssh.go), [`why.go`](../../internal/netproxy/why.go), [`proxies.go`](../../internal/gui/proxies.go) |
 
diff --git a/internal/provider/test.go b/internal/provider/test.go
index a25b4bd..84948ca 100644
--- a/internal/provider/test.go
+++ b/internal/provider/test.go
@@ -689,6 +689,7 @@ const zenPublicNone = "no free model of OpenCode Zen is listed for this API: the
 // is served on, or none (z'x on Discord: Test asked public for
 // claude-fable-5 on Messages, gemini-3-flash on Gemini and big-pickle on
 // Responses, and every one failed, though big-pickle answers on chat).
+// A Claude subscription prefers an allowed Haiku within each pool (#7135).
 func (p Provider) testModel(q Provider, proto Protocol) string {
 	k := q.first()
 	// a model the key's vendor lists it, and the user lets it serve
@@ -720,14 +721,28 @@ func (p Provider) testModel(q Provider, proto Protocol) string {
 		func(string) bool { return !public },
 	} {
 		for _, pool := range pools {
+			first := ""
 			for _, m := range pool {
 				if public && !p.OpenCodeFree(m.ID) {
 					continue
 				}
 				if !p.DecidesModel(m.ID) && !off(p.ID, m.ID) && want(m.ID) && sees(m.ID) {
-					return m.ID
+					if !p.isClaudeAccount() || proto != Anthropic {
+						return m.ID
+					}
+					if strings.HasPrefix(m.ID, "claude-haiku-") {
+						if _, ok := p.accountFor(m.ID); ok {
+							return m.ID
+						}
+					}
+					if first == "" {
+						first = m.ID
+					}
 				}
 			}
+			if first != "" {
+				return first
+			}
 		}
 	}
 	if proto == Chat && q.Account == nil && !public {
diff --git a/internal/provider/claude_probe_model_test.go b/internal/provider/claude_probe_model_test.go
new file mode 100644
index 0000000..dd860d2
--- /dev/null
+++ b/internal/provider/claude_probe_model_test.go
@@ -0,0 +1,49 @@
+package provider
+
+import (
+	"testing"
+	"time"
+
+	"github.com/yetone/magpie/internal/catalog"
+)
+
+func TestClaudeEndpointProbePrefersHaiku(t *testing.T) {
+	home := claudeHome(t)
+	claudeSignIn(t, home, time.Now().Add(time.Hour))
+	t.Cleanup(catalog.Reset)
+	writeAnthropicCatalog(t, mdOpus55, mdHaiku55, mdFable52)
+	p, ok := find(All(), "claude")
+	if !ok {
+		t.Fatal("Claude provider missing")
+	}
+	if got := p.testModel(p, Anthropic); got != "claude-haiku-5-5" {
+		t.Fatalf("endpoint probe chose %q, want available Haiku", got)
+	}
+	limited := p
+	limited.Models = []string{"claude-fable-5-2"}
+	if got := limited.testModel(limited, Anthropic); got != "claude-fable-5-2" {
+		t.Fatalf("explicit exposure changed: %q", got)
+	}
+	keyProvider := p
+	keyProvider.Account = nil
+	if got := keyProvider.testModel(keyProvider, Anthropic); got != "claude-fable-5-2" {
+		t.Fatalf("non-subscription order changed: %q", got)
+	}
+	restricted := p
+	restricted.AccountModels = map[string][]string{}
+	for _, a := range p.AccountsOn() {
+		restricted.AccountModels[accountKey(a.Account.User)] = []string{"claude-fable-5-2"}
+	}
+	if _, ok := restricted.accountFor("claude-haiku-5-5"); ok {
+		t.Fatal("fixture did not restrict Haiku")
+	}
+	if got := restricted.testModel(restricted, Anthropic); got != "claude-fable-5-2" {
+		t.Fatalf("preferred an account-barred model: %q", got)
+	}
+	if err := DisableModels("claude/claude-haiku-5-5"); err != nil {
+		t.Fatal(err)
+	}
+	if got := p.testModel(p, Anthropic); got != "claude-fable-5-2" {
+		t.Fatalf("disabled Haiku fallback: %q", got)
+	}
+}

yhdhaidong avatar Nov 18 '26 17:11 yhdhaidong