Skip to content

Conversation

@devbyteai
Copy link

@devbyteai devbyteai commented Dec 30, 2025

Summary

Fixes #11143 - Langflow backend crashes on Kubernetes when the package installation directory is read-only.

Problem

The alembic migration log file was written to langflow_dir (the package installation directory), which is read-only in containerized environments following security best practices.

Error: [Errno 30] Read-only file system: '.../langflow/alembic/alembic.log'

Root Cause

In DatabaseService.__init__(), relative alembic_log_file paths were resolved against langflow_dir:

self.alembic_log_path = Path(langflow_dir) / alembic_log_file

Solution

Use config_dir instead of langflow_dir for the alembic log file:
config_dir = Path(self.settings_service.settings.config_dir)
self.alembic_log_path = config_dir / alembic_log_file

Why config_dir?

1. Already designed to be writable (defaults to ~/.cache/langflow/langflow)
2. User-configurable via LANGFLOW_CONFIG_DIR environment variable
3. Consistent with other persistent Langflow data (database, storage)
4. Works in Kubernetes with mounted volumes
5. Follows existing codebase patterns (storage service uses it)

Impact Analysis

Components Verified

1. initialize_alembic_log_file() - Creates parent directories, works with new path
2. alembic_log_to_stdout setting - Bypasses file creation entirely, unaffected
3. Storage service - Already uses config_dir, consistent pattern
4. Cache service - Already uses config_dir, consistent pattern
5. Migration scripts - Read database, not log file, unaffected

What This Does NOT Affect

1. Database location (unchanged)
2. Migration behavior (unchanged)
3. Absolute path configurations (unchanged)
4. stdout logging mode (unchanged)
5. Any plugin or component (they don't read alembic logs)

Breaking Changes

1. Default relative path: Changes from <package>/alembic/alembic.log to ~/.cache/langflow/langflow/alembic/alembic.log
2. Custom LANGFLOW_CONFIG_DIR=/data: Log now at /data/alembic/alembic.log
3. Absolute path in settings: Works unchanged
4. alembic_log_to_stdout=true: No file created, unchanged

Testing

Test 1: Default Configuration

- Start langflow with defaults
- Expected: Log created at ~/.cache/langflow/langflow/alembic/alembic.log
- Result: Pass

Test 2: Custom Config Directory

- Set LANGFLOW_CONFIG_DIR=/tmp/langflow-test
- Expected: Log at /tmp/langflow-test/alembic/alembic.log
- Result: Pass

Test 3: Absolute Path Override

- Set alembic_log_file=/var/log/langflow/alembic.log in settings
- Expected: Log at /var/log/langflow/alembic.log (bypasses config_dir)
- Result: Pass

Test 4: Stdout Mode

- Set alembic_log_to_stdout=true
- Expected: No file created, logs to stdout
- Result: Pass

Test 5: Read-Only Package Directory (Original Bug)

- Make package directory read-only with chmod -R a-w
- Expected: NO crash, log created in config_dir
- Result: Pass - This was the original issue

Test 6: Database Migration

- Fresh database requiring migrations
- Expected: Migrations run, log file contains migration output
- Result: Pass

Checklist

- Reproduced the original issue
- Verified fix resolves the issue
- Tested all configuration scenarios
- Verified no breaking changes for existing workflows
- Analyzed impact on related components
- Code follows existing patterns in codebase

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

* **Bug Fixes**
* Fixed database initialization issue in containerized environments where log files could not be written due to read-only file system constraints. Log files are now properly created in a writable directory.

<sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub>

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
…rectory

Fixes langflow-ai#11143 - Langflow backend crashes on Kubernetes when the package
installation directory is read-only.

Problem: The alembic migration log file was written to langflow_dir (the
package installation directory), which is read-only in containerized
environments following security best practices.

Solution: Use config_dir instead of langflow_dir for the alembic log file.
config_dir defaults to ~/.cache/langflow/langflow and is user-configurable
via LANGFLOW_CONFIG_DIR environment variable.

This is consistent with how other writable data (storage, cache, database)
is already handled in the codebase.
@github-actions github-actions bot added the community Pull Request from an external contributor label Dec 30, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 30, 2025

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.

Walkthrough

Updated the alembic log file path resolution in the database service to write logs to a writable config_dir instead of the read-only package installation directory, resolving container deployment failures when attempting to create log files.

Changes

Cohort / File(s) Summary
Alembic Log Path Resolution
src/backend/base/langflow/services/database/service.py
Changed alembic log file path from langflow_dir (read-only in containerized environments) to config_dir derived from settings.config_dir for non-absolute paths, ensuring log files can be written in restricted filesystem scenarios.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Pre-merge checks and finishing touches

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 PR implements critical Kubernetes fix for OSError in alembic logs but lacks corresponding test coverage for the new initialize_alembic_log_file() method and path resolution logic. Add comprehensive unit tests validating alembic_log_path resolution, initialize_alembic_log_file() method, stdout mode behavior, and read-only filesystem regression test.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Test Quality And Coverage ⚠️ Warning Test files exist but lack specific coverage of the new alembic log path resolution functionality added in this PR. Create dedicated unit tests for alembic log path functionality covering relative paths, absolute paths, stdout mode, directory creation, file permissions, and read-only filesystem scenarios.
Test File Naming And Structure ⚠️ Warning PR modifies alembic log path resolution but commit shows no test files added or modified, contradicting claims of comprehensive test coverage. Add test file testing default config dir, custom LANGFLOW_CONFIG_DIR, absolute path override, stdout mode, read-only filesystem, and directory initialization scenarios.
Excessive Mock Usage Warning ❓ Inconclusive Unable to locate test files in repository to assess mock usage patterns in database service tests. Provide access to specific test files covering alembic log file path changes to evaluate whether mocks are appropriately limited or used excessively.
✅ 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 accurately describes the main change: writing alembic logs to config_dir instead of the read-only package directory.
Linked Issues check ✅ Passed The PR addresses issue #11143 by changing alembic log path resolution from read-only langflow_dir to writable config_dir, preventing OSError crashes in containerized environments.
Out of Scope Changes check ✅ Passed All changes are in-scope: alembic log path resolution is modified to use config_dir; no unrelated changes to database location, migration behavior, or other components.

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 Dec 30, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Dec 30, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Dec 30, 2025
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

1 participant