Skip to content

fix: tolerate unpickleable Redis cache entries#13166

Open
1507819106zxzx-crypto wants to merge 3 commits into
langflow-ai:mainfrom
1507819106zxzx-crypto:redis-cache-pickle-guard
Open

fix: tolerate unpickleable Redis cache entries#13166
1507819106zxzx-crypto wants to merge 3 commits into
langflow-ai:mainfrom
1507819106zxzx-crypto:redis-cache-pickle-guard

Conversation

@1507819106zxzx-crypto
Copy link
Copy Markdown

@1507819106zxzx-crypto 1507819106zxzx-crypto commented May 17, 2026

Summary

Fixes #8476.

Redis-backed cache writes can fail when a running graph or vertex cache entry contains runtime-only objects that dill cannot serialize, such as rich console thread locals or client SSL contexts. When Redis is configured as the cache backend, that serialization failure can bubble out of graph execution and fail otherwise valid flows.

This change:

  • reports Redis serialization failures before attempting the network write
  • keeps cache type metadata as a qualified type name instead of a Python class object
  • treats unpickleable external cache writes as cache misses rather than flow failures

Tests

  • uv run ruff check src/backend/base/langflow/services/cache/service.py src/backend/base/langflow/services/chat/service.py src/backend/tests/unit/services/cache/test_chat_cache.py
  • uv run pytest -p no:timeout src/backend/tests/unit/services/cache/test_chat_cache.py

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Enhanced cache serialization error handling with more informative error messages when caching operations fail
    • Improved reliability of chat data caching with better type metadata handling
    • Strengthened validation of cacheable data to prevent network errors
  • Tests

    • Added comprehensive unit test coverage for cache behavior validation

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 17, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 80de2582-3a0e-4857-825a-508cd21438f2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This PR adds robust error handling for cache serialization failures in Redis and chat services. RedisCache.set now explicitly catches serialization errors (TypeError, AttributeError, PicklingError) with descriptive messages. ChatService.set_cache stores type metadata as strings to avoid pickling type objects, and gracefully skips cache writes when serialization fails. Three new tests validate the type-metadata change, graceful failure, and early error detection.

Changes

Cache Serialization Error Handling

Layer / File(s) Summary
RedisCache serialization error handling
src/backend/base/langflow/services/cache/service.py
RedisCache.set now wraps dill.dumps(value, recurse=True) in explicit try/except capturing pickle.PicklingError, TypeError, and AttributeError; raises TypeError with value type and cache key for better diagnostics.
ChatService cache type metadata and error resilience
src/backend/base/langflow/services/chat/service.py
Adds internal helpers to compute type names as module-qualified strings and detect pickle-related TypeErrors. ChatService.set_cache stores type metadata as string (not raw type object), wraps cache upsert in try/except, and returns False with async warning on pickling failures instead of propagating exceptions.
Cache test module and validation
src/backend/tests/unit/services/cache/__init__.py, src/backend/tests/unit/services/cache/test_chat_cache.py
Test package initialization, async cache test doubles (RecordingAsyncCache, RejectingAsyncCache), and three test cases validating type-metadata string storage, graceful failure on unpickleable values, and early error detection before network calls.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 7 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Test Quality And Coverage ⚠️ Warning Tests cover main features but miss sync cache path, non-pickle TypeError handling, and direct testing of _is_pickle_error. Coverage is incomplete for implemented code paths. Add tests: (1) sync cache path, (2) non-pickle TypeError re-raise, (3) multiple error types in RedisCache, (4) _is_pickle_error helper function.
✅ Passed checks (7 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: tolerate unpickleable Redis cache entries' directly describes the main change: handling serialization failures in Redis cache by gracefully tolerating unpickleable values instead of crashing.
Linked Issues check ✅ Passed The PR successfully addresses issue #8476 by preventing cache serialization failures from breaking flow execution, storing type metadata as strings, and treating unpickleable cache writes as misses.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing Redis cache serialization: RedisCache error handling, ChatService type storage, related tests, and package initialization for tests.
Test Coverage For New Implementations ✅ Passed New test file test_chat_cache.py contains 3 unit tests covering all code changes with proper assertions and test fixtures, not placeholders.
Test File Naming And Structure ✅ Passed All criteria met: proper test_*.py naming, descriptive test names, pytest async markers, positive and negative scenario coverage, edge cases tested, proper helper classes and package structure.
Excessive Mock Usage Warning ✅ Passed No excessive mocks. Minimal test doubles at appropriate boundaries. Real dill serialization, error handling, and async execution tested. Uses actual rich.Console object from bug report.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the bug Something isn't working label May 17, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels May 17, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flows not working when using celery rabitmq and redis

2 participants