All-Hands-AI / OpenHands

πŸ™Œ OpenHands: Code Less, Make More
https://all-hands.dev
MIT License
34.19k stars 3.89k forks source link

[Bug]: Gets stuck while trying to activate virtual environment #2799

Closed anjor closed 3 weeks ago

anjor commented 4 months ago

Is there an existing issue for the same bug?

Describe the bug

OpenDevin gets stuck while trying to activate an existing virtual environment.

OpenDevin often wants to install packages to be able to test locally. I would prefer it to use a virtual environment, so I usually ask it to activate the virtual environment. And I have consistently seen it get stuck:

==============
CodeActAgent LEVEL 0 STEP 1

19:55:20 - opendevin:INFO: llm.py:239 - Cost: 0.02 USD | Accumulated Cost: 0.04 USD
19:55:20 - ACTION
**CmdRunAction**
THOUGHT: Great! Now, let's activate the Python virtual environment stored in `.venv`.
COMMAND:
source .venv/bin/activate

Current OpenDevin version

ghcr.io/opendevin/opendevin:0.7

Installation and Configuration

WORKSPACE_BASE=$(pwd)/workspace
docker run -it \
    --pull=always \
    -e SANDBOX_USER_ID=$(id -u) \
    -e WORKSPACE_MOUNT_PATH=$WORKSPACE_BASE \
    -v $WORKSPACE_BASE:/opt/workspace_base \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -p 3000:3000 \
    --add-host host.docker.internal:host-gateway \
    --name opendevin-app-$(date +%Y%m%d%H%M%S) \
    ghcr.io/opendevin/opendevin:0.7

Vanilla configuration using default gpt-4o and my api key.



### Model and Agent

- Model: gpt-4o
- Agent: CodeActAgent

### Operating System

Mac OS

### Reproduction Steps

1. set up a python virtual environment in the workspace
2. Ask OpenDevin to activate the virtual environment
3. It should try to execute the command but then get stuck.

### Logs, Errors, Screenshots, and Additional Context

_No response_
tobitege commented 4 months ago

If you'd run the command manually, check what interactive prompt messages you get. Not sure, if you could ask the LLM to use sudo?

anjor commented 4 months ago

When I do it from the opendevin terminal, It get's stuck the same way with nothing in the logs.

If I do it from just the native mac terminal it works.

amosk commented 4 months ago

Same issue. I create a new project and it gets stuck trying to activate the environment. Apple M1, Docker Desktop w/ 26.1.4.

image

Terminal:

image

Workspace directory: workspace directory: /Users/amosk/opendevin

Started with

~ % docker run -it \
    --pull=always \
    -e SANDBOX_USER_ID=$(id -u) \
    -e WORKSPACE_MOUNT_PATH=$WORKSPACE_BASE \
    -v $WORKSPACE_BASE:/opt/workspace_base \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -p 3000:3000 \
    --add-host host.docker.internal:host-gateway \
    --name opendevin-app-$(date +%Y%m%d%H%M%S) \
    ghcr.io/opendevin/opendevin:0.7
tobitege commented 4 months ago

OpenDevin is using miniforge3, that might be the reason. πŸ€” @Shimada666 wdyt?

anjor commented 4 months ago

Is there any way to get more logs? How do I switch on debug logging?

Faultyskullslayer commented 4 months ago

Hope some expert comes in here with a solution this really needs to be fixed makes doing certain things pointless.

mamoodi commented 4 months ago

I'll try to ping some people to take a look at this ASAP.

Faultyskullslayer commented 4 months ago

344762419-25541142-7f25-4645-895f-1b59e3ff577b Dropping a screenshot here as well of the issue

iFurySt commented 4 months ago

It may be that the virtual environment changes the shell prompt. My first thought is that the prompt in the shell is being modified, which prevents the proper detection of command completion, similar to the following:

➜  ~
(base) ➜  ~

However, I'm not 100% sure if this is the issue.

anjor commented 4 months ago

Oh yes. I have a oh-my-zsh setup that shows the current branch. So the prompt does in fact change!

xingyaoww commented 4 months ago

It may be that the virtual environment changes the shell prompt.

@iFurySt Yes - I think this is the root cause! So right now the prompt change would break pxssh's parsing logic, which would be hard to fix temporarily. A workaround we used was to set conda config --set changeps1 False before everything starts (https://github.com/OpenDevin/OpenDevin/blob/038e8f8caa3c2f5bedfd2a2d62cedf8fb309cad1/containers/sandbox/Dockerfile#L38), the it will not change the PS1 prompt hence not breaking it.

But it is not perfect, since ideally the agent should know what environment it is dealing with. The slightly long-term plan was to completely replace pxssh with pexcept in the architecture refractor (https://github.com/OpenDevin/OpenDevin/issues/2404) and write these parsing logic ourselves to try to address this completely 😒 (but this could take a while).

anjor commented 4 months ago

@xingyaoww is there an equivalent temporary workaround for virtualenv? Right now this is the main blocker for me.

Shimada666 commented 4 months ago

@anjor

Hi anjor. We are working to make the opendevin Python runtime completely transparent to users. Once this PR #2796 is merged, the default Python will point to a clean python environment /usr/bin/python instead of the current opendevin python runtime /opendevin/miniforge3/bin/python. You will then be able to use the default python interpretor /usr/bin/python to install dependencies instead of a virtual environment. Maybe this can solve your problem.

anjor commented 4 months ago

Sorry maybe I am misunderstanding. I don't want to use the default interpreter. I would prefer to have a virtualenv per project.

Or does opendevin maintain it's own sandbox anyway?

Shimada666 commented 4 months ago

@anjor Maybe you can run each project in a different opendevin container? One container for each of your projects. This way, you won't need to use virtual environments.

anjor commented 4 months ago

Yeah that will work. Thanks!

mamoodi commented 3 months ago

@xingyaoww just so I understand this for future. Is this an issue we want to tackle and one that should stay open?

xingyaoww commented 3 months ago

@mamoodi Yes! This is among the first batch of issues we want to address after the architecture refractor.

github-actions[bot] commented 2 months ago

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

ywatanabe1989 commented 2 months ago

I attempted to run init.sh as follows. However, CUDA was not installed due to an interruption, likely caused by a timeout (43 seconds).

./workspace/requirements.txt

matplotlib
numpy
pandas
pytest
scikit-learn
scipy
torch

./workspace/init.sh

#!/bin/bash
# /workspace/init.sh

# Store original directory
ORIG_DIR=$PWD
cd /workspace

# Display user and home directory
echo $USER
echo $HOME

# Create and setup virtual environment
/opendevin/miniforge3/bin/python -m venv /home/opendevin/env
sudo chmod 7777 /home/opendevin
export VIRTUAL_ENV_DISABLE_PROMPT=1
source /home/opendevin/env/bin/activate

# Check Python and pip locations
which python
which pip

# Update pip and install requirements
pip install -U pip

if [ -f "requirements.txt" ]; then
    echo "requirements.txt found in /workspace"
    pip install -r requirements.txt 2>&1
else
    echo "requirements.txt not found in /workspace"
fi

pip freeze

# Return to original directory
cd $ORIG_DIR

# EOF

Standard Output

Downloading torch-2.4.0-cp310-cp310-manylinux1_x86_64.whl (797.2 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 797.2/797.2 MB 11.7 MB/s eta 0:00:00
Downloading nvidia_cublas_cu12-12.1.3.1-py3-none-manylinux1_x86_64.whl (410.6 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 410.6/410.6 MB 11.6 MB/s eta 0:00:00
Downloading nvidia_cuda_cupti_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (14.1 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.1/14.1 MB 11.4 MB/s eta 0:00:00
Downloading nvidia_cuda_nvrtc_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (23.7 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 23.7/23.7 MB 11.6 MB/s eta 0:00:00
Downloading nvidia_cuda_runtime_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (823 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 823.6/823.6 kB 12.1 MB/s eta 0:00:00
Downloading nvidia_cudnn_cu12-9.1.0.70-py3-none-manylinux2014_x86_64.whl (664.8 MB)
   ━━━━━━━╸━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 131.6/664.8 MB 11.7 MB/s eta 0:00:46
ERROR: Operation cancelled by user
github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 3 weeks ago

This issue was closed because it has been stalled for over 30 days with no activity.