mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-11 21:59:38 +01:00
fix: checkpoint adapter usage and preserve unknown prices (#14991)
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
3ebd7bc0c9
commit
eab93fd4a0
42 files changed
+1957
-561
No files matched your search
@@ -125,6 +125,9 @@ function undeliveredSuffix(delivered: string, final: string): string {
|
||||
if (!final) return "";
|
||||
if (delivered.length === 0) return final;
|
||||
if (final.startsWith(delivered)) return final.slice(delivered.length);
|
||||
// Some providers retain only the last 4 MiB while streaming the full output.
|
||||
// Replaying that captured tail would count its usage receipts a second time.
|
||||
if (delivered.endsWith(final)) return "";
|
||||
return final;
|
||||
}
|
||||
|
||||
|
||||
@@ -12251,6 +12251,10 @@ export function heartbeatService(
|
||||
? await getOldestRunForSession(agent.id, sessionId)
|
||||
: (runs[runs.length - 1] ?? latestRun);
|
||||
const latestRawUsage = readRawUsageTotals(latestRun?.usageJson);
|
||||
// Historical Codex/Gemini raw input includes cache reads. Only add the
|
||||
// separate cache counter when the writer explicitly saved exclusive input.
|
||||
const latestRawInputTokens = (latestRawUsage?.inputTokens ?? 0) +
|
||||
(latestRun?.usageJson?.rawInputIncludesCached === false ? latestRawUsage?.cachedInputTokens ?? 0 : 0);
|
||||
const sessionAgeHours =
|
||||
latestRun && oldestRun
|
||||
? Math.max(
|
||||
@@ -12267,10 +12271,10 @@ export function heartbeatService(
|
||||
} else if (
|
||||
policy.maxRawInputTokens > 0 &&
|
||||
latestRawUsage &&
|
||||
latestRawUsage.inputTokens >= policy.maxRawInputTokens
|
||||
latestRawInputTokens >= policy.maxRawInputTokens
|
||||
) {
|
||||
reason =
|
||||
`session raw input reached ${formatCount(latestRawUsage.inputTokens)} tokens ` +
|
||||
`session raw input reached ${formatCount(latestRawInputTokens)} tokens ` +
|
||||
`(threshold ${formatCount(policy.maxRawInputTokens)})`;
|
||||
} else if (
|
||||
policy.maxSessionAgeHours > 0 &&
|
||||
@@ -25624,6 +25628,7 @@ export function heartbeatService(
|
||||
...(rawUsage
|
||||
? {
|
||||
rawInputTokens: rawUsage.inputTokens,
|
||||
rawInputIncludesCached: false,
|
||||
rawCachedInputTokens: rawUsage.cachedInputTokens,
|
||||
rawOutputTokens: rawUsage.outputTokens,
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user