Commit Graph
1 Commits
Author SHA1 Message Date
yetone 0620fd661e gateway: two Codex conversations on one model id keep their own context, in the usage Codex is handed and in Routing's prompt (zhemu on Discord)
zhemu took Routing's context figure for the sum of every Codex Desktop
conversation on one model id, and thought that was why new conversations
and subagents compact early. It isn't: each route's Prompt is that
request's own vendor-counted input + cache (prompt.calibrated over
promptCounted), the rules' tokens floor is keyed per conversation
(ruleKey), and the usage handed back to Codex is that request's own.
Codex compacts by its own per-thread count against the context_window
magpie writes into its catalog. No code change; this test guards it.

The test runs a long and a new conversation (session_id thread-long /
thread-new) on wb/flash concurrently, six requests each, against a fake
Chat upstream, and checks every response.completed input_tokens and every
route's Prompt (Counted, own tokens, window 200000).

Run: go test -tags nogui -p 1 -count=3 -run
'TestCodexConversationsOnOneModelKeepTheirOwnContext|TestRuleTokensFloorFromUsage'
./internal/gateway/ ok. Broken by hand twice, red each time: summing
promptCounted per model in a global map (thread-new Tokens 475000, want
5000), and making Usage.responses cumulative (input_tokens 95000, want
90000). gofmt -l clean; go vet -tags nogui ./internal/gateway/ for
GOOS=darwin, linux, windows ok. A -race run failed to build (disk full,
not the test).

Full suite: SUITE_LINE
2026-10-15 23:08:04 +08:00