Skip to content

[Bug][Windows] #1540 fix incomplete: CLI UnifiedSessionStore still uses hard fcntl import — breaks import and pytest on Windows #1836

@Dhivya-Bharathy

Description

@Dhivya-Bharathy

Summary

Issue #1540 was closed after PR #1792, which made file locking cross-platform in praisonai-agents (praisonaiagents/session/store.py).

On Windows, the same class of failure still exists in the PraisonAI CLI package at:

src/praisonai/praisonai/cli/session/unified.py

Because unified.py performs a top-level import fcntl, any code path that imports praisonai.cli.session crashes at import time on Windows. This blocks pytest collection for tests/unit/cli/test_unified_session.py and breaks CLI/TUI session persistence features that depend on UnifiedSessionStore.

This is a follow-up / incomplete fix for #1540, not a new unrelated bug.


Background — what was reported and what was fixed

Original report (#1540)

Field Value
Title Windows test collection fails due to Unix-only fcntl import in session store
Symptom ModuleNotFoundError: No module named 'fcntl' during pytest collection on Windows
Expectation Session store should use cross-platform locking (or optional fcntl) so Windows dev/CI can import and test

What PR #1792 actually changed

Commit bc73dd1d"Issue #1540: Changes from Claude (#1792)" — modified only:

File Change
src/praisonai-agents/praisonaiagents/session/store.py Optional fcntl import, _HAS_FCNTL, msvcrt on Windows, regression tests
src/praisonai-agents/tests/unit/session/test_session_store.py Tests for missing-fcntl path

Not modified:

File Still broken on Windows
src/praisonai/praisonai/cli/session/unified.py Hard import fcntl at line 12
src/praisonai/praisonai/cli/session/__init__.py Re-exports from unified → import fails

GitHub state vs runtime state

Item GitHub Windows runtime (v4.6.52)
Issue #1540 CLOSED CLI path still fails
praisonai-agents session store Fixed in #1792 PASSpytest -k fcntl passes
praisonai CLI unified session Not updated FAIL — import error

Architecture — two session stores, one fixed, one not

PraisonAI currently has two parallel session persistence implementations. Only one received the #1540 fix.

flowchart TB
    subgraph AgentsPkg["praisonai-agents (FIXED in #1792)"]
        AS["praisonaiagents/session/store.py"]
        AS --> FL["FileLock class"]
        FL --> WIN1["Windows: msvcrt.locking"]
        FL --> UNIX1["Unix: fcntl.flock (optional)"]
        AS --> DSS["DefaultSessionStore"]
    end

    subgraph CLIPkg["praisonai CLI (NOT FIXED)"]
        INIT["praisonai/cli/session/__init__.py"]
        UNI["praisonai/cli/session/unified.py"]
        INIT --> UNI
        UNI --> FCNTL["import fcntl (line 12)"]
        FCNTL --> CRASH["ModuleNotFoundError on Windows"]
        UNI --> USS["UnifiedSessionStore.save/load"]
        USS --> FCNTL2["fcntl.flock in save/load"]
    end

    subgraph Consumers["Broken import chain on Windows"]
        TEST["tests/unit/cli/test_unified_session.py"]
        MAIN["praisonai/cli/main.py (TUI / interactive)"]
        TEST --> INIT
        MAIN --> get_store["get_session_store()"]
        get_store --> INIT
    end

    style CRASH fill:#8B0000,color:#fff
    style FCNTL fill:#8B0000,color:#fff
    style WIN1 fill:#2d6a4f,color:#fff
    style UNIX1 fill:#2d6a4f,color:#fff
Loading

Failure flow (Windows)

sequenceDiagram
    participant Dev as Developer (Windows)
    participant Py as python -m pytest
    participant Test as test_unified_session.py
    participant Init as cli/session/__init__.py
    participant Uni as cli/session/unified.py
    participant OS as Windows Python 3.13

    Dev->>Py: collect tests/unit/cli/test_unified_session.py
    Py->>Test: import test module
    Test->>Init: from praisonai.cli.session.unified import ...
    Init->>Uni: load unified.py
    Uni->>OS: import fcntl
    OS-->>Uni: ModuleNotFoundError
    Uni-->>Py: ImportError during collection
    Py-->>Dev: ERROR: interrupted - 1 error during collection
Loading

Reproduction (verified on Windows)

Environment

Key Value
OS Windows 10/11
Python 3.13.2
Version v4.6.52 (praisonai __version__ = "4.6.52")
Install Editable: pip install -e src/praisonai
Working directory src/praisonai (important — tests live under this package root)

Step 1 — Import fails (root cause)

cd C:\Users\DELL\Downloads\praisonai\src\praisonai
python -c "import praisonai.cli.session.unified"

Actual output:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import praisonai.cli.session.unified
  File ".../praisonai/cli/session/__init__.py", line 7, in <module>
    from .unified import UnifiedSession, UnifiedSessionStore, get_session_store
  File ".../praisonai/cli/session/unified.py", line 12, in <module>
    import fcntl
ModuleNotFoundError: No module named 'fcntl'

Step 2 — Pytest collection fails

cd C:\Users\DELL\Downloads\praisonai\src\praisonai
python -m pytest tests/unit/cli/test_unified_session.py --collect-only -q

Actual output (abbreviated):

ImportError while importing test module '...\tests\unit\cli\test_unified_session.py'.
...
praisonai\cli\session\unified.py:12: in <module>
    import fcntl
E   ModuleNotFoundError: No module named 'fcntl'
!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!

Step 3 — Agents package fix works (contrast)

cd C:\Users\DELL\Downloads\praisonai\src\praisonai-agents
python -m pytest tests/unit/session/test_session_store.py -k fcntl -q

Result: 1 passed — confirms #1792 fix is valid only in praisonai-agents.

Common mistake (not this bug)

Running pytest from repo root praisonai/ without the src/praisonai prefix gives:

ERROR: file or directory not found: tests/unit/cli/test_unified_session.py

That is a wrong working directory, not evidence that #1540 is fixed.


Code comparison

Broken — praisonai/cli/session/unified.py (v4.6.52)

# Line 12 — unconditional import; fails on Windows at import time
import fcntl

# Lines 146-150, 183-187 — direct fcntl usage in save/load
fcntl.flock(f.fileno(), fcntl.LOCK_EX)
fcntl.flock(f.fileno(), fcntl.LOCK_UN)

Fixed pattern — praisonaiagents/session/store.py (#1792)

try:
    import fcntl
    _HAS_FCNTL = True
except ImportError:
    _HAS_FCNTL = False

# FileLock.acquire() — Windows branch:
if sys.platform == "win32":
    import msvcrt
    msvcrt.locking(self._lock_file.fileno(), msvcrt.LK_NBLCK, 1)
elif _HAS_FCNTL:
    fcntl.flock(...)

Recommendation: Reuse the same FileLock helper from praisonaiagents.session.store or duplicate the same cross-platform pattern in unified.py (prefer reuse to avoid drift).


User impact

Area Impact on Windows
tests/unit/cli/test_unified_session.py Cannot collect or run
praisonai TUI / interactive session resume main.py imports get_session_store() → may fail when session module loads
Windows CI for praisonai package Collection error count ≥ 1 (full suite: 5435+ collected, 1 error observed)
Developer experience Issue #1540 appears closed on GitHub but CLI path still broken

Proposed fix

  1. Remove top-level import fcntl from unified.py.
  2. Use cross-platform locking consistent with praisonaiagents/session/store.py:
    • msvcrt on win32
    • optional fcntl on Unix
    • one-time warning if locking degraded
  3. Add regression test under src/praisonai/tests/unit/cli/ that mocks or skips when needed, and verifies import praisonai.cli.session.unified succeeds without fcntl on Windows.
  4. Update Windows test collection fails due to Unix-only fcntl import in session store #1540 closure comment or link this issue — fix was partial.

Acceptance criteria

  • python -c "import praisonai.cli.session.unified" succeeds on Windows without fcntl installed
  • pytest tests/unit/cli/test_unified_session.py --collect-only collects tests with zero import errors on Windows
  • UnifiedSessionStore.save() / load() still provide exclusive/shared locking on Unix (no regression)
  • Windows locking uses msvcrt (or shared FileLock class)
  • Existing praisonai-agents session store tests remain green

Verification

Manual verification on Windows:


Labels (suggested)

bug, windows, documentation (optional — if tracking partial #1540 closure)


References

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationImprovements or additions to documentationsecurity

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions