Skip to content

feat: add compare MCP trace metadata - #214

Merged
mohanagy merged 6 commits into
mainfrom
issue-162-mcp-trace-compare
May 19, 2026
Merged

mohanagy merged 6 commits into
mainfrom
issue-162-mcp-trace-compare

Conversation

@mohanagy

@mohanagy mohanagy commented May 19, 2026 •

Copy link
Copy Markdown
Owner

Closes #162

Summary

  • add optional graphify trace metadata to compare reports with safe tool-call counts and per-turn summaries
  • persist and summarize Graphify MCP/tool usage without storing raw tool payloads or prompt bodies
  • cover trace persistence, failed-run behavior, ordering, and summary output in compare tests

Test Plan

  • npm run typecheck
  • npm run build
  • npm run test:run

Summary by CodeRabbit

  • New Features

    • Terminal compare summaries show a compact "Graphify trace:" line with aggregated tool-call totals and top tools.
    • Compare reports persist compact trace metadata with per-turn tool usage summaries and aggregate statistics.
  • Documentation

    • Clarified that persisted trace metadata intentionally excludes raw tool inputs, prompts, and full payloads.
  • Tests

    • Added coverage ensuring traces are persisted in compact, redacted form and omitted when no trace data is present.

Review Change Stack

mohanagy and others added 5 commits May 19, 2026 00:30
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented May 19, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ff73fc58-bc2a-4681-97cd-25c54fb52d8d

📥 Commits

Reviewing files that changed from the base of the PR and between f001571 and 1b3073d.

📒 Files selected for processing (2)
  • src/infrastructure/compare.ts
  • tests/unit/compare.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/infrastructure/compare.ts

📝 Walkthrough

Walkthrough

Compare reports now capture and persist compact Graphify tool-call trace metadata: tool counts, tool names, and per-turn summaries extracted from Graphify runner stdout. Terminal compare output displays a single Graphify trace: summary line; raw payloads and full tool inputs are excluded from persisted trace data.

Changes

Graphify Trace Tracking and Reporting

Layer / File(s) Summary
Trace types and report schema
src/infrastructure/compare.ts
New CompareGraphifyTraceTurnSummary and CompareGraphifyTrace types define per-turn tool-call summaries and overall trace structure; ComparePromptReport extended with optional graphify_trace field; import of parsePromptRunnerJsonRecord added for JSON parsing.
Trace extraction and execution integration
src/infrastructure/compare.ts
Helper functions parse JSON records from Graphify stdout, iterate tool-use content parts, aggregate counts by tool name, and group calls by turn. In executeCompareRuns, trace extraction is attempted for Graphify executions; extracted trace persists to report.graphify_trace when available, and is deleted on errors or when absent.
Trace summary formatting and display
src/infrastructure/compare.ts
formatCompareGraphifyTraceSummary aggregates all question-level traces to compute total tool calls, turns, and top tools, returning a single formatted summary line; integrated into formatCompareSummary to append trace details to overall comparison output.
Test infrastructure and comprehensive coverage
tests/unit/compare.test.ts
New test helper makeClaudeStructuredCompareStdout constructs Claude structured stdout JSON with configurable usage and assistant_turns; new test case verifies graphify_trace persistence excludes raw payloads; existing runner mock reworked to use helper with structured assistant_turns containing tool_use events; assertions updated for trace content redaction, per-turn structure, summary formatting, and error cases.
Documentation and changelog
CHANGELOG.md, docs/benchmarks/govalidate-suite/README.md
Changelog notes compact compare trace summaries with single Graphify trace: line; docs explain graphify_trace object contents (aggregate counts, tool names, per-turn summaries), non-persistence of raw inputs/prompts, and terminal summary presentation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • mohanagy/graphify-ts#19: Adds provider usage fields to ComparePromptReport and formatCompareSummary, sharing the same compare report extraction and formatting pipeline.
  • mohanagy/graphify-ts#22: Modifies stdout parsing behavior in src/infrastructure/compare.ts by delegating to shared parsing utilities, overlapping with this PR's trace extraction changes.
  • mohanagy/graphify-ts#208: Extends ComparePromptReport output with persisted pack metadata, touching the same compare-report schema and serialization paths.

"🐰 A trace of tools we now keep,
Compact counts that insights reap,
No raw payloads, just the tale,
Of which MCP calls did prevail,
Compare reports now more precise—✨"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add compare MCP trace metadata' clearly and concisely summarizes the main change - adding trace metadata for MCP tool calls to compare reports.
Description check ✅ Passed The description covers the summary and test plan sections, with all test commands marked as completed. However, the checklist section is incomplete.
Linked Issues check ✅ Passed The PR successfully implements all acceptance criteria from issue #162: reports tool-call counts [src/infrastructure/compare.ts], records tool names and per-turn usage [src/infrastructure/compare.ts], persists compact trace metadata [ComparePromptReport.graphify_trace], keeps sensitive content out [src/infrastructure/compare.ts], and adds comprehensive tests [tests/unit/compare.test.ts].
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #162 requirements: CHANGELOG documents feature, README explains trace metadata, core implementation in compare.ts, and tests validate behavior per issue specifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-162-mcp-trace-compare

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/infrastructure/compare.ts`:
- Around line 716-721: The parseTraceTurnNumber function currently accepts any
positive number then truncates, allowing fractional inputs like 0.4/1.9 to
collapse to incorrect turns; change the validation to require a positive integer
(use Number.isInteger(value) && value > 0) and return the value directly instead
of truncating so fractional turn values are rejected and fallbackTurn is used
for non-integer or invalid inputs; update the function parseTraceTurnNumber
accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 066ba34c-79b0-49b0-8519-edc1f90cd321

📥 Commits

Reviewing files that changed from the base of the PR and between d3c1b56 and f001571.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • docs/benchmarks/govalidate-suite/README.md
  • src/infrastructure/compare.ts
  • tests/unit/compare.test.ts

Comment thread src/infrastructure/compare.ts Resolved
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mohanagy
mohanagy merged commit 0ffbfd5 into main May 19, 2026
7 checks passed
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.

[P1][Compare] Track MCP tool-call counts and trace summaries in compare reports

1 participant