Repository navigation
Description
Problem
Spend on failed attempts cannot be reported. Three defects: (1) a Claude run that hits a usage limit throws before execution logs are persisted, so it writes no llm_executions or llm_logs row; agent catch paths write no row either; (2) when a step after the agent run fails, the error handler calls recordLLMMetrics a second time for the same result, so the execution can be counted twice; (3) the analytics aggregates sum all executions regardless of success.
Goal
Every agent execution that consumed tokens has exactly one execution row, and analytics can split spend by outcome.
Acceptance criteria
- Executions that end in a usage limit or a thrown agent error record one
llm_executionsrow withsuccess = false, the error message, and whatever token and cost figures were observed in the stream (zero when none were). recordLLMMetricsis idempotent per execution: a second call for the same execution id does not insert a second row. Covered for both the issue path and the PR-comment path.loadRecordedSpendandloadModelUsagereturn spend split into successful and failed executions; totals are unchanged in meaning. The stats/overview and dashboard responses expose the split as additional fields (no existing field is renamed or removed).- The Analytics page shows "spend on failed attempts" for the selected window.
- Redis
llm:metrics:*counters stay consistent with the rows (no double increment). - Tests cover the usage-limit path, the thrown-error path, the idempotency guard, and the aggregate split.
Implementation
Key files: packages/core/src/agents/impl/utils/dockerResultProcessor.ts (usage limit thrown before logging), packages/core/src/agents/impl/ClaudeAgent.ts (persistExecutionLogs, catch path), packages/core/src/agents/impl/CodexAgent.ts, packages/core/src/utils/llmMetrics.ts (recordLLMMetrics, persistToDatabase), double-call sites src/jobs/processPullRequestCommentJob.ts + src/jobs/prCommentJobUtils.ts and src/jobs/processGitHubIssueJob.ts + src/jobs/errorHandlers.ts, packages/api/routes/analyticsAggregates.ts, packages/api/routes/analyticsModelUsage.ts, packages/api/routes/statsRoutes.ts, propr-ui/src/pages/AnalyticsPage.tsx. Tests: test/llmMetrics*.test.ts, test/claudeRateLimitPropagation.test.ts, packages/api/test/analyticsAggregates.test.ts. Verify with the standard commands (test:prepare, typecheck, changed tests, eslint --max-warnings 0 per package).
Activity
propr-dev commentedon Nov 11, 2026
🤖 AI processing has started for this issue using claude agent with claude-opus-5-5 model.
I'll analyze the problem and work on a solution. This may take a few minutes.
Processing Details:
claudeclaude-opus-5-53437/claude-opus-5-5-record-and-report-spend-o-20261111-2200-41r3437-epic-cost-visibility-oluissue-3437-20261111-2200-claude-opus-5-5-41r🔍 Track Task Execution