ac4af582301a4e8a29245dbba767eba31334ddf9
6
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
abe7b00631 |
gateway: a key+URL provider is sent the agent's own User-Agent by default, through a remote magpie too
nb5p runs a gateway of their own behind magpie and saw nearly every request arrive as "magpie/<version>". The agent's User-Agent now goes on as the agent sent it, wherever magpie isn't itself the client. What each path sends now: - Key+URL providers (official vendor keys and custom OpenAI/Anthropic compatible ones), on chat, Anthropic, Responses, Gemini, count_tokens, embeddings, images and videos: the agent's User-Agent, as sent. Before, this was the opt-in passUserAgent (#1851) and the default was magpie's. The opt-out is magpieUserAgent: `magpie provider set <id> user-agent=magpie`, or untick "Send the agent's own User-Agent" in the editor. passUserAgent is no longer a field, so a file that set it true reads the same as the new default. A provider someone turned back off after opting in can't be told apart from one never touched, and now sends the agent's too. - When the agent sent no User-Agent, and on magpie's own requests (classifier magpie-router/1, vision, search, the image tool, model lists): magpie's, unchanged. - A header.User-Agent the user set: still wins over both. - Subscription accounts (Claude, Codex, Copilot, Google, ZCode…), plugins, and OpenCode/Cline/Kilo: unchanged. Their signing sets the official client's UA (provider.PassesUserAgent still refuses an Account or OwnClient). - Claude Code and Codex header copies: unchanged. - Remote magpie: the near magpie still asks as magpie/<v>, because the far end trusts X-Magpie-Agent/Via only from that. It now adds X-Magpie-User-Agent (passOnUA, on forwardOnce, embeddings, draw and video; the classifier's decision request names none). The far end takes it only from a magpie/ request (callerFrom) and strips it on arrival (withCaller). agentUA/callerUA then hand it to userAgentFor, so the far vendor sees the agent's. A client that writes the header itself, straight to a magpie, is ignored. magpie's own UAs are never relayed (magpiesOwn). Vendor check: invalid-key requests with magpie/, claude-cli, a Chrome UA and pi's went to Anthropic, OpenAI, Gemini, DeepSeek, Moonshot, Kimi For Coding, Zhipu, OpenRouter, xAI, DashScope, MiniMax, Volcengine Ark, Groq and Mistral. Every vendor gave the same auth error for every UA, so no edge-level UA gating was seen. Kimi For Coding's agent allow-list sits behind a valid key, which wasn't tried. Run (mote): - go test -run 'UserAgent|RemoteMagpie|ZCode|Blocked' ./internal/gateway: ok - go test ./internal/provider ./internal/cli ./internal/gui: ok - node --test provider-user-agent, provider-native-compaction and i18n-keys (chromium and webkit; en/zh/zh-TW/ja/de; 900 and 440 wide): 123 of 124 pass. The red is i18n-keys "a plugin's words are its own" (plugins' words said in files this change doesn't touch), already filed as #5327/#5332, #5426 and #5482. - gofmt -l clean; go vet; GOOS=linux -tags nogui and GOOS=windows vet: ok at the rebased head (on |
||
|
|
65d6b1dee9 |
provider: ZCode's 3012 risk control is not told as an IP firewall
windy_66454 (Discord, 10-31, v0.1.2297) had every request to a ZCode
group answered "ZCode: 405 Method Not Allowed — the provider's network
firewall blocked requests from this IP; wait a while, or switch to
another network or proxy", and both members rested together on the
account as "why other".
The plugin tells ZCode's Start Plan 3012 ("request has been blocked due
to unusual activity", the account's risk control) apart from Alibaba
Cloud's block page: 3012 carries ZCodeRestrictedHint. APIError matched
"request has been blocked" with edgeBlocked first and rewrote the whole
body to "<status> — BlockedHint", so the restricted hint was cut, the
user was told to change networks, and the gateway rested the account
with failOther's backoff instead of failRestricted. A body that already
carries ZCodeRestrictedHint or WBRestrictedHint now keeps its words.
The reporter's text is what both cases read as before this, so which
one they met is not known from the text.
Run (mote, at this tree):
- TestZCodeRiskControlNotToldAsFirewall: red on the old provider/test.go
(told "ZCode: 405 Method Not Allowed — the provider's network firewall
..."), green now; its block-page case still says BlockedHint and
rests as failOther.
- go test ./internal/gateway -run 'ZCode|Edge|Relay|Restricted|WorkBuddy|Blocked|Refusal'
and go test ./internal/provider: ok.
- gofmt -l clean; go vet darwin/linux/windows of gateway and provider ok.
Not tried: the reporter's real account; no ZCode account answers 3012
here.
|
||
|
|
3b2794cadd |
provider: a relay's 403 in markup says its words, not a bare "403 Forbidden"
maralica (Discord #help) sent WorkBuddy through a custom Chat relay,
"magpie-grok", that serves only some agents' clients, and WorkBuddy was
told only "magpie-grok: 403 Forbidden". apiError dropped any body that
starts with "<" and isn't a whole web page (a page's fragment such as
"<h1>Forbidden</h1><p>…</p>", an XML error), and WebPage said a page
with no <title> as "a web page, not an API reply" alone, so a relay's
reason in either never reached the agent.
Now such markup is said by its words (provider.MarkupText: scripts,
styles, comments and declarations out, tags out, entities read,
whitespace folded, 300 runes), and a page with no title by its words
(120 runes, as a title). Markup with no words still says the status
alone. JSON, plain text and empty bodies read as before. Every APIError
caller and WebPage's (Unsaid, errorSaid, vendorMessage, vendorSaid) get
it.
Checked on the way, unchanged: the relay is asked for "grok-4.7" by
model "magpie-grok/grok-4.7" and by a group of it, never a magpie-named
id; with "Send the agent's own User-Agent" on, it gets WorkBuddy's
User-Agent as sent, and none of the agent's X-Agent-*, Acp-Connection-Id
or Traceparent headers (only Codex's and Claude Code's own identity
headers are passed on to a relay).
Tests: TestChatRelayRefusalSaysWhy (custom Chat provider, WorkBuddy's
User-Agent, by provider/model and by group, streaming: the model and
User-Agent the relay got, and the message for plain text, JSON, an
untitled page, a fragment, XML and an empty body); TestAPIErrorShapes
updated (untitled page, script-only page, XML, a bare XML tag).
Broken by hand: MarkupText made to return "": TestAPIErrorShapes red,
and TestChatRelayRefusalSaysWhy red in untitled page, fragment and xml
(said "magpie-grok: 403 Forbidden", the reporter's words). Restored,
green.
Run (mote, go1.26.8, tree at origin/main
|
||
|
|
4ed6b42f6b |
provider: an upstream refusal with an empty body or a web page says what it was
maralica's custom Responses relay answered 403, and Codex was told only
"<provider>: 403 Forbidden": apiError dropped any body starting with "<"
and said nothing of an empty one, so a Cloudflare block page, a proxy's
nginx page and a firewall's empty refusal all read the same.
apiError now says a web page by its <title> (provider.WebPage: markup
and entities taken out, whitespace folded, 120 runes at most), and an
empty body, when the fallback is an HTTP status ("403 Forbidden" or
"Forbidden", statusLine), as refused with no details, often a firewall
or proxy in front of the API (NoDetails). An empty body under any other
fallback stays bare: sniff's response.failed with no error still reads
"upstream stream failed" (TestNativeStreamFailureAccounting). Every
caller of APIError (passthrough, translated tries, routing, search,
decide, the built-in clients) says the same. edgeBlocked now also knows
Cloudflare's block pages ("Sorry, you have been blocked", "used
Cloudflare to restrict access", plain "error code: 1005-1012/1020"), and
APIError puts the page's title before BlockedHint. JSON errors read as
their message, as before; other markup (XML) still says nothing.
Siblings: planquota's vendorSaid and the gateway's HTTP error sites for
drawing, embeddings, video and WorkBuddy's config said a bare status or
dumped raw HTML; they use provider.Unsaid (empty or page) now, through
errorSaid in draw.go, and vendorMessage names a page by its title.
notAnAPIReply's webPage and codexSaidNothing kept their own title regex;
both read provider.PageTitle now.
Routing effect: a 4xx Cloudflare block page now counts as EdgeBlocked,
so retryable() lets a 400/405 one fail over as Alibaba's does (a 403 was
retryable already).
Tests: TestAPIErrorUnsaid (Cloudflare WAF page, plain-text 1020, nginx
page with markup and an entity in its title, a 200-rune title cut,
empty and whitespace bodies under "403 Forbidden", "Forbidden" and
"502", nil under a non-status fallback left bare, JSON unchanged,
vendorSaid);
TestRelayRefusalSaysWhatItWas (a custom Responses provider answering 403
with each through /v1/responses; message has no markup);
TestAPIErrorShapes updated for the page case.
Broken by hand: the page branch and the NoDetails line in apiError off:
TestAPIErrorShapes and TestAPIErrorUnsaid red ("403 Forbidden"), and
TestRelayRefusalSaysWhatItWas red in cloudflare, page and empty
("Relay: 403 Forbidden"). Restored, green.
Earlier, the Cloudflare words out of edgeBlocked turned TestAPIErrorUnsaid
red too.
Run (worktree, go1.26.8, rebased on origin/main
|
||
|
|
7034378669 |
zcode: the Start Plan's 405 code 3012 says ZCode blocked the account, and rests it as restricted (plugins#348)
Since 10-24 many ZCode Start Plan accounts get 405 {"code":3012,"msg":
"request has been blocked due to unusual activity."} on every request.
On several of them ZCode's own app (3.16.3) gets the same 405, and
ZCode's support bot calls 3012 risk control on the account. magpie said
"though magpie sends it as the ZCode app does; it can be a network block
of this IP", rested the account as an unknown failure, and asked it again
soon after.
- provider.ZCodeRestrictedHint: the words @magpie-community/opencode-
zcode-auth 0.1.27 puts after ZCode's own ("ZCode's risk control blocked
this account for unusual activity (code 3012); it rests, and the
group's other providers are used. If the ZCode app fails on this
account too, only ZCode support can lift the block").
- gateway: restrictedSaid reads those words as failRestricted, as
WorkBuddy's 11140: the account rests restrictedRest (2h), the next
member is asked, and the Routing page's lift button brings it back.
- Routing page: the hint replaces the old one, in zh, zh-TW, ja and de.
- zcode mover min 0.1.27 (npm view --prefer-online: 0.1.27).
Not proven: why ZCode flags these accounts. Diffed against ZCode 3.16.3's
glm/zcode.cjs: the Start Plan goes unsigned there too (client request
signing is off for zhipu-account start-plan), and the headers match the
plugin's. Not tried with a real blocked account.
Run (sandbox HOME, at this tree): go test ./internal/provider ok;
go test -tags nogui ./internal/gui/... ok; go test ./internal/gateway
-run 'ZCode|Restricted|Blocked|EdgeBlocked|Moved' ok, and the new
TestZCodeStartPlanBlockRestsRestricted is red with routing.go reverted;
go vet darwin, linux, windows on provider and gateway ok; gofmt clean.
GUI (Playwright 1.62.0, chromium + webkit): routing-zcode-blocked,
i18n-keys, routing-blocked, routing-wb-restricted, gui-de, gui-ja,
gui-zh-tw: 41 pass, 0 fail. Not run: the full ./... suite (the machine
had a queue of full suites at load ~120).
|
||
|
|
15fa17f1c4 | gateway: ZCode's count_tokens is estimated, and a vendor's firewall block is said in plain words (ZCode Start Plan: HTTP 405 "request has been blocked due to unusual activity") — Claude Code asks count_tokens before every turn, and magpie sent each to zcode.z.ai/api/v1/zcode-plan/anthropic/v1/messages/count_tokens, which answers it with an error every time and which ZCode itself never asks; a ZCode account's count, built-in or on its plugin, is now estimated as Cursor's, Grok's and Kiro's are, and zcode.z.ai is not asked. The 405 is Alibaba Cloud's edge firewall (ESA) in front of zcode.z.ai blocking the address: its HTML page was shown as "405 Method Not Allowed" and, a 405 not passing as a provider's failure, no other member of a group was asked. A block page (request has been blocked, errors.aliyun.com) now reads "the provider's network firewall blocked requests from this IP; wait a while, or switch to another network or proxy" to the agent and in the trace, where the Routing page gives it on its own line in English or Chinese, and the group goes on to its next member, the blocked one resting as for any other failure. No request header, user agent or device id changes. TestZCodeCountTokensEstimated, TestMovedZCodeCountTokensEstimated, TestEdgeBlockedSaidPlainly and routing-blocked.test.cjs fail without the change. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass; routing-blocked, routing-wb-refused, routing-proxy, routing-shape, click-scroll, old-webkit pass. |