@@ -62,7 +62,7 @@ export const SqlExecuteTool = Tool.define("sql_execute", {
6262 // but does NOT block execution. Used to measure catch rate before deciding
6363 // whether to enable blocking in a future release. Fire-and-forget so it
6464 // doesn't add latency to the sql_execute hot path.
65- preValidateSql ( args . query , args . warehouse , queryType ) . catch ( ( ) => { } )
65+ preValidateSql ( args . query , args . warehouse , queryType , ctx . workspaceId ) . catch ( ( ) => { } )
6666 // altimate_change end
6767
6868 try {
@@ -111,6 +111,7 @@ export const SqlExecuteTool = Tool.define("sql_execute", {
111111 type : "sql_fingerprint" ,
112112 timestamp : Date . now ( ) ,
113113 session_id : ctx . sessionID ,
114+ workspace_id : ctx . workspaceId ,
114115 statement_types : JSON . stringify ( fp . statement_types ) ,
115116 categories : JSON . stringify ( fp . categories ) ,
116117 table_count : fp . table_count ,
@@ -132,6 +133,7 @@ export const SqlExecuteTool = Tool.define("sql_execute", {
132133 if ( suggestion ) {
133134 output += "\n\n" + suggestion
134135 PostConnectSuggestions . trackSuggestions ( {
136+ workspaceId : ctx . workspaceId ,
135137 suggestionType : "progressive_disclosure" ,
136138 suggestionsShown : [ "sql_analyze" ] ,
137139 warehouseType : args . warehouse ?? "default" ,
@@ -179,6 +181,7 @@ async function preValidateSql(
179181 sql : string ,
180182 warehouse : string | undefined ,
181183 queryType : string ,
184+ workspaceId ?: number ,
182185) : Promise < PreValidationResult > {
183186 const startTime = Date . now ( )
184187 // Yield the event loop before heavy synchronous SQLite work so concurrent
@@ -208,6 +211,7 @@ async function preValidateSql(
208211 warehouse_type : warehouseType ,
209212 query_type : queryType ,
210213 masked_sql_hash : maskedSqlHash ,
214+ workspace_id : workspaceId ,
211215 }
212216
213217 if ( ! warehouseName ) {
@@ -301,7 +305,12 @@ async function preValidateSql(
301305 return { blocked : false }
302306 } catch {
303307 // Validation failure should never block execution
304- const ctx : TrackCtx = { warehouse_type : "unknown" , query_type : queryType , masked_sql_hash : maskedSqlHash }
308+ const ctx : TrackCtx = {
309+ warehouse_type : "unknown" ,
310+ query_type : queryType ,
311+ masked_sql_hash : maskedSqlHash ,
312+ workspace_id : workspaceId ,
313+ }
305314 trackPreValidation ( "error" , "validation_exception" , 0 , Date . now ( ) - startTime , false , ctx )
306315 return { blocked : false }
307316 }
@@ -311,6 +320,8 @@ interface TrackCtx {
311320 warehouse_type : string
312321 query_type : string
313322 masked_sql_hash : string
323+ /** The turn's workspace, named on the rows. */
324+ workspace_id ?: number
314325}
315326
316327function trackPreValidation (
@@ -330,6 +341,7 @@ function trackPreValidation(
330341 type : "sql_pre_validation" ,
331342 timestamp : Date . now ( ) ,
332343 session_id : Telemetry . getContext ( ) . sessionId ,
344+ workspace_id : ctx . workspace_id ,
333345 outcome,
334346 reason,
335347 warehouse_type : ctx . warehouse_type ,
0 commit comments