mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-29 02:39:13 +00:00
fix: four provider parsing and pricing attribution bugs (#1489)
Antigravity now stores the command basename instead of the full command line, so secrets in flags no longer reach the on-disk session cache, matching every other provider. A Copilot OpenTelemetry skill or tool is credited once per trace instead of once per chat span, so a multi-span trace no longer multiplies it in the skill and tool breakdowns; grand totals are unchanged, and the copilot parse version and the status snapshot version are bumped so warm caches re-derive. The daily-cache carried-remainder row now also carries a token shortfall, so per-model token sums reconcile to the day total where cost and calls already did. Bedrock provisioned-model and custom-model ARNs are recognised as unpriced Bedrock rather than hidden as local inference. Verified against the real cache: report, models and menubar totals identical to the cent.
This commit is contained in:
parent
80931d3ba3
commit
3925cade06
10 changed files with 231 additions and 10 deletions
|
|
@ -484,7 +484,12 @@ function creditCarriedRemainder(
|
|||
for (const key of REMAINDER_KEYS) {
|
||||
rest[key] = Math.max(0, num(totals[key]) - rows.reduce((sum, m) => sum + m[key], 0))
|
||||
}
|
||||
if (rest.calls <= 0 && rest.cost < CENT && rest.savingsUSD < CENT) return
|
||||
// Token remainders (whole tokens) are part of REMAINDER_KEYS too: a day whose
|
||||
// cost and calls reconcile but whose token totals fall short must still credit
|
||||
// the missing tokens to the carried row, or the model rows sum to fewer tokens
|
||||
// than the day headline.
|
||||
const tokenRemainder = rest.inputTokens + rest.outputTokens + rest.cacheReadTokens + rest.cacheWriteTokens
|
||||
if (rest.calls <= 0 && rest.cost < CENT && rest.savingsUSD < CENT && tokenRemainder < 1) return
|
||||
const acc = Object.hasOwn(models, CARRIED_MODEL_NAME) ? models[CARRIED_MODEL_NAME]! : emptyModelStats()
|
||||
for (const key of REMAINDER_KEYS) acc[key] += rest[key]
|
||||
setOwn(models, CARRIED_MODEL_NAME, acc)
|
||||
|
|
|
|||
|
|
@ -1090,6 +1090,11 @@ function looksLikeLocalModel(name: string): boolean {
|
|||
// one with no price must reach the unpriced list rather than be treated as
|
||||
// free local inference.
|
||||
if (/-v?\d+:\d+$/.test(name)) return false
|
||||
// Bedrock provisioned-model / custom-model ARNs carry colons from the ARN
|
||||
// structure (arn:aws:bedrock:<region>:<account>:provisioned-model/<id>), but
|
||||
// they are metered Bedrock, not local: an unpriced one must reach the
|
||||
// unpriced list rather than be hidden as free local inference.
|
||||
if (/^arn:aws:bedrock:/i.test(name)) return false
|
||||
// Ollama and LM Studio tags include `:tag` (e.g. qwen3.6:35b-a3b-bf16).
|
||||
if (name.includes(':') && !name.startsWith('http')) return true
|
||||
// GGUF / quantized fingerprints commonly seen in local inference.
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import { homedir } from 'os'
|
|||
import { fileURLToPath } from 'url'
|
||||
import https from 'https'
|
||||
|
||||
import { extractBashCommands } from '../bash-utils.js'
|
||||
import { getCodeburnCacheDir, readExistingTextFile } from '../cache-dir.js'
|
||||
import { calculateCost } from '../models.js'
|
||||
import { isSqliteAvailable, isSqliteBusyError, openDatabase } from '../sqlite.js'
|
||||
|
|
@ -843,7 +844,7 @@ function extractAntigravityToolFromStep(metadataBytes: Uint8Array, turn: TurnToo
|
|||
if (toolName === 'run_command') {
|
||||
turn.tools.push(toolName)
|
||||
const cmd = typeof args?.['CommandLine'] === 'string' ? args['CommandLine'].trim() : ''
|
||||
if (cmd) turn.bashCommands.push(cmd)
|
||||
if (cmd) turn.bashCommands.push(...extractBashCommands(cmd))
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1934,6 +1934,19 @@ function createOtelParser(
|
|||
}
|
||||
}
|
||||
|
||||
// Attribute trace-level tool/skill/bash metadata to a single chat
|
||||
// span. execute_tool spans happen ONCE in a trace, not once per chat
|
||||
// span, so re-reading them for every span billed a 5-span trace's one
|
||||
// skill call ~5x turns/cost (and split it across periods when the
|
||||
// trace crossed midnight). Order spans by start time and credit the
|
||||
// first one that actually yields, so the metadata lands on exactly one
|
||||
// call in the trace's opening period. Subagent names stay per-trace:
|
||||
// every chat span in a subagent's trace is genuinely that subagent's
|
||||
// call, so all of them are correctly labelled.
|
||||
chatSpanIds.sort((a, b) =>
|
||||
(spanMetaById.get(a)?.start_time_ms ?? 0) - (spanMetaById.get(b)?.start_time_ms ?? 0))
|
||||
const creditedTraces = new Set<string>()
|
||||
|
||||
// Yield one ParsedProviderCall per chat span
|
||||
for (const spanId of chatSpanIds) {
|
||||
const attrs = loadSpanAttributesFromTable(db, spanId)
|
||||
|
|
@ -1970,9 +1983,11 @@ function createOtelParser(
|
|||
seenKeys.add(jsonlDedupKey)
|
||||
}
|
||||
|
||||
const tools = toolsByTrace.get(spanMetadata.trace_id) ?? []
|
||||
const skills = skillsByTrace.get(spanMetadata.trace_id) ?? []
|
||||
const bashCommands = bashByTrace.get(spanMetadata.trace_id) ?? []
|
||||
const ownsTraceMetadata = !creditedTraces.has(spanMetadata.trace_id)
|
||||
if (ownsTraceMetadata) creditedTraces.add(spanMetadata.trace_id)
|
||||
const tools = ownsTraceMetadata ? (toolsByTrace.get(spanMetadata.trace_id) ?? []) : []
|
||||
const skills = ownsTraceMetadata ? (skillsByTrace.get(spanMetadata.trace_id) ?? []) : []
|
||||
const bashCommands = ownsTraceMetadata ? (bashByTrace.get(spanMetadata.trace_id) ?? []) : []
|
||||
const subagentTypes = subagentsByTrace.get(spanMetadata.trace_id)
|
||||
const timestamp = epochToISO(spanMetadata.start_time_ms)
|
||||
|
||||
|
|
|
|||
|
|
@ -390,7 +390,10 @@ export const PROVIDER_PARSE_VERSIONS: Record<string, string> = {
|
|||
// chatsession-otel-skills-v1: structured Skill calls are now extracted from
|
||||
// VS Code chatSessions and OTel execute_tool spans. Cached calls lack those
|
||||
// fields, so force one re-parse before serving period breakdowns.
|
||||
copilot: 'cli-shutdown-cost-v1-skills-source-provenance-v1-session-store-v3-chatsession-otel-skills-v1',
|
||||
// otel-trace-metadata-once-v1: trace-level tool/skill/bash metadata is now
|
||||
// attributed to one chat span per trace instead of every span, so cached
|
||||
// calls carry the old per-span duplication - force one re-parse.
|
||||
copilot: 'cli-shutdown-cost-v1-skills-source-provenance-v1-session-store-v3-chatsession-otel-skills-v1-otel-trace-metadata-once-v1',
|
||||
// authoritative-usage-v4: persist one Grok session call from top-level
|
||||
// authoritative totals, use modelUsage only for priced attribution, clamp
|
||||
// reasoning per record, and label mixed sessions estimated.
|
||||
|
|
|
|||
|
|
@ -34,7 +34,10 @@ import { DAILY_CACHE_VERSION } from './daily-cache.js'
|
|||
// v10: current.skills is rebuilt from the newly reparsed Copilot
|
||||
// chatSessions/OTel calls; older snapshots can contain stale or empty skill
|
||||
// breakdowns for otherwise identical period queries.
|
||||
export const STATUS_SNAPSHOT_RENDER_VERSION = 10
|
||||
// v11: Copilot OTel trace-level tool/skill/bash metadata is now attributed
|
||||
// once per trace, so older snapshots can carry per-span-duplicated skill/tool
|
||||
// turns and cost for otherwise identical period queries.
|
||||
export const STATUS_SNAPSHOT_RENDER_VERSION = 11
|
||||
|
||||
/// The semantic key recorded on every status snapshot. A snapshot whose stored
|
||||
/// key differs (an older render revision, or a different daily-cache version)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue