Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

Token Usage lens: do not call a trace silent when its events carry usage

Claude1e77427af764
diff --git a/cli/beacon/internal/endpoint/dashboard/lenses/token-usage.lens.html b/cli/beacon/internal/endpoint/dashboard/lenses/token-usage.lens.html
index 991517de..8ad11bde 100644
--- a/cli/beacon/internal/endpoint/dashboard/lenses/token-usage.lens.html
+++ b/cli/beacon/internal/endpoint/dashboard/lenses/token-usage.lens.html
@@ -132,9 +132,6 @@
var summary = trace.summary || {};
var counted = data.token_usage;
- var note = coverageNote(data.token_coverage, summary.harness && summary.harness.name);
- if (note) root.appendChild(note);
-
// Line items: every event that reported usage, attributed to the prompt before it.
var items = [];
var turns = [];
@@ -158,6 +155,13 @@
});
var reported = items.reduce(function (sum, e) { return add(sum, e.usage); }, {});
+ // Coverage is judged from the live log, so a trace served from history can carry usage in its
+ // events while the live log has none. Usage in hand is not a silent runtime.
+ var coverage = data.token_coverage;
+ if (coverage && coverage.status === "silent" && items.length) coverage = null;
+ var note = coverageNote(coverage, summary.harness && summary.harness.name);
+ if (note) root.appendChild(note);
+
var hasCounted = !!(counted && counted.events_with_usage);
if (!hasCounted && items.length === 0) {
if (!note) root.appendChild(el("p", "No token usage was reported in this trace.", "muted"));
diff --git a/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/tests/builtin-token-usage.spec.ts b/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/tests/builtin-token-usage.spec.ts
index 2ac3699c..66a7c7a0 100644
--- a/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/tests/builtin-token-usage.spec.ts
+++ b/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/tests/builtin-token-usage.spec.ts
@@ -69,3 +69,16 @@ test('token usage: a gap between reported and counted usage is explained without
await expect(frame.locator('#root')).toContainText('The events below report 12,300 tokens in total; Beacon counts 11,300.');
await expect(frame.locator('#root')).toContainText('can also differ when this trace was truncated');
});
+
+test('token usage: events that carry usage are never called silent', async ({ page }) => {
+ // The live log has no usage lines left for this trace, but its events, served from history, do.
+ await editLensData(page, (data) => {
+ data.token_usage = { totals: {}, events_with_usage: 0 };
+ data.token_coverage = { status: 'silent', expectation: 'native', reason: 'no usage in the live log' };
+ });
+ await page.goto('/session.html?id=rich&lens=token-usage');
+ const frame = page.frameLocator('iframe.lens-frame');
+ await expect(frame.locator('h2').first()).toHaveText('Reported usage');
+ await expect(frame.locator('#root')).toContainText('12,300 tokens over 2 usage reports');
+ await expect(frame.locator('#root')).not.toContainText('this trace reported none');
+});