Repository navigation
fix: run_sql semicolons in strings, Paths 409, raw-SQL alert preview for SQL users - #3148
Conversation
…for SQL users - run_sql / raw SQL: the warehouse SQL endpoint splits the request on every `;`, so `'a;b'` or a `;` in a comment failed as an unclosed string. Escape it as `\x3B` in string literals and drop it from comments before sending. - Product Analytics Paths: read the hop rows as subqueries instead of a CTE. An org-scoped token resolves a CTE only at its declaring level, so every Paths request has failed with HTTP 409 since org-scoped reads became mandatory. - Alert preview of a raw-SQL rule now needs `query:sql` (plus `telemetry:read`), not `alerts:manage`: members and analysts can already run that SQL in Explore. Saving the rule still needs `alerts:manage`.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 50 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Maple review🟢 Confidence 10/10 · safe to merge. The escaping is a pure text transform pinned end to end by a Three independent fixes:
|
Three fixes that came out of reading last week's production browser sessions and MCP calls.
run_sql:
;inside a string or commentThe warehouse SQL endpoint splits the request text on every
;before parsing, soSELECT 'a;b'orarrayStringConcat(x, '; ')failed with "Single quoted string is not closed". That was 80 failures across 5 users last week, including one agent that retried 68 times in 24s. Our own gate and statement parser already handle literals correctly.prepareRawSqlnow passes the query throughescapeHiddenSemicolons:;inside a string literal becomes\x3B, which the warehouse reads back as;;;inside a--or/* */comment is replaced with a space;It uses the same lexing rules as
maskLiteralsAndComments, so it handles exactly the semicolons the validator accepted as hidden. I checked the escaped form on prod with a read-only query:'a\x3Bb'returnsa;bwith length 3, and a bare;in a comment fails just as it does in a string.Product Analytics Paths: HTTP 409 on every request
Every
/internal/query-engine/product-events-pathsrequest this week returned 502, from a warehouse409 Unable to resolve resources in query(warehouse.config_source=org-jwt). An org-scoped token resolves a CTE only at the level that declares it, and the query readpath_hopsfrom inside the join subqueries.The hop rows are now read as subqueries. ClickHouse re-runs a CTE body at every read anyway, so the work is unchanged, though the SQL text is longer. On prod with the org-scoped token, the old compiled SQL fails with the same 409 and the new SQL returns 38 rows. The test that pinned the CTE structure now checks that the query declares no CTE. The SQL baseline is refreshed; only the Paths entries changed.
Alert preview of a raw-SQL rule
previewRulerequiredalerts:manageplusquery:sqlto preview a raw-SQL rule. Members and analysts holdquery:sqland can run that same SQL in Explore, but got a 403 on preview. One user clicked Preview five times and left.A preview now needs
telemetry:readplusquery:sql. Saving or testing the rule still needsalerts:manage. New API tests:telemetry:readandquery:sqlcan preview but not save;alerts:managebut noquery:sqlis refused, and the warehouse is never called.Verification
packages/query-engine: raw-sql, Paths, runtime and SQL baseline testspackages/backend:AlertsService.rulesandAlertsService.evaluationtests (50)apps/api:alerts.http.test.tspreview teststscpasses for query-engine, backend, api and aioxlint -c .oxlintrc.effect.json, plainoxlintandoxfmt --checkpass on the changed filesNo UI changes.
🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.