Files
magpie/docs/subsystems
yetone f5553d7103 sessions: a Pi subagent's calls are its lead session's, on its own model (nzvzbmz78932 on X)
nzvzbmz78932 on X: "在pi子代理中使用了deepseek 但是不显示用量". pi-subagents
(npm 0.88.1) runs each subagent as a Pi of its own, its session in
<lead file's folder>/<run id>/run-<n>/session.jsonl (async and parallel
runs a level deeper), or under extensions/subagent/config.json's
defaultSessionDir, its header's parentSession naming the lead's file.
magpie read only sessions/*/*.jsonl, so those files were never read. The
lead's `subagent` tool result carries the subagents' usage summed, and
piParse counted it on the lead's model and provider: a lead on magpie's
entry made it the gateway's (piGateway), so DeepSeek's calls were on no
page, Usage or Sessions.

- piFilesIn reads every session file under a lead's folder as the
  lead's (non-main, like omp's), and the defaultSessionDir ones through
  their headers' parentSession, up to 8 levels.
- piSubagentsRead: a tool result whose every sessionFile is one of those
  counts nothing, in piParse and piCall; one naming a file not read
  still counts as before.
- The scout's header id is in Session.Subs (pi is idInFile), so a
  subagent on magpie's entry is the lead's row to the gateway too.
- state.codexPath is parsePath, the file read, for piLeadID: a new field
  took state past its 416-byte class (TestStateFitsItsSizeClass).
- parseVersions and callParseVersions pi/raft/cindy raised.

The fixture is a real run: Pi 1.4.0 with pi-subagents 0.88.1 in a
sandbox PI_CODING_AGENT_DIR, a lead and one scout on a relay's
deepseek/deepseek-flash; system prompts dropped, paths rewritten.

Run (mica, at this head):
- go test ./internal/sessions: ok (119s)
- GOOS=linux and GOOS=windows go vet ./internal/sessions: ok; gofmt clean.
- Linux (wsl-run, magpie-desktop): TestPi*, TestOmp*, TestCodex*,
  TestStateFits*: ok
TestPiSubagentCalls: beside the lead and in defaultSessionDir, each with
the lead on the relay and on magpie's entry (the reporter's case).
Broken by hand: without the walk, 3 of 5 calls and 0 of 2 with the lead
on magpie (red); without the tool-result skip, 6 calls, the sum counted
again (red); the Subs check was red while it named the run id.
Not tried: the reporter's own files; a subagent nesting subagents; a
subagent run on magpie's entry against a live gateway.

With f0fb22c6b and 5bc816c1a below it, at this head (mica): go test
./internal/sessions ./internal/agent ./internal/claudecode ok,
./internal/gateway -run TestClaude ok, GOOS=linux and windows go vet of
the four ok, gofmt clean.
2026-11-13 19:07:34 +08:00
..
2026-11-10 03:25:44 +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
One MCP server, magpie, given to every agent in place of the Library's servers MCP router
Memory shared by every agent: the memory MCP server, the digest in instructions, the Memory tab Memory
One skill, magpie-skills, listing the Library's skills in place of each agent's own Skill router
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.