Files
magpie/docs/subsystems
yetone 7ea8aeaba7 gateway: DSML written with a run of pipes (<||DSML||invoke) is made the call too, not left as text (#2623, OKURBITO)
DeepSeek wrote its tool call as <||DSML||invoke name="get_weather">…
(two full-width pipes each side) and the reply reached the Responses
client as that markup: textCallAt only knew the one-pipe marks, so
nothing was held and parseTextCalls, whose regexes already read a run
of pipes, never ran. dsmlMark now finds a DSML tag's mark as the parse
regexes (dsmlTag) read one, with no list of spellings: <, spaces, / and
spaces for a close, a pipe, a run of pipes and spaces, DSML, and
another run that may be empty. A pipe is ASCII | or full-width |, in
any number and any mix of widths. textCallAt uses it to find a call
and to hold a mark still being written (down to a full-width pipe's
first bytes); cutMark uses it to trim a tag cut short at the end, once
the tag has begun its pipes, so a value ending "a < " keeps its "<".
Every route goes through these: textCallSee (translations),
textCallTidy (relayed Chat streams) and wholeTextCalls (whole Chat
replies). OKURBITO pointed out on the issue that a spelling table
leaves |||, ||, || and the like as text; this reads the class.

Tests (textcalls_pipes_test.go). Which cases were seen and which were
made up, as OKURBITO set out on the issue: one reply was written by a
model on its own in real use (deepseek-flash offered web_search:
<||DSML|| calls> … <||DSML|| invoke name="web_search"> …), kept
byte for byte as observedPipes; the issue's get_weather reply came from
asking the model to echo the markup; every other spelling (three pipes,
ASCII, widths that disagree, spaces after <, no pipes after DSML) is
constructed and has not been seen.
- TestTextWrittenDSMLDoublePipe: the observed reply, relayed Chat
  streamed and whole, is a web_search call with its query and no DSML
  left; the issue's reply through /v1/responses, streamed and whole, and
  a whole Chat reply, is a get_weather call with {"city":"Beijing"} and
  no message item.
- TestTextWrittenDSMLAnyPipes: | | || || || || ||| ||| "| |", each reply
  sent one character per chunk: the call, wrapped with text before, a
  space before invoke (the live <||DSML|| invoke), no parameters, cut
  short, tags only with the last cut short, a tool not offered, a mark's
  start at the end, pipes without DSML; each ends as the one-pipe reply.
- TestTextWrittenDSMLDoublePipeEveryCut: the reply split at every byte
  boundary JSON allows is the same call; textCallAt holds each prefix of
  the mark, a full-width pipe's first bytes too.
- TestTextWrittenDSMLMarkAsParsed: widths that disagree within a tag
  and between its open and close, spaces after < and around /, no pipes
  after DSML are each the call; a cut-short <parameter> value ending in
  "a < " keeps it; "x < y and a <" stays text.

Fails without the change: with b7d9616d0's textcalls.go all four
FAIL, the observed reply among them ("text \"<||DSML||invoke …\" calls
map[] finish \"stop\"", "a message item beside the call"; MarkAsParsed's
widths that disagree, spaces after <, no pipes after DSML); the one-pipe
rows pass there. With an earlier draft of dsmlMark (a run of pipes,
none after <, one required after DSML) MarkAsParsed FAILs its
spaces-after-< and no-pipes-after-DSML rows; with cutMark's
has-begun-its-pipes guard taken out it FAILs the cut-short value ("a "
for "a < ").

Not tried against a real DeepSeek upstream: the fixtures are the
bytes OKURBITO posted. In the observed event the request offered only
a hosted web_search ({"type":"web_search"}), not a function; a call to
a tool the request didn't offer by name still goes on as text, as
before, and the test offers web_search as a function.

Run with both #2623's and #2625's changes, on b7d9616d0 (macOS, Go
1.26.8, load average 80-270 from other sessions):
- gofmt -l: nothing. go vet -tags nogui ./... with GOOS darwin, linux and
  windows: clean.
- set -o pipefail; go test -timeout 45m ./...: every package ok except
  internal/agent (2702s) and internal/gateway (2721s), which ran past
  45m under the load (#2544, #2108; no test hung, each was seconds into
  its run). Rerun with -timeout 90m: internal/agent ok (2816s);
  internal/gateway's only red is TestDesktopSubagentUnsetDoesNotDecode,
  "allocated 1 times" (10/10 green alone, filed as #2699). The textcalls
  tests passed in that run.
2026-10-17 18:41:43 +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.