Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-7382 docs(agent): clarify token usage normalization contract (#8423)
importcppa843b44a48b4
diff --git a/server/pkg/agent/agent.go b/server/pkg/agent/agent.goindex bb788786a0..2658bb445b 100644--- a/server/pkg/agent/agent.go+++ b/server/pkg/agent/agent.go@@ -210,8 +210,8 @@ type Message struct {// TokenUsage tracks token consumption for a single model.// Its four token counts are mutually exclusive: InputTokens excludes cache-// reads and writes, and OutputTokens already includes reasoning/thinking.-// Provider-specific breakdowns must not be added to those totals again.+// reads and writes, and OutputTokens includes reasoning/thinking.+// Breakdowns already included in a total must not be added to that total again.// Zero counters alone do not establish that the provider reported complete usage.type TokenUsage struct {InputTokens int64diff --git a/server/pkg/agent/codex.go b/server/pkg/agent/codex.goindex 6fb84d8b7e..2845308392 100644--- a/server/pkg/agent/codex.go+++ b/server/pkg/agent/codex.go@@ -3850,6 +3850,9 @@ func codexSessionRoot(codexHome string) string {return ""}+// codexRawTokenUsage retains ReasoningOutputTokens to mirror the provider payload+// and keep resume-baseline subtraction symmetric. No downstream consumer uses+// this breakdown; normalized usage reads OutputTokens, which already includes it.type codexRawTokenUsage struct {InputTokens int64 `json:"input_tokens"`OutputTokens int64 `json:"output_tokens"`diff --git a/server/pkg/agent/usage_contract_test.go b/server/pkg/agent/usage_contract_test.goindex 3a459eba4e..331eec6105 100644--- a/server/pkg/agent/usage_contract_test.go+++ b/server/pkg/agent/usage_contract_test.go@@ -7,8 +7,9 @@ import ("testing")-// Provider fields do not share an input-token convention, but their normalized-// usage must share the TokenUsage contract. Reasoning is already in output.+// Every adapter must normalize provider usage to the TokenUsage contract.+// These cases cover Codex and Claude's different input-token conventions;+// both providers include reasoning/thinking in output.// https://developers.openai.com/api/docs/guides/reasoning#managing-the-context-window// https://platform.claude.com/docs/en/build-with-claude/prompt-caching#tracking-cache-performancefunc TestProviderTokenUsageContract(t *testing.T) {