Commit Graph
2 Commits
Author SHA1 Message Date
yetone d792e7ce4d gateway: a Codex request's client_metadata is read without decoding the whole body (#3394)
requestSessionMetadata is asked four or five times for every Codex
request (the title, description and prediction checks, the subagent
pick, serve). Each time it ran json.Unmarshal over the whole body to
read one top-level member, so a long conversation was walked again
and again. It now takes client_metadata with topMember, which checks
and splits a long body once, and decodes only that member. What a
body gives is unchanged: a body that isn't an object, or whose
client_metadata isn't an object or null, still falls back to the
x-codex-turn-metadata header. One difference: Go's struct decoding
matched the name without regard to case, topMember matches it
exactly; Codex sends it lower case.

Run:
- BenchmarkRequestSessionMetadata (5.8MB body): 12.7ms/op before,
  0.50ms/op after (-count 3 each).
- Real DeepSeek account in a sandbox HOME, magpie serve on 3482, 12
  streamed /v1/responses requests of a synthetic 1.5MB Codex body with
  client_metadata (codexload.py, 2 at a time), magpie's CPU time read
  with ps, two rounds each: a84d2ec80 1.01s and 0.95s, this 0.68s and
  0.67s, about 84ms -> 56ms a request. All 48 answered 200.
- New TestSessionMetadataOddBodies (string, null, cut-short, array and
  nested client_metadata, a duplicate member, long bodies): passes on
  the old code and the new, so it holds the behaviour, not the speed.
- go test ./internal/gateway -run 'Session|Title|Parent|Prediction|
  Description|Subagent|CallKind|Fork|Metadata': ok. The whole gateway
  package was not run before the push.
- gofmt -l clean; GOOS=linux and windows go vet -tags nogui ./internal/gateway ok.
2026-10-25 00:39:25 +08:00
Zhu Wang 1adb2b571e feat(routing): group requests by session with names and estimated costs (#396)
* feat(routing): group requests by session with names and estimated costs

* fix(routing): address session view review feedback

Preserve Luna Reserve and other header fallbacks for ordinary Codex turn metadata; reuse metadata and the kind across trace and native accounting. Default to By request and persist the grouping choice. Store only token accounting fields in route history while retaining legacy JSON compatibility.

Add regressions for helper precedence, native kind accounting, history compatibility and grouping preferences.
2026-10-01 20:50:15 +08:00