Fix safety finding leaks in LangChain cache wrappers and LlamaIndex streaming depth counters - #18
Merged
manas-fortifyroot merged 1 commit intoApr 3, 2026
Conversation
…h counter leak in LlamaIndex streaming wrappers LangChain: base_chat_model_generate_with_cache_wrapper and base_llm_generate_helper_wrapper were missing discard_deferred_findings(), allowing stale safety findings from a prior request on the same thread to leak into cached/helper response paths. Their non-cached counterparts already had this call. LlamaIndex: All 4 streaming wrappers (llm_stream_chat_wrapper, llm_astream_chat_wrapper, llm_stream_complete_wrapper, llm_astream_complete_wrapper) had _enter_safety() calls without guaranteed _exit_safety() on all code paths. If wrapped(), await, or LlamaIndexStreamingSafety() threw, the depth counter stayed elevated permanently, breaking safety for all subsequent requests on the thread. Restructured all 4 to use try/finally.
manas-fortifyroot
deleted the
fix/safety-deferred-findings-and-stream-depth-leak
branch
April 3, 2026 09:21
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
discard_deferred_findings()tobase_chat_model_generate_with_cache_wrapperandbase_llm_generate_helper_wrapper— stale findings from prior requests could leak into cached response pathsllm_stream_chat_wrapper,llm_astream_chat_wrapper,llm_stream_complete_wrapper,llm_astream_complete_wrapper) to usetry/finallyfor_exit_safety()— depth counter leaked permanently on exceptions, breaking safety for all subsequent requests on the threadFound during T6 SDK safety cassette test implementation (PE-level code review).
Test plan
./scripts/run-tests.sh --fr --package '*langchain*'— 23 passed./scripts/run-tests.sh --fr --package '*llamaindex*'— 54 passed