The gateway takes gateway.Token, and the keys that name an agent
(gateway.TokenFor), only from loopback. When MAGPIE_ADDR pins the
gateway to an address beyond loopback and sharing is on, keyAt gives the
LAN sharing key, and most writers use it. T3 Code's instance still wrote
gateway.Token, so every call it made got 401. Air's and OpenChamber's
Checks compared against gateway.Token, so they said the wiring Sync had
just written was off.
The same mistake was in every writer that pairs gateway.URL() or
gatewayV1() with a fixed token:
- agy, Alma, Cindy, Claude Desktop, Copilot for JetBrains, Cursor's
local agent, OpenHanako, Pencil, VS Code / Insiders / VSCodium,
WorkBuddy-family models.json, ZCode (both files), Zed's credential,
Aside's provider, and the legacy Claude token rename.
- Fix: these now take agentKey(agent) or hereKey(), which are keyAt and
agentKeyAt for gateway.URL(). On loopback they are unchanged.
- Alma re-keys a provider that holds any of magpie's keys other than the
one it should have now.
- WorkBuddy and Aside also count the new key as theirs.
- ZCode treats a saved address equal to the pinned gateway as this
machine's, not another magpie's.
What was run:
- New tests: TestT3CodeKeyBeyondLoopback and
TestAirAndOpenChamberChecksTakeTheKeyForTheGateway (from the
reporter's patch), and TestPinnedGatewayKeyForEveryWriter, which covers
the other writers.
- With the product files reverted, all three are red. The T3 token reads
"magpie", and each of the 11 writers shows its old key. They are green
with the fix.
- go test -tags nogui ./internal/agent/ is green.
- gofmt -l and go vet are clean on darwin, linux and windows.
Not tried with a real T3 Code, Air, OpenChamber or a real pinned
MAGPIE_ADDR on a second machine.
A server magpie signed in to (#615) is given to the agents at the
gateway's /mcp/<name>, at the address each reaches the gateway at. A WSL
distro under NAT reaches it at Windows' address, so its requests come
from another machine, and lanGuard refuses such a request without an
enabled gateway key with a 401, which an MCP client takes for the server
asking it to sign in. through() gave it no key. Its models already carry
the LAN sharing key there (keyAt, whqtian on Discord); the relay didn't.
The gateway's checks are unchanged: a request from another machine still
needs the key, and mcpProxy still lends a sign-in beyond loopback only
to a request that carried it (sharedWith).
What changed:
- agent.KeyAt exports keyAt: the LAN sharing key for an agent that
reaches the gateway from another machine while sharing is on, else
gateway.Token.
- through() gives such an agent Authorization: Bearer <that key>. The
gateway takes it in lanGuard, and mcpProxy drops Authorization for
magpie's token, so the server never sees it. An agent on loopback, and
one in WSL while nothing is shared, stay keyless.
- access.LANChanged runs after sharing is turned on or off or its key is
made anew; the library syncs again then when it relays any server, so
the entry carries the key there is now without a visit to the Library.
- docs/subsystems/library.md says so.
Run:
- TestSignedInServerCarriesKeyBeyondLoopback (library: a FakeWSL distro
routed via 172.20.0.1, LAN on) fails on the old through() ("claude@wsl:
Ubuntu under NAT is given headers map[X-Team:acme], want the LAN key as
its Authorization") and passes now; with the LANChanged call commented
out it fails at "after a new key ... is given" the old key.
- TestMCPProxyFromWSLWithLANKey (gateway, through lanGuard as the server
runs it): 401 without the key and the server not called, 200 with it,
the server gets magpie's token and never the key.
- go test -tags nogui ./... under a temp HOME; gofmt -l; GOOS=linux and
GOOS=windows go vet -tags nogui on the touched packages.
- Not tried on a real Windows + WSL NAT machine with a real OAuth MCP
server; FakeWSL and httptest only.
Patch by ggbdpq in #1488; the LANChanged resync added on top.
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
The drift check asked only whether refs.MAGPIE_GATEWAY_KEY equals the key
magpie writes into .env, so a caller key the gateway itself issued — which
dsh's store prefers and the gateway authenticates — was named as "another
MAGPIE_GATEWAY_KEY" and the user was told to remove it there, while
delete → disconnect → re-apply wrote the very same state back. The check
now asks the gateway's own Authenticate first: a key it takes means dsh is
going through magpie, and only a key it would refuse (a foreign one, a
switched-off one) is drift. The .env side needs nothing: the serving round
rewrites .env to magpie's key, so a stray value there heals itself.
TestDshStoreHoldingAGatewayCallerKey (a key from access.Update add-key in
the store's refs) failed without the change with the "holds another
MAGPIE_GATEWAY_KEY" drift; with it the check is quiet, and a key the
gateway doesn't take still reports.
Verified: go test -tags nogui ./internal/agent -count=1; the three dsh
store tests under -race -count=10; gofmt -l clean; go vet -tags nogui
./internal/agent; go build and GOOS=linux/GOOS=windows go build -tags
nogui.
Generated-by: GLM-5.3-Flash (ZCode)