Skip to content

Commit 501bf55

Browse files
committed
fix(qa): reject inconsistent measured cache totals
1 parent cbb50c6 commit 501bf55

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

‎extensions/qa-lab/src/token-efficiency-report.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,38 @@ describe("token efficiency report", () => {
390390
]);
391391
});
392392

393+
it("fails unexplained totals when both cache counters have already been measured", () => {
394+
const report = buildTokenEfficiencyReport({
395+
summary: makeLiveSummary([
396+
makeRuntimeParity(
397+
"unexplained-cache-totals",
398+
makeCell("openclaw", {
399+
inputTokens: 100,
400+
outputTokens: 20,
401+
totalTokens: 120,
402+
}),
403+
makeCell("codex", {
404+
inputTokens: 100,
405+
outputTokens: 20,
406+
totalTokens: 1_000,
407+
cacheRead: 100,
408+
cacheWrite: 0,
409+
}),
410+
),
411+
]),
412+
});
413+
414+
expect(report.pass).toBe(false);
415+
expect(report.rows[0]?.codex).toMatchObject({
416+
cacheReadTokens: 100,
417+
cacheWriteTokens: 0,
418+
processedTokenEvidence: "unavailable",
419+
});
420+
expect(report.failures).toEqual([
421+
"unexplained-cache-totals codex live processed-token usage cannot be verified from cache-write telemetry or coherent cache-read totals",
422+
]);
423+
});
424+
393425
it("does not derive cache writes from partially observed post-warm cache reads", () => {
394426
const openclaw = makeCell("openclaw", {
395427
inputTokens: 100,

‎extensions/qa-lab/src/token-efficiency-report.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,12 @@ function runtimeUsage(cell: RuntimeParityCell): TokenEfficiencyRuntimeUsage {
201201
if (
202202
cacheWriteTokens !== null &&
203203
unaccountedCacheTokens >= 0 &&
204+
(cacheReadTokens === null || unaccountedCacheTokens === 0) &&
204205
(completeCacheTelemetry || unaccountedCacheTokens === 0)
205206
) {
206207
processedTokens += cacheWriteTokens;
207208
processedTokenEvidence = "measured";
208-
} else if (cacheReadTokens !== null && completeCacheTelemetry) {
209+
} else if (cacheReadTokens !== null && cacheWriteTokens === null && completeCacheTelemetry) {
209210
const derivedCacheWriteTokens = totalTokens - baseProcessedTokens - cacheReadTokens;
210211
if (derivedCacheWriteTokens >= 0) {
211212
processedTokens += derivedCacheWriteTokens;

0 commit comments

Comments
 (0)