AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Missing Language.PERL Separators And InMemoryCache Maxsize Update Bug

Two bugs are reported: (1) The Language.PERL enum is defined but not handled in get_separators_for_language, causing a ValueError when using RecursiveCharacterTextSplitter.from_language(Language.PERL). (2) InMemoryCache.update() evicts the oldest entry even when updating an existing key while the cache is at maxsize, leading to unnecessary cache misses.

mediumConfidence 85%LangchainChainsEmbeddingsAffected Vlangchain-Core==1.2.11Affected Vlangchain-Text-Splitters==1.2.11

Origin Analysis

The Language enum includes PERL, but the separator mapping function lacks a corresponding branch, causing a fall-through error. In InMemoryCache, the update method performs an unconditional eviction when the cache size equals maxsize, without checking whether the key already exists; thus updating an existing key incorrectly removes another entry.
1. Call RecursiveCharacterTextSplitter.from_language(Language.PERL, chunk_size=10, chunk_overlap=0) and observe ValueError. 2. Create InMemoryCache(maxsize=2), update with two distinct keys, then update one of those keys again. Check that the other key has been evicted unexpectedly.

Fixing Code Block

```python # Fix 1: Add PERL separator support in langchain_text_splitters/character.py # Inside get_separators_for_language, add the following branch: elif language == Language.PERL: return [ "\nsub ", "\npackage ", "\ndo ", "\neval ", "\n#", "\n//", "\n=cut", "\n__END__", "\n__DATA__", "\n=pod", ] # Fix 2: Modify InMemoryCache.update in langchain_core/caches.py # Replace the existing update method with: def update(self, prompt: str, llm_string: str, return_val: RETURN_VAL_TYPE) -> None: key = (prompt, llm_string) if key in self._cache: # Update existing entry without evicting others del self._cache[key] elif self._maxsize is not None and len(self._cache) >= self._maxsize: # Evict only when adding a new key and cache is full del self._cache[next(iter(self._cache))] self._cache[key] = return_val ```
For PERL, the added branch returns common Perl code separators (sub, package, do, eval, comments, POD markers) mirroring the approach used for other languages. For InMemoryCache, the updated method first checks if the key exists; if so, it removes and reinserts it to maintain LRU order without evicting other entries. Eviction only occurs when a new key is added and the cache is at capacity.

Edge Case Audit

The PERL separator list may not cover all Perl code styles (e.g., anonymous subs, one-liners) and could affect chunking granularity. The InMemoryCache change preserves data but alters eviction timing; code relying on the old buggy behavior may behave differently. Rollback is straightforward by reverting to the previous implementation or using a version prior to the fix.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state