Skip to content

Commit eac0000

Browse files
authored
Merge pull request #27 from comet-ml/codex/fix-billing-score-review
[codex] Fix billing catalog attribution
2 parents 1d95c60 + f98bb8b commit eac0000

3 files changed

Lines changed: 11 additions & 41 deletions

File tree

src/billing.go

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -333,42 +333,6 @@ func conversationPieces(entries []TranscriptEntry, skillBodyNames map[string]str
333333
}
334334
add("file_attachments", ext, kindUsage, float64(tokEstimate(w.File.Content)), false)
335335
}
336-
case "deferred_tools_delta":
337-
// The deferred catalog mixes built-in tool names with MCP
338-
// ones — split so each lands in its lane (built-in names are
339-
// part of Claude Code's own overhead, not MCP rent).
340-
lines := e.Attachment.AddedLines
341-
names := e.Attachment.AddedNames
342-
if len(lines) != len(names) {
343-
lines = names // fall back to names-only sizing
344-
}
345-
var builtinPayload, mcpPayload []string
346-
for i, name := range names {
347-
line := name
348-
if i < len(lines) {
349-
line = lines[i]
350-
}
351-
if strings.HasPrefix(name, "mcp__") {
352-
mcpPayload = append(mcpPayload, line)
353-
} else {
354-
builtinPayload = append(builtinPayload, line)
355-
}
356-
}
357-
add("static_overhead", "deferred_tool_names", kindDefinition,
358-
float64(measuredOrEstimate(strings.Join(builtinPayload, "\n"), "deferred_tools_payload")), false)
359-
add("mcp_servers", "catalog_deltas", kindDefinition,
360-
float64(measuredOrEstimate(strings.Join(mcpPayload, "\n"), "deferred_tools_payload")), false)
361-
case "mcp_instructions_delta":
362-
// Per-server when the parallel arrays line up.
363-
if len(e.Attachment.AddedNames) == len(e.Attachment.AddedBlocks) && len(e.Attachment.AddedNames) > 0 {
364-
for i, name := range e.Attachment.AddedNames {
365-
add("mcp_servers", name, kindDefinition,
366-
float64(measuredOrEstimate(e.Attachment.AddedBlocks[i], "prose")), false)
367-
}
368-
} else {
369-
add("mcp_servers", "instructions", kindDefinition,
370-
float64(tokEstimateAs(strings.Join(e.Attachment.AddedBlocks, "\n"), "prose")), false)
371-
}
372336
}
373337
case "assistant":
374338
if e.Message == nil || len(e.Message.Content) == 0 {

src/billing_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,25 +239,31 @@ func TestDeferredCatalogSplitsBuiltinFromMcp(t *testing.T) {
239239
soItems := lanes["static_overhead"].(map[string]interface{})["items"].([]map[string]interface{})
240240
foundBuiltin := false
241241
for _, it := range soItems {
242-
if it["name"] == "deferred_tool_names" && it["total"].(int) > 0 {
242+
if it["name"] == "observed_builtin_schemas" && it["total"].(int) > 0 {
243243
foundBuiltin = true
244244
}
245+
if it["name"] == "deferred_tool_names" {
246+
t.Errorf("deferred tool delta should not be replayed separately: %v", soItems)
247+
}
245248
}
246249
if !foundBuiltin {
247-
t.Errorf("expected deferred_tool_names under static_overhead: %v", soItems)
250+
t.Errorf("expected observed_builtin_schemas under static_overhead: %v", soItems)
248251
}
249252
mcp, ok := lanes["mcp_servers"].(map[string]interface{})
250253
if !ok {
251254
t.Fatal("expected mcp_servers lane")
252255
}
253256
foundMcp := false
254257
for _, it := range mcp["items"].([]map[string]interface{}) {
255-
if it["name"] == "catalog_deltas" && it["total"].(int) > 0 {
258+
if it["name"] == "slack" && it["total"].(int) > 0 {
256259
foundMcp = true
257260
}
261+
if it["name"] == "catalog_deltas" {
262+
t.Errorf("MCP catalog delta should not be replayed separately: %v", mcp["items"])
263+
}
258264
}
259265
if !foundMcp {
260-
t.Errorf("expected catalog_deltas under mcp_servers: %v", mcp["items"])
266+
t.Errorf("expected slack server under mcp_servers: %v", mcp["items"])
261267
}
262268
}
263269

src/metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func postReconciliationScore(traceID string, billing interface{}) {
322322
recon["cache_creation_delta"], recon["output_delta"])
323323
}
324324

325-
if err := api.Put("/traces/feedback-scores", map[string]interface{}{
325+
if err := api.Post("/traces/feedback-scores", map[string]interface{}{
326326
"scores": []interface{}{score},
327327
}); err != nil {
328328
debugLog("post reconciliation score: %v", err)

0 commit comments

Comments
 (0)