Repository navigation
[3438 by Claude Opus 5.5] Metrics and LLM-cost export (CSV, JSON, CLI, MCP) - #3459
Conversation
…. It was a leftover wait loop from an earlier test run. It never exited because its `pgrep -f "costExport.test"` matched its own command line. The actual test runs finished separately and passed (8/8 for the API tests), so I didn't restart it. The implementation and test results in my previous summary still stand.
|
/ultrafix goal=8 max=10 |
|
🔄 Ultrafix loop started (goal: 8/10, max cycles: 10) First action:
|
|
✅ AI Code Review Complete requested by @propr-ultrafix Posted 1 review: |
🔍 AI Code Review — codex:gpt-6-astraOverall EvaluationThe PR adds a shared cost-export implementation across HTTP, CLI, and MCP, with documentation and generated API types. It needs changes before merge because the log-attribution query fails under SQLite and its fallback can attribute spend to unrelated runs. ✅ Shared aggregation — HTTP and MCP use ✅ Scoped MCP access — Explicit repositories pass through dispatch authorization; omitted repositories are restricted through ✅ Export coverage — Added tests cover grouping, repository filtering, token fallback, unknown costs, and CSV escaping. This review is a static analysis of the supplied code; no commands were run. The supplied current checks report 34 passed, zero failed, and one pending. Merge blockersEvery finding below was introduced by this PR and must be resolved before merging. F1: 🔴 Correlated ordering breaks log-based grouping
F2: 🔴 Missing metadata is borrowed from unrelated runs
SuggestionsThese are optional follow-ups and are not sent to No suggestions. ScoreThe shared export structure and coverage are useful, but two advertised grouping dimensions have execution and attribution defects requiring correction. Passing checks do not resolve those code-level problems. Score: 5/10 🤖 Review Details
Copy and edit to choose records from this review: 🤖 Review by ProPR |
|
✅ Applied the requested follow-up changes in commit 8773783
Summary of ChangesI fixed F1 and F2 together: agent and execution type now come from the one log call matched to each execution, and stay null when no call matches. All 9 cost-export tests pass on SQLite, the API typecheck is clean, and eslint F1 didn't reproduce. The old correlated What changed (
One rule is stricter than the finding asked for. A session-less execution no longer matches a call that has a session, even on the same model. I did this because an execution and its log call take their session from the same result, so a log with a session belongs to some other run. Otherwise the test would pass only because of the New test: "agent and execution type come from one matching call; nothing is borrowed from other runs of the task". It covers three cases:
I checked that this test fails on the previous code, which gives I found nothing else outside the selected findings to report. 🤖 Implementation Details
💡 ProPR Slash Commands
🤖 Generated by ProPR |
…me from the one log call matched to each execution, and stay null when no call matches. All 9 cost-export tests pass on SQLite, the API typecheck is clean, and eslint `--max-warnings 0` passes on both changed files. I fixed F1 and F2 together: agent and execution type now come from the one log call matched to each execution, and stay null when no call matches. All 9 cost-export tests pass on SQLite, the API typecheck is clean, and eslint `--max-warnings 0` passes on both changed files. **F1 didn't reproduce.** The old correlated `ORDER BY` query works on this SQLite (3.53.4, better-sqlite3): the existing agent/type test passed before I changed anything, run with `PROPR_DEMO_MODE=true`. I replaced the query anyway, because fixing F2 needs one ranked match per execution. **What changed** (`loggedRuns` in `packages/api/routes/costExport.ts`): - The export now joins each execution in the window to candidate log calls and ranks them with `row_number()`: same session first, then same model, then nearest start time, then `log_id`. The best candidate is the only row joined, and both agent and execution type are read from it. A null `agent_alias` on that row stays null and isn't taken from another call. - A call counts as a match only if: - **Execution with a task:** the call has the same task and the same session. If neither has a session, it needs the same task and the same model instead. Calls that only share the task, or that come from a different session, no longer match. - **Execution without a task:** the call has the same session (unchanged). - The task and session paths both use the new query. The join only runs when `agent` or `execution_type` is requested. One rule is stricter than the finding asked for. A session-less execution no longer matches a call that has a session, even on the same model. I did this because an execution and its log call take their session from the same result, so a log with a session belongs to some other run. Otherwise the test would pass only because of the `log_id` tie-break. **New test:** "agent and execution type come from one matching call; nothing is borrowed from other runs of the task". It covers three cases: - **F2's own case:** the matching call has a type but no agent, and another review call on the task has `codex`. The result is `null / implementation`. - **No matching call:** an execution whose session no call recorded gets `null / null`. - **No session:** the nearer of two session-less same-model calls wins, and a nearer call from another session is never picked. I checked that this test fails on the previous code, which gives `codex / implementation` and `codex / review`. I found nothing else outside the selected findings to report. PR: #3459 Comment by: @propr-ultrafix (ID: 0) Model: Claude Opus 5.5
|
✅ AI Code Review Complete requested by @propr-ultrafix Posted 1 review: |
🔍 AI Code Review — codex:gpt-6-astraOverall EvaluationThe PR adds a shared cost aggregation implementation exposed through HTTP, CSV, CLI, and MCP, with documentation and generated types. It needs a targeted correction before merge: sessionless executions can inherit another run’s agent and execution type. ✅ Shared aggregation — HTTP and MCP use ✅ Repository authorization — MCP dispatch authorizes explicit repositories before execution, while omitted repositories use the grant-scoped list. ✅ Export coverage — Added tests cover aggregation, repository filtering, unknown costs, and CSV escaping. This review is a static analysis of the supplied code; no commands were run. Current checks report 34 passed, none failed, and one pending. Merge blockersEvery finding below was introduced by this PR and must be resolved before merging. F3: 🔴 Sessionless runs borrow unrelated attribution
SuggestionsThese are optional follow-ups and are not sent to S1: 🟢 Exercise MCP authorization through dispatchThe MCP test invokes ScoreThe implementation has good surface coverage and passing checks, but incorrect attribution can materially distort the central cost breakdown. The required correction is confined to matching executions with log calls. Score: 6/10 🤖 Review Details
Copy and edit to choose records from this review: 🤖 Review by ProPR |
|
✅ Applied the requested follow-up changes in commit 8301f37
Summary of ChangesI fixed F3. An execution without a session now gets an agent and execution type only when there's real evidence that a log call belongs to that run. If there isn't, both stay null, so the later run in the finding's example is no longer credited to the earlier run's call. What changed (
Executions with a session, and executions with no task, still match exactly as before. The HTTP JSON, CSV, CLI and MCP outputs all share this loader, so they all get the fix. Tests (
Verification:
One thing to know: the overlap rule assumes an execution row's time span actually covers its agent run. The execution's start is computed when it is saved, as save time minus the run's duration. If a run were saved long after it ended, its spans wouldn't overlap and its agent and type would show as unknown rather than wrong. I found nothing else outside F3 to report. This change has no visual effect, so I made no preview. 🤖 Implementation Details
💡 ProPR Slash Commands
🤖 Generated by ProPR |
…t and execution type only when there's real evidence that a log call belongs to that run. If there isn't, both stay null, so the later run in the finding's example is no longer credited to the earlier run's call. I fixed F3. An execution without a session now gets an agent and execution type only when there's real evidence that a log call belongs to that run. If there isn't, both stay null, so the later run in the finding's example is no longer credited to the earlier run's call. **What changed** (`loggedRuns` in `packages/api/routes/costExport.ts`): a session-less execution and a session-less call on the same task and model now pair up only when: - **Their time spans overlap.** Both rows come from the same agent run, so the real call always overlaps its execution. A missing end time counts as the start time. - **They are each other's nearest overlapping match.** One call can therefore never be credited to two executions. - **The match is decided across all executions, not just the requested period.** If a call's own execution started before the period, the call isn't credited to a later overlapping execution inside it. Executions with a session, and executions with no task, still match exactly as before. The HTTP JSON, CSV, CLI and MCP outputs all share this loader, so they all get the fix. **Tests** (`packages/api/test/costExport.test.ts`): - **New regression test** with three cases: - **The finding's case:** two session-less runs of one task on one model, with a call recorded only for the earlier run. The later run is counted as unknown, and its $4 is no longer credited to `claude / implementation`. - **Two runs overlapping one call:** only the run nearest the call gets it. The other stays unknown. - **Call's own run outside the period:** the call isn't credited to the overlapping run inside the period. - **One existing test fixture adjusted.** In the earlier test's session-less case, the matching call started an hour before the execution and recorded no end time, so it never overlapped the run. I gave it an end time so that it covers the run. That case still checks that the matching call wins over a call from another session. **Verification:** - All 10 cost-export tests pass. - The new test fails on the previous `costExport.ts`, and that is the only test that fails there. - The `packages/api` typecheck is clean. - eslint `--max-warnings 0` passes on both changed files. One thing to know: the overlap rule assumes an execution row's time span actually covers its agent run. The execution's start is computed when it is saved, as save time minus the run's duration. If a run were saved long after it ended, its spans wouldn't overlap and its agent and type would show as unknown rather than wrong. I found nothing else outside F3 to report. This change has no visual effect, so I made no preview. PR: #3459 Comment by: @propr-ultrafix (ID: 0) Model: Claude Opus 5.5
|
✅ AI Code Review Complete requested by @propr-ultrafix Posted 1 review: |
🔍 AI Code Review — codex:gpt-6-astraOverall EvaluationThe PR adds a shared cost aggregation implementation across HTTP, CSV, CLI, and MCP, with substantial tests and documentation. It needs a localized validation fix before merge. ✅ Shared aggregation — HTTP and MCP use ✅ Grant enforcement — Explicit MCP repositories pass through dispatcher authorization; omitted repositories use the grant-scoped repository list. Review was static only; no commands were run. No current-head check runs were reported. Merge blockersEvery finding below was introduced by this PR and must be resolved before merging. F4: 🔴 Reject malformed repository filters
SuggestionsThese are optional follow-ups and are not sent to S2: 🟢 Test authorization through the dispatcherThe MCP test calls ScoreThe implementation has good reuse and targeted coverage, but malformed repository filters can silently produce an incorrectly scoped export. The required correction is localized. Score: 6/10 🤖 Review Details
Copy and edit to choose records from this review: 🤖 Review by ProPR |
|
✅ Applied the requested follow-up changes in commit cbeda8d
Summary of ChangesI fixed F4: when a repository filter isn't a plain string, both cost export endpoints now return 400 instead of exporting every repository. The fix ( New test ( Verification:
Other places I checked:
🤖 Implementation Details
💡 ProPR Slash Commands
🤖 Generated by ProPR |
…both cost export endpoints now return 400 instead of exporting every repository. I fixed F4: when a repository filter isn't a plain string, both cost export endpoints now return 400 instead of exporting every repository. **The fix** (`packages/api/routes/costExport.ts`, in `readExport`): `validateRepositoryFilter` now checks the raw `req.query.repository` before anything else. A missing or empty value still means "all repositories". Repeated parameters (`?repository=acme/alpha&repository=acme/beta`) and nested ones (`?repository[name]=…`) get a 400 with "Repository must be a string". Both `/api/stats/cost` and `/api/stats/cost.csv` go through this one function, so one change covers both. **New test** (`packages/api/test/costExport.test.ts`): for both endpoints, it sends two repeated values, one value in array form, and an object. It checks each gets a 400 with that error. **Verification:** - The cost-export suite passes 11/11. I ran it with `PROPR_DEMO_MODE=true` because without GitHub auth configured, the test file fails before any test runs. - With the original route code put back, the new test fails, so it does catch the bug. - The API typecheck is clean, and eslint `--max-warnings 0` passes on both changed files. **Other places I checked:** - The MCP tool `get_cost_breakdown` isn't affected: its input schema already requires `repository` to be a single repository handle, so it can't receive an array or object. - **Not fixed, separate issue:** `readSummary` in `packages/api/routes/reviewScoreStats.ts` (around line 388) has the same pattern. It turns any non-string `repository` into `'all'` before validating, so repeated parameters widen the review-score summary to every repository. This PR only exported `csvCell` from that file and didn't touch this code, so I left it out of scope. PR: #3459 Comment by: @propr-ultrafix (ID: 0) Model: Claude Opus 5.5
|
✅ AI Code Review Complete requested by @propr-ultrafix Posted 1 review: |
🔍 AI Code Review — codex:gpt-6-astraOverall EvaluationThe PR adds a shared cost-export implementation across HTTP, CLI, and MCP, with schemas, documentation, and focused tests. It is merge-ready within the reviewed scope, conditional on the two pending checks completing successfully. ✅ Shared aggregation — JSON, CSV, CLI, and MCP use the same export logic, including distinct-task counts and null costs for groups without recorded cost. ✅ Repository boundaries — HTTP rejects malformed repository filters; MCP applies grant scope when no repository is supplied, while the existing dispatcher authorizes explicit repositories. ✅ Attribution coverage — Tests cover session matching, sessionless overlap, competing runs, and preventing a log outside the window from being reassigned. This assessment is based on static review of the supplied diff and context; no commands or tests were run. The supplied check status reports 32 passed, zero failed, and two pending. Merge blockersNo merge blockers. SuggestionsThese are optional follow-ups and are not sent to S3: 🟢 Clarify log-matching documentationIn S4: 🟢 Exercise producer-to-export attributionThe added tests seed execution and log timestamps directly. A follow-up integration test using the actual metrics and log producers would strengthen confidence in sessionless attribution, since those producers independently construct their timestamps. This is optional coverage; the supplied context does not demonstrate an attribution failure. ScoreThe implementation is cohesive, with meaningful coverage of aggregation, filtering, attribution, and CSV behavior. No merge-blocking defect was verified; final readiness remains conditional on the pending checks. Score: 8/10 🤖 Review Details
Copy and edit to choose records from this review: 🤖 Review by ProPR |
AI Implementation Summary
Closes #3438
Branch:
3438/claude-opus-5-5-metrics-and-llm-cost-expo-20261111-2357-0bsCommits: ✅ Changes committed (29d79cc)
AI Processing Completed
Execution Details:
Summary:
A background task was stopped at its time limit, but nothing was lost. It was a leftover wait loop from an earlier test run. It never exited because its
pgrep -f "costExport.test"matched its own command line. The actual test runs finished separately and passed (8/8 for the API tests), so I didn't restart it. The implementation and test results in my previous summary still stand.Detailed Logs:
26f12c00-07e8-4350-a8a5-873352df6453Log files stored at:
/usr/src/app/logs/executions/issue-3438-2026-11-12T00-29-19-969Z-conversation.json/usr/src/app/logs/executions/issue-3438-2026-11-12T00-29-19-969Z-output.txtLatest Conversation Messages
This PR was created automatically by ProPR after processing issue #3438.
💡 Need changes?
Comment on this PR to request refinements — the AI agent monitors comments and will update the implementation based on your feedback. Keep iterating until you're satisfied!