Skip to content

fix(mcp): Validate negative durations in search_traces (#8856)#8962

Open
ParthKadam11 wants to merge 2 commits into
jaegertracing:mainfrom
ParthKadam11:fix-mcp-negative-duration-validation
Open

fix(mcp): Validate negative durations in search_traces (#8856)#8962
ParthKadam11 wants to merge 2 commits into
jaegertracing:mainfrom
ParthKadam11:fix-mcp-negative-duration-validation

Conversation

@ParthKadam11

Copy link
Copy Markdown

Which problem is this PR solving?

Description of the changes

  • Added validation for negative duration_min values in search_traces — returns "invalid duration_min: duration cannot be negative" instead of silently accepting it
  • Added validation for negative duration_max values in search_traces — returns "invalid duration_max: duration cannot be negative" instead of silently accepting it
  • Validations run immediately after time.ParseDuration succeeds, before any other duration comparisons

How was this change tested?

  • Added TestSearchTracesHandler_Handle_DurationValidation — a table-driven test with 8 cases:
  • Negative duration_min only, negative duration_max only, both negative
  • Valid ranges, zero durations, duration_max < duration_min (existing check still works)
  • Single-sided inputs (only min or only max provided)
  • All 8 cases pass; ran make lint test successfully

Checklist

AI Usage in this PR

  • Light: AI provided minor assistance (formatting, simple suggestions)

Copilot AI review requested due to automatic review settings July 7, 2026 11:08
@ParthKadam11
ParthKadam11 requested a review from a team as a code owner July 7, 2026 11:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses #8856 by adding explicit validation to the search_traces MCP handler so negative duration_min / duration_max inputs are rejected immediately, preventing “impossible” duration filters from reaching the storage query layer.

Changes:

  • Reject negative duration_min values with invalid duration_min: duration cannot be negative after successful parsing.
  • Reject negative duration_max values with invalid duration_max: duration cannot be negative after successful parsing.
  • Add a table-driven unit test covering negative durations, valid ranges, single-sided inputs, zero durations, and the existing duration_max < duration_min check.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
cmd/jaeger/internal/extension/jaegerquery/internal/mcptools/internal/handlers/search_traces.go Adds fail-fast validation for negative parsed durations before comparing min/max or executing queries.
cmd/jaeger/internal/extension/jaegerquery/internal/mcptools/internal/handlers/search_traces_test.go Adds a table-driven test exercising negative duration validation and confirming existing duration ordering validation still triggers.

…#8856)

Signed-off-by: Parth Kadam <parthkadamalt@gmail.com>
@ParthKadam11
ParthKadam11 force-pushed the fix-mcp-negative-duration-validation branch from 53f3c48 to a719dcc Compare July 7, 2026 11:28
Copilot AI review requested due to automatic review settings July 26, 2026 18:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

[Bug]: search_traces MCP tool does not validate against negative time durations

2 participants