agent: VS Code's Agents window (vscode_agent_host) counts as VS Code, its turns as Codex's
justruman on Discord (#general, 11-01): VS Code's Agents window showed
in Usage as a raw "vscode_agent_host" row, 23 calls, 7 failed, beside
the "VS Code" row.
Why: VS Code's agent host runs `codex app-server` with clientInfo
{name: "vscode_agent_host"} (microsoft/vscode main at 8fb6054,
src/vs/platform/agentHost/node/codex/codexAgent.ts CLIENT_INFO; it
bundles @openai/codex 0.163.0). Codex sends that name as its
originator and at the head of its User-Agent, and it reads the user's
~/.codex config, so with Codex connected to magpie its turns come here
under VS Code's name. No agent's UA list had it.
- Usage: vscode_agent_host is in VS Code's UA list
(vscodeAgentHostUA), so those calls are VS Code's. Records are named
again at read time (ReportedAs -> AgentOf), so calls already logged
under the raw name fold into VS Code too. Insiders' and VSCodium's
agent host send the same name and are counted as VS Code (Stable):
nothing in the request tells them apart.
- Routing: fromCodex also takes vscode_agent_host (hostedCodex), so
every Codex rule holds for those turns. The one that fails without
it: one of Codex's own models asked there, which no account in
magpie serves, was answered 404 "magpie knows no model" instead of
going on Codex's sign-in (codexOwnOffMagpie). Also now applied:
spawn_agent's model list, compaction told in the stream on a byte
cap/overflow, Codex's headers to a keyed Codex-only relay.
- A test asked as Codex keeps only Codex's own names (codexNamed) as
Codex's shape: the agent host's headers never become it.
- VS Code's Copilot-proxied names (vscode_codex, vscode_claude_code) go
to GitHub, not magpie, and are not matched.
- docs/subsystems/gateway-routing.md says so.
Run on mote at this change rebased on origin/main 16ce5ed23; the
one commit since, e65bc8473 (#4802), changes internal/plugin and GUI
files only: gofmt -l empty; go vet ./internal/agent ./internal/gateway
./internal/usage for darwin, GOOS=linux -tags nogui and GOOS=windows
ok; go test -count=1 -timeout 45m on the three packages: agent ok,
usage ok, gateway ok except TestCodexPoolSaysTheClientsVersion
(#4807, filed at origin/main 79f83798f before this change; it sends
codex_cli_rs, which this change leaves as it was, and passes alone
at this head and at its base).
Broken by hand, each red: without hostedCodex in fromCodex,
TestVSCodeAgentHostIsCodex, TestVSCodeAgentHostOwnModelGoesOnSignIn
(404 "magpie knows no model \"gpt-6.1-sol\"") and
TestVSCodeAgentHostNotCodexTestShape (relay sent magpie/dev); with
SawClient ungated, TestVSCodeAgentHostNotCodexTestShape (as Codex sent
vscode_agent_host, 403); without the UA list entry, TestVSCodeAgentHostUA.
Not tried: a real VS Code Agents window against magpie (no VS Code on
this machine or mote). The UA and originator are from VS Code's and
Codex's source, not captured bytes, and the terminal part of the UA is
a guess (it isn't matched). The reporter's 7 failures weren't seen:
the 404 above is the failure class the source shows, not one confirmed
in their log. Other checks keyed on agent == "codex" (Codex memory
calls, image drawing on Codex's own models, title links, CodexBusy)
don't apply to these turns, since they are counted as VS Code.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -51,6 +51,16 @@ const vscodeDefault = `chat\.defaultModel`
|
||||
// can't change.
|
||||
const vscodeUA = "githubcopilotchat"
|
||||
|
||||
// vscodeAgentHostUA is VS Code's Agents window: its agent host runs
|
||||
// `codex app-server` with clientInfo named vscode_agent_host (VS Code's
|
||||
// src/vs/platform/agentHost/node/codex/codexAgent.ts), and Codex makes
|
||||
// that its originator and the start of its User-Agent
|
||||
// ("vscode_agent_host/0.163.0 (Mac OS …; arm64) … (vscode_agent_host;
|
||||
// 0.1.0)"). Its calls were listed under that raw name beside VS Code's
|
||||
// (justruman on Discord). Insiders' and VSCodium's agent host send the
|
||||
// same name, so they are counted as VS Code too.
|
||||
const vscodeAgentHostUA = "vscode_agent_host"
|
||||
|
||||
// The providers magpie's group can be written for: VS Code's Custom
|
||||
// Endpoint, and the OpenAI Compatible one of the Copilot Chat VSCodium
|
||||
// installs.
|
||||
@@ -99,7 +109,7 @@ type vscodeKind struct {
|
||||
}
|
||||
|
||||
var (
|
||||
vscodeStable = vscodeKind{id: "vscode", name: "VS Code", folder: "Code", bin: "code", aliases: []string{"vs-code", "copilot-chat", "vscode-chat"}, ua: []string{vscodeUA}}
|
||||
vscodeStable = vscodeKind{id: "vscode", name: "VS Code", folder: "Code", bin: "code", aliases: []string{"vs-code", "copilot-chat", "vscode-chat"}, ua: []string{vscodeUA, vscodeAgentHostUA}}
|
||||
vscodeInsiders = vscodeKind{id: "vscode-insiders", name: "VS Code Insiders", folder: "Code - Insiders", bin: "code-insiders", aliases: []string{"vs-code-insiders", "code-insiders"}}
|
||||
vscodiumKind = vscodeKind{id: "vscodium", name: "VSCodium", folder: "VSCodium", bin: "codium", aliases: []string{"codium", "vscodium-chat"}, exts: ".vscode-oss"}
|
||||
)
|
||||
|
||||
@@ -234,6 +234,18 @@ func TestVSCodeUA(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// VS Code's Agents window runs Codex under the name vscode_agent_host,
|
||||
// its User-Agent and originator: its calls are VS Code's, not a row of
|
||||
// their own named vscode_agent_host (justruman on Discord). VS Code's
|
||||
// Copilot-proxied Codex and Claude names are not it.
|
||||
func TestVSCodeAgentHostUA(t *testing.T) {
|
||||
for _, ua := range []string{"vscode_agent_host/0.163.0 (Mac OS 26.2.0; arm64) unknown (vscode_agent_host; 0.1.0)", "vscode_agent_host"} {
|
||||
if got := usage.AgentOf(ua); got != "vscode" {
|
||||
t.Errorf("%q: %q", ua, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// VS Code Insiders is its own row (wani on Discord): its User folder is
|
||||
// "Code - Insiders" beside VS Code's "Code", connected it writes only there,
|
||||
// and its models send a token of its own, since its chat's User-Agent is
|
||||
|
||||
@@ -4959,7 +4959,9 @@ func (s *Server) forwardOnce(ctx context.Context, p provider.Provider, to provid
|
||||
seen[k] = vs
|
||||
}
|
||||
}
|
||||
provider.SawClient(provider.ClientCodex, seen)
|
||||
if codexNamed(in) {
|
||||
provider.SawClient(provider.ClientCodex, seen)
|
||||
}
|
||||
}
|
||||
if p.Account == nil && biliProxied(req.URL.Path) {
|
||||
// a billion-context proxy put in front of the provider (#3052)
|
||||
@@ -5119,7 +5121,20 @@ func claudeCodeHeader(k string) bool {
|
||||
// desktop app or ACP adapter — by the User-Agent (codex_cli_rs/0.159.2
|
||||
// (Mac OS 26.6.0; arm64) kitty, Codex Desktop/0.162.3 …) or the originator it gives
|
||||
// (codex_cli_rs, codex_exec, codex_vscode, Codex Desktop, acp-extension-codex).
|
||||
// VS Code's Agents window runs `codex app-server` under the name
|
||||
// vscode_agent_host, which Codex sends as both: those are Codex's turns
|
||||
// too, though they are counted under VS Code (agent.vscodeAgentHostUA).
|
||||
// Without it one of Codex's own models asked there was answered 404
|
||||
// "magpie knows no model" rather than going on Codex's sign-in
|
||||
// (codexOwnOffMagpie; justruman on Discord).
|
||||
func fromCodex(in http.Header) bool {
|
||||
return codexNamed(in) || hostedCodex(in)
|
||||
}
|
||||
|
||||
// codexNamed is a request whose User-Agent or originator is one of Codex's
|
||||
// own names, not an app's that runs it: only those are Codex's shape for
|
||||
// a test asked as Codex (provider.SawClient).
|
||||
func codexNamed(in http.Header) bool {
|
||||
for _, v := range []string{in.Get("User-Agent"), in.Get("originator")} {
|
||||
v = strings.ToLower(v)
|
||||
if strings.HasPrefix(v, "codex") || strings.HasPrefix(v, "acp-extension-codex") {
|
||||
@@ -5129,6 +5144,19 @@ func fromCodex(in http.Header) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// hostedCodex is a Codex an app runs under the app's own name and that
|
||||
// name only Codex is run under: VS Code's agent host (its codexAgent.ts
|
||||
// CLIENT_INFO). An app that runs Codex as its own engine under a name it
|
||||
// uses for more than that (Lody) is not told apart this way.
|
||||
func hostedCodex(in http.Header) bool {
|
||||
for _, v := range []string{in.Get("User-Agent"), in.Get("originator")} {
|
||||
if strings.HasPrefix(strings.ToLower(strings.TrimSpace(v)), "vscode_agent_host") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// codexAsSent says a Responses request goes to p as Codex sent it, its
|
||||
// model name alone swapped: Codex's own, to a relay set codex=as-sent,
|
||||
// which checks that a request is Codex's own (#1758).
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
// VS Code's Agents window runs `codex app-server` (main at 8fb6054,
|
||||
// 11-01: @openai/codex 0.163.0) with clientInfo {name: "vscode_agent_host"}, in
|
||||
// src/vs/platform/agentHost/node/codex/codexAgent.ts. Codex sends the name
|
||||
// as its originator and at the head of its User-Agent, as it does Claude
|
||||
// Code's plugin's (TestCodexPluginForClaudeCodeIsCodex). The headers are a
|
||||
// Codex turn's under that name.
|
||||
func vscodeAgentHostHeader() http.Header {
|
||||
return http.Header{
|
||||
"User-Agent": {"vscode_agent_host/0.163.0 (Mac OS 26.2.0; arm64) unknown (vscode_agent_host; 0.1.0)"},
|
||||
"Originator": {"vscode_agent_host"},
|
||||
"X-Codex-Window-Id": {"019a0f7e-0000-7000-8000-000000000001:0"},
|
||||
"X-Codex-Turn-Metadata": {`{"turn_id":"019a0f7e-0000-7000-8000-000000000002","sandbox":"none"}`},
|
||||
"Session-Id": {"019a0f7e-0000-7000-8000-000000000001"},
|
||||
}
|
||||
}
|
||||
|
||||
// Its turns are Codex's: a Codex rule holds for them. They are not Codex's
|
||||
// own name, so they never stand for Codex in a test asked as Codex.
|
||||
func TestVSCodeAgentHostIsCodex(t *testing.T) {
|
||||
h := vscodeAgentHostHeader()
|
||||
if !fromCodex(h) {
|
||||
t.Fatal("VS Code's agent host's Codex turn isn't Codex's")
|
||||
}
|
||||
if !fromCodex(http.Header{"Originator": {"vscode_agent_host"}}) {
|
||||
t.Fatal("by its originator alone, it isn't Codex's")
|
||||
}
|
||||
if codexNamed(h) {
|
||||
t.Fatal("the agent host's name counted as Codex's own")
|
||||
}
|
||||
for _, other := range []string{"vscode_codex/0.163.0", "vscode_claude_code/2.1.0", "GitHubCopilotChat/0.69.0"} {
|
||||
if fromCodex(http.Header{"User-Agent": {other}}) {
|
||||
t.Errorf("%s counted as Codex", other)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// One of Codex's own models asked from the Agents window on Codex's
|
||||
// magpie provider, which no account in magpie serves, goes on Codex's own
|
||||
// sign-in as the Codex CLI's does (TestCodexOwnModelOnMagpieThreadGoesOnSignIn),
|
||||
// not 404 "magpie knows no model" (justruman on Discord: 7 of 23 calls
|
||||
// failed).
|
||||
func TestVSCodeAgentHostOwnModelGoesOnSignIn(t *testing.T) {
|
||||
_, models := codexOwnOffMagpieSetup(t, false)
|
||||
req := codexOnMagpieRequest("127.0.0.1:51000")
|
||||
for k, v := range vscodeAgentHostHeader() {
|
||||
req.Header[k] = v
|
||||
}
|
||||
rec := httptest.NewRecorder()
|
||||
New().Handler().ServeHTTP(rec, req)
|
||||
if rec.Code != 200 || !strings.Contains(rec.Body.String(), "pong") {
|
||||
t.Fatalf("got %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
if len(*models) != 1 || (*models)[0] != "gpt-6.1-sol" {
|
||||
t.Fatalf("backend asked for %v", *models)
|
||||
}
|
||||
}
|
||||
|
||||
// Its headers go on to a keyed relay as Codex's do, but a test asked as
|
||||
// Codex still asks as Codex itself: the agent host's name is no Codex
|
||||
// official client a Codex-only relay lets in.
|
||||
func TestVSCodeAgentHostNotCodexTestShape(t *testing.T) {
|
||||
fresh(t)
|
||||
f := &clientOnlyRelay{}
|
||||
up := httptest.NewServer(f)
|
||||
t.Cleanup(up.Close)
|
||||
if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Models: []string{"gpt-5.5"},
|
||||
Chat: up.URL + "/v1", Responses: up.URL + "/v1"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
req := httptest.NewRequest("POST", "/v1/responses", strings.NewReader(`{"model":"relay/gpt-5.5","stream":true,"input":"hi"}`))
|
||||
req.Header = vscodeAgentHostHeader()
|
||||
req.Header.Set("Authorization", "Bearer "+Token)
|
||||
New().Handler().ServeHTTP(httptest.NewRecorder(), req)
|
||||
head, _, _ := f.last()
|
||||
if head.Get("Originator") != "vscode_agent_host" {
|
||||
t.Fatalf("the relay wasn't sent the agent host's turn as it sent it: %v", head)
|
||||
}
|
||||
p, err := provider.Find("relay")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := p.TestModels(provider.TestAs(context.Background(), provider.ClientCodex), []string{"gpt-5.5"})[0]
|
||||
head, _, _ = f.last()
|
||||
if !r.OK || !strings.HasPrefix(head.Get("User-Agent"), "codex_cli_rs/") {
|
||||
t.Fatalf("as Codex after the agent host came: %+v, User-Agent %q", r, head.Get("User-Agent"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user