@@ -1944,7 +1944,16 @@ export namespace Telemetry {
19441944 return { iKey, endpoint : `${ base } v2/track` }
19451945 }
19461946
1947- function toAppInsightsEnvelopes ( events : Event [ ] , cfg : AppInsightsConfig ) : object [ ] {
1947+ // altimate_change — `ids` lets a caller build envelopes for a machine and identity other than
1948+ // the module's current state (the opt-out marker runs while telemetry is disabled and must not
1949+ // touch the state an enabled init may be using concurrently).
1950+ function toAppInsightsEnvelopes (
1951+ events : Event [ ] ,
1952+ cfg : AppInsightsConfig ,
1953+ ids ?: { machineId : string ; identity : TelemetryIdentity . Identity | undefined } ,
1954+ ) : object [ ] {
1955+ const mid = ids ? ids . machineId : machineId
1956+ const who = ids ? ids . identity : identity
19481957 // Process-level client, read live from the env flag (defaults to "cli") so events
19491958 // emitted before any prompt runs — startup, connection setup, standalone CLI
19501959 // subcommands — are labelled correctly instead of stuck at a hardcoded default.
@@ -1961,10 +1970,10 @@ export namespace Telemetry {
19611970 cli_version : InstallationVersion ,
19621971 source : clientSource ,
19631972 project_id : fields . project_id ?? projectId ,
1964- ...( machineId && { machine_id : machineId } ) ,
1973+ ...( mid && { machine_id : mid } ) ,
19651974 // altimate_change — the backend user uuid and tenant when signed in to Altimate, so a CLI
19661975 // row joins the PostHog person and the backend record for the same account.
1967- ...( identity && { user_id : identity . user_id , tenant : identity . tenant } ) ,
1976+ ...( who && { user_id : who . user_id , tenant : who . tenant } ) ,
19681977 // altimate_change — groups every event from one process launch. The onboarding funnel
19691978 // spans the TUI main thread and the server worker, and most of it runs before any chat
19701979 // session exists, so `session_id` is empty for the first half and real for the second —
@@ -1992,7 +2001,7 @@ export namespace Telemetry {
19922001 // altimate_change start — the backend user uuid when signed in, else the machine id.
19932002 // Anonymous machines each keep a distinct identity (the random machine UUID, already a
19942003 // custom property) instead of sharing ai.user.id="". No email, hashed or not, is sent.
1995- "ai.user.id" : identity ?. user_id || machineId || "" ,
2004+ "ai.user.id" : who ?. user_id || mid || "" ,
19962005 // altimate_change end
19972006 "ai.cloud.role" : "altimate" ,
19982007 "ai.application.ver" : InstallationVersion ,
@@ -2185,14 +2194,11 @@ export namespace Telemetry {
21852194 const explicit = process . env . APPLICATIONINSIGHTS_CONNECTION_STRING
21862195 const cfg = parseConnectionString ( explicit ?? DEFAULT_CONNECTION_STRING )
21872196 if ( ! cfg ) return
2188- machineId = id
2189- identity = await TelemetryIdentity . cached ( )
21902197 const envelopes = toAppInsightsEnvelopes (
21912198 [ { type : "telemetry_opted_out" , timestamp : Date . now ( ) , opt_out_source : source } ] ,
21922199 cfg ,
2200+ { machineId : id , identity : await TelemetryIdentity . cached ( ) } ,
21932201 )
2194- machineId = ""
2195- identity = undefined
21962202 const controller = new AbortController ( )
21972203 const timeout = setTimeout ( ( ) => controller . abort ( ) , OPT_OUT_TIMEOUT_MS )
21982204 try {
@@ -2208,8 +2214,6 @@ export namespace Telemetry {
22082214 }
22092215 } catch {
22102216 // The opt-out path never surfaces: a missed marker only means one more attempt next launch.
2211- machineId = ""
2212- identity = undefined
22132217 }
22142218 }
22152219 // altimate_change end
0 commit comments