OpenHands icon indicating copy to clipboard operation
OpenHands copied to clipboard

RuntimeError: cannot call recv while another coroutine is already waiting for the next message

Open katmai opened this issue 1 year ago • 8 comments

Describe the bug

starting opendevin opens up the interface, but getting no answer in the chat box. it seems to be stuck on some sandbox,py. not even sure where that came from or what it's for.

Setup and configuration

Current version:

commit 973a42fd789c4b7e66038b2b9579de02cf508271 (HEAD -> main, origin/main, origin/HEAD)
Author: Engel Nyst <[email protected]>
Date:   Wed Apr 10 20:03:20 2024 +0200

    More json cleaning (#924)

    * More json cleaning

    * remove redundant check

My config.toml and environment vars (be sure to redact API keys):

LLM_API_KEY="ollama"
LLM_MODEL="ollama/dolphin-mistral:latest"
LLM_EMBEDDING_MODEL="local"
LLM_BASE_URL="http://localhost:11434"
WORKSPACE_DIR="./workspace"

My model and agent (you can see these settings in the UI):

  • Model:
  • Agent:

Commands I ran to install and run OpenDevin:

Steps to Reproduce:

  1. start opendevin
  2. go to interface

Logs, error messages, and screenshots: 21:16:04 - opendevin:INFO: sandbox.py:119 - Using workspace directory: /home/atlas/OpenDevin/workspace 21:16:04 - opendevin:INFO: sandbox.py:210 - Connecting to opendevin@localhost via ssh. If you encounter any issues, you can try ssh -v -p 2222 opendevin@localhost with the password '57dcd835-c9a5-43f2-b799-cb38a1c69b34' and report the issue on GitHub. 21:16:05 - opendevin:ERROR: session.py:43 - Error in loop_recv: cannot call recv while another coroutine is already waiting for the next message Traceback (most recent call last): File "/home/atlas/OpenDevin/opendevin/server/session/session.py", line 28, in loop_recv data = await self.websocket.receive_json() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/atlas/.cache/pypoetry/virtualenvs/opendevin-WmySEtCI-py3.11/lib/python3.11/site-packages/starlette/websockets.py", line 157, in receive_json message = await self.receive() ^^^^^^^^^^^^^^^^^^^^ File "/home/atlas/.cache/pypoetry/virtualenvs/opendevin-WmySEtCI-py3.11/lib/python3.11/site-packages/starlette/websockets.py", line 49, in receive message = await self._receive() ^^^^^^^^^^^^^^^^^^^^^ File "/home/atlas/.cache/pypoetry/virtualenvs/opendevin-WmySEtCI-py3.11/lib/python3.11/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 379, in asgi_receive data = await self.recv() ^^^^^^^^^^^^^^^^^ File "/home/atlas/.cache/pypoetry/virtualenvs/opendevin-WmySEtCI-py3.11/lib/python3.11/site-packages/websockets/legacy/protocol.py", line 533, in recv raise RuntimeError( RuntimeError: cannot call recv while another coroutine is already waiting for the next message

Additional Context

katmai avatar Apr 10 '24 19:04 katmai

@katmai do this please:

  • Close the browser tabs when you have localhost with opendevin. All :)
  • from opendevin directory, remove the cache directory
  • git pull
  • make build
  • still in console, run poetry run python opendevin/main.py -d ./workspace/ -t "write a bash script that prints hi"

Does it work?

enyst avatar Apr 10 '24 21:04 enyst

@katmai do this please:

  • Close the browser tabs when you have localhost with opendevin. All :)
  • from opendevin directory, remove the cache directory
  • git pull
  • make build
  • still in console, run poetry run python opendevin/main.py -d ./workspace/ -t "write a bash script that prints hi"

Does it work?

ok now we're getting somewhere. this seems to work. took a little while and a few tries. but cli seems to do the trick. i think the problem from me logging this issue is that i wasn't seeing the container output and didn't bother to look inside as instructed :) but it does go on and it looks like it's using the local ollama, because the cpu is spiking while it's doing it's thing.

what would be nice is if it could somehow use all this "knowledge" if i were to ask the same thing over and over a few times, so that it "knows" what it previously did and just do it better on each subsequent run.

atlas@chia01:~/OpenDevin$ poetry run python opendevin/main.py -d ./workspace/ -t "write a bash script that prints hi"
/home/atlas/.cache/pypoetry/virtualenvs/opendevin-WmySEtCI-py3.11/lib/python3.11/site-packages/pydantic/_internal/_fields.py:151: UserWarning: Field "model_list" has conflict with protected namespace "model_".

You may be able to resolve this warning by setting `model_config['protected_namespaces'] = ()`.
  warnings.warn(
/home/atlas/.cache/pypoetry/virtualenvs/opendevin-WmySEtCI-py3.11/lib/python3.11/site-packages/pydantic/_internal/_fields.py:151: UserWarning: Field "model_name" has conflict with protected namespace "model_".

You may be able to resolve this warning by setting `model_config['protected_namespaces'] = ()`.
  warnings.warn(
/home/atlas/.cache/pypoetry/virtualenvs/opendevin-WmySEtCI-py3.11/lib/python3.11/site-packages/pydantic/_internal/_fields.py:151: UserWarning: Field "model_group_alias" has conflict with protected namespace "model_".

You may be able to resolve this warning by setting `model_config['protected_namespaces'] = ()`.
  warnings.warn(
/home/atlas/.cache/pypoetry/virtualenvs/opendevin-WmySEtCI-py3.11/lib/python3.11/site-packages/pydantic/_internal/_fields.py:151: UserWarning: Field "model_info" has conflict with protected namespace "model_".

You may be able to resolve this warning by setting `model_config['protected_namespaces'] = ()`.
  warnings.warn(
/home/atlas/.cache/pypoetry/virtualenvs/opendevin-WmySEtCI-py3.11/lib/python3.11/site-packages/pydantic/_internal/_fields.py:151: UserWarning: Field "model_id" has conflict with protected namespace "model_".

You may be able to resolve this warning by setting `model_config['protected_namespaces'] = ()`.
  warnings.warn(
/home/atlas/.cache/pypoetry/virtualenvs/opendevin-WmySEtCI-py3.11/lib/python3.11/site-packages/torch/cuda/__init__.py:141: UserWarning: CUDA initialization: The NVIDIA driver on your system is too old (found version 11040). Please update your GPU driver by downloading and installing a new version from the URL: http://www.nvidia.com/Download/index.aspx Alternatively, go to: https://pytorch.org to install a PyTorch version that has been compiled with your version of the CUDA driver. (Triggered internally at ../c10/cuda/CUDAFunctions.cpp:108.)
  return torch._C._cuda_getDeviceCount() > 0
Running agent MonologueAgent (model: ollama/dolphin-mixtral:latest, directory: ./workspace/) with task: "write a bash script that prints hi"
23:58:23 - opendevin:INFO: ssh_box.py:65 - Using workspace directory: /home/atlas/OpenDevin/workspace
23:58:23 - opendevin:INFO: ssh_box.py:280 - Container stopped
23:58:23 - opendevin:INFO: ssh_box.py:315 - Container started
23:58:24 - opendevin:INFO: ssh_box.py:331 - waiting for container to start: 1, container status: running
23:58:24 - opendevin:INFO: ssh_box.py:156 - Connecting to opendevin@localhost via ssh. If you encounter any issues, you can try `ssh -v -p 2222 opendevin@localhost` with the password '699f7ef2-0973-4854-a174-5ea338816e6f' and report the issue on GitHub.


==============
STEP 0

PLAN:
write a bash script that prints hi

ACTION:
FileReadAction(path='/workspace/file1', action=<ActionType.READ: 'read'>)

ERROR:
[Errno 2] No such file or directory: './workspace/file1'
Traceback (most recent call last):
  File "/home/atlas/OpenDevin/opendevin/controller/agent_controller.py", line 173, in step
    if inspect.isawaitable(action.run(self)):
                           ^^^^^^^^^^^^^^^^
  File "/home/atlas/OpenDevin/opendevin/action/fileop.py", line 27, in run
    with open(path, "r", encoding="utf-8") as file:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: './workspace/file1'

OBSERVATION:
[Errno 2] No such file or directory: './workspace/file1'


==============
STEP 1

PLAN:
write a bash script that prints hi

ACTION:
AgentThinkAction(thought="I tried to read a file that doesn't exist. I should use the write action to create a new file first.", action=<ActionType.THINK: 'think'>)


==============
STEP 2

PLAN:
write a bash script that prints hi

ACTION:
AgentThinkAction(thought='I should create a new file called script.sh in the /workspace directory. I can use the write action to do that.', action=<ActionType.THINK: 'think'>)


==============
STEP 3

PLAN:
write a bash script that prints hi

ACTION:
FileWriteAction(path='/workspace/script.sh', content="#!/bin/bash\necho 'Hi'\n", action=<ActionType.WRITE: 'write'>)

OBSERVATION:



==============
STEP 4

PLAN:
write a bash script that prints hi

ACTION:
AgentThinkAction(thought='I should check if the file I created exists and has the expected content.', action=<ActionType.THINK: 'think'>)


==============
STEP 5

PLAN:
write a bash script that prints hi

ACTION:
FileReadAction(path='/workspace/script.sh', action=<ActionType.READ: 'read'>)

OBSERVATION:
#!/bin/bash
echo 'Hi'



==============
STEP 6

PLAN:
write a bash script that prints hi

ACTION:
AgentThinkAction(thought='I should check if the file I created exists and has the expected content.', action=<ActionType.THINK: 'think'>)


==============
STEP 7

PLAN:
write a bash script that prints hi

ACTION:
CmdRunAction(command='bash ./workspace/script.sh', background=False, action=<ActionType.RUN: 'run'>)

OBSERVATION:
bash: ./workspace/script.sh: No such file or directory


==============
STEP 8

PLAN:
write a bash script that prints hi

katmai avatar Apr 10 '24 22:04 katmai

it's going on and on but it's working indeed.

==============
STEP 8

PLAN:
write a bash script that prints hi

ACTION:
AgentThinkAction(thought='I should check if the file I created exists and has the expected content.', action=<ActionType.THINK: 'think'>)


==============
STEP 9

PLAN:
write a bash script that prints hi

ACTION:
AgentThinkAction(thought='I should check if the file I created exists and has the expected content.', action=<ActionType.THINK: 'think'>)


==============
STEP 10

PLAN:
write a bash script that prints hi

ACTION:
AgentThinkAction(thought='I should check if the file I created exists and has the expected content.', action=<ActionType.THINK: 'think'>)


==============
STEP 11

PLAN:
write a bash script that prints hi

ACTION:
AgentThinkAction(thought='I should create a new file called script.sh in the /workspace directory. I can use the write action to do that.', action=<ActionType.THINK: 'think'>)


==============
STEP 12

PLAN:
write a bash script that prints hi

ACTION:
FileWriteAction(path='/workspace/script.sh', content="#!/bin/bash\necho 'Hi'\n", action=<ActionType.WRITE: 'write'>)

OBSERVATION:



==============
STEP 13

PLAN:
write a bash script that prints hi

ACTION:
AgentThinkAction(thought='I should check if the file I created exists and has the expected content.', action=<ActionType.THINK: 'think'>)


==============
STEP 14

PLAN:
write a bash script that prints hi

ACTION:
FileReadAction(path='/workspace/script.sh', action=<ActionType.READ: 'read'>)

OBSERVATION:
#!/bin/bash
echo 'Hi'



==============
STEP 15

PLAN:
write a bash script that prints hi

ACTION:
AgentThinkAction(thought='I should check if the file I created exists and has the expected content.', action=<ActionType.THINK: 'think'>)


==============
STEP 16

PLAN:
write a bash script that prints hi

ACTION:
AgentThinkAction(thought='I should check if the file I created exists and has the expected content.', action=<ActionType.THINK: 'think'>)


==============
STEP 17

PLAN:
write a bash script that prints hi

ACTION:
AgentThinkAction(thought='I should check if the file I created exists and has the expected content.', action=<ActionType.THINK: 'think'>)


==============
STEP 18

PLAN:
write a bash script that prints hi

ACTION:
AgentThinkAction(thought='I need to make sure that the script.sh file was created correctly and has the expected content.', action=<ActionType.THINK: 'think'>)


==============
STEP 19

PLAN:
write a bash script that prints hi

ACTION:
AgentThinkAction(thought='I should check if the file I created exists and has the expected content.', action=<ActionType.THINK: 'think'>)


==============
STEP 20

PLAN:
write a bash script that prints hi

ACTION:
AgentThinkAction(thought='I should make sure the file I created exists and has the expected content.', action=<ActionType.THINK: 'think'>)

katmai avatar Apr 10 '24 22:04 katmai

Error in loop_recv is a server error, due to websocket connections. So the problem is somewhere in the backend, rather than the agent controller

rbren avatar Apr 10 '24 22:04 rbren

However, we all know that it can't "improve" because it's a read-only model/algorithm even when hosted locally w/ ollama.

katmai avatar Apr 10 '24 22:04 katmai

i'll let it run. see where this goes.

katmai avatar Apr 10 '24 22:04 katmai

@katmai do this please:

  • Close the browser tabs when you have localhost with opendevin. All :)
  • from opendevin directory, remove the cache directory
  • git pull
  • make build
  • still in console, run poetry run python opendevin/main.py -d ./workspace/ -t "write a bash script that prints hi"

Does it work?

eventually, i ran into an error.

ERROR:
FileWriteAction.__init__() got an unexpected keyword argument 'append'
Traceback (most recent call last):
  File "/home/atlas/OpenDevin/opendevin/controller/agent_controller.py", line 135, in step
    action = self.agent.step(self.state)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/atlas/OpenDevin/agenthub/monologue_agent/agent.py", line 217, in step
    action = prompts.parse_action_response(action_resp)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/atlas/OpenDevin/agenthub/monologue_agent/utils/prompts.py", line 158, in parse_action_response
    return action_from_dict(action_dict)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/atlas/OpenDevin/opendevin/action/__init__.py", line 40, in action_from_dict
    return action_class(**args)
           ^^^^^^^^^^^^^^^^^^^^
TypeError: FileWriteAction.__init__() got an unexpected keyword argument 'append'
00:34:42 - opendevin:ERROR: agent_controller.py:113 - Error in loop
Traceback (most recent call last):
  File "/home/atlas/OpenDevin/opendevin/controller/agent_controller.py", line 111, in start_loop
    finished = await self.step(i)
               ^^^^^^^^^^^^^^^^^^
  File "/home/atlas/OpenDevin/opendevin/controller/agent_controller.py", line 135, in step
    action = self.agent.step(self.state)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/atlas/OpenDevin/agenthub/monologue_agent/agent.py", line 217, in step
    action = prompts.parse_action_response(action_resp)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/atlas/OpenDevin/agenthub/monologue_agent/utils/prompts.py", line 158, in parse_action_response
    return action_from_dict(action_dict)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/atlas/OpenDevin/opendevin/action/__init__.py", line 40, in action_from_dict
    return action_class(**args)
           ^^^^^^^^^^^^^^^^^^^^
TypeError: FileWriteAction.__init__() got an unexpected keyword argument 'append'
ERROR:root:  File "/home/atlas/OpenDevin/opendevin/main.py", line 96, in <module>
    asyncio.run(main())
  File "/home/atlas/.pyenv/versions/3.11.3/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/home/atlas/.pyenv/versions/3.11.3/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/atlas/.pyenv/versions/3.11.3/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/atlas/OpenDevin/opendevin/main.py", line 92, in main
    await controller.start_loop(task)
  File "/home/atlas/OpenDevin/opendevin/controller/agent_controller.py", line 114, in start_loop
    raise e
  File "/home/atlas/OpenDevin/opendevin/controller/agent_controller.py", line 111, in start_loop
    finished = await self.step(i)
               ^^^^^^^^^^^^^^^^^^
  File "/home/atlas/OpenDevin/opendevin/controller/agent_controller.py", line 135, in step
    action = self.agent.step(self.state)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/atlas/OpenDevin/agenthub/monologue_agent/agent.py", line 217, in step
    action = prompts.parse_action_response(action_resp)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/atlas/OpenDevin/agenthub/monologue_agent/utils/prompts.py", line 158, in parse_action_response
    return action_from_dict(action_dict)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/atlas/OpenDevin/opendevin/action/__init__.py", line 40, in action_from_dict
    return action_class(**args)
           ^^^^^^^^^^^^^^^^^^^^

ERROR:root:<class 'TypeError'>: FileWriteAction.__init__() got an unexpected keyword argument 'append'

katmai avatar Apr 10 '24 22:04 katmai

i am re-running it, but it seems like it has some issues with paths. i've corrected it by making a symlink of /workspace into the homedir.

nevermind. forgot it's a docker container.

==============
STEP 0

PLAN:
write a bash script that prints hi, then look for a response and move forward from there

ACTION:
FileReadAction(path='/workspace/scripts.sh', action=<ActionType.READ: 'read'>)

ERROR:
[Errno 2] No such file or directory: './workspace/scripts.sh'
Traceback (most recent call last):
  File "/home/atlas/OpenDevin/opendevin/controller/agent_controller.py", line 173, in step
    if inspect.isawaitable(action.run(self)):
                           ^^^^^^^^^^^^^^^^
  File "/home/atlas/OpenDevin/opendevin/action/fileop.py", line 27, in run
    with open(path, "r", encoding="utf-8") as file:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: './workspace/scripts.sh'

OBSERVATION:
[Errno 2] No such file or directory: './workspace/scripts.sh'

katmai avatar Apr 10 '24 22:04 katmai

at this moment i am starting to believe i'm stupid. color me puzzled but why are we doing this?

katmai avatar Apr 11 '24 08:04 katmai

@katmai From your original post, I thought you were not able to start with frontend, since the app was giving you an error at the beginning. So I asked you to see if it works when we exclude frontend. It seems it does. The LLM will do its thing, which is not always great but it depends on LLM really.

So my suggestion is to go back and see if we can get it with frontend too. Or have you tried meanwhile?

enyst avatar Apr 11 '24 11:04 enyst

@katmai From your original post, I thought you were not able to start with frontend, since the app was giving you an error at the beginning. So I asked you to see if it works when we exclude frontend. It seems it does. The LLM will do its thing, which is not always great but it depends on LLM really.

So my suggestion is to go back and see if we can get it with frontend too. Or have you tried meanwhile?

you're right, the initial issue was not getting any output in the front end, but now that we've gone to CLI, i am more comfortable sitting here watching for the time being. i don't really need the front end to be working for now.

katmai avatar Apr 11 '24 11:04 katmai

stumbled upon another error:

PLAN:
write a bash script that prints hi

ERROR:
FileWriteAction.__init__() got an unexpected keyword argument 'replace'
Traceback (most recent call last):
  File "/home/atlas/OpenDevin/opendevin/controller/agent_controller.py", line 135, in step
    action = self.agent.step(self.state)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/atlas/OpenDevin/agenthub/monologue_agent/agent.py", line 217, in step
    action = prompts.parse_action_response(action_resp)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/atlas/OpenDevin/agenthub/monologue_agent/utils/prompts.py", line 158, in parse_action_response
    return action_from_dict(action_dict)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/atlas/OpenDevin/opendevin/action/__init__.py", line 40, in action_from_dict
    return action_class(**args)
           ^^^^^^^^^^^^^^^^^^^^
TypeError: FileWriteAction.__init__() got an unexpected keyword argument 'replace'

OBSERVATION:
FileWriteAction.__init__() got an unexpected keyword argument 'replace'

katmai avatar Apr 11 '24 17:04 katmai

took 3 hours but it completed! (minus the failed subsequent runs) but this is pretty cool.

==============
STEP 99

PLAN:
write a bash script that prints hi

ACTION:
FileWriteAction(path='/workspace/output4.txt', content='The diff command shows no differences between output2.txt and script.sh. This means that the output of output2.txt matches exactly with the content of script.sh.', action=<ActionType.WRITE: 'write'>)

OBSERVATION:

21:40:00 - opendevin:INFO: agent_controller.py:118 - Exited before finishing the task.

katmai avatar Apr 11 '24 20:04 katmai

Litellm made an update for an error i reported earlier: https://github.com/BerriAI/litellm/issues/2960

katmai avatar Apr 11 '24 21:04 katmai

@katmai it looks like the remaining issues are all the LLM sending back malformed actions, which is somewhat expected.

Sounds like maybe the original issue is still a problem (I've seen this error before too). Are you still seeing it? Or should we close this?

rbren avatar Apr 12 '24 09:04 rbren

@katmai it looks like the remaining issues are all the LLM sending back malformed actions, which is somewhat expected.

Sounds like maybe the original issue is still a problem (I've seen this error before too). Are you still seeing it? Or should we close this?

i think this can be closed. i'm good with the CLI for the time being. i'm also running on CPU so, i'm busy slowing down time over here :)))))

i mean the original problem i think still exists (haven't tested), but it doesn't preoccupy me anymore.

katmai avatar Apr 12 '24 09:04 katmai

@katmai do this please:

  • Close the browser tabs when you have localhost with opendevin. All :)
  • from opendevin directory, remove the cache directory
  • git pull
  • make build
  • still in console, run poetry run python opendevin/main.py -d ./workspace/ -t "write a bash script that prints hi"

Does it work?

sorry to necro this but i have a question: the -d ./workspace/ parameter - does this tell docker to load the workspace folder from local, or does this tell the LLM to use ./workspace/ as a work folder?

The reason i ask is because i see it keep trying to search stuff in ./workspace/

This is again something i don't understand, in config.toml WORKSPACE_DIR="./workspace"

for which does this apply, because when you exec shell to the container, the path is actually /workspace

katmai avatar Apr 12 '24 15:04 katmai

@katmai the workspace dir is the directory that gets mounted into the sandbox. It's a little buggy today--I have an incoming fix for it.

rbren avatar Apr 14 '24 13:04 rbren

@katmai the workspace dir is the directory that gets mounted into the sandbox. It's a little buggy today--I have an incoming fix for it.

oki dokie

katmai avatar Apr 14 '24 13:04 katmai