Skip to content

[jaegermcp] Fix searchDepth clamped to zero when maxResults is unlimited#8250

Closed
lopster568 wants to merge 1 commit intojaegertracing:mainfrom
lopster568:jaegermcp-fix-search-depth-clamp
Closed

[jaegermcp] Fix searchDepth clamped to zero when maxResults is unlimited#8250
lopster568 wants to merge 1 commit intojaegertracing:mainfrom
lopster568:jaegermcp-fix-search-depth-clamp

Conversation

@lopster568
Copy link
Copy Markdown
Contributor

Which problem is this PR solving?

Follow-up to #8242. When MaxSearchResults is 0 (unlimited), the searchDepth clamp incorrectly evaluates 10 > 0 as true and sets searchDepth to 0. This causes the storage query to request zero results even though the config intends no limit.

Description of the changes

One-line guard: if h.maxResults > 0 && searchDepth > h.maxResults

Without the guard, the default searchDepth of 10 is always clamped to 0 when maxResults is 0 (unlimited), making search_traces return empty results.

How was this change tested?

  • TestSearchTracesHandler_Handle_SearchDepthNotClampedWhenUnlimited — sets maxResults=0 with searchDepth=50, asserts the query receives searchDepth=50 unchanged
  • All existing tests pass
  • make fmt && make lint && make test — all green

Checklist

When MaxSearchResults is 0 (unlimited), the searchDepth clamp
`if searchDepth > h.maxResults` evaluates as `10 > 0 == true` and
sets searchDepth to 0. This causes the storage query to return no
results even though the config intends no limit.

Guard the clamp with `h.maxResults > 0` so that an unlimited config
preserves the requested or default search depth.

Found while reviewing jaegertracing#8242.

Signed-off-by: Roshan <rosh.s568@gmail.com>

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Roshan <rosh.s568@gmail.com>
Copilot AI review requested due to automatic review settings March 26, 2026 15:03
@lopster568 lopster568 requested a review from a team as a code owner March 26, 2026 15:03
@dosubot dosubot bot added the bug label Mar 26, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an edge case in the Jaeger MCP search_traces handler where searchDepth was incorrectly clamped to 0 when MaxSearchResults is set to 0 (intended as “unlimited”), causing storage queries to request zero results.

Changes:

  • Guard searchDepth clamping logic so it only applies when maxResults > 0.
  • Add a unit test ensuring searchDepth is not clamped when maxResults == 0.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
cmd/jaeger/internal/extension/jaegermcp/internal/handlers/search_traces.go Fixes clamping condition to avoid forcing searchDepth to 0 when maxResults is unlimited.
cmd/jaeger/internal/extension/jaegermcp/internal/handlers/search_traces_test.go Adds regression coverage for the unlimited (maxResults=0) case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +522 to +524
// When maxResults=0 (unlimited), searchDepth must not be clamped to 0
assert.Equal(t, 50, query.SearchDepth)
return func(yield func([]ptrace.Traces, error) bool) {
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

This test assumes maxResults=0 is a supported “unlimited” configuration, but the Jaeger MCP config currently validates max_search_results as range(1|1000) (so 0 would be rejected). Consider either (a) updating the config validation/docs to explicitly allow 0 for unlimited, or (b) adding a brief note here explaining why 0 is still a meaningful/possible value for searchTracesHandler.maxResults (e.g., internal usage) to avoid confusion for future maintainers.

Copilot uses AI. Check for mistakes.
@yurishkuro
Copy link
Copy Markdown
Member

When MaxSearchResults is 0 (unlimited)

Considering that we have config validation for it, what is the path for this value to be zero?

@github-actions github-actions bot added the waiting-for-author PR is waiting for author to respond to maintainer's comments label Mar 26, 2026
@lopster568
Copy link
Copy Markdown
Contributor Author

lopster568 commented Mar 26, 2026

You're right, config validation enforces range(1|1000) so MaxSearchResults can't be zero in production.

The zero path exists only in unit tests where handlers are constructed directly (e.g. &searchTracesHandler{maxResults: 0} in test struct literals). Without the guard, those tests would silently clamp searchDepth to 0 and pass vacuously. The guard makes the handler internally consistent regardless of how it's constructed, but I understand if you'd prefer to just not worry about test-only paths.

Happy to close this if you think it's not worth the churn.

@github-actions github-actions bot removed the waiting-for-author PR is waiting for author to respond to maintainer's comments label Mar 26, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.67%. Comparing base (8a4c314) to head (8c3ecc5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8250      +/-   ##
==========================================
+ Coverage   95.64%   95.67%   +0.03%     
==========================================
  Files         319      319              
  Lines       16804    16804              
==========================================
+ Hits        16072    16078       +6     
+ Misses        578      574       -4     
+ Partials      154      152       -2     
Flag Coverage Δ
badger_direct 9.06% <ø> (ø)
badger_e2e 1.04% <ø> (ø)
cassandra-4.x-direct-manual 13.25% <ø> (ø)
cassandra-4.x-e2e-auto 1.03% <ø> (ø)
cassandra-4.x-e2e-manual 1.03% <ø> (ø)
cassandra-5.x-direct-manual 13.25% <ø> (ø)
cassandra-5.x-e2e-auto 1.03% <ø> (ø)
cassandra-5.x-e2e-manual 1.03% <ø> (ø)
clickhouse 1.16% <ø> (ø)
elasticsearch-6.x-direct 16.84% <ø> (ø)
elasticsearch-7.x-direct 16.87% <ø> (ø)
elasticsearch-8.x-direct 17.02% <ø> (ø)
elasticsearch-8.x-e2e 1.04% <ø> (ø)
elasticsearch-9.x-e2e 1.04% <ø> (ø)
grpc_direct 7.79% <ø> (ø)
grpc_e2e 1.04% <ø> (ø)
kafka-3.x-v2 1.04% <ø> (ø)
memory_v2 1.04% <ø> (ø)
opensearch-1.x-direct 16.91% <ø> (ø)
opensearch-2.x-direct 16.91% <ø> (ø)
opensearch-2.x-e2e 1.04% <ø> (ø)
opensearch-3.x-e2e 1.04% <ø> (ø)
query 1.04% <ø> (ø)
tailsampling-processor 0.52% <ø> (ø)
unittests 94.37% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yurishkuro
Copy link
Copy Markdown
Member

production code should not be sanity-checking every single parameter at every single turn just because the unit tests might invoke internal functions.

@yurishkuro yurishkuro closed this Mar 26, 2026
@github-actions github-actions bot added the waiting-for-author PR is waiting for author to respond to maintainer's comments label Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug waiting-for-author PR is waiting for author to respond to maintainer's comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants