Skip to content

🐛 xaibo init removes existing venv and forces Python 3.10 even when user wants 3.12 #29

@MFA-X-AI

Description

@MFA-X-AI

Bug Description

When running xaibo init in an existing uv workspace, the command:

  1. Removes the existing .venv at the workspace root
  2. Forces Python 3.10 even when Python 3.12 is available and preferred

This happens because the init command runs uv init --bare followed by uv add, which triggers uv to recreate the workspace virtual environment, and the generated requires-python = ">=3.10" causes uv to select the lowest compatible Python version.

The current behavior is particularly disruptive because:

  1. It destroys the existing venv without warning
  2. It silently downgrades Python versions, which can break other tools expecting a newer Python
  3. There's no way for the user to control this behavior via CLI arguments

Steps to Reproduce

  1. Have an existing uv workspace with a virtual environment
  2. Ensure Python 3.12 is available on your system
  3. Run:
    uvx xaibo init my_first_agent
  4. Select any dependencies (e.g., webserver, openai, livekit)
  5. Observe the output:
    Removed virtual environment at: /home/fahreza/Github/xaibo-test-2/.venv
    Creating virtual environment at: /home/fahreza/Github/xaibo-test-2/.venv
    Using CPython 3.10.15 interpreter at: /usr/bin/python3.10
    

Expected Behavior

  • The existing venv should be preserved or at least recreated with the same Python version
  • OR the user should be able to specify which Python version to use

Actual Behavior

  • The venv is removed and recreated
  • Python 3.10 is forced even when 3.12 is available

Root Cause Analysis

In src/xaibo/cli/__init__.py:

def init(args, extra_args=[]):
    # ...
    universal_run(f"uv init --bare {project_name}", cwd=curdir)
    universal_run(f"uv add xaibo xaibo[{','.join(modules)}] pytest", cwd=project_dir)

The uv add command in a workspace context triggers uv to sync the workspace environment, which recreates .venv. The generated pyproject.toml has requires-python = ">=3.10", so uv selects Python 3.10 (the lowest compatible version).

Proposed Solutions

Option 1: Add --python argument to init command (Recommended)

Allow users to specify their preferred Python version:

xaibo init my_agent --python 3.12

Implementation:

init_parser.add_argument('--python', type=str, default='3.10',
                        help='Python version to use for the project (default: 3.10)')
# ...
universal_run(f"uv init --bare --python {args.python} {project_name}", cwd=curdir)

Option 2: Detect existing Python version

If a .venv already exists, detect its Python version and preserve it when recreating:

def get_existing_python_version(venv_path):
    """Detect Python version from existing venv if present."""
    python_exe = venv_path / "bin" / "python"
    if python_exe.exists():
        result = subprocess.run([str(python_exe), "--version"], 
                               capture_output=True, text=True)
        # Parse version from output
        return parse_version(result.stdout)
    return None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions