Skip to content

[3438 by Claude Opus 5.5] Metrics and LLM-cost export (CSV, JSON, CLI, MCP) - #3459

Merged
integry merged 4 commits into
3437-epic-cost-visibility-olufrom
3438/claude-opus-5-5-metrics-and-llm-cost-expo-20261111-2357-0bs
Nov 12, 2026
Merged

integry merged 4 commits into
3437-epic-cost-visibility-olufrom
3438/claude-opus-5-5-metrics-and-llm-cost-expo-20261111-2357-0bs

Conversation

@propr-dev

@propr-dev propr-dev Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

AI Implementation Summary

Closes #3438

Branch: 3438/claude-opus-5-5-metrics-and-llm-cost-expo-20261111-2357-0bs
Commits: ✅ Changes committed (29d79cc)


AI Processing Completed

Execution Details:

  • Issue: Metrics and LLM-cost export (CSV, JSON, CLI, MCP) #3438
  • Repository: integry/propr
  • Status: Success
  • Execution Time: 31m 28s
  • Tokens used: 12.12M tokens [12.11M input + 1.32K output]
  • API cost: $3.25
  • Timestamp: Nov 12, 2026, 12:29 AM UTC
  • LLM Model: Claude Opus 5.5
  • Subscription usage: Weekly +2%, Fable +1%

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:

  • Conversation: 252 messages
  • Session: 26f12c00-07e8-4350-a8a5-873352df6453

Log files stored at:

  • conversation: /usr/src/app/logs/executions/issue-3438-2026-11-12T00-29-19-969Z-conversation.json
  • output: /usr/src/app/logs/executions/issue-3438-2026-11-12T00-29-19-969Z-output.txt
Latest Conversation Messages
ASSISTANT: The cost export is in place: two API routes, a CLI command and an MCP read tool, all returning the same rows. Every test I ran passes, the API and CLI typecheck cleanly, eslint with `--max-warnings 0`...

ASSISTANT: [content unavailable]

ASSISTANT: 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 co...


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!

…. 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.
@propr-dev

propr-dev Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

/ultrafix goal=8 max=10
Triggered automatically by the requested execution settings.

@propr-dev propr-dev Bot added the ultrafix label Nov 12, 2026
@propr-dev

propr-dev Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

🔄 Ultrafix loop started (goal: 8/10, max cycles: 10)

First action: /review

💡 Tip: Remove the ultrafix label from this PR to stop further ultrafix cycles.

@propr-dev

propr-dev Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ AI Code Review Complete requested by @propr-ultrafix

Posted 1 review:

View Task Details

@propr-dev

propr-dev Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

🔍 AI Code Review — codex:gpt-6-astra

Overall Evaluation

The 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 loadCostExport, and CSV renders the same exported rows.

✅ Scoped MCP access — Explicit repositories pass through dispatch authorization; omitted repositories are restricted through listScope.

✅ 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 blockers

Every finding below was introduced by this PR and must be resolved before merging.

F1: 🔴 Correlated ordering breaks log-based grouping

  • Required behavior: Supported agent and execution_type groupings must execute successfully on the application's SQLite database.

  • Evidence: packages/api/routes/costExport.ts:loggedRunColumn

    1. A caller requests group_by=agent or group_by=execution_type on a database containing llm_logs.
    2. executionRows inserts a scalar subquery whose ORDER BY references outer execution columns, including e.session_id, e.model_name, and e.start_time.
    3. SQLite cannot resolve these outer references in the subquery's ORDER BY. Preparing the query fails with a missing-column error instead of producing grouped rows.
    4. HTTP returns 500; CLI and MCP requests using these dimensions also fail.

    static trace: both viaTask and viaSession contain this unsupported correlation in their ordering expressions. Schema probes only check table and column existence and do not prevent the SQL resolution failure. The added agent/type test targets this path, but the supplied check summary does not establish how this exact query passed; no test was executed during this review.

  • Minimum fix: Express candidate ranking in a SQLite-supported query, such as joining executions to candidate logs and ranking candidates per execution. Correct both task and session matching paths and verify the agent/type test against SQLite.

F2: 🔴 Missing metadata is borrowed from unrelated runs

  • Required behavior: Exported agent and execution type must describe the same execution; unrecorded dimensions must remain null rather than being inferred from an unrelated call.

  • Evidence: packages/api/routes/costExport.ts:loggedRunColumn

    1. A task has execution A and its matching log, whose execution_type is implementation but whose agent_alias is null. The same task also has a separate review log B with agent codex.
    2. The agent lookup excludes A's matching log through l.agent_alias is not null, leaving B eligible regardless of its different session, model, or start time.
    3. The execution-type lookup independently selects A's matching log.
    4. The resulting attribution combines B's agent with A's execution type, assigning A's spend to codex / implementation even though that agent was not recorded for A.

    static trace: each dimension selects its own candidate, and task equality is the only mandatory relationship in viaTask; session and model merely affect ordering. This attribution defect remains after correcting F1's SQL execution failure. Existing tests give matching logs complete metadata and do not cover this case. The same fallback also assigns a task's other logs to executions with no matching log at all.

  • Minimum fix: Resolve one defensibly matching log per execution and read both dimensions from that row, preserving null fields. Return null when no matching run can be established instead of borrowing another task call's metadata.

Suggestions

These are optional follow-ups and are not sent to /fix.

No suggestions.

Score

The 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

  • Model: GPT-6 Astra
  • Time: 47s
  • Tokens: 63,444 (62,305 in / 1,139 out)
  • Cost: $0.57

View Task


💡 Next step: Comment /fix to address every F# merge blocker, /fix all for every pending blocker and suggestion, or name records explicitly, as in /fix F3 S5.
F# and S# IDs increment across review comments and remain permanent, so selectors such as /fix F3 F5 stay unambiguous across cycles. S# suggestions stay optional: they are implemented only when you name them or request /fix all, and they never relax a merge blocker.

Copy and edit to choose records from this review:

/fix F1 F2

🤖 Review by ProPR

@propr-dev

propr-dev Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Applied the requested follow-up changes in commit 8773783

Addressed 1 AI review comment (IDs: 6811115360)

Addressed findings F1, F2

Summary of Changes

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.


🤖 Implementation Details

  • Model: Claude Opus 5.5 (medium)
  • Requested By: @propr-ultrafix
  • Time: 6m 52s
  • Tokens: 1,749,927 (1,737,189 in / 12,738 out)
  • Cost: $0.93

View Task Execution


💡 ProPR Slash Commands
Command Description Example
/merge Merge target branch into this PR and resolve conflicts /merge
/review Request an AI code review /review or /review claude-sonnet
/fix Address review blockers, or blockers and suggestions with /fix all /fix, /fix all, or /fix F3 S5
/switch Change the AI model for this PR /switch claude-opus
/use Override the model for a single follow-up run /use claude-sonnet
/ultrafix Loop review→fix cycles until score goal is met /ultrafix or /ultrafix goal=8 max=10

🤖 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
@propr-dev

propr-dev Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ AI Code Review Complete requested by @propr-ultrafix

Posted 1 review:

View Task Details

@propr-dev

propr-dev Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

🔍 AI Code Review — codex:gpt-6-astra

Overall Evaluation

The 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 loadCostExport; CSV serializes the same grouped rows.

✅ 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 blockers

Every finding below was introduced by this PR and must be resolved before merging.

F3: 🔴 Sessionless runs borrow unrelated attribution

  • Required behavior: The export must attribute agent and execution type to the same execution’s log call and preserve unknown attribution when that call is unavailable.

  • Evidence: packages/api/routes/costExport.ts:loggedRuns, particularly the viaTask join and per-execution ranking.

    1. A task has two executions on the same model, both with null session IDs. Only the earlier execution has a corresponding sessionless llm_logs row. Missing log matches are explicitly supported by this implementation and its tests.
    2. Request a breakdown grouped by agent or execution_type. The join admits that earlier log as a candidate for both executions because task and model match and both sessions are null.
    3. Each execution ranks candidates independently. The single log receives rank 1 for both executions, regardless of how far apart their start times are.
    4. The export assigns both executions—and both costs—to the earlier log’s agent and execution type. The later execution’s unknown attribution disappears, producing an incorrect spend breakdown.

    The nearest-start ordering cannot reject an unrelated candidate; there is no maximum separation or restriction against reusing one log for distinct runs. The added tests cover missing matches on different models or sessions, but not a missing match alongside an older sessionless call on the same model. static trace: This follows directly from the join predicate and partition by re.execution_id; it affects HTTP JSON, CSV, CLI, and MCP through their shared loader.

  • Minimum fix: Require reliable same-run evidence before using a sessionless log for attribution; otherwise retain null agent and execution type. Add a regression with two sessionless executions and only one corresponding log, ensuring the unmatched execution does not inherit that log’s attribution.

Suggestions

These are optional follow-ups and are not sent to /fix.

S1: 🟢 Exercise MCP authorization through dispatch

The MCP test invokes tool.run directly, bypassing the repository authorization shown in toolExecution.ts. An integration test through dispatch would protect the verified authorization boundary against future changes, including rejection of an explicit repository outside the grant. This is optional because the supplied dispatcher already performs that check.

Score

The 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

  • Model: GPT-6 Astra
  • Time: 59s
  • Tokens: 63,425 (62,247 in / 1,178 out)
  • Cost: $0.57

View Task


💡 Next step: Comment /fix to address every F# merge blocker, /fix all for every pending blocker and suggestion, or name records explicitly, as in /fix F3 S5.
F# and S# IDs increment across review comments and remain permanent, so selectors such as /fix F3 F5 stay unambiguous across cycles. S# suggestions stay optional: they are implemented only when you name them or request /fix all, and they never relax a merge blocker.

Copy and edit to choose records from this review:

/fix F3 S1

🤖 Review by ProPR

@propr-dev

propr-dev Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Applied the requested follow-up changes in commit 8301f37

Addressed 1 AI review comment (IDs: 6811608054)

Addressed finding F3

Summary of Changes

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.


🤖 Implementation Details

  • Model: Claude Opus 5.5 (medium)
  • Requested By: @propr-ultrafix
  • Time: 7m 10s
  • Tokens: 1,292,757 (1,280,218 in / 12,539 out)
  • Cost: $0.81

View Task Execution


💡 ProPR Slash Commands
Command Description Example
/merge Merge target branch into this PR and resolve conflicts /merge
/review Request an AI code review /review or /review claude-sonnet
/fix Address review blockers, or blockers and suggestions with /fix all /fix, /fix all, or /fix F3 S5
/switch Change the AI model for this PR /switch claude-opus
/use Override the model for a single follow-up run /use claude-sonnet
/ultrafix Loop review→fix cycles until score goal is met /ultrafix or /ultrafix goal=8 max=10

🤖 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
@propr-dev

propr-dev Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ AI Code Review Complete requested by @propr-ultrafix

Posted 1 review:

View Task Details

@propr-dev

propr-dev Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

🔍 AI Code Review — codex:gpt-6-astra

Overall Evaluation

The 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 loadCostExport, keeping grouping and totals consistent across interfaces.

✅ 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 blockers

Every finding below was introduced by this PR and must be resolved before merging.

F4: 🔴 Reject malformed repository filters

  • Required behavior: Invalid repository filters must return HTTP 400, and a malformed filter must not silently broaden an export to every repository.

  • Evidence: packages/api/routes/costExport.ts, createCostExportRoutes.readExport

    1. A caller requests /api/stats/cost?repository=acme/alpha&repository=acme/beta. Repeated query parameters produce a non-string repository value.
    2. readExport replaces every non-string value with 'all' before calling validateRepositoryFilter.
    3. Validation consequently succeeds, and loadCostExport returns executions from every repository, including repositories outside the supplied filters. The CSV endpoint follows the same path.

    The resulting export silently contains unintended repository costs instead of reporting invalid input. The shared validator explicitly rejects non-string values, but this normalization prevents it from seeing them. Existing route tests cover an invalid string, not repeated repository parameters. Verification provenance: static trace of the supplied route and validator; no test was executed.

  • Minimum fix: Validate the original repository query value before applying the omitted-filter default. Reject non-string values with 400, and cover repeated repository parameters for both export endpoints.

Suggestions

These are optional follow-ups and are not sent to /fix.

S2: 🟢 Test authorization through the dispatcher

The MCP test calls tool.run directly, bypassing the dispatcher that enforces explicit repository authorization. An integration test demonstrating rejection of an out-of-grant repository would protect that dependency. This is optional because the supplied dispatcher already performs the required authorization.

Score

The 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

  • Model: GPT-6 Astra
  • Time: 41s
  • Tokens: 64,526 (63,652 in / 874 out)
  • Cost: $0.57

View Task


💡 Next step: Comment /fix to address every F# merge blocker, /fix all for every pending blocker and suggestion, or name records explicitly, as in /fix F3 S5.
F# and S# IDs increment across review comments and remain permanent, so selectors such as /fix F3 F5 stay unambiguous across cycles. S# suggestions stay optional: they are implemented only when you name them or request /fix all, and they never relax a merge blocker.

Copy and edit to choose records from this review:

/fix F4 S2

🤖 Review by ProPR

@propr-dev

propr-dev Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Applied the requested follow-up changes in commit cbeda8d

Addressed 1 AI review comment (IDs: 6811759702)

Addressed finding F4

Summary of Changes

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.

🤖 Implementation Details

  • Model: Claude Opus 5.5 (medium)
  • Requested By: @propr-ultrafix
  • Time: 5m 5s
  • Tokens: 777,288 (773,729 in / 3,559 out)
  • Cost: $0.47

View Task Execution


💡 ProPR Slash Commands
Command Description Example
/merge Merge target branch into this PR and resolve conflicts /merge
/review Request an AI code review /review or /review claude-sonnet
/fix Address review blockers, or blockers and suggestions with /fix all /fix, /fix all, or /fix F3 S5
/switch Change the AI model for this PR /switch claude-opus
/use Override the model for a single follow-up run /use claude-sonnet
/ultrafix Loop review→fix cycles until score goal is met /ultrafix or /ultrafix goal=8 max=10

🤖 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
@propr-dev

propr-dev Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ AI Code Review Complete requested by @propr-ultrafix

Posted 1 review:

View Task Details

@propr-dev

propr-dev Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

🔍 AI Code Review — codex:gpt-6-astra

Overall Evaluation

The 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 blockers

No merge blockers.

Suggestions

These are optional follow-ups and are not sent to /fix.

S3: 🟢 Clarify log-matching documentation

In docs/docs/operations/metrics.md, the description says matching prefers the same session, then model, then nearest start. However, packages/api/routes/costExport.ts requires equal sessions for session-bearing executions and uses mutual-nearest, overlapping, same-model matching only when both sessions are absent. Documenting these separate rules would explain why some dimensions remain null. This is a documentation clarification, not a demonstrated runtime blocker.

S4: 🟢 Exercise producer-to-export attribution

The 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.

Score

The 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

  • Model: GPT-6 Astra
  • Time: 42s
  • Tokens: 63,825 (63,046 in / 779 out)
  • Cost: $0.56

View Task


💡 Next step: Comment /fix to address every F# merge blocker, /fix all for every pending blocker and suggestion, or name records explicitly, as in /fix F3 S5.
F# and S# IDs increment across review comments and remain permanent, so selectors such as /fix F3 F5 stay unambiguous across cycles. S# suggestions stay optional: they are implemented only when you name them or request /fix all, and they never relax a merge blocker.

Copy and edit to choose records from this review:

/fix S3 S4

🤖 Review by ProPR

@propr-dev propr-dev Bot removed the ultrafix label Nov 12, 2026
@integry
integry merged commit 58f293b into 3437-epic-cost-visibility-olu Nov 12, 2026
50 checks passed
@integry
integry deleted the 3438/claude-opus-5-5-metrics-and-llm-cost-expo-20261111-2357-0bs branch November 12, 2026 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant