Skip to content

Commit 37563d1

Browse files
fix: every emitter with a tool context or the loop's handle names the turn's workspace
`sql_fingerprint`, `sql_pre_validation`, `feature_suggestion`, `environment_census`, `filetime_drift`, `filetime_assert`, `review_run` and the processor's streaming `error` row carry it explicitly; `FileTime.read`/`assert` and the suggestion tracker take it from the tool context. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_011AhtJPr3nmT1Po92ZQk4VE
1 parent 9bfe318 commit 37563d1

17 files changed

Lines changed: 95 additions & 12 deletions

‎packages/opencode/src/altimate/review/telemetry.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ export function emitReviewRun(input: {
8181
durationMs: number
8282
/** Empty on the CLI path, which has no chat session. */
8383
sessionID: string
84+
/** The turn's workspace on the tool path; none on the CLI path. */
85+
workspaceId?: number
8486
envelope?: VerdictEnvelope
8587
error?: unknown
8688
}): void {
@@ -89,6 +91,7 @@ export function emitReviewRun(input: {
8991
type: "review_run" as const,
9092
timestamp: Date.now(),
9193
session_id: input.sessionID,
94+
workspace_id: input.workspaceId,
9295
invocation: input.invocation,
9396
duration_ms: input.durationMs,
9497
}

‎packages/opencode/src/altimate/telemetry/index.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ export namespace Telemetry {
342342
}
343343
| {
344344
type: "error"
345+
/** altimate_change — the turn's workspace, named by the emitter */
346+
workspace_id?: number
345347
timestamp: number
346348
session_id: string
347349
error_name: string
@@ -502,6 +504,8 @@ export namespace Telemetry {
502504
}
503505
| {
504506
type: "environment_census"
507+
/** altimate_change — the turn's workspace, named by the emitter */
508+
workspace_id?: number
505509
timestamp: number
506510
session_id: string
507511
warehouse_types: string[]
@@ -890,6 +894,8 @@ export namespace Telemetry {
890894
// altimate_change start — feature_suggestion event for post-connect and progressive disclosure tracking
891895
| {
892896
type: "feature_suggestion"
897+
/** altimate_change — the turn's workspace, named by the emitter */
898+
workspace_id?: number
893899
timestamp: number
894900
session_id: string
895901
suggestion_type: "post_warehouse_connect" | "dbt_detected" | "progressive_disclosure"
@@ -931,6 +937,8 @@ export namespace Telemetry {
931937
// KQL: customEvents | where name == "filetime_drift" | extend drift = todouble(customMeasurements.drift_ms)
932938
| {
933939
type: "filetime_drift"
940+
/** altimate_change — the turn's workspace, named by the emitter */
941+
workspace_id?: number
934942
timestamp: number
935943
session_id: string
936944
/** Absolute difference in ms between Date.now() and filesystem mtime */
@@ -943,6 +951,8 @@ export namespace Telemetry {
943951
// KQL: customEvents | where name == "filetime_assert" | extend delta = todouble(customMeasurements.delta_ms)
944952
| {
945953
type: "filetime_assert"
954+
/** altimate_change — the turn's workspace, named by the emitter */
955+
workspace_id?: number
946956
timestamp: number
947957
session_id: string
948958
outcome: "stale"
@@ -1030,6 +1040,8 @@ export namespace Telemetry {
10301040
// sql structure fingerprint — AST shape without content
10311041
| {
10321042
type: "sql_fingerprint"
1043+
/** altimate_change — the turn's workspace, named by the emitter */
1044+
workspace_id?: number
10331045
timestamp: number
10341046
session_id: string
10351047
/** JSON-encoded statement types, e.g. ["SELECT"] */
@@ -1095,6 +1107,8 @@ export namespace Telemetry {
10951107
// altimate_change start — pre-execution SQL validation telemetry
10961108
| {
10971109
type: "sql_pre_validation"
1110+
/** altimate_change — the turn's workspace, named by the emitter */
1111+
workspace_id?: number
10981112
timestamp: number
10991113
session_id: string
11001114
/** skipped = no cache or stale, passed = valid SQL, blocked = invalid SQL caught, error = validation itself failed */
@@ -1327,6 +1341,8 @@ export namespace Telemetry {
13271341
// ALTIMATE_CLI_CLIENT is already attributed.
13281342
| {
13291343
type: "review_run"
1344+
/** altimate_change — the turn's workspace, named by the emitter */
1345+
workspace_id?: number
13301346
timestamp: number
13311347
/** Real session on the tool path; empty for the CLI command, which has no chat session. */
13321348
session_id: string

‎packages/opencode/src/altimate/tools/dbt-pr-review.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const DbtPrReviewTool = Tool.define("dbt_pr_review", {
5656
invocation: "tool",
5757
durationMs: Date.now() - startedAt,
5858
sessionID: ctx.sessionID,
59+
workspaceId: ctx.workspaceId,
5960
error: err,
6061
})
6162
throw err
@@ -64,6 +65,7 @@ export const DbtPrReviewTool = Tool.define("dbt_pr_review", {
6465
invocation: "tool",
6566
durationMs: Date.now() - startedAt,
6667
sessionID: ctx.sessionID,
68+
workspaceId: ctx.workspaceId,
6769
envelope: env,
6870
})
6971
// altimate_change end

‎packages/opencode/src/altimate/tools/post-connect-suggestions.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,16 @@ export namespace PostConnectSuggestions {
119119
| "progressive_disclosure"
120120
suggestionsShown: string[]
121121
warehouseType?: string
122+
/** The turn's workspace, named on the row. */
123+
workspaceId?: number
122124
}): void {
123125
try {
124126
const sessionId = Telemetry.getContext().sessionId || "unknown-session"
125127
Telemetry.track({
126128
type: "feature_suggestion",
127129
timestamp: Date.now(),
128130
session_id: sessionId,
131+
workspace_id: opts.workspaceId,
129132
suggestion_type: opts.suggestionType,
130133
suggestions_shown: opts.suggestionsShown,
131134
warehouse_type: opts.warehouseType ?? "unknown",

‎packages/opencode/src/altimate/tools/project-scan.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ export const ProjectScanTool = Tool.define("project_scan", {
748748
try {
749749
const { PostConnectSuggestions } = await import("./post-connect-suggestions")
750750
PostConnectSuggestions.trackSuggestions({
751+
workspaceId: ctx.workspaceId,
751752
suggestionType: "dbt_detected",
752753
suggestionsShown: ["dbt-develop", "dbt-troubleshoot", "dbt-analyze"],
753754
})
@@ -894,6 +895,7 @@ export const ProjectScanTool = Tool.define("project_scan", {
894895
type: "environment_census",
895896
timestamp: Date.now(),
896897
session_id: Telemetry.getContext().sessionId,
898+
workspace_id: ctx.workspaceId,
897899
warehouse_types: warehouseTypes,
898900
warehouse_count: existingConnections.length,
899901
dbt_detected: dbtProject.found,

‎packages/opencode/src/altimate/tools/schema-index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const SchemaIndexTool = Tool.define("schema_index", {
2424
if (suggestion) {
2525
output += "\n\n" + suggestion
2626
PostConnectSuggestions.trackSuggestions({
27+
workspaceId: ctx.workspaceId,
2728
suggestionType: "progressive_disclosure",
2829
suggestionsShown: ["sql_analyze", "schema_inspect", "lineage_check"],
2930
warehouseType: result.type,

‎packages/opencode/src/altimate/tools/schema-inspect.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export const SchemaInspectTool = Tool.define("schema_inspect", {
6262
if (suggestion) {
6363
output += "\n\n" + suggestion
6464
PostConnectSuggestions.trackSuggestions({
65+
workspaceId: ctx.workspaceId,
6566
suggestionType: "progressive_disclosure",
6667
suggestionsShown: ["lineage_check"],
6768
warehouseType: args.warehouse ?? "unknown",

‎packages/opencode/src/altimate/tools/sql-analyze.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export const SqlAnalyzeTool = Tool.define("sql_analyze", {
5959
if (suggestion) {
6060
output += "\n\n" + suggestion
6161
PostConnectSuggestions.trackSuggestions({
62+
workspaceId: ctx.workspaceId,
6263
suggestionType: "progressive_disclosure",
6364
suggestionsShown: ["schema_inspect"],
6465
warehouseType: "unknown",

‎packages/opencode/src/altimate/tools/sql-execute.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

316327
function 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,

‎packages/opencode/src/altimate/tools/warehouse-add.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ IMPORTANT: For private key file paths, always use "private_key_path" (not "priva
109109
if (suggestionCtx.dbtDetected) suggestionsShown.push("dbt-develop", "dbt-troubleshoot")
110110
if (suggestionCtx.connectionCount > 1) suggestionsShown.push("data_diff")
111111
PostConnectSuggestions.trackSuggestions({
112+
workspaceId: ctx.workspaceId,
112113
suggestionType: "post_warehouse_connect",
113114
suggestionsShown,
114115
warehouseType: result.type,

0 commit comments

Comments
 (0)