Skip to content

fix: tolerate unpickleable Redis cache values#13170

Open
jynbil1 wants to merge 6 commits into
langflow-ai:mainfrom
jynbil1:fix/tolerate-unpickleable-redis-cache
Open

fix: tolerate unpickleable Redis cache values#13170
jynbil1 wants to merge 6 commits into
langflow-ai:mainfrom
jynbil1:fix/tolerate-unpickleable-redis-cache

Conversation

@jynbil1
Copy link
Copy Markdown

@jynbil1 jynbil1 commented May 18, 2026

Fixes #8476.

Summary

  • make Redis cache serialization failures explicit for TypeError/AttributeError/PicklingError before network writes
  • keep chat cache type metadata as a string and treat pickle-only cache write failures as cache misses
  • apply the same non-fatal cache-write handling to session cache writes so graph execution can continue when Redis cannot serialize runtime objects
  • add regression coverage for async chat cache, sync chat cache, session cache, load-session fallback, unrelated TypeError re-raise, and Redis pre-network serialization failure

Validation

  • uv run ruff check src/backend/base/langflow/services/cache/service.py src/backend/base/langflow/services/cache/utils.py src/backend/base/langflow/services/chat/service.py src/backend/base/langflow/services/session/service.py src/backend/tests/unit/services/test_cache_serialization.py
  • uv run pytest src/backend/tests/unit/services/test_cache_serialization.py
  • git diff --check

Summary by CodeRabbit

  • Chores

    • Updated langchain_core dependency to version 1.4.0 across all starter projects.
  • Bug Fixes

    • Improved cache reliability with enhanced error handling and recovery mechanisms for serialization failures, ensuring smoother operation when caching encounters issues.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 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: 78503235-9a02-4b91-8e78-26bf513ead26

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 improves cache serialization robustness to address Celery/Redis deployment failures when flows contain unpickleable objects. Serialization errors are now caught at the Redis level, classified for error-specific handling in ChatService and SessionService, and gracefully degraded (cache write skipped, warning logged). The PR also bumps langchain_core from 1.3.2 to 1.4.0 across 18 starter projects.

Changes

Cache Serialization Resilience

Layer / File(s) Summary
Redis Cache Validation and Error Detection
src/backend/base/langflow/services/cache/service.py, src/backend/base/langflow/services/cache/utils.py
RedisCache.set now serializes explicitly via dill.dumps with comprehensive exception handling for serialization failures, empty data, and Redis write failures. New is_cache_serialization_error utility classifies TypeError messages to distinguish pickle-related failures from unrelated errors by checking for "pickle" or "pickled" substrings.
Chat Service Cache Resilience
src/backend/base/langflow/services/chat/service.py
ChatService.set_cache stores cached payloads with string type metadata via _cache_type_name utility instead of raw class objects. Cache write path is wrapped in TypeError handling: serialization-related failures are logged and return False, enabling graceful fallback; unrelated TypeErrors are re-raised.
Session Service Cache Resilience
src/backend/base/langflow/services/session/service.py
SessionService introduces _set_cache_value helper for unified async/sync cache writes with serialization error handling. Both load_session and update_session now delegate through this helper, which skips cache writes and logs warnings on serialization failures, allowing sessions to load even with unpickleable state.
Test Infrastructure and Fakes
src/backend/tests/unit/services/test_cache_serialization.py (imports and helpers)
Defines async/sync cache service test doubles (RecordingAsyncCache, RejectingAsyncCache, RecordingSyncCache, RejectingSyncCache), UnpickleableValue type for triggering serialization failures, and make_chat_service helper for test dependency injection.
Cache Serialization Test Suite
src/backend/tests/unit/services/test_cache_serialization.py (test functions)
Comprehensive tests validating ChatService type name storage and pickle failure handling (async/sync paths), SessionService graceful degradation during update_session and load_session, and RedisCache early rejection of unpickleable values before network calls.

Starter Projects Dependency Bump

Layer / File(s) Summary
Starter Project langchain_core Updates
src/backend/base/langflow/initial_setup/starter_projects/*.json
Consistent version bump of langchain_core from 1.3.2 to 1.4.0 in Agent, File, ApifyActors, MCPTools, and YfinanceComponent nodes across 18 starter project definitions. Each file receives 1–4 dependency version updates matching the components present in that flow.

Sequence Diagram

sequenceDiagram
  participant Caller
  participant ChatService
  participant CacheService
  participant Dill
  participant Logger
  Caller->>ChatService: set_cache(key, data)
  ChatService->>ChatService: type_name = _cache_type_name(data)
  ChatService->>CacheService: upsert(key, {type: type_name, ...})
  alt Pickle/Serialization TypeError
    CacheService->>Dill: dumps(data)
    Dill-->>CacheService: PicklingError or TypeError
    CacheService-->>ChatService: TypeError
    ChatService->>Logger: awarning(pickle error)
    ChatService-->>Caller: False
  else Success
    CacheService->>Dill: dumps(data)
    Dill-->>CacheService: pickled bytes
    CacheService->>CacheService: store in memory/Redis
    CacheService-->>ChatService: success
    ChatService->>CacheService: contains(key)
    ChatService-->>Caller: cache_updated boolean
  else Unrelated TypeError
    CacheService-->>ChatService: TypeError
    ChatService-->>Caller: re-raise
  end
Loading

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 8 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (8 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: making the system tolerate unpickleable Redis cache values by handling serialization failures gracefully.
Linked Issues check ✅ Passed The PR fully addresses issue #8476 by implementing error handling for unpickleable Redis values, treating serialization failures as non-fatal cache misses so flows continue execution.
Out of Scope Changes check ✅ Passed All changes are in-scope: cache serialization error handling, chat/session cache tolerance logic, and corresponding tests. Version bumps in starter projects are unrelated but minimal and acceptable.
Test Coverage For New Implementations ✅ Passed Test file test_cache_serialization.py with 8 tests covers cache serialization error handling. Tests follow naming conventions and use proper assertions.
Test Quality And Coverage ✅ Passed 8 async tests cover type caching, pickle handling, graceful degradation. Proper patterns, behavior validation, and all required paths tested.
Test File Naming And Structure ✅ Passed File meets all requirements: test_*.py pattern, pytest structure with async, unit test directory, descriptive test names, helper classes/setup, edge case coverage, and positive/negative scenarios.
Excessive Mock Usage Warning ✅ Passed Test doubles are minimal, purpose-specific implementations of cache interfaces. No mock libraries used. 8 tests verify real service behavior with appropriate test doubles for isolated unit testing.

✏️ 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 18, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels May 18, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels May 18, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels May 18, 2026
@jynbil1
Copy link
Copy Markdown
Author

jynbil1 commented May 18, 2026

Maintainer note: the current Update Component Index failure appears to be a fork checkout issue rather than a component-index diff. The job log stops in actions/checkout with A branch or tag with the name 'fix/tolerate-unpickleable-redis-cache' could not be found, which is looking on langflow-ai/langflow instead of the fork branch.

Local verification on the current PR branch still passes:

uv run pytest src/backend/tests/unit/services/test_cache_serialization.py
# 8 passed

git diff --check origin/main...HEAD
# no output

@jynbil1
Copy link
Copy Markdown
Author

jynbil1 commented May 19, 2026

CI triage after the latest run:

  • Update Component Index failed before running project logic: actions/checkout could not find an upstream branch/tag named fix/tolerate-unpickleable-redis-cache. This appears to be a fork-PR workflow/ref issue rather than a source diff issue.
  • Merge Frontend Jest + Playwright Coverage Reports reached Codecov upload, then failed with Token required - not valid tokenless upload, also outside the patch.
  • The only test failure is tests/core/integrations/assistant-panel.spec.ts:5 waiting for assistant-input-textarea; this is unrelated to the backend cache/starter-project diff in this PR.

The focused cache serialization changes remain covered by the added unit tests; I can patch source issues quickly if a maintainer sees a diff-related failure.

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels May 19, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels May 19, 2026
@jynbil1
Copy link
Copy Markdown
Author

jynbil1 commented May 19, 2026

Follow-up after rebasing/merging latest main into the PR branch and pushing 39dbf85:

Local verification on the current branch still passes:

uv run pytest src/backend/tests/unit/services/test_cache_serialization.py
# 8 passed

uv run ruff check src/backend/base/langflow/services/cache/service.py src/backend/base/langflow/services/cache/utils.py src/backend/base/langflow/services/chat/service.py src/backend/base/langflow/services/session/service.py src/backend/tests/unit/services/test_cache_serialization.py
# All checks passed

git diff --check origin/main...HEAD
# no output

The new Docker-image failure appears to be infrastructure cancellation, not a test/build assertion from this patch. The job ends with:

The runner has received a shutdown signal
ERROR: failed to build: failed to receive status: rpc error: code = Unavailable desc = error reading from server: EOF
The operation was canceled.

The other remaining failures are still the fork checkout issue in Update Component Index and the unrelated frontend assistant-panel Playwright shard.

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

1 participant