Skip to content

Commit 8557bc3

Browse files
Claudeclaude
authored andcommitted
fix: auto-detect agent in recordMetrics to prevent NULL agent values
Only session_start, session_refresh, and session_close passed agent to recordMetrics(). All other tools (recall, search, log, create_learning, etc.) omitted it, resulting in NULL agent values in gitmem_query_metrics. recordMetrics() now calls getAgentIdentity() as fallback when callers don't provide agent, ensuring all metrics rows have proper agent identity. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7b145b6 commit 8557bc3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/services/metrics.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { v4 as uuidv4 } from "uuid";
99
import * as supabase from "./supabase-client.js";
1010
import { getEffectTracker } from "./effect-tracker.js";
1111
import { hasSupabase } from "./tier.js";
12+
import { getAgentIdentity } from "./agent-detection.js";
1213

1314
/**
1415
* Tool names that can be tracked
@@ -142,10 +143,13 @@ export class Timer {
142143
*/
143144
export async function recordMetrics(metrics: QueryMetrics): Promise<void> {
144145
if (!hasSupabase()) return; // No-op on free tier — don't record failures
146+
// Auto-detect agent if not provided by caller
147+
const agent = metrics.agent || getAgentIdentity() || null;
148+
145149
const record: Record<string, unknown> = {
146150
id: metrics.id,
147151
session_id: metrics.session_id || null,
148-
agent: metrics.agent || null,
152+
agent,
149153
tool_name: metrics.tool_name,
150154
query_text: metrics.query_text || null,
151155
tables_searched: metrics.tables_searched || null,

0 commit comments

Comments
 (0)