Skip to content

fix(graph): treat missing frozen cache as cache miss#12495

Open
suyua9 wants to merge 2 commits into
langflow-ai:mainfrom
suyua9:suyua9-fix-frozen-cache-miss
Open

fix(graph): treat missing frozen cache as cache miss#12495
suyua9 wants to merge 2 commits into
langflow-ai:mainfrom
suyua9:suyua9-fix-frozen-cache-miss

Conversation

@suyua9

@suyua9 suyua9 commented Apr 3, 2026

Copy link
Copy Markdown

Summary

  • return CacheMiss() from the fallback frozen-cache getter when the chat service is unavailable
  • apply the same fallback in both graph execution paths that currently create no-op cache functions
  • add a small regression test covering the fallback cache-miss behavior

Testing

  • python3 -m py_compile src/lfx/src/lfx/graph/graph/base.py src/backend/tests/unit/graph/test_cache_restoration.py
  • git diff --check
  • not run: pytest src/backend/tests/unit/graph/test_cache_restoration.py -q (pytest is not installed in this environment)

Closes #12408

Summary by CodeRabbit

  • Bug Fixes

    • Improved cache miss handling when the cache service is unavailable, ensuring consistent behavior by returning explicit cache miss indicators instead of null values.
  • Tests

    • Added test coverage for cache fallback behavior to verify proper handling of service-unavailability scenarios.

Signed-off-by: suyua9 <1521777066@qq.com>
@github-actions github-actions Bot added the community Pull Request from an external contributor label Apr 3, 2026
@coderabbitai

coderabbitai Bot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

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: 4496cf1d-f270-456c-a271-7170dc43ed4e

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

Updated fallback cache behavior to return CacheMiss() instead of None when the chat service is unavailable. Added a unit test validating that the fallback cache getter correctly returns CacheMiss(), ensuring frozen vertices are handled gracefully in standalone mode without triggering type errors.

Changes

Cohort / File(s) Summary
Fallback Cache Behavior
src/lfx/src/lfx/graph/graph/base.py
Modified fallback get_cache_func in two locations (astep and process methods) to return CacheMiss() instead of None, ensuring cache misses are consistently represented as CacheMiss instances rather than null values.
Cache Restoration Test
src/backend/tests/unit/graph/test_cache_restoration.py
Added new async unit test with CacheMiss import that validates fallback cache getter behavior returns CacheMiss() instance, establishing correct cache miss handling when service is unavailable.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 3 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Test Coverage For New Implementations ❌ Error Regression test does not exercise actual Graph.astep() or Graph.process() code paths with real fallback cache functions; only validates isolated mock function. Update test to execute Graph methods with get_chat_service() mocked to None, verify CacheMiss() is returned instead of None from actual code paths.
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% 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 Test is a smoke test of isolated pattern rather than regression test validating actual Graph.astep() and Graph.process() fixes work with frozen vertices and unavailable chat service. Enhance test to instantiate Graph with frozen vertices, mock get_chat_service() to return None, call Graph methods, and verify CacheMiss() fallback behavior prevents TypeError.
Excessive Mock Usage Warning ⚠️ Warning Test file uses excessive mocks (24 Mock() instantiations) without importing or calling real Graph/Vertex classes, failing to validate PR's core fallback changes through actual code paths. Rewrite regression test using real Graph and Component instances, call Graph.astep() with mocked get_chat_service() returning None, verify fallback cache getter returns CacheMiss(), and replace mock-heavy tests with integration tests exercising real code paths.
Test File Naming And Structure ❓ Inconclusive Test file structure and naming cannot be verified; test file is inaccessible in current repository state. Provide access to test_cache_restoration.py content or ensure files are available in repository for verification of test coverage and structure compliance.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(graph): treat missing frozen cache as cache miss' clearly and concisely summarizes the main change: updating fallback cache behavior to return CacheMiss() instead of None when the cache service is unavailable.
Linked Issues check ✅ Passed The pull request fully addresses the primary coding requirement from issue #12408: implementing Option A by changing the fallback get_cache_func to return CacheMiss() instead of None in both execution paths, plus adding a regression test.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the issue: modifications to fallback cache behavior in base.py and addition of a focused regression test in test_cache_restoration.py; no unrelated changes detected.
✨ 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 bug Something isn't working and removed bug Something isn't working labels Apr 3, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/backend/tests/unit/graph/test_cache_restoration.py`:
- Around line 242-251: The test currently only calls a local get_cache_func and
doesn't exercise Graph's fallback; update the test to simulate
get_chat_service() being unavailable (e.g., monkeypatch/getattr to raise or
return None) and invoke build_vertex (the real code path that uses
Graph.astep/Graph.process) so the actual fallback cache getter runs; await the
build_vertex call and assert that the cache getter used by build_vertex returns
an instance of CacheMiss() (reference Graph.astep, Graph.process,
get_chat_service, build_vertex, CacheMiss).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 773f9f13-32ea-493e-8750-a46708950aed

📥 Commits

Reviewing files that changed from the base of the PR and between 65c3139 and b8cd539.

📒 Files selected for processing (2)
  • src/backend/tests/unit/graph/test_cache_restoration.py
  • src/lfx/src/lfx/graph/graph/base.py

Comment on lines +242 to +251
@pytest.mark.asyncio
async def test_service_unavailable_fallback_returns_cache_miss(self):
"""Fallback cache getter should behave like a cache miss, not a cache hit."""

async def get_cache_func(*args, **kwargs): # noqa: ARG001
return CacheMiss()

cached_result = await get_cache_func(key="frozen-vertex")

assert isinstance(cached_result, CacheMiss)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Regression test does not exercise the changed Graph fallback path.

This test only checks a locally defined get_cache_func, so it will still pass even if Graph.astep/Graph.process regress back to returning None. Please drive one real execution path with get_chat_service() unavailable and assert the cache getter used by build_vertex yields CacheMiss().

As per coding guidelines: "Test both sync and async code paths, mock external dependencies appropriately, test error handling and edge cases, validate input/output behavior, and test component initialization and configuration".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/backend/tests/unit/graph/test_cache_restoration.py` around lines 242 -
251, The test currently only calls a local get_cache_func and doesn't exercise
Graph's fallback; update the test to simulate get_chat_service() being
unavailable (e.g., monkeypatch/getattr to raise or return None) and invoke
build_vertex (the real code path that uses Graph.astep/Graph.process) so the
actual fallback cache getter runs; await the build_vertex call and assert that
the cache getter used by build_vertex returns an instance of CacheMiss()
(reference Graph.astep, Graph.process, get_chat_service, build_vertex,
CacheMiss).

@cuyua9

cuyua9 commented Apr 14, 2026

Copy link
Copy Markdown

Follow-up update: I addressed the CodeRabbit test-coverage concern in the latest push (aaddf96). The regression test now drives the real Graph.astep() -> Graph.build_vertex() fallback path with get_chat_service() unavailable, and asserts that the frozen vertex is freshly built through the cache-miss fallback.\n\nVerification: uv run pytest src/backend/tests/unit/graph/test_cache_restoration.py -q passes locally (12 passed).

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Apr 14, 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 community Pull Request from an external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: 'NoneType' object is not subscriptable in build_vertex when flow has frozen nodes and chat_service is unavailable

2 participants