Repository navigation
AIML-358: Fix session metadata filtering 400 Bad Request error - #65
Merged
Merged
Conversation
The session metadata filtering feature was returning 400 Bad Request because the SDK was sending string field names (e.g., "branch") instead of numeric IDs (e.g., "87") that TeamServer expects. - Add ExtendedTraceFilterBody with fromWithSession() factory method - Add resolveSessionMetadataFieldId() to look up numeric ID from field name - Return user-friendly error if field name not found - Update tests to mock session metadata resolution
ChrisEdwards
requested review from
JacobMagesHaskinsContrast,
dougj-contrast and
seschis
January 9, 2026 16:02
JacobMagesHaskinsContrast
approved these changes
Jan 9, 2026
JacobMagesHaskinsContrast
left a comment
Collaborator
There was a problem hiding this comment.
One small idea. Otherwise, I think it looks ok
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The
search_app_vulnerabilitiestool was failing with HTTP 400 Bad Request errors when using session metadata filtering (sessionMetadataNameandsessionMetadataValueparameters).Root cause: The TeamServer API requires numeric field IDs for metadata filtering (e.g.,
"fieldID": "87"), but the tool was passing human-readable field names (e.g.,"fieldID": "branch").This blocked AI agents from using a key feature for filtering vulnerabilities by session metadata like branch name, commit hash, or build ID.
What
This PR:
/traces/{appId}/filterand/orgtraces/filterPOST endpoints withTraceFilterBodyinstead of deprecated GET endpoints with query parametersTraceFilterFormdefaulted totracked=true, filtering out untracked vulnerabilities. The newTraceFilterBodyuses primitive defaults (false,false) meaning "return all"How
1. Session Metadata Field Resolution (
SearchAppVulnerabilitiesTool.java)Added
resolveSessionMetadataFieldId()method that:getSessionMetadataForApplication()API to get available metadata fields2. POST Endpoint Migration (
SDKExtension.java)Added two new methods using body-based filtering:
getTraces()- For app-scoped vulnerability searchgetTracesInOrg()- For org-wide vulnerability searchThese use
TraceFilterBodywhich has the correct primitive defaults for tracked/untracked.3. Extended Filter Body (
ExtendedTraceFilterBody.java)New helper class that:
TraceFilterBodyagentSessionId,metadataFilters)4. Test Refactoring
Refactored tests to mock at the SDK boundary (HTTP layer) instead of internal SDK methods:
mockSdkWithTracesResponse()- MocksmakeRequestWithBody()to return JSON responsesTracesJsonFixture- Provides JSON fixtures for test responsesStep-by-Step Walkthrough
SDK Layer Changes
SDKExtension.java- AddedgetTraces()andgetTracesInOrg()methodsgetTraces()for app-scoped search with POST bodygetTracesInOrg()for org-wide search with POST bodytoExpandString()helper for expand query parameterExtendedTraceFilterBody.java(new file)TraceFilterBodywith session-aware factory methodfromWithSession()copies base filters and adds session paramsTool Layer Changes
SearchAppVulnerabilitiesTool.javaexecuteWithServerSidePagination()- non-session path using POSTexecuteWithInMemorySessionFiltering()- session path with field resolutionresolveSessionMetadataFieldId()- resolves field name to numeric IDSearchVulnerabilitiesTool.javaSDKExtension.getTracesInOrg()Params Layer Changes
VulnerabilityFilterParams.javatoTraceFilterBody()replaces deprecatedtoTraceFilterForm()SearchAppVulnerabilitiesParams.javatoTraceFilterBody()for base filterstoTraceFilterBodyWithSessionId()adds session paramsTest Changes
SearchAppVulnerabilitiesToolTest.javaSearchVulnerabilitiesToolTest.javaTracesJsonFixture.java(new file)singleTrace(),emptyTraces(),tracesWithTotal(), etc.ExtendedTraceFilterBodyTest.java(new file)SearchAppVulnerabilitiesToolIT.javaTesting
Unit Tests
should_pass_resolved_field_id_to_sdk- verifies numeric ID sentshould_return_error_when_field_name_not_found- verifies clear error messageshould_resolve_field_name_case_insensitively- verifies case-insensitive matchingIntegration Tests
searchAppVulnerabilities_should_support_sessionMetadataName_filter- verifies no 400 errorsearchAppVulnerabilities_should_return_error_for_invalid_sessionMetadataName- verifies error handlingManual Testing
Files Changed: 15 files (+1,163 / -190)