@@ -15,6 +15,7 @@ import { isStickyEnabled, getStickyBinding, setStickyBinding, clearStickyBinding
1515import { isExperimentalEnabled } from './runtime-config.js' ;
1616import { readFileSync , writeFileSync , existsSync , unlinkSync , readdirSync } from 'fs' ;
1717import { config , log } from './config.js' ;
18+ import { safeAccountRef } from './log-safety.js' ;
1819import { renameSyncWithRetry } from './fs-atomic.js' ;
1920import { getEffectiveProxy } from './dashboard/proxy-config.js' ;
2021import { getTierModels , getModelKeysByEnum , MODELS , registerDiscoveredFreeModel } from './models.js' ;
@@ -429,7 +430,7 @@ export function addAccountByKey(apiKey, label = '', apiServerUrl = '') {
429430 account . credits = null ;
430431 accounts . push ( account ) ;
431432 saveAccounts ( ) ;
432- log . info ( `Account added: ${ account . id } ( ${ account . email } ) [api_key]` ) ;
433+ log . info ( `Account added: ${ safeAccountRef ( account ) } [api_key]` ) ;
433434 return account ;
434435}
435436
@@ -462,7 +463,7 @@ export async function addAccountByToken(token, label = '') {
462463 } ;
463464 accounts . push ( account ) ;
464465 saveAccounts ( ) ;
465- log . info ( `Account added: ${ account . id } ( ${ account . email } ) [token] server=${ account . apiServerUrl } ` ) ;
466+ log . info ( `Account added: ${ safeAccountRef ( account ) } [token] server=${ account . apiServerUrl } ` ) ;
466467 return account ;
467468}
468469
@@ -507,7 +508,7 @@ export async function addAccountByEmail(email, password) {
507508 } ) ;
508509 }
509510 saveAccounts ( ) ;
510- log . info ( `Account added via email: ${ account . id } ( ${ account . email } ) ` ) ;
511+ log . info ( `Account added via email: ${ safeAccountRef ( account ) } ` ) ;
511512 return account ;
512513}
513514
@@ -666,7 +667,7 @@ export function removeAccount(id) {
666667 // Drop any Cascade conversations owned by this key so future requests
667668 // don't try to resume on an account that no longer exists.
668669 import ( './conversation-pool.js' ) . then ( m => m . invalidateFor ( { apiKey : account . apiKey } ) ) . catch ( ( ) => { } ) ;
669- log . info ( `Account removed: ${ id } ( ${ account . email } ) ` ) ;
670+ log . info ( `Account removed: ${ safeAccountRef ( account ) } ` ) ;
670671 return true ;
671672}
672673
@@ -883,7 +884,7 @@ function startInflightCleanup() {
883884 const now = Date . now ( ) ;
884885 for ( const a of accounts ) {
885886 if ( ( a . _inflight || 0 ) > 0 && a . _inflightAt && ( now - a . _inflightAt ) > INFLIGHT_STALE_MS ) {
886- log . warn ( `Account ${ a . id } ( ${ a . email } ) inflight=${ a . _inflight } stale >${ Math . round ( ( now - a . _inflightAt ) / 1000 ) } s, auto-resetting` ) ;
887+ log . warn ( `Account ${ safeAccountRef ( a ) } inflight=${ a . _inflight } stale >${ Math . round ( ( now - a . _inflightAt ) / 1000 ) } s, auto-resetting` ) ;
887888 a . _inflight = 0 ;
888889 a . _inflightAt = 0 ;
889890 }
@@ -1061,10 +1062,10 @@ export function markRateLimited(apiKey, durationMs = 5 * 60 * 1000, modelKey = n
10611062 if ( modelKey ) {
10621063 if ( ! account . _modelRateLimits ) account . _modelRateLimits = { } ;
10631064 account . _modelRateLimits [ modelKey ] = Math . max ( account . _modelRateLimits [ modelKey ] || 0 , until ) ;
1064- log . warn ( `Account ${ account . id } ( ${ account . email } ) rate-limited on ${ modelKey } for ${ Math . round ( safeMs / 60000 ) } min` ) ;
1065+ log . warn ( `Account ${ safeAccountRef ( account ) } rate-limited on ${ modelKey } for ${ Math . round ( safeMs / 60000 ) } min` ) ;
10651066 } else {
10661067 account . rateLimitedUntil = Math . max ( account . rateLimitedUntil || 0 , until ) ;
1067- log . warn ( `Account ${ account . id } ( ${ account . email } ) rate-limited (all models) for ${ Math . round ( safeMs / 60000 ) } min` ) ;
1068+ log . warn ( `Account ${ safeAccountRef ( account ) } rate-limited (all models) for ${ Math . round ( safeMs / 60000 ) } min` ) ;
10681069 }
10691070}
10701071
@@ -1105,7 +1106,7 @@ export function reportError(apiKey) {
11051106 account . errorCount ++ ;
11061107 if ( account . errorCount >= 3 ) {
11071108 account . status = 'error' ;
1108- log . warn ( `Account ${ account . id } ( ${ account . email } ) disabled after ${ account . errorCount } errors` ) ;
1109+ log . warn ( `Account ${ safeAccountRef ( account ) } disabled after ${ account . errorCount } errors` ) ;
11091110 }
11101111}
11111112
@@ -1141,7 +1142,7 @@ export function reportInternalError(apiKey) {
11411142 account . internalErrorStreak = ( account . internalErrorStreak || 0 ) + 1 ;
11421143 if ( account . internalErrorStreak >= 2 ) {
11431144 account . rateLimitedUntil = Date . now ( ) + 5 * 60 * 1000 ;
1144- log . warn ( `Account ${ account . id } ( ${ account . email } ) quarantined 5min after ${ account . internalErrorStreak } consecutive upstream internal errors` ) ;
1145+ log . warn ( `Account ${ safeAccountRef ( account ) } quarantined 5min after ${ account . internalErrorStreak } consecutive upstream internal errors` ) ;
11451146 }
11461147}
11471148
@@ -1194,13 +1195,13 @@ export function reportBanSignal(apiKey, message, { windowMs = 30 * 60 * 1000 } =
11941195 account . _banSignalAt = now ;
11951196 account . _banSignalCount = ( now - last < windowMs ) ? ( account . _banSignalCount || 0 ) + 1 : 1 ;
11961197 account . _banSignalLastMessage = String ( message || '' ) . slice ( 0 , 240 ) ;
1197- log . warn ( `Account ${ account . id } ( ${ account . email } ) emitted ban-shaped error #${ account . _banSignalCount } : "${ account . _banSignalLastMessage } "` ) ;
1198+ log . warn ( `Account ${ safeAccountRef ( account ) } emitted ban-shaped error #${ account . _banSignalCount } : "${ account . _banSignalLastMessage } "` ) ;
11981199 if ( account . _banSignalCount >= 2 ) {
11991200 account . status = 'banned' ;
12001201 account . bannedAt = now ;
12011202 account . bannedReason = account . _banSignalLastMessage ;
12021203 saveAccounts ( ) ;
1203- log . error ( `Account ${ account . id } ( ${ account . email } ) marked BANNED after ${ account . _banSignalCount } ban-shaped errors` ) ;
1204+ log . error ( `Account ${ safeAccountRef ( account ) } marked BANNED after ${ account . _banSignalCount } ban-shaped errors` ) ;
12041205 // Drop any cascade-pool entries owned by this key.
12051206 import ( './conversation-pool.js' ) . then ( m => m . invalidateFor ( { apiKey } ) ) . catch ( ( ) => { } ) ;
12061207 return true ;
@@ -1543,7 +1544,7 @@ export async function fetchUserStatus(id, { allowLsStart = true } = {}) {
15431544 try {
15441545 status = await client . getUserStatus ( ) ;
15451546 } catch ( err ) {
1546- log . warn ( `GetUserStatus ${ account . id } ( ${ account . email } ) failed: ${ err . message } ` ) ;
1547+ log . warn ( `GetUserStatus ${ safeAccountRef ( account ) } failed: ${ err . message } ` ) ;
15471548 return null ;
15481549 }
15491550
@@ -1593,9 +1594,9 @@ export async function fetchUserStatus(id, { allowLsStart = true } = {}) {
15931594 }
15941595
15951596 if ( prevTier !== account . tier ) {
1596- log . info ( `Tier change ${ account . id } ( ${ account . email } ) : ${ prevTier } → ${ account . tier } (plan="${ status . planName } ", ${ status . allowedModels . length } allowed models)` ) ;
1597+ log . info ( `Tier change ${ safeAccountRef ( account ) } : ${ prevTier } → ${ account . tier } (plan="${ status . planName } ", ${ status . allowedModels . length } allowed models)` ) ;
15971598 } else {
1598- log . info ( `UserStatus ${ account . id } ( ${ account . email } ) : tier=${ account . tier } plan="${ status . planName } " allowed=${ status . allowedModels . length } ` ) ;
1599+ log . info ( `UserStatus ${ safeAccountRef ( account ) } : tier=${ account . tier } plan="${ status . planName } " allowed=${ status . allowedModels . length } ` ) ;
15991600 }
16001601 saveAccounts ( ) ;
16011602 return status ;
@@ -1710,7 +1711,7 @@ async function _probeAccountImpl(account, { allowLsStart = true } = {}) {
17101711 } ) ;
17111712
17121713 if ( needsProbe . length > 0 ) {
1713- log . info ( `Probing account ${ account . id } ( ${ account . email } ) across ${ needsProbe . length } canary models (GetUserStatus ${ status ? 'OK' : 'unavailable' } )` ) ;
1714+ log . info ( `Probing ${ safeAccountRef ( account ) } across ${ needsProbe . length } canary models (GetUserStatus ${ status ? 'OK' : 'unavailable' } )` ) ;
17141715
17151716 for ( const modelKey of needsProbe ) {
17161717 const info = getModelInfo ( modelKey ) ;
@@ -1758,7 +1759,7 @@ async function _probeAccountImpl(account, { allowLsStart = true } = {}) {
17581759 } ) . slice ( 0 , MAX_CLOUD_PROBES ) ;
17591760
17601761 if ( cloudCandidates . length > 0 ) {
1761- log . info ( `Dynamic cloud probe: ${ cloudCandidates . length } candidates for ${ account . email } (cap=${ MAX_CLOUD_PROBES } )` ) ;
1762+ log . info ( `Dynamic cloud probe: ${ cloudCandidates . length } candidates for ${ safeAccountRef ( account ) } (cap=${ MAX_CLOUD_PROBES } )` ) ;
17621763 let rateLimited = false ;
17631764 for ( const modelKey of cloudCandidates ) {
17641765 if ( rateLimited ) break ;
@@ -2010,12 +2011,12 @@ async function refreshAllFirebaseTokens({ skipBusy = false } = {}) {
20102011 // Re-register to get a fresh API key (may be the same key)
20112012 const { apiKey } = await reRegisterWithCodeium ( idToken , proxy ) ;
20122013 if ( apiKey && apiKey !== a . apiKey ) {
2013- log . info ( `Firebase refresh: ${ a . email } got new API key` ) ;
2014+ log . info ( `Firebase refresh: ${ safeAccountRef ( a ) } got new API key` ) ;
20142015 a . apiKey = apiKey ;
20152016 }
20162017 saveAccounts ( ) ;
20172018 } catch ( e ) {
2018- log . warn ( `Firebase refresh ${ a . email } failed: ${ e . message } ` ) ;
2019+ log . warn ( `Firebase refresh ${ safeAccountRef ( a ) } failed: ${ e . message } ` ) ;
20192020 }
20202021 }
20212022}
0 commit comments