Repository navigation
Description
This is Part 1 of the AI Stats Dashboard Epic.
Before we can display AI resource consumption statistics (cost, model usage, token/turn counts) on the dashboard, we must first persist this discrete data in Redis when a job completes.
Currently, detailed metrics like claudeCostUsd, claudeModel, and claudeNumTurns are calculated in src/worker.js and included in the final Pino log entry, but they are not passed back to the queue completion handler or stored in Redis for aggregation. The existing system:activity:log list only stores a generic completion message, not the quantitative metrics we need.
Goal
Modify the BullMQ worker event handlers in src/queue/taskQueue.js to extract detailed AI metrics from the job's return value (from processGitHubIssueJob) and store them in a new Redis Sorted Set for time-based querying.
Implementation Steps
-
Analyze
src/worker.js: Confirm that theprocessGitHubIssueJobfunction returns an object that includes theclaudeResult(which containsclaudeCostUsd,model,finalResult.num_turns,executionTime, etc.). The current implementation logs this, so the data is available within the worker process. Ensure this comprehensiveresultobject is what the worker processor returns on success. -
Modify
src/queue/taskQueue.js-worker.on('completed', ...)handler:- Inside this handler, access the
resultobject returned by the job processor. - Extract the key AI metrics from
result.claudeResult(e.g., cost, model, turns, execution time). - Define a new JSON object
aiMetricscontaining this data, plus timestamp, status (success), issue number, and repo name. - Create a new Redis key for this data:
metrics:ai:log:v1. - Use
await metricsRedis.zadd()to add the JSON.stringifiedaiMetricsobject to this Sorted Set. Use the job's start timestamp (job.timestamp) as the score for the sorted set. This enables efficient time-range queries. - Also, ensure the
repoFullNamelogic correctly handles the job data structure to populateactive:repositories(this logic seems adjacent and must be preserved).
- Inside this handler, access the
-
Modify
src/queue/taskQueue.js-worker.on('failed', ...)handler:- Inside this handler, create a similar
aiMetricsobject. - Set
status: 'failed',cost: 0, and extract any available metadata (likemodelNamefromjob.data). - Add this failure record to the same sorted set (
metrics:ai:log:v1) using itsjob.timestampas the score. This ensures our stats (like success/failure rates) are accurate.
- Inside this handler, create a similar
This issue only covers storing the data. A follow-up issue will cover the API endpoint and frontend panel creation.
Activity
integry commentedon Sep 16, 2025
Here is the suggested implementation diff for
src/queue/taskQueue.jsto capture the AI metrics in Redis:propr-dev commentedon Sep 18, 2025
🤖 AI processing has started for this issue using claude-opus-4-20250514 model.
I'll analyze the problem and work on a solution. This may take a few minutes.
Processing Details:
claude-opus-4-20250514ai-fix/72-epic-1-2-store-ai-usage-m-20250918-1511-claude-opus-4-20250514-8lxmainissue-72-20250918-1511-claude-opus-4-20250514-8lxfix(ai): Resolve issue #72 - Epic (1/2): Store AI Usage Metrics (Cost…
Merge pull request #81 from integry/ai-fix/72-epic-1-2-store-ai-usage…