ac4af582301a4e8a29245dbba767eba31334ddf9
5
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
a4916aec10 |
gateway: a Codex websocket turn sent to a Responses relay leaves Lite's client_metadata marker behind (#4853)
A Codex title request through a Responses relay (CPA) failed with "X-OpenAI-Internal-Codex-Responses-Lite requires reasoning.context to be all_turns". fromLite took Lite's shape off for a backend that isn't OpenAI's: it lifted additional_tools, left reasoning.context out and didn't send the Lite header on. But over a websocket Codex says it is Lite a second way, in client_metadata (ws_request_header_x_openai_internal_codex_responses_lite: "true", codex-rs client.rs build_ws_client_metadata). magpie left that marker in, so the relay still read the request as Lite and passed it to the ChatGPT backend without the context it had been told to expect. fromLite now also drops that one client_metadata key (withoutLiteMetadata). Every other client_metadata entry, the instructions and the identity line go as Codex sent them. Reported by ChangQiu on Discord and filed as #4853 by ZyphrZero. The withoutLiteMetadata patch and its two tests are ported from ZyphrZero's fork commit 7f67c732. TestCodexSocketLiteTurnLeavesLiteForARelay is new: it sends #4853's title request through passthrough to a fake relay and checks that the marker, the context and the header are all gone. Run on mote at this head: - the three new tests plus TestLiteSubagentLeavesLite and the additional_tools tests: ok - go test -timeout 45m ./internal/gateway: one red, TestCodexPoolSaysTheClientsVersion (#4807). It passes 3/3 alone here and on origin/main. - go vet ./internal/gateway with GOOS=linux, windows and darwin: clean. gofmt -l: clean. Broken by hand: with withoutLiteMetadata stubbed to return its input, all three new tests went red. Not tried: a real CPA, or a real Codex websocket session through magpie. |
||
|
|
1ff928139d |
gateway: a remote magpie's codex model gets Codex's Responses Lite as it was sent (#4445)
What changed: a Codex Desktop turn on one of its own Lite models (gpt-6.1-sol) routed through Model Map to a Remote Magpie provider answered 400 "Remote magpie: Codex: X-OpenAI-Internal-Codex-Responses-Lite requires `reasoning.context` to be `all_turns`". liteKept treats a Remote Magpie like any plain Responses upstream, so passthrough ran fromLite (the additional_tools item lifted into tools, reasoning.context taken off) and forwardOnce dropped the Lite header. The remote serves codex/<model> through its ChatGPT account, which passes on what it got, and the ChatGPT backend refuses a request for one of its Lite models without reasoning context "all_turns" (#534): the request arrived stripped of exactly what that model demands. Had it gone as Codex sent it, the remote's account path keeps the Lite shape (liteKept true there) and its answer is 200, as the reporter's codex=as-sent workaround showed. liteKept now also keeps the shape, with the model it is asked for: a Remote Magpie's codex model, named codex/<model> — the ChatGPT account's namespace in every magpie's catalog, so the remote lists one only when that account is there to serve it. Its other models still get what Codex sends a model that isn't Lite (#350), header and reasoning context included in the lift (#350, TangForX). Run: go test -tags nogui -run 'TestRemoteMagpieCodexModelKeepsLite| TestRemoteMagpieOtherModelLeavesLite' ./internal/gateway/ — the first failed with the 400 above before the change and passes after; the second keeps the old behavior. go test -tags nogui ./internal/gateway/ passes. Fixes #4445 Generated-by: GLM-5.3-Flash (ZCode) |
||
|
|
254461829b |
gateway: a Codex Lite request is no longer decoded whole, nor parsed twice for its facts
XiaoYin_OK on X: after a long run the app's memory climbs toward 2 GB. The owner's own app (26h up) showed RSS 550 MB, HeapInuse 317 MB but HeapSys 992 MB: the heap peaks while requests are in flight. Its profile had 209 GB allocated, ~94 GB of it under codexBackend/serve, of which: - parseResponses 24.7 GB, liftAdditionalTools 14.9 GB of it; - factsOf 24.6 GB, reached from turnOf (13.6 GB) and dirOf (11.0 GB), the same conversation parsed twice per request. Three causes, each fixed where it is: 1. liftAdditionalTools decoded the whole Lite request into maps to move its additional_tools item, and wrote it all again: ~7.6x the body. Now only that item and the tools are decoded; every other item and member goes byte for byte as it came, written once into one buffer. 2. affine counted the turn in the masked body while dirOf read the plain one, two different slices, so factsOf's memo could never serve both. affine now counts it in the body as the agent wrote it. 3. That body is rarely the one readRequestBody held (requestModel, spawnAgentModels and the lift each write a new one), so factsOf's memo missed for it anyway. serve now holds it (holdBody), and holdBody lists a body once when it is held twice. Tests (internal/gateway/lite_lift_test.go), each red on the old code: - TestLiteLiftMovesOnlyTheTools: same result as the old whole decode (liftWhole, kept in the test) on testdata/context/codex.json, the merged-namespace case, a 2,000-word conversation and the no-op shapes; an item with its keys unsorted, \u escapes and 2.50 goes as written. Old: the kept item came back re-sorted and re-escaped. - TestLiteLiftAllocatesAboutTheBody: under 2x a 1.35 MB body. Old: 14,126,976 B (10.4x). - TestMaskedRequestParsedOnceForItsFacts: a served masked Lite request is parsed once for its turn and folder (factsParsed hook in readFacts). Old: 2. With only change 2 it was still 2 (cause 3). Measured (darwin/arm64, a 4,012,240 B Lite body): - liftAdditionalTools: 30.46 MB/op, 98,560 allocs -> 5.17 MB/op, 6,609. - readFacts of it: 54.0 MB/op -> 26.7 MB/op. - Served through New().Handler() with masking on, 8 concurrent x 5 rounds of a 4,010,268 B body, two runs each: allocated per request 215.6 / 220.7 MB -> 116.2 / 116.2 MB; peak HeapInuse 993 / 802 MB -> 612 / 561 MB; HeapSys 1001 / 892 MB -> 699 / 674 MB. - The live app's WebKit processes were ~8-9 MB RSS each, so the webview is not where the memory went on macOS; the live pid sat at 476-596 MB RSS over a 15-minute sample. Run at this head: gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet ./...; go build (gui and nogui); go test -tags nogui -timeout 45m ./... in a sandbox HOME at |
||
|
|
9949ad5eb0 |
gateway: a subagent a Responses Lite lead spawns elsewhere goes without Lite's reasoning context and header (TangForX on X)
TangForX: Codex with gpt-6.1-sol leading spawned a subagent on OpenCode Go's DeepSeek v4.1 flash, and every turn of it answered 503 "Endpoint is unavailable"; the same subagent under a DeepSeek lead, and on DeepSeek's own API, worked. Cause: gpt-6.1-sol is use_responses_lite, and Codex sends a subagent it spawns in the lead's Lite shape with only the model name swapped: reasoning.context "all_turns", tools in an additional_tools input item, and the X-OpenAI-Internal-Codex-Responses-Lite header. passthrough lifted additional_tools (#350) but sent the reasoning context on, and forwardOnce copied the Lite header (an x-openai-* header Codex sends) to every key+URL provider. OpenCode Go's DeepSeek route refuses that shape. Fix: fromLite takes the whole Lite shape off (additional_tools lifted, reasoning.context dropped, effort and summary kept) for every Responses upstream that isn't OpenAI, a Codex account, or a codexAsSent relay (liteKept); forwardOnce drops the Lite header on the same rule, for a translated Chat upstream too. A body with no Lite in it goes byte for byte as before. codexAsSent relays still get the request and header as Codex sent them (TestCodexAsSent). Run at the pushed head: - TestLiteSubagentLeavesLite: Codex's code-mode request with Lite's fields and the collab_spawn subagent headers, to opencode-go deepseek-v4.1-flash, deepseek and a custom Responses relay; the fake upstream answers 503 "Endpoint is unavailable" to any Lite remnant. TestFromLite: a non-Lite body is unchanged byte for byte. - gofmt -l; go vet ./...; GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet ./...: clean. - go test -tags nogui -count=1 ./internal/gateway (Lite, Codex, CodexAsSent, DeepSeek, OpenCode tests): ok. - go test -tags nogui -timeout 45m ./... at ecfab308e (on |
||
|
|
4ead7c84a3 | gateway: Codex's Responses Lite tools reach SuperGrok and every other backend, and a group moves on when a member can't read a request (#350) — Codex sends a Lite model's tools as an additional_tools input item, its own functions in a "functions" namespace; magpie relayed the item to xAI, which 422s on it (unknown item type), and translated routes (Cursor, Anthropic, Chat…) dropped it, so the model had no tools. Outside OpenAI the item's tools now go in tools, the functions namespace opened into plain tools and earlier calls un-namespaced; OpenAI and the ChatGPT account still get Codex's own form. A 400/422 over the request's shape (failed to deserialize, unknown item type/parameter…) now moves to the group's next member, each asked once, the member not resting; the Routing page says so. TestAdditionalToolsRelayed, TestAdditionalToolsTranslated and TestGroupFailsOverARequestShape fail without the change; routing-shape.test.cjs (Chromium, WebKit, en/zh) added. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass; click-scroll, old-webkit, routing-wb-refused pass. |