Commit Graph
3 Commits
Author SHA1 Message Date
yetone d155ab1619 gateway: a relayed Responses item keeps the id it was added with, so Codex on Copilot shows a message once (echo_ts on Discord)
echo_ts (v0.1.1293, Codex desktop, a GPT model on GitHub Copilot): each
commentary paragraph was shown twice; fine around v0.1.1280.

Cause: since ec7f47432 (v0.1.1287) a Codex turn on Copilot offering
web_search is relayed, not translated. Copilot's /responses gives an item
a new id in every event: output_item.added, each delta, output_item.done
and response.completed's output all differ (checked 2026-10-19 on the
owner's account, gpt-5.5 with web_search, in a sandbox HOME). Codex starts
an item by the added's id and ends one by the done's, so the streamed
message and the finished one were two messages. Translated, magpie's
encoder had given each item one id of its own, so it didn't show before.

Fix: idTidy (itemids.go), in passthrough before phaseTidy for every
relayed Responses stream: each later event's item_id / item.id, and
response.completed/incomplete/failed's output[i].id, take the id the
item was added with. An upstream whose ids agree goes through byte for
byte. docs/subsystems/gateway-routing.md says so.

Tests:
- TestCopilotItemKeepsItsID: a real Copilot reply (testdata, encrypted
  parts cut short) relayed through the handler from a fake Copilot
  (copilotSol now takes a reply); each output item goes by one id.
- TestItemIDsThatAgreeGoAsTheyCame: OpenAI-shaped ids, fed in 7-byte
  pieces, come out unchanged.
Broken by hand (idTidy off in passthrough): TestCopilotItemKeepsItsID
FAIL "item 0 went by 3 ids", items 1-3 by 6, 8, 5. Restored: ok.

Real use: built magpie serve in a sandbox HOME (port 3478, only the
Copilot sign-in copied), the real codex-cli 0.162.1 exec --json with
web_search on copilot/gpt-5.5:
- before: web_search item.started and item.completed under different ids;
- after: same id for each, and the follow-up requests carrying the kept
  ids back to Copilot were answered. A raw stream gave one id per item.
Not tried in the Codex desktop app itself.

Sibling found, not changed: on the translated path a reasoning item with
a non-rs_ id and a summary reaches the client twice (filed #2974; Copilot
gave summary [] in every capture).

Run at b9d1cd36f plus this change: gofmt -l clean; go vet ./... for
darwin, linux (-tags nogui) and windows ok; go test -timeout 45m ./...:
64 packages ok (internal/gateway 2023s), exit 0.
2026-10-20 00:33:40 +08:00
yetone ec7f474323 gateway: Codex on Copilot is relayed with its web_search, and a translated call's arguments stream (echo_ts)
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.
2026-10-19 00:33:29 +08:00
yetone b6467c9551 codex: Ultra on GPT-6.1 Sol wherever it is served, Copilot's too, with Codex's agents taking parts of the task (#656) — Codex offers Ultra on a model whose entry lists "ultra", and on a thread at multi-agent V2 hands parts of the task to agents of its own; its catalog (models-manager/models.json) lists it for gpt-6.1-sol, gpt-6-sol, gpt-6-astra, gpt-5.6-sol and gpt-5.6-terra, not the Lunas, which stop at max. magpie listed Copilot's gpt-6.1-sol only up to max, so Codex had no Ultra for it. Now an entry for one of those models (by the id the vendor serves: openai/…, dated snapshots) that reaches max lists ultra too, in Codex's catalog and /v1/models, and its Codex entry says multi_agent_version v2, as Codex's own does; GPT-6 Luna still stops at max. A ChatGPT account's entry stays as the backend lists it, and a group with a ChatGPT account in it offers ultra but isn't told V2 (its lead's subagent tasks come sealed, #141); the "subagents on any model" setting still stamps v1 on OpenAI's entries. Ultra is no API's level: the gateway now always sends max for it (fitEffort), even to a model whose list says ultra. Subagent tasks with web_search kept (the translated path) were fixed in v0.1.689 (#613); TestCopilotUltraSubagentWithWebSearch now covers it against a stub Copilot: the lead's spawn_agent comes back with plain arguments and encrypted_function_args [], no "encrypted" goes upstream, and the subagent's agent_message reaches Copilot as text. TestCopilotSolOffersUltra (sol has ultra in /v1/models and Codex's catalog with v2, luna not; ultra goes to Copilot as max, with and without web_search) and TestUltraIsSentAsMax fail on the old code; TestUltraOnModelsThatOfferIt and TestUltraEntriesSayV2 cover entries, groups and the catalog. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. Not tried in the Codex App with a real Copilot account. 2026-10-03 16:08:26 +08:00