Files
magpie/docs/subsystems
yetone 6690caaaec gateway: auto mode's review isn't asked of another subscription's Claude model, and Claude Code's set model is judged where it goes
Claude Code 2.1.302 tells a session behind magpie "this session isn't
eligible because your requests go through 127.0.0.1:3425" and points the
gateway at code.claude.com/docs/en/auto-mode-classifier-billing. That
page asks a gateway to forward the dangerous-tool-use-2026-09-03 beta and
the top-level `safeguards` field, and to return `safeguard_results`
(message_delta.delta in a stream) with tool-use ids unchanged; one that
can't should have clients set CLAUDE_CODE_AUTO_MODE_SERVER=0. magpie
already does this on every route Anthropic answers (Claude subscription
bridge, api.anthropic.com, relays, Bedrock, Vertex) and writes the 0
when no reachable model is reviewed (24350a372). Only Anthropic can
produce safeguard_results, so for any other model the 0 is the remedy;
magpie never answers one on Anthropic's behalf.

Gap fixed here: AutoModeReviewed counted any claude-* name as reviewed,
so a Claude model on another vendor's subscription or a plugin (Copilot,
Kiro, Cursor…) was sent the beta and safeguards (Copilot 400s on them,
#1756) and counted as reviewed by the agent wiring, which then left
CLAUDE_CODE_AUTO_MODE_SERVER unset and the notice showing. Now an
account provider counts only when it is the Claude subscription or sits
on api.anthropic.com; providers with a key keep the name rule. And
claudeReviewed resolves the models Claude Code is set to (group,
provider, fallback) before judging them, as the gateway would, instead
of by name alone.

Tests: TestAutoModeReviewedRoutes (copilot/kiro/plugin cases),
TestAutoModeReviewLeftOffOtherSubscriptions,
TestClaudeReviewedJudgesTheSetModelWhereItGoes. Broken by hand: with
automode.go reverted, the first two go red (copilot/kiro/x-plugin true;
copilot beta+safeguards sent); with claude.go reverted, the third goes
red (v/gpt-x falling back to a/claude-sonnet-5 not reviewed).

Run at 2042123f4 + this change, sandbox HOME, load ~350:
- gofmt -l: clean. go vet ./... (darwin), GOOS=linux and GOOS=windows
  go vet -tags nogui ./...: clean.
- go test -timeout 45m ./...: 63 ok, 3 red, all filed and none in code
  this touches: internal/agent hit 45m (#2723, #2544); gateway's
  TestPluginStreamLargeReplies/JSON_fast hit its client timeout (#2551);
  gui's TestMainWindowCorners was killed at its deadline (#1936, #2645).
- Reruns alone: internal/agent -timeout 90m ok (2637s);
  TestPluginStreamLargeReplies ok; TestMainWindowCorners/macOS_26_SDK
  killed at 40s again at load ~200 (#1936).
After rebasing onto origin/main c4aeaec74 (6 commits, none in these
files): go vet of gateway and agent clean; TestAutoMode*,
TestSafeguards*, TestClaudeBridgeSafeguard* ok; the agent review tests
printed one bare FAIL whose output was cut off by tail, then passed
alone and -count=3 -v (all PASS); cause of that one FAIL not known.
Not run: a real Copilot/Kiro account through Claude Code (the agent test
covers the resolution with key providers; the account rule is covered
in the gateway unit tests), the GUI node suite (no GUI change).
2026-10-17 22:43:54 +08:00
..

Subsystem design references

These pages describe current responsibilities, runtime paths, state, and contracts. Start with the subsystem relevant to your task, then follow its source links to verify the implementation you change.

Subsystem Reference
Built-in subscriptions moving to plugins Provider and plugin ownership
Built-in plugins: registry, lifecycle, plugins.yml, presets, settings schemas, the window's kernel (slots, error boundary, kit) Plugin runtime
Plugins that run on the gateway's requests and replies Gateway middleware
Tools that plugins give, offered to every agent as an MCP server Plugin tools
Plugins that await context recall and observe completed replies Asynchronous gateway request hooks
Claude subscription turns across Claude Code runs Claude subscription bridge
How the gateway picks a provider, key or account, and falls back Gateway routing and fallback
Gateway Session Aggregation Gateway Session Aggregation
Connecting an agent's config to the gateway, drift, disconnect, WSL twins Agent wiring
Providers, keys, subscription accounts, refresh and allowance Providers and accounts
Instructions, MCP servers, skills and RTK written into agents Library
Tray, panel, window, magpie web and the page's JSON API GUI app shell
Encrypted backups and setup synchronization over WebDAV, S3 or GitHub Sync and backup

A subsystem can span several packages or repositories. Its reference describes the behavior those parts provide together; it does not need to list every function.

Maintain a reference

Update the owning reference in the same PR when a change alters a documented responsibility, interface, state transition, runtime path, compatibility rule, or failure behavior. An internal refactor that preserves these contracts does not require a prose change.

Keep each fact in one reference and link to it from agent instructions or other pages. Link to source files and named symbols rather than copying implementation details that change frequently. Explain field meanings and constraints that signatures alone do not express.

For a new reference, include the responsibilities and boundaries, source of truth, main runtime paths, state transitions, important constraints, and existing verification commands. Include failure and compatibility behavior where relevant. Document current behavior separately from proposed changes; the proposal belongs in its issue or PR.

Describe a PR's semantic changes

For each affected subsystem, explain the observable change with its trigger and before/after behavior. Include changes to interfaces, state, compatibility, and failure behavior when relevant. Link the affected reference, implementation, and verification evidence. State when a refactor preserves the documented behavior.

For example, a change to plugin adoption should explain which migration state and account condition trigger it, which implementation handles requests before and after adoption, and which test exercises that transition.

This is an author-provided explanation that a reviewer verifies against the diff and surrounding code. It is not an automatically proven compatibility verdict.

Review a change

  1. Identify the affected subsystem and the actual runtime path, including plugin or built-in ownership.
  2. Compare the claimed before/after behavior with the base and head implementation. Trace relevant callers and state transitions beyond the changed lines.
  3. Check that changed contracts appear in the owning reference and that source links still resolve.
  4. Check that the cited tests or runtime evidence exercise the claimed behavior. Report checks that were not run.

A documentation update alone does not prove the implementation. Existing tests and runtime evidence remain necessary for behavior changes.