mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 22:49:00 +01:00
fix(runner): preserve unknown candidate eval costs and unpriced models
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
7721662f20
commit
25ab093921
2 files changed
+55
-3
No files matched your search
@@ -314,4 +314,31 @@ describe("eval-session usage", () => {
|
||||
{ usageLedger: [] } as unknown as CapabilityLiveSessionSnapshot,
|
||||
)).toThrow("omitted usage accounting");
|
||||
});
|
||||
|
||||
it.each(["pi", "cursor", "copilot"])("retains unpriced %s usage without inventing an invoice or substituting a model", (agent) => {
|
||||
const snapshot = {
|
||||
config: { provider: "acpx", acpxAgent: agent },
|
||||
usageLedger: [{
|
||||
receiptId: "candidate-turn-receipt", providerCalls: 1, providerRequests: 2,
|
||||
inputTokens: 1_000, outputTokens: 100, cachedInputTokens: 400,
|
||||
reasoningTokens: 50, costNanodollars: 0,
|
||||
}],
|
||||
} as unknown as CapabilityLiveSessionSnapshot;
|
||||
expect(evalSessionUsage("exact-provider-model[context=272k]", snapshot)).toMatchObject({
|
||||
agentTurns: 1, providerRequests: 2, inputTokens: 1_000, outputTokens: 100,
|
||||
providerReportedCostNanodollars: null,
|
||||
providerReportedCostProvenance: "unavailable",
|
||||
estimatedCostNanodollars: null, pricingVersion: null, ratesUsdPerMillionTokens: null,
|
||||
costCoverage: "unpriced",
|
||||
});
|
||||
const priced = evalSessionUsage("openrouter/deepseek/deepseek-v4-flash-0731", snapshot);
|
||||
expect(priced.providerReportedCostNanodollars).toBeNull();
|
||||
expect(priced.costCoverage).toBe("estimated");
|
||||
expect(priced.estimatedCostNanodollars).toBeGreaterThan(0);
|
||||
expect(priced.pricingVersion).toBe("provider-list-prices-2026-09-07-openrouter");
|
||||
expect(priced.ratesUsdPerMillionTokens).toEqual({ input: 0.14, cachedInput: 0.028, output: 0.28 });
|
||||
expect(() => evalSessionUsage("unpriced-qualified-model", {
|
||||
...snapshot, config: { provider: "codex" },
|
||||
} as unknown as CapabilityLiveSessionSnapshot)).toThrow("model pricing unavailable");
|
||||
});
|
||||
});
|
||||
@@ -83,14 +83,19 @@ export interface EvalSessionRequest {
|
||||
includeCollaborationModeInstructions?: true;
|
||||
}
|
||||
|
||||
export interface EvalSessionUsage extends EstimatedModelCost {
|
||||
export interface EvalSessionUsage {
|
||||
agentTurns: number;
|
||||
providerRequests: number;
|
||||
inputTokens: number;
|
||||
outputTokens: number;
|
||||
cachedInputTokens: number;
|
||||
reasoningTokens: number;
|
||||
providerReportedCostNanodollars: number;
|
||||
providerReportedCostNanodollars: number | null;
|
||||
providerReportedCostProvenance: "legacy_runner_usage_ledger" | "unavailable";
|
||||
estimatedCostNanodollars: number | null;
|
||||
pricingVersion: EstimatedModelCost["pricingVersion"] | null;
|
||||
ratesUsdPerMillionTokens: EstimatedModelCost["ratesUsdPerMillionTokens"] | null;
|
||||
costCoverage: "estimated" | "unpriced" | "legacy_ledger_and_estimate";
|
||||
}
|
||||
|
||||
function object(value: unknown, path: string): Record<string, unknown> {
|
||||
@@ -388,8 +393,28 @@ export function evalSessionUsage(
|
||||
if (unique.size === 0) {
|
||||
throw new Error("completed turn omitted usage accounting");
|
||||
}
|
||||
const candidate = snapshot.config?.provider === "acpx"
|
||||
&& ["pi", "cursor", "copilot"].includes(snapshot.config.acpxAgent ?? "");
|
||||
let estimate: EstimatedModelCost | null;
|
||||
try {
|
||||
estimate = estimateModelCostNanodollars(model, totals);
|
||||
} catch (error) {
|
||||
// An exact candidate model can be advertised before our pricing catalog
|
||||
// contains it. Preserve unpriced usage for billing reconciliation instead
|
||||
// of substituting a model or converting unknown spend into zero.
|
||||
if (!candidate || !(error instanceof Error) || !error.message.startsWith("model pricing unavailable for ")) throw error;
|
||||
estimate = null;
|
||||
}
|
||||
return {
|
||||
...totals,
|
||||
...estimateModelCostNanodollars(model, totals),
|
||||
// Candidate ACP adapters do not supply authenticated USD receipts. The
|
||||
// shared legacy ledger fills absent cost with zero, so its numeric value
|
||||
// cannot establish an invoice amount for these profiles.
|
||||
providerReportedCostNanodollars: candidate ? null : totals.providerReportedCostNanodollars,
|
||||
providerReportedCostProvenance: candidate ? "unavailable" : "legacy_runner_usage_ledger",
|
||||
estimatedCostNanodollars: estimate?.estimatedCostNanodollars ?? null,
|
||||
pricingVersion: estimate?.pricingVersion ?? null,
|
||||
ratesUsdPerMillionTokens: estimate?.ratesUsdPerMillionTokens ?? null,
|
||||
costCoverage: candidate ? (estimate === null ? "unpriced" : "estimated") : "legacy_ledger_and_estimate",
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user