echo_ts (magpie 0.1.1279, macOS): Codex on a GitHub Copilot subscription
through magpie was about 10x slower than Copilot directly. Two causes,
both in the gateway:
- Codex offers web_search on every turn, and magpie counted Copilot as a
provider that can't search, so every Codex turn on Copilot was
translated for magpie's search instead of relayed.
- On that translated path responsesDecoder held a call's argument deltas
until the call was done, so Codex saw nothing while the model wrote a
command or a patch, then all of it at once. A custom tool (apply_patch)
got no custom_tool_call_input deltas at all.
Fixes:
- search.go: searchesItself counts a Copilot account on Responses. Real
check on 2026-10-17 with the owner's account: gpt-5.3-codex,
gpt-5.4-mini, gpt-6-luna, grok-4.7 and mai-code-1.1-flash each answered
a request offering web_search with web_search_call items and cited
pages. searchRank never picks Copilot to search for another provider's
models (its premium requests).
- gateway.go: a Copilot Responses request whose tools mark an argument
"encrypted" (MultiAgentV2's spawn_agent message) is still translated,
marks left out (asksSealing in responses.go). Checked on the real
account: relayed, Copilot seals the message ("UlQC...", no
encrypted_function_args), and the subagent's turn carrying it came back
"Encrypted function output content could not be decrypted or
decoded". This was already broken for a Copilot turn without
web_search; it is fixed for that too. An unsealed agent_message relayed
with web_search answers normally (checked).
- responses.go: responsesDecoder gives argument deltas as they come. It
holds only the deltas that make the arguments whole JSON, until the
done events, so #613's case (deltas that disagree with done) still
ends with the fuller arguments. The encoder sends a custom tool's input
as custom_tool_call_input.delta, read out of the {"input": ...}
arguments as they stream (customStream in custom_tool.go, which waits
for cut escapes, surrogate pairs and UTF-8), and closes it with
custom_tool_call_input.done.
- docs/subsystems/gateway-routing.md says the above.
Not changed: the HTTP/2 connection. Head-of-line blocking from large
uploads on the one connection to Copilot was measured on the real
account with a Go client: a 4MB request and a small one 300ms later,
5 rounds x 2, same connection vs a new one. The small request's first
byte took 0.93-1.68s on the shared connection, 1.26-4.77s on its own
(handshake included), 0.66-1.08s alone. No sign of blocking.
Small requests slower while a long session runs (echo_ts, 42.8s vs
17-29s first text, xhigh): nothing in magpie serializes Copilot requests
by default (lanes need MaxConcurrency, the RPM gate MaxRPM; Go's h2
windows are 1GB per connection, 4MB per stream). Measured: small
requests beside a 412s xhigh stream (16,617 output tokens) were as fast
as idle, via magpie 0.8-1.1s first text, direct 1.3-2.0s, sent_ms
1-10ms. One global lock found: copilotMu is held across the token
refresh's HTTP call, which stalls every Copilot request only around a
refresh, filed as #2762, not changed here. usage.jsonl's own_ms,
queued_ms and sent_ms against ttft_ms tell magpie's time from Copilot's.
Tests:
- TestCallArgsStreamWhenTranslated (function and custom), through the
real handler with an upstream that holds the rest of the call until
the client has the first delta.
- TestResponsesCallArgsStream, TestCustomInputStreams (pieces of 1, 2, 3,
5, 7 bytes and whole).
- TestCopilotRelayedUnlessAskedToSeal; TestCopilotUltraSubagentWithWebSearch
now expects the subagent relayed with the search.
Broken by hand at this tree, each went red:
- decoder holding every delta: TestCallArgsStreamWhenTranslated,
TestResponsesCallArgsStream;
- no custom input delta: TestCallArgsStreamWhenTranslated/custom;
- Copilot out of searchesItself: TestCopilotRelayedUnlessAskedToSeal,
TestCopilotUltraSubagentWithWebSearch;
- the asksSealing check off: the same two.
Real use: a built magpie serve in a sandbox HOME (port 3461) with the
owner's Copilot account, Codex-shaped requests offering exec_command,
apply_patch and web_search to copilot/gpt-5.3-codex:
- unmarked: relayed (Copilot's own response ids), apply_patch gave 93
custom_tool_call_input deltas from 3.55s to 11.69s;
- with a sealed spawn_agent: translated, apply_patch 117 deltas from
1.45s to 11.73s, exec_command 92 function_call_arguments deltas from
1.55s to 8.16s.
Not tried with the Codex binary itself.
Run at d783df46c plus this change (load 160-330 from other sessions): gofmt -l clean; go vet ./... for darwin,
linux (-tags nogui) and windows ok; go test -timeout 45m ./...:
60 packages ok; internal/agent, internal/gateway and internal/library
timed out at 45m (#2544/#2723, #2108, filed #2853), internal/gui's
TestSetAnswersWhileDevinAndProvidersHang (#1375) and TestMainWindowCorners
(#2645) red. Rerun alone: internal/library ok 1184s; the two gui tests
ok; internal/gateway timed out at 45m again (load ~300), then at
-timeout 3h ran 2887s with one red, TestClaudeAccountsSpentFallBackToCodex
"stream=true: no answer" at its 30s wall wait (filed #2858; -count=3
alone ok). The tests above, after the rebase: ok.
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
- Identify the affected subsystem and the actual runtime path, including plugin or built-in ownership.
- Compare the claimed before/after behavior with the base and head implementation. Trace relevant callers and state transitions beyond the changed lines.
- Check that changed contracts appear in the owning reference and that source links still resolve.
- 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.