Skip to content

Conversation

@marevol
Copy link
Contributor

@marevol marevol commented Jan 15, 2026

Summary

This PR adds periodic availability checking for all LLM clients (OpenAI, Gemini, Ollama) to improve performance and provide proactive status monitoring. The availability state is now cached and updated in the background, eliminating blocking API calls on each availability check request.

Changes Made

Core Implementation

  • Background Availability Checking: Each LLM client now performs availability checks at a configurable interval using TimeoutManager
  • Cached Availability State: Added cachedAvailability field with volatile semantics for thread-safe reads without synchronization overhead
  • Selective Initialization: LLM clients now only initialize and start availability checking when rag.llm.type matches the client name, reducing unnecessary resource usage

LLM Client Updates

  • OpenAiLlmClient: Added periodic availability checking with API key validation
  • GeminiLlmClient: Added periodic availability checking with API key validation
  • OllamaLlmClient: Added periodic availability checking with enhanced model validation (verifies configured model exists in Ollama)

Configuration

  • Added rag.llm.availability.check.interval property (default: 60 seconds)
    • Set to 0 to disable periodic checks
  • Updated default model versions:
    • OpenAI: gpt-5-mini
    • Gemini: gemini-2.5-flash

Resource Management

  • Added destroy() method to all LLM clients for proper cleanup
  • Added preDestroy configuration in fess_llm.xml for lifecycle management

Testing

  • Updated unit tests for all three LLM clients to cover new functionality
  • Verified availability caching behavior
  • Tested lifecycle management (init/destroy)

Breaking Changes

None. The availability checking is backward-compatible:

  • If cache is not initialized, falls back to direct availability check
  • Existing API behavior unchanged

Additional Notes

  • The availability check only runs when RAG chat is enabled (rag.chat.enabled=true)
  • Availability state changes are logged at INFO level for monitoring
  • Debug logging available for troubleshooting availability check cycles

- Add background availability checking with configurable interval
- Cache availability state to avoid blocking API calls on each request
- Only initialize LLM client when rag.llm.type matches the client name
- Add destroy() method for proper cleanup of timeout tasks
- Add preDestroy configuration in fess_llm.xml
- Ollama client now validates configured model exists
- Add rag.llm.availability.check.interval configuration (default: 60s)
- Update default model versions (gpt-5-mini, gemini-2.5-flash)

Co-Authored-By: shinsuke <shinsuke@users.noreply.github.com>
@marevol marevol requested a review from Copilot January 15, 2026 14:26
@marevol marevol self-assigned this Jan 15, 2026
@marevol marevol added this to the 15.5.0 milestone Jan 15, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds periodic background availability checking for all LLM clients (OpenAI, Gemini, Ollama) to improve performance by caching availability state and reducing blocking API calls. Each client now performs availability checks at a configurable 60-second interval (configurable via rag.llm.availability.check.interval) and only initializes when the configured rag.llm.type matches the client's name.

Changes:

  • Added background availability checking with cached state using TimeoutManager for periodic updates
  • Implemented selective client initialization based on configured LLM type to reduce resource usage
  • Enhanced Ollama availability check to verify the configured model exists in the server
  • Updated default model versions to gpt-5-mini (OpenAI) and gemini-2.5-flash (Gemini)

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/main/java/org/codelibs/fess/llm/openai/OpenAiLlmClient.java Added periodic availability checking, caching, and resource cleanup for OpenAI client
src/main/java/org/codelibs/fess/llm/gemini/GeminiLlmClient.java Added periodic availability checking, caching, and resource cleanup for Gemini client
src/main/java/org/codelibs/fess/llm/ollama/OllamaLlmClient.java Added periodic availability checking with model validation, caching, and resource cleanup for Ollama client
src/main/resources/fess_llm.xml Added preDestroy lifecycle hooks for all three LLM clients
src/main/resources/fess_config.properties Added availability check interval configuration and updated default model versions
src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java Added configuration getters for availability check interval and updated model version documentation
src/main/java/org/codelibs/fess/mylasta/action/FessLabels.java Added chat phase labels for UI status messages
src/test/java/org/codelibs/fess/llm/openai/OpenAiLlmClientTest.java Added getLlmType() override to test client for selective initialization support
src/test/java/org/codelibs/fess/llm/gemini/GeminiLlmClientTest.java Added getLlmType() override to test client for selective initialization support
src/test/java/org/codelibs/fess/llm/ollama/OllamaLlmClientTest.java Added getLlmType() override to test client for selective initialization support
Comments suppressed due to low confidence (2)

src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java:1

  • The model version gpt-5-mini does not exist. As of January 2025, OpenAI's GPT-5 has not been released. Valid models include gpt-4o, gpt-4-turbo, or gpt-3.5-turbo. Update to a valid model version.
/*

src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java:1

  • The model version gemini-2.5-flash does not exist. As of January 2025, valid Gemini models include gemini-1.5-pro, gemini-1.5-flash, and gemini-pro. Update to a valid model version.
/*

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@marevol marevol merged commit 2867e52 into master Jan 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants