@@ -356,8 +356,11 @@ func generateMessage(ctx context.Context, provider llm.Provider, changes string,
356356func generateMessageWithCache (ctx context.Context , provider llm.Provider , store * store.StoreMethods , providerType types.LLMProvider , changes string , opts * types.GenerationOptions ) (string , error ) {
357357 startTime := time .Now ()
358358
359+ // Determine if this is a first attempt (cache check eligible)
360+ isFirstAttempt := opts == nil || opts .Attempt <= 1
361+
359362 // Check cache first (only for first attempt to avoid caching regenerations)
360- if opts == nil || opts . Attempt <= 1 {
363+ if isFirstAttempt {
361364 if cachedEntry , found := store .GetCachedMessage (providerType , changes , opts ); found {
362365 pterm .Info .Printf ("Using cached commit message (saved $%.4f)\n " , cachedEntry .Cost )
363366
@@ -369,6 +372,7 @@ func generateMessageWithCache(ctx context.Context, provider llm.Provider, store
369372 TokensUsed : 0 , // No tokens used for cached result
370373 Cost : 0 , // No cost for cached result
371374 CacheHit : true ,
375+ CacheChecked : true ,
372376 Timestamp : time .Now ().UTC ().Format (time .RFC3339 ),
373377 }
374378
@@ -398,6 +402,7 @@ func generateMessageWithCache(ctx context.Context, provider llm.Provider, store
398402 TokensUsed : inputTokens + outputTokens ,
399403 Cost : cost ,
400404 CacheHit : false ,
405+ CacheChecked : isFirstAttempt , // Only first attempts check cache
401406 Timestamp : time .Now ().UTC ().Format (time .RFC3339 ),
402407 }
403408
@@ -416,7 +421,7 @@ func generateMessageWithCache(ctx context.Context, provider llm.Provider, store
416421 }
417422
418423 // Cache the result (only for first attempt)
419- if opts == nil || opts . Attempt <= 1 {
424+ if isFirstAttempt {
420425 // Store in cache
421426 if cacheErr := store .SetCachedMessage (providerType , changes , opts , message , cost , nil ); cacheErr != nil {
422427 // Log cache error but don't fail the generation
0 commit comments