Skip to content

AI Fix for Issue #72: Epic (1/2): Store AI Usage Metrics (Cost, Model, Turns) in Redis for Dashboard Aggregation - #81

Merged
integry merged 1 commit into
mainfrom
ai-fix/72-epic-1-2-store-ai-usage-m-20250918-1511-claude-opus-4-20250514-8lx
Sep 18, 2025
Merged

integry merged 1 commit into
mainfrom
ai-fix/72-epic-1-2-store-ai-usage-m-20250918-1511-claude-opus-4-20250514-8lx

Conversation

@propr-dev

@propr-dev propr-dev Bot commented Sep 18, 2025

Copy link
Copy Markdown
Contributor

AI Implementation Summary

Closes #72

Model Used: claude-opus-4-20250514
Status: ✅ Implementation Completed
Branch: ai-fix/72-epic-1-2-store-ai-usage-m-20250918-1511-claude-opus-4-20250514-8lx
Commits: ✅ Changes committed (2c0b3dd)


🤖 AI Processing Completed

Execution Details:

Summary:

Summary

I have successfully implemented the solution for GitHub issue #72. Here's what I did:

Changes Made to /home/node/workspace/src/queue/taskQueue.js:

  1. Modified the worker.on('completed', ...) handler to:

    • Extract the repository full name from either job.data.repository or by combining job.data.repoOwner and job.data.repoName
    • Add logic to extract AI metrics from result.claudeResult when available
    • Create an aiMetrics object containing:
      • timestamp: Job start time (used as score for sorted set)
      • cost: Extracted from various possible fields (claudeCostUsd, costUsd, finalResult.cost_usd)
      • model: The AI model used
      • turns: Number of conversation turns
      • executionTimeMs: Execution time in milliseconds
      • issueNumber: Issue number
      • repo: Repository full name
      • status: 'success'
      • correlationId: Correlation ID for tracking
    • Store the metrics in Redis sorted set metrics:ai:log:v1 using zadd with timestamp as the score
  2. Modified the worker.on('failed', ...) handler to:

    • Extract repository full name in the same way as the completed handler
    • Create an aiMetrics object for failed jobs containing:
      • Similar fields as successful jobs
      • cost: Set to 0 for failed jobs
      • turns: Set to 0 for failed jobs
      • executionTimeMs: Calculated from job timestamps
      • status: 'failed'
      • error: First 100 characters of the error message
    • Store the failed job metrics in the same sorted set for complete statistics

Key Implementation Details:

  1. Redis Sorted Set: Used metrics:ai:log:v1 as the key for storing AI metrics with job timestamps as scores, enabling efficient time-range queries
  2. Data Extraction: Handled multiple possible locations for cost data (claudeCostUsd, costUsd, finalResult.cost_usd) to ensure compatibility
  3. Repository Name Handling: Fixed the repository tracking to handle both old format (job.data.repository) and new format (job.data.repoOwner + job.data.repoName)
  4. Failed Job Metrics: Included failed jobs in the metrics to enable accurate success/failure rate calculations
  5. Error Handling: Added proper checks for timestamp existence before adding to sorted set

The implementation follows the exact specifications in the issue and the suggested diff, storing comprehensive AI usage metrics that can be queried by time range for dashboard aggregation.

Claude Code Results:

  • Turns Used: 34
  • Cost: $unknown
  • Session ID: 11c85aef-8c3b-4681-9797-ba226b22e6f8

📁 Detailed Logs:
Execution logs generated:

  • Conversation: 34 messages
  • Session: 11c85aef-8c3b-4681-9797-ba226b22e6f8
  • Raw Output: 187,236 characters

Log files stored at:

  • conversation: /tmp/claude-logs/issue-72-2025-09-18T15-14-15-826Z-conversation.json
  • output: /tmp/claude-logs/issue-72-2025-09-18T15-14-15-826Z-output.txt
💬 Latest Conversation Messages
ASSISTANT: [content unavailable]

ASSISTANT: ## Summary

I have successfully implemented the solution for GitHub issue #72. Here's what I did:

### Changes Made to `/home/node/workspace/src/queue/taskQueue.js`:

1. **Modified the `worker.on('com...


Powered by Claude Code v1.0.0


This PR was created automatically by Claude Code after processing issue #72.

…, Model, T

Implemented by Claude Code using claude-opus-4-20250514 model.

Implementation completed successfully.
@integry
integry merged commit 37ba45b into main Sep 18, 2025
@integry
integry deleted the ai-fix/72-epic-1-2-store-ai-usage-m-20250918-1511-claude-opus-4-20250514-8lx branch September 18, 2025 22:45
propr-dev Bot pushed a commit that referenced this pull request Sep 17, 2026
…ications are the only group left, and cards are titled by their actual PR or issue title. The type checks, lint (zero warnings), 124 UI notification tests, the server notification tests and 7 browser tests all pass.

The Inbox is now one plain list, newest first. System notifications are the only group left, and cards are titled by their actual PR or issue title. The type checks, lint (zero warnings), 124 UI notification tests, the server notification tests and 7 browser tests all pass.

**Layout**
- The "Needs attention", "Ready for review" and "Completed" groups are gone. Everything except system updates is in one list sorted by time, newest on top.
- System and indexing updates stay in one collapsed "System" section above the list. Its header is plain grey text with a count and a chevron.
- Cards no longer have colored backgrounds, including the teal fill on unread ones. Every card is white with a grey border. Unread is shown only by the small dot and a bold title.

**Titles and IDs**
- The title is now the PR or issue title. For example, "Review completed for PR #81" becomes "Guard Inbox recaps against empty metadata". The server gets it from the title stored with the task, stripping prefixes like "Follow-up PR #42:" and "New Issue:".
- If a task has no stored title, the old wording is used.
- Plan notifications are titled by the plan name, with "Ready for review with 4 planned tasks." underneath.
- The PR or issue number is still shown, as a small grey `PR81` or `#12` chip. The chips and dot separators are copied from the metadata row on the task details page (the one in your screenshot), so no new element styles were added.
- The event type (e.g. "Review completed", "Fix completed") is plain grey text in that same row.

Notifications already stored keep their old titles; only new ones get the PR/issue title.

I updated the existing unit and browser tests for the flat list. I also added one server test checking that merge and failed-issue notifications use the real title.

PR: #2441
Comment by: @integry (ID: 5711992010)
Model: claude-opus-5
propr-dev Bot pushed a commit that referenced this pull request Nov 27, 2026
The failing check was at fault, not the runtime. Issue #80's agent did launch from the derived image. I fixed the check without weakening it, and the cap-mode summary now says which image the queued run used.

**What happened in 45982542980:** the step searched only `flyctl logs --no-tail`, which keeps just the most recent lines. When it ran at 10:44:22, the oldest line it had was from 10:43:16. Both runs had built and started around 10:41, and issue #81 (the queued one) finished at 10:43:18, before #80. So the build line had already dropped out of the buffer when the step looked. The worker process was the same one throughout (pid 20), so it wasn't a restart either.

**What I found in the code:** there was a real gap, though it isn't what failed this run. The build line is logged once per shared build, under whichever run started it. In cap mode that can be #81's run. A run that reuses the worker's cached image logged nothing at all, so the queued run's image couldn't be shown.

**Changes:**
- **Runtime (`fly/derivedImage.ts`):** every agent Machine created from a derived image now logs `Launched the agent Fly Machine from the derived image`, with `run`, `machine`, `image` and the package-list digest. That covers a run that built the image, one that found the registry tag, one that used the cache, and the retry after Fly refuses a create. I added a sentence about it to `agent-runtime.md`.
- **Workflow, "Observe idle stop…":** the full log stream (`$OUT/app-logs.jsonl`) now starts at the idle stop in every mode, not only MCP or cap mode.
- **Workflow, "Verify the linked PR…":**
  - It reads the stream plus the `--no-tail` buffer, filtered to after the idle stop.
  - It still requires the `Installed agent runtime packages in a derived Fly Machine image` line, with the same digest, count and `registry.fly.io/$AGENT_APP@sha256:` checks.
  - It now also requires a launch line whose run name matches `issue-$ISSUE-` (the format is `<agent>-issue-<n>-<task id>`), with the same image as the build.
- **Workflow, cap step:**
  - It requires a launch line for the run of `$ISSUE2` with the same `DERIVED_IMAGE`.
  - It requires exactly one build line since the idle stop.
  - The step summary now shows the queued run's name, its Machine, the image it launched from, and the build count.

**Testing:**
- I added a test where one run builds and a second run reuses the cached image; both log a launch line with the same image and the build is logged once. The derived-image, capacity and Fly runtime suites pass (117 tests).
- Core typecheck and zero-warning lint pass.
- The three changed steps parse with `bash -n`.
- I ran the new jq selection on logs shaped like this run's. The old query comes back empty, and the new one finds the build and matches the launch line to `issue-80` (and not to `issue-8`).
- I couldn't confirm the exact run-name format from real logs, because the failure dump redacts `run` as `<long>`. The `issue-<n>` match is based on the code (`buildClaudeContainerName`). If your cap run fails with "No 'Launched the agent Fly Machine…' record for the run of …", that match is the place to look.

Because this touches runtime code (one new log line, no behaviour change), you may want to run default mode once more along with cap mode. Default mode now also runs the new launch-line check for its first issue.

PR: #3825
Comment by: @integry (ID: 7216310644)
Model: Claude Opus 5.5

ProPR-Agent: claude/claude-opus-5-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Epic (1/2): Store AI Usage Metrics (Cost, Model, Turns) in Redis for Dashboard Aggregation

2 participants