Conversation
…rialization (CLI-FA) Two fixes for the CLI-FA issue group (95 users, 1589 events): 1. Search query auto-repair: When the PEG parser fails on a malformed query, tryRepairQuery attempts common fixes before passing through to the API: - Trailing commas in in-list filters: key:[a,b,] → key:[a,b] - Wrong closing delimiter: key:[a,b,) → key:[a,b] This prevents cryptic 400 Bad Request errors from the API when the user's intent is clear (common with AI agents constructing queries). 2. Telemetry tag serialization: setFlagContext now JSON-serializes object values (like TimeRange) instead of producing '[object Object]' via String(). Arrays still serialize as comma-separated for backwards compat.
Contributor
|
Contributor
Codecov Results 📊✅ 6244 passed | Total: 6244 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
All tests are passing successfully. ❌ Patch coverage is 71.43%. Project has 13048 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 75.99% 75.90% -0.09%
==========================================
Files 293 293 —
Lines 54000 54138 +138
Branches 0 0 —
==========================================
+ Hits 41036 41090 +54
- Misses 12964 13048 +84
- Partials 0 0 —Generated by Codecov Action |
The PEG parser accepts trailing commas before ] (valid syntax), so only the wrong-delimiter case (,) triggers auto-repair. Updated tests to reflect actual behavior. Addresses Seer and Cursor Bugbot review comments.
Ensures false would serialize as 'false' not 'true' if the caller ever passes it through. Addresses Cursor Bugbot low-severity finding.
Exclude '[' from the capture group so the in-list repair regex doesn't greedily match past a second filter's opening bracket. Addresses Cursor Bugbot medium-severity finding.
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d728f30. Configure here.
Move log.warn after parse(repaired) confirms the repair produced valid syntax. Prevents misleading warnings when the repair didn't actually help. Addresses Cursor Bugbot low-severity finding.
BYK
added a commit
that referenced
this pull request
Apr 29, 2026
… query repair (CLI-FA) (#880) ## Summary Follow-up to #872 — replaces the specific `tryRepairQuery` (single regex, catch-block-only) with a generic `normalizeQuery` pipeline that runs **before** PEG parsing on every query. ## What changed ### Before (PR #872) - `tryRepairQuery` only ran when PEG parsing failed (catch block) - Single regex for `[a,b,)` → `[a,b]` - Couldn't fix patterns that PEG parses but the API rejects (e.g., `[a,b,]`) ### After (this PR) - `normalizeQuery` runs on **every query** before PEG parsing — cheap string ops - Pipeline of focused transform functions: 1. `fixMismatchedBrackets`: `[a,b,)` → `[a,b]` (wrong closing delimiter) 2. `stripTrailingListCommas`: `[a,b,]` → `[a,b]` (balanced bracket trailing comma) 3. Whitespace collapse: double spaces → single, trim edges - Architecture makes it easy to add more passes without growing complexity ### Why pre-parse? Only 1 of the observed CLI-FA patterns actually fails PEG parsing — the rest parse fine but the Sentry API rejects them semantically. Running normalization before parsing catches both syntactic and PEG-valid-but-API-invalid patterns. ## Tests - 62 tests: unit tests for each normalizer (brackets, commas, whitespace, passthrough, cross-boundary safety) - Integration tests verifying the full `sanitizeQuery` → `normalizeQuery` → PEG parse flow - Property tests still pass
5 tasks
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.

Summary
Investigation of actual CLI-FA events revealed the 400 Bad Request errors are caused by:
error.http.status_code:[401,403,429,500,)(trailing comma + wrong closing delimiter)[object Object]in telemetry tags —TimeRangeobjects were serialized viaString()instead of JSONChanges
Search query auto-repair (
src/lib/search-query.ts)tryRepairQuery()attempts common fixes before passing through to the APIkey:[a,b,]→key:[a,b]) and wrong closing delimiters (key:[a,b,)→key:[a,b])Telemetry fix (
src/lib/telemetry.ts)flagValueToTag()now JSON-serializes non-array objects to avoid[object Object]flag.periodnow shows{"type":"relative","period":"90d"}instead of[object Object]Tests
tryRepairQueryunit behaviorsanitizeQueryrepairs and returns the fixed queryFixes https://sentry.sentry.io/issues/7341195391/