Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix agent session error in logs #4669

Merged
merged 4 commits into from
Nov 1, 2024
Merged

Fix agent session error in logs #4669

merged 4 commits into from
Nov 1, 2024

Conversation

tofarr
Copy link
Collaborator

@tofarr tofarr commented Oct 31, 2024

Fix for error in logs on file change if the app did not finish starting up.

  • Include this change in the Release Notes. If checked, you must provide an end-user friendly description for your change below

Happens in development mode when you save a file if the app did not finish starting up correctly - basically we try to close and event loop that was never opened:

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/Users/tofarr/dev/all-hands/OpenHands/openhands/server/session/session.py", line 62, in loop_recv
    data = await self.websocket.receive_json()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/starlette/websockets.py", line 135, in receive_json
    self._raise_on_disconnect(message)
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/starlette/websockets.py", line 113, in _raise_on_disconnect
    raise WebSocketDisconnect(message["code"], message.get("reason"))
starlette.websockets.WebSocketDisconnect: (1012, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 242, in run_asgi
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/starlette/applications.py", line 113, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 152, in __call__
    await self.app(scope, receive, send)
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 101, in __call__
    await self.app(scope, receive, send)
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 101, in __call__
    await self.app(scope, receive, send)
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/starlette/middleware/cors.py", line 77, in __call__
    await self.app(scope, receive, send)
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/starlette/routing.py", line 715, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/starlette/routing.py", line 735, in app
    await route.handle(scope, receive, send)
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/starlette/routing.py", line 362, in handle
    await self.app(scope, receive, send)
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/starlette/routing.py", line 95, in app
    await wrap_app_handling_exceptions(app, session)(scope, receive, send)
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/starlette/routing.py", line 93, in app
    await func(session)
  File "/Users/tofarr/dev/all-hands/OpenHands/.venv/lib/python3.12/site-packages/fastapi/routing.py", line 383, in app
    await dependant.call(**solved_result.values)
  File "/Users/tofarr/dev/all-hands/OpenHands/openhands/server/listen.py", line 357, in websocket_endpoint
    await session.loop_recv()
  File "/Users/tofarr/dev/all-hands/OpenHands/openhands/server/session/session.py", line 68, in loop_recv
    await self.close()
  File "/Users/tofarr/dev/all-hands/OpenHands/openhands/server/session/session.py", line 54, in close
    await self.agent_session.close()
  File "/Users/tofarr/dev/all-hands/OpenHands/openhands/server/session/agent_session.py", line 142, in close
    self.loop.stop()
  File "uvloop/loop.pyx", line 1357, in uvloop.loop.Loop.stop
  File "uvloop/loop.pyx", line 678, in uvloop.loop.Loop._call_soon_handle
  File "uvloop/loop.pyx", line 673, in uvloop.loop.Loop._append_ready_handle
  File "uvloop/loop.pyx", line 705, in uvloop.loop.Loop._check_closed
RuntimeError: Event loop is closed

To run this PR locally, use the following command:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   -e SANDBOX_RUNTIME_CONTAINER_IMAGE=ghcr.io/all-hands-ai/runtime:f2881d9-nikolaik   --name openhands-app-f2881d9   ghcr.io/all-hands-ai/runtime:f2881d9

@tofarr tofarr marked this pull request as ready for review October 31, 2024 21:11
@xingyaoww xingyaoww merged commit 6414b1a into main Nov 1, 2024
13 checks passed
@xingyaoww xingyaoww deleted the fix-agent-session-error branch November 1, 2024 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants