Skip to content

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

Canonicalize both sides of the coverage harness scope

Claudee8691406b9e1
diff --git a/cli/beacon/cmd/token_usage.go b/cli/beacon/cmd/token_usage.go
index 4a7d36bf..33caf6e3 100644
--- a/cli/beacon/cmd/token_usage.go
+++ b/cli/beacon/cmd/token_usage.go
@@ -105,15 +105,30 @@ func runTokenUsage(cmd *cobra.Command, args []string) error {
// them would find every runtime covered and prove nothing. The window is what a reader is
// actually asking about.
func runTokenCoverage(cmd *cobra.Command, logPath string, query dashboard.EventQuery) error {
- scoped := dashboard.EventQuery{
- Since: query.Since,
- Until: query.Until,
- Harness: query.Harness,
- }
- events, _, err := dashboard.ReadTokenEventsAppendOrder(logPath, scoped)
+ // The harness scope is deliberately NOT handed to the event reader. Its filter compares the
+ // flag to harness.name with case-insensitive equality on the raw string, while events carry
+ // the canonical name written by NormalizeHarnessName -- so `--harness vscode` matches nothing,
+ // every vscode_copilot event being named vscode_copilot. Applied here that asymmetry is worse
+ // than a plain miss: the installed list below canonicalizes, so the runtime stays in the
+ // report while its events vanish, and a runtime that spent tokens is labelled inactive.
+ // Both sides are canonicalized here instead.
+ events, _, err := dashboard.ReadTokenEventsAppendOrder(logPath, dashboard.EventQuery{
+ Since: query.Since,
+ Until: query.Until,
+ })
if err != nil {
return err
}
+ want := asymptoteobserve.NormalizeHarnessName(strings.TrimSpace(query.Harness))
+ if want != "" {
+ scopedEvents := events[:0]
+ for _, event := range events {
+ if asymptoteobserve.NormalizeHarnessName(event.Harness.Name) == want {
+ scopedEvents = append(scopedEvents, event)
+ }
+ }
+ events = scopedEvents
+ }
// Installed runtimes come from the config scanner rather than from the log, because the
// whole question is which installed runtime is missing from the log. tokens.InstalledRuntimes
// decides which scanner rows are real evidence of an install; the scanner reports files a
@@ -133,8 +148,7 @@ func runTokenCoverage(cmd *cobra.Command, logPath string, query dashboard.EventQ
// Otherwise every other installed runtime has no events in the filtered set and is reported
// inactive -- which reads as "installed but unused this window" when the truth is only that
// the reader asked about a different runtime.
- if harness := strings.TrimSpace(scoped.Harness); harness != "" {
- want := asymptoteobserve.NormalizeHarnessName(harness)
+ if want != "" {
kept := installed[:0]
for _, name := range installed {
if asymptoteobserve.NormalizeHarnessName(name) == want {
diff --git a/cli/beacon/cmd/token_usage_test.go b/cli/beacon/cmd/token_usage_test.go
index 799aac38..02bb8e1a 100644
--- a/cli/beacon/cmd/token_usage_test.go
+++ b/cli/beacon/cmd/token_usage_test.go
@@ -279,3 +279,34 @@ func TestTokenUsageCoverageHarnessScopeDoesNotStrandOtherRuntimes(t *testing.T)
t.Fatalf("want exactly the scoped runtime, covered; got %+v", report.Runtimes)
}
}
+
+// An alias in --harness must select the same runtime on both sides of the join.
+//
+// The event reader compares the flag to harness.name with case-insensitive equality on the raw
+// string, while events carry the canonical name. So `--harness vscode` matches no event, every
+// VS Code event being named vscode_copilot. On its own that is a plain miss; combined with an
+// installed list that canonicalizes, it is worse -- the runtime stays in the report while its
+// events vanish, and a runtime that spent tokens is reported inactive.
+func TestTokenUsageCoverageHarnessScopeAcceptsAliases(t *testing.T) {
+ home := t.TempDir()
+ t.Setenv("HOME", home)
+ logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
+ line := `{"timestamp":"2026-06-11T10:00:00Z","vendor":"beacon","product":"endpoint-agent","schema_version":"1.0","event":{"kind":"agent_runtime","action":"token.usage","category":"metric"},"severity":"info","endpoint":{"hostname":"h"},"harness":{"name":"vscode_copilot"},"model":"gpt-4o","session":{"id":"s1"},"gen_ai":{"usage":{"input_tokens":42}},"message":"usage"}`
+ if err := os.WriteFile(logPath, []byte(line+"\n"), 0o600); err != nil {
+ t.Fatalf("write log: %v", err)
+ }
+
+ // "vscode" is the spelling the hook installer uses; the log carries "vscode_copilot".
+ output := runTokenUsageCommand(t, "--log-path", logPath, "--coverage", "--json", "--harness", "vscode")
+ var report tokens.CoverageReport
+ if err := json.Unmarshal([]byte(output), &report); err != nil {
+ t.Fatalf("unmarshal coverage report: %v\n%s", err, output)
+ }
+ if len(report.Runtimes) != 1 {
+ t.Fatalf("want one row for the aliased runtime, got %+v", report.Runtimes)
+ }
+ line0 := report.Runtimes[0]
+ if line0.Harness != "vscode_copilot" || line0.Status != tokens.CoverageCovered || line0.Tokens != 42 {
+ t.Fatalf("row = %+v, want vscode_copilot covered with 42 tokens", line0)
+ }
+}