fix: prevent session context leakage by clearing Ollama KV cache on flush - #14673
Open
flysheep-ai wants to merge 1 commit into
Open
Conversation
…eakage When flushing the application cache, also send a POST to Ollama's /api/clear endpoint to purge the model's server-side KV cache. This prevents context from previous conversations or runs from leaking into new chat sessions. The Ollama host is read from the OLLAMA_HOST environment variable, defaulting to http://localhost:11434. If the Ollama server is unreachable or the request times out, a warning is logged but the flush operation continues — model cache clearing is best-effort and should never block the main cache flush.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LibreChat currently does not clear the Ollama model's server-side KV cache when flushing the application cache, leading to context bleeding between separate chat sessions. A user reported receiving responses containing context from a previous BAML test run after starting a new chat (issue #14669).
This fix extends the cache flushing script (
config/flush-cache.js) to also send a request to Ollama's/api/clearendpoint (if configured), ensuring the model's context cache is emptied alongside application caches.Changes
flushOllamaCache()function that sends a POST to Ollama's/api/clearendpointOLLAMA_HOSTenvironment variable (defaults tohttp://localhost:11434)Validation
--dry-run) shows the endpoint that would be called without making the request--verbose) logs the exact endpoint being contacted/api/clearcall simply fails gracefullyRisks
Closes #14669