Skip to content

Add retry and cache invalidation for Gemini AI services - #105

Merged
thomas-vilte merged 1 commit into
masterfrom
dev
Jul 29, 2026
Merged

Add retry and cache invalidation for Gemini AI services#105
thomas-vilte merged 1 commit into
masterfrom
dev

Conversation

@thomas-vilte

@thomas-vilte thomas-vilte commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Description

I implemented a retry mechanism for Gemini AI service calls (commit summarization, issue content generation, PR summarization, and release notes generation). This change addresses scenarios where the AI service returns an empty or malformed response, such as truncated JSON, which can occur due to network issues or incomplete generation.

To support this, I added an InvalidateCache method to the CostAwareWrapper and cache.go. This method allows the system to remove a problematic cached response immediately upon detecting an invalid AI output, ensuring that subsequent retries fetch a fresh response instead of repeatedly serving the bad cached data until its TTL expires. Each AI generation function now attempts to generate content up to two times, invalidating the cache if the first attempt yields an unusable response.

Fixes #

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

I added unit tests in internal/ai/gemini/release_generator_test.go to verify the retry logic. These tests cover cases where the AI initially returns truncated JSON but succeeds on a retry, and where it consistently returns malformed data, leading to the retry mechanism giving up.

  • Unit tests
  • Integration tests
  • Manual test: (describe below)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Test Plan & Evidence

Suggested Manual Verification

  • API/Backend: Attach JSON response or logs as evidence of correct behavior
  • Performance: Ensure no significant latency increase
  • Unit Tests: Run go test ./... and ensure all tests pass
  • No Regressions: Verify that related features still work as expected

@thomas-vilte thomas-vilte changed the title placeholder Add retry and cache invalidation for Gemini AI services Jul 29, 2026
@thomas-vilte thomas-vilte added feature New features test Testing, trials, and coverage labels Jul 29, 2026
@thomas-vilte
thomas-vilte merged commit 7a48df4 into master Jul 29, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New features test Testing, trials, and coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant