Skip to content

fix(tests): Resolve caio context leak causing EAGAIN on CI #11936

Merged
Cristhianzl merged 9 commits intomainfrom
cz/fix-load-starter-projects
Feb 27, 2026
Merged

fix(tests): Resolve caio context leak causing EAGAIN on CI #11936
Cristhianzl merged 9 commits intomainfrom
cz/fix-load-starter-projects

Conversation

@Cristhianzl
Copy link
Member

@Cristhianzl Cristhianzl commented Feb 27, 2026

Objective

Fix persistent SystemError: (11, 'Resource temporarily unavailable') in test_get_project_data on Linux CI caused by aiofile/caio async I/O context accumulation.

Changes

  • Replace aiofile.async_open() with anyio.Path.read_text() in load_starter_projects() to eliminate caio context leak
  • Add regression test test_should_not_leak_caio_contexts_when_loading_starter_projects that asserts zero caio context growth
  • Fix unawaited coroutine warnings in Ollama mock tests by replacing AsyncMock().raise_for_status with MagicMock(return_value=None)

Summary by CodeRabbit

  • Bug Fixes

    • Improved robustness of starter projects loading with automatic retry logic on failures, ensuring more reliable initialization.
    • Fixed potential context leak issues that could occur during startup on Linux CI environments.
  • Tests

    • Enhanced test coverage to prevent context leak regressions during startup processes.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 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.

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

Replaces async file reading with synchronous read_text() and adds retry logic for JSON parsing failures in the setup module, standardizes HTTP mock configurations across multiple test files using MagicMock wrappers, and adds a new test to detect context leaks during startup project loading.

Changes

Cohort / File(s) Summary
Setup Module Updates
src/backend/base/langflow/initial_setup/setup.py
Replaces async file reading with synchronous read_text(encoding="utf-8"), implements retry logic with configurable retries and delays for JSON decode failures, and raises ValueError on exhausted retries while maintaining existing logging behavior.
Test Mock Configuration Standardization
src/backend/tests/unit/components/embeddings/test_ollama_embeddings_component.py, src/backend/tests/unit/components/languagemodels/test_chatollama_component.py
Updates mock object configurations across HTTP response mocks by replacing mock_object.raise_for_status.return_value = None assignments with mock_object.raise_for_status = MagicMock(return_value=None) to properly wrap the method as a callable MagicMock.
Initial Setup Tests
src/backend/tests/unit/test_initial_setup.py
Adds new async test test_should_not_leak_caio_contexts_when_loading_starter_projects() that verifies load_starter_projects() does not leak caio AsyncioContext instances by measuring context store state before and after execution.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 6 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Test Quality And Coverage ⚠️ Warning Test suite for load_starter_projects() lacks coverage of retry logic, error handling, and JSON decode failures; only happy path and regression test present. Add tests for retry behavior, JSON decode errors, delay timing, exhausted retries, and edge cases using mocks and @pytest.mark.asyncio decorators.
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically addresses the main objective: fixing a caio context leak causing EAGAIN errors on CI by replacing aiofile with anyio and adding a regression test.
Docstring Coverage ✅ Passed Docstring coverage is 82.61% which is sufficient. The required threshold is 80.00%.
Test Coverage For New Implementations ✅ Passed PR adds regression test test_should_not_leak_caio_contexts_when_loading_starter_projects() to verify the bug fix for context leaks in load_starter_projects(). Test is properly located in src/backend/tests/unit/test_initial_setup.py with correct naming conventions and includes actual assertions.
Test File Naming And Structure ✅ Passed All test files follow test_*.py naming pattern, use descriptive test function names, implement proper pytest structure with appropriate imports and decorators, and are logically organized.
Excessive Mock Usage Warning ✅ Passed Test files appropriately mock only external dependencies while testing real component behavior; PR changes simplify mock configuration and improve quality without introducing excessive mocking.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cz/fix-load-starter-projects

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 Feb 27, 2026
@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 78.26087% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 35.73%. Comparing base (655aee4) to head (edb9c49).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
src/backend/base/langflow/api/v2/mcp.py 77.27% 5 Missing ⚠️

❌ Your project status has failed because the head coverage (42.40%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #11936      +/-   ##
==========================================
+ Coverage   35.71%   35.73%   +0.01%     
==========================================
  Files        1528     1528              
  Lines       73928    73958      +30     
  Branches    11134    11154      +20     
==========================================
+ Hits        26407    26427      +20     
- Misses      46081    46093      +12     
+ Partials     1440     1438       -2     
Flag Coverage Δ
backend 56.39% <78.26%> (+0.08%) ⬆️
frontend 17.18% <ø> (-0.01%) ⬇️
lfx 42.40% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/backend/base/langflow/initial_setup/setup.py 52.30% <100.00%> (-0.07%) ⬇️
src/backend/base/langflow/api/v2/mcp.py 51.00% <77.27%> (-0.33%) ⬇️

... and 25 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 27, 2026

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 19%
18.98% (6167/32488) 12.5% (3176/25389) 12.68% (884/6969)

Unit Test Results

Tests Skipped Failures Errors Time
2346 0 💤 0 ❌ 0 🔥 33.91s ⏱️

@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Feb 27, 2026
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Feb 27, 2026
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Feb 27, 2026
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Feb 27, 2026
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Feb 27, 2026
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Feb 27, 2026
@Cristhianzl Cristhianzl merged commit 5210b9e into main Feb 27, 2026
99 of 100 checks passed
@Cristhianzl Cristhianzl deleted the cz/fix-load-starter-projects branch February 27, 2026 13:31
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.

1 participant