@@ -194,7 +194,7 @@ interface SessionLogData {
194194
195195class CopilotTokenTracker implements vscode . Disposable {
196196 // Cache version - increment this when making changes that require cache invalidation
197- private static readonly CACHE_VERSION = 7 ; // Fix JSONL model extraction for Today data (2026-01-30 )
197+ private static readonly CACHE_VERSION = 8 ; // Skip sessions with 0 models in avg calculation (2026-02-02 )
198198
199199 private diagnosticsPanel ?: vscode . WebviewPanel ;
200200 // Tracks whether the diagnostics panel has already received its session files
@@ -1104,38 +1104,42 @@ class CopilotTokenTracker implements vscode.Disposable {
11041104 } ;
11051105 }
11061106
1107- period . modelSwitching . totalSessions ++ ;
1108- period . modelSwitching . modelsPerSession . push ( analysis . modelSwitching . modelCount ) ;
1109-
1110- // Track unique models by tier
1111- for ( const model of analysis . modelSwitching . tiers . standard ) {
1112- if ( ! period . modelSwitching . standardModels . includes ( model ) ) {
1113- period . modelSwitching . standardModels . push ( model ) ;
1107+ // Only count sessions with at least 1 model detected for model switching stats
1108+ // Sessions without detected models (modelCount === 0) should not affect the average
1109+ if ( analysis . modelSwitching . modelCount > 0 ) {
1110+ period . modelSwitching . totalSessions ++ ;
1111+ period . modelSwitching . modelsPerSession . push ( analysis . modelSwitching . modelCount ) ;
1112+
1113+ // Track unique models by tier
1114+ for ( const model of analysis . modelSwitching . tiers . standard ) {
1115+ if ( ! period . modelSwitching . standardModels . includes ( model ) ) {
1116+ period . modelSwitching . standardModels . push ( model ) ;
1117+ }
11141118 }
1115- }
1116- for ( const model of analysis . modelSwitching . tiers . premium ) {
1117- if ( ! period . modelSwitching . premiumModels . includes ( model ) ) {
1118- period . modelSwitching . premiumModels . push ( model ) ;
1119+ for ( const model of analysis . modelSwitching . tiers . premium ) {
1120+ if ( ! period . modelSwitching . premiumModels . includes ( model ) ) {
1121+ period . modelSwitching . premiumModels . push ( model ) ;
1122+ }
11191123 }
1120- }
1121- for ( const model of analysis . modelSwitching . tiers . unknown ) {
1122- if ( ! period . modelSwitching . unknownModels . includes ( model ) ) {
1123- period . modelSwitching . unknownModels . push ( model ) ;
1124+ for ( const model of analysis . modelSwitching . tiers . unknown ) {
1125+ if ( ! period . modelSwitching . unknownModels . includes ( model ) ) {
1126+ period . modelSwitching . unknownModels . push ( model ) ;
1127+ }
1128+ }
1129+
1130+ // Count sessions with mixed tiers
1131+ if ( analysis . modelSwitching . hasMixedTiers ) {
1132+ period . modelSwitching . mixedTierSessions ++ ;
1133+ }
1134+
1135+ // Calculate aggregate statistics
1136+ if ( period . modelSwitching . modelsPerSession . length > 0 ) {
1137+ const counts = period . modelSwitching . modelsPerSession ;
1138+ period . modelSwitching . averageModelsPerSession = counts . reduce ( ( a , b ) => a + b , 0 ) / counts . length ;
1139+ period . modelSwitching . maxModelsPerSession = Math . max ( ...counts ) ;
1140+ period . modelSwitching . minModelsPerSession = Math . min ( ...counts ) ;
1141+ period . modelSwitching . switchingFrequency = ( counts . filter ( c => c > 1 ) . length / counts . length ) * 100 ;
11241142 }
1125- }
1126-
1127- // Count sessions with mixed tiers
1128- if ( analysis . modelSwitching . hasMixedTiers ) {
1129- period . modelSwitching . mixedTierSessions ++ ;
1130- }
1131-
1132- // Calculate aggregate statistics
1133- if ( period . modelSwitching . modelsPerSession . length > 0 ) {
1134- const counts = period . modelSwitching . modelsPerSession ;
1135- period . modelSwitching . averageModelsPerSession = counts . reduce ( ( a , b ) => a + b , 0 ) / counts . length ;
1136- period . modelSwitching . maxModelsPerSession = Math . max ( ...counts ) ;
1137- period . modelSwitching . minModelsPerSession = Math . min ( ...counts ) ;
1138- period . modelSwitching . switchingFrequency = ( counts . filter ( c => c > 1 ) . length / counts . length ) * 100 ;
11391143 }
11401144 }
11411145
0 commit comments