Problem
autoModelRouter (src/node/services/autoModelRouter.ts, around lines 82-116) calls experimental_evaluate directly. When the evaluation response is rejected as invalid, the router returns an error without usage. agentSession then takes its fallback path, which skips both recordHeadlessUsage and deferEvaluatorGoalCharge. The provider has already billed that classifier request, but it never reaches the workspace ledger or the goal's cost cap.
The cause is the one fixed for workflow and intuition evaluations in #4773 (Refs #4728). @ai-sdk/provider-utils EvaluationLanguageModel validates answers inside doEvaluate and throws InvalidResponseDataError before it returns usage.
Proposed fix
Reuse #4773's capture in the router: the per-call doEvaluate wrapper plus the AsyncLocalStorage scope around the inner doGenerate. Export a small helper from evaluationService.ts if needed. On an invalid-answer failure that carries billed usage, record the headless row with analyticsSource: "auto_model_routing" and apply the deferred goal charge, as the success path does.
Trigger
#4773 merged (the capture helper exists on main). Owner: the issue coordinator.
Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high • Cost: $46.76
Problem
autoModelRouter(src/node/services/autoModelRouter.ts, around lines 82-116) callsexperimental_evaluatedirectly. When the evaluation response is rejected as invalid, the router returns an error without usage.agentSessionthen takes its fallback path, which skips bothrecordHeadlessUsageanddeferEvaluatorGoalCharge. The provider has already billed that classifier request, but it never reaches the workspace ledger or the goal's cost cap.The cause is the one fixed for workflow and intuition evaluations in #4773 (Refs #4728).
@ai-sdk/provider-utilsEvaluationLanguageModelvalidates answers insidedoEvaluateand throwsInvalidResponseDataErrorbefore it returns usage.Proposed fix
Reuse #4773's capture in the router: the per-call
doEvaluatewrapper plus theAsyncLocalStoragescope around the innerdoGenerate. Export a small helper fromevaluationService.tsif needed. On an invalid-answer failure that carries billed usage, record the headless row withanalyticsSource: "auto_model_routing"and apply the deferred goal charge, as the success path does.Trigger
#4773 merged (the capture helper exists on main). Owner: the issue coordinator.
Generated with
xum• Model:anthropic:claude-opus-5-5• Thinking:high• Cost:$46.76