Skip to content

Commit a256526

Browse files
josers18claude
andcommitted
fix(usage): stamp resolved model id on second-stack usage events
streamHeroku now yields the tier's resolved modelId on its usage event instead of callers hardcoding kimi-k2-thinking. Removes the now-unused optionalEnv imports from askDataAgent/analyzeAgent. Addresses final-review Minor #1 (model mislabel if reasoning tier is ever non-Kimi). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ebdb72e commit a256526

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

lib/inference/analyzeAgent.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { stripThinkTags } from "@/lib/analyze/sanitize";
2525
import { extractStructuredFromProse } from "@/lib/analyze/proseToData";
2626
import { sortRowsByDateLikeColumn } from "@/lib/analyze/sortByDate";
2727
import { log } from "@/lib/log";
28-
import { optionalEnv } from "@/lib/utils";
2928

3029
/**
3130
* Tools Kimi is allowed to see on the Analyze surface. Doc-grounded
@@ -260,7 +259,7 @@ export async function* runAnalyzeAgent(
260259
inputTokens: ev.inputTokens,
261260
outputTokens: ev.outputTokens,
262261
exact: ev.exact,
263-
model: optionalEnv("HEROKU_INFERENCE_ONYX_MODEL_ID") || "kimi-k2-thinking",
262+
model: ev.model,
264263
};
265264
}
266265
}

lib/inference/askDataAgent.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import type {
2828
FirstPartyDcToolDef,
2929
} from "@/lib/mcp/firstPartyDataCloud";
3030
import { stripThinkTags } from "@/lib/analyze/sanitize";
31-
import { optionalEnv } from "@/lib/utils";
3231

3332
// Soft budget: if the agent hasn't answered after N tool-call iterations
3433
// we bail. Heroku router already stalls long requests — this keeps us well
@@ -223,7 +222,7 @@ export async function* runAskDataAgent(
223222
inputTokens: ev.inputTokens,
224223
outputTokens: ev.outputTokens,
225224
exact: ev.exact,
226-
model: optionalEnv("HEROKU_INFERENCE_ONYX_MODEL_ID") || "kimi-k2-thinking",
225+
model: ev.model,
227226
};
228227
}
229228
}

lib/inference/heroku.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export type HerokuInferenceEvent =
5151
| { type: "done"; stopReason: string | null }
5252
| {
5353
type: "usage";
54+
model: string;
5455
inputTokens: number;
5556
outputTokens: number;
5657
exact: boolean;
@@ -297,15 +298,20 @@ export async function* streamHeroku(
297298
};
298299
}
299300

301+
// why: stamp the usage event with the tier's RESOLVED model id (from
302+
// clientFor) rather than letting callers guess — otherwise a tier served
303+
// by a non-Kimi backend would be mislabeled in the token-spend panel.
300304
yield usageAcc.exact
301305
? {
302306
type: "usage" as const,
307+
model: modelId,
303308
inputTokens: usageAcc.inputTokens,
304309
outputTokens: usageAcc.outputTokens,
305310
exact: true,
306311
}
307312
: {
308313
type: "usage" as const,
314+
model: modelId,
309315
inputTokens: estimateTokens(
310316
messages
311317
.map((m) =>
@@ -320,9 +326,6 @@ export async function* streamHeroku(
320326
};
321327

322328
yield { type: "done", stopReason };
323-
// Avoid "modelId was defined but unused" false-negative — it's surfaced
324-
// on the caller via inferHeroku's result, not through the stream.
325-
void modelId;
326329
}
327330

328331
function safeParseJson(s: string): unknown {

0 commit comments

Comments
 (0)