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

Error: Playwright crashing when agent starts searching the browser. [Docker build] #238

Closed
Sridhar701Pitt opened this issue Mar 29, 2024 · 4 comments

Comments

@Sridhar701Pitt
Copy link

devika-backend-engine-1  | 
devika-backend-engine-1  | Exception in thread Thread-278 (<lambda>):
devika-backend-engine-1  | Traceback (most recent call last):
devika-backend-engine-1  |   File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
devika-backend-engine-1  |     self.run()
devika-backend-engine-1  |   File "/usr/lib/python3.11/threading.py", line 975, in run
devika-backend-engine-1  |     self._target(*self._args, **self._kwargs)
devika-backend-engine-1  |   File "/home/nonroot/devika/devika.py", line 52, in <lambda>
devika-backend-engine-1  |     target=lambda: Agent(base_model=base_model).execute(prompt, project_name)
devika-backend-engine-1  |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/src/agents/agent.py", line 335, in execute
devika-backend-engine-1  |     search_results = self.search_queries(queries, project_name)
devika-backend-engine-1  |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/src/agents/agent.py", line 67, in search_queries
devika-backend-engine-1  |     browser = Browser()
devika-backend-engine-1  |               ^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/src/browser/browser.py", line 14, in __init__
devika-backend-engine-1  |     self.browser = chromium.launch()
devika-backend-engine-1  |                    ^^^^^^^^^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/.venv/lib/python3.11/site-packages/playwright/sync_api/_generated.py", line 13854, in launch
devika-backend-engine-1  |     self._sync(
devika-backend-engine-1  |   File "/home/nonroot/devika/.venv/lib/python3.11/site-packages/playwright/_impl/_sync_base.py", line 113, in _sync
devika-backend-engine-1  |     return task.result()
devika-backend-engine-1  |            ^^^^^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/.venv/lib/python3.11/site-packages/playwright/_impl/_browser_type.py", line 94, in launch
devika-backend-engine-1  |     Browser, from_channel(await self._channel.send("launch", params))
devika-backend-engine-1  |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/.venv/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 59, in send
devika-backend-engine-1  |     return await self._connection.wrap_api_call(
devika-backend-engine-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/.venv/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 509, in wrap_api_call
devika-backend-engine-1  |     return await cb()
devika-backend-engine-1  |            ^^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/.venv/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 97, in inner_send
devika-backend-engine-1  |     result = next(iter(done)).result()
devika-backend-engine-1  |              ^^^^^^^^^^^^^^^^^^^^^^^^^
devika-backend-engine-1  | playwright._impl._errors.Error: Executable doesn't exist at /home/nonroot/devika/.cache/ms-playwright/chromium-1105/chrome-linux/chrome
devika-backend-engine-1  | ╔════════════════════════════════════════════════════════════╗
devika-backend-engine-1  | ║ Looks like Playwright was just installed or updated.       ║
devika-backend-engine-1  | ║ Please run the following command to download new browsers: ║
devika-backend-engine-1  | ║                                                            ║
devika-backend-engine-1  | ║     playwright install                                     ║
devika-backend-engine-1  | ║                                                            ║
devika-backend-engine-1  | ║ <3 Playwright Team                                         ║
devika-backend-engine-1  | ╚════════════════════════════════════════════════════════════╝
devika-backend-engine-1  | 24.03.29 06:31:59: root: INFO   : /api/token-usage GET

The agent gets stuck without any further prompt after this error.

I have tried updating the playwright within the docker file before running this but the issue still persists.
RUN pip install pytest-playwright playwright -U --break-system-packages

Any suggestion to fix this issue?

@hqnicolas
Copy link

hqnicolas commented Mar 29, 2024

devika-backend-engine-1  | 
devika-backend-engine-1  | Exception in thread Thread-373 (<lambda>):
devika-backend-engine-1  | Traceback (most recent call last):
devika-backend-engine-1  |   File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
devika-backend-engine-1  |     self.run()
devika-backend-engine-1  |   File "/usr/lib/python3.11/threading.py", line 975, in run
devika-backend-engine-1  |     self._target(*self._args, **self._kwargs)
devika-backend-engine-1  |   File "/home/nonroot/devika/devika.py", line 52, in <lambda>
devika-backend-engine-1  |     target=lambda: Agent(base_model=base_model).execute(prompt, project_name)
devika-backend-engine-1  |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/src/agents/agent.py", line 335, in execute
devika-backend-engine-1  |     search_results = self.search_queries(queries, project_name)
devika-backend-engine-1  |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/src/agents/agent.py", line 67, in search_queries
devika-backend-engine-1  |     browser = Browser()
devika-backend-engine-1  |               ^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/src/browser/browser.py", line 14, in __init__
devika-backend-engine-1  |     self.browser = chromium.launch()
devika-backend-engine-1  |                    ^^^^^^^^^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/.venv/lib/python3.11/site-packages/playwright/sync_api/_generated.py", line 13854, in launch
devika-backend-engine-1  |     self._sync(
devika-backend-engine-1  |   File "/home/nonroot/devika/.venv/lib/python3.11/site-packages/playwright/_impl/_sync_base.py", line 113, in _sync
devika-backend-engine-1  |     return task.result()
devika-backend-engine-1  |            ^^^^^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/.venv/lib/python3.11/site-packages/playwright/_impl/_browser_type.py", line 94, in launch
devika-backend-engine-1  |     Browser, from_channel(await self._channel.send("launch", params))
devika-backend-engine-1  |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/.venv/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 59, in send
devika-backend-engine-1  |     return await self._connection.wrap_api_call(
devika-backend-engine-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/.venv/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 509, in wrap_api_call
devika-backend-engine-1  |     return await cb()
devika-backend-engine-1  |            ^^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/.venv/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 97, in inner_send
devika-backend-engine-1  |     result = next(iter(done)).result()
devika-backend-engine-1  |              ^^^^^^^^^^^^^^^^^^^^^^^^^
devika-backend-engine-1  | playwright._impl._errors.Error: Executable doesn't exist at /home/nonroot/devika/.cache/ms-playwright/chromium-1105/chrome-linux/chrome
devika-backend-engine-1  | ╔════════════════════════════════════════════════════════════╗
devika-backend-engine-1  | ║ Looks like Playwright was just installed or updated.       ║
devika-backend-engine-1  | ║ Please run the following command to download new browsers: ║
devika-backend-engine-1  | ║                                                            ║
devika-backend-engine-1  | ║     playwright install                                     ║
devika-backend-engine-1  | ║                                                            ║
devika-backend-engine-1  | ║ <3 Playwright Team                                         ║
devika-backend-engine-1  | ╚════════════════════════════════════════════════════════════╝
devika-backend-engine-1  | 24.03.29 21:53:12: root: INFO   : /api/token-usage GET
devika-backend-engine-1  | 24.03.29 21:53:12: root: INFO   : /api/project-list GET
devika-backend-engine-1  | 24.03.29 21:53:12: root: DEBUG  : /api/token-usage GET - Response: {"token_usage":2392}
devika-backend-engine-1  | 
devika-backend-engine-1  | 24.03.29 21:53:12: root: DEBUG  : /api/project-list GET - Response: {"projects":["projeto002"]}
devika-backend-engine-1  | 
devika-backend-engine-1  | 24.03.29 21:53:12: root: INFO   : /api/model-list GET

@Sridhar701Pitt I'm stuck here to
is this a Microsoft Playwright version problem?
I have fount this issue on Playwright github
PlaywrightGitHub

It seems like the Docker image messes a bit around with Linux user accounts. It has some special user called nonroot. And root's home directory is /home/nonroot which seems against any Linux best practise.

@hqnicolas
Copy link

How did I fix it?

Change devika.dockerfile user to root

FROM debian:12

# setting up os env
USER root
WORKDIR /home/nonroot/devika

ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1

# setting up python3
RUN apt-get update && apt-get upgrade
RUN apt-get install -y build-essential software-properties-common curl sudo wget git
RUN apt-get install -y python3 python3-pip
RUN curl -fsSL https://astral.sh/uv/install.sh | sudo -E bash -
RUN $HOME/.cargo/bin/uv venv
ENV PATH="/home/nonroot/devika/.venv/bin:$HOME/.cargo/bin:$PATH"

# copy devika python engine only
RUN $HOME/.cargo/bin/uv venv
COPY requirements.txt /home/nonroot/devika/
RUN UV_HTTP_TIMEOUT=100000 $HOME/.cargo/bin/uv pip install -r requirements.txt 
RUN playwright install --with-deps chromium

COPY src /home/nonroot/devika/src
COPY config.toml /home/nonroot/devika/
COPY devika.py /home/nonroot/devika/
RUN chown -R root:root /home/nonroot/devika

USER root
WORKDIR /home/nonroot/devika
ENV PATH="/home/nonroot/devika/.venv/bin:$HOME/.cargo/bin:$PATH"
RUN mkdir /home/nonroot/devika/db

ENTRYPOINT [ "python3", "-m", "devika" ]

@mufeedvh
Copy link
Member

Can you please contribute this as a PR? @hqnicolas

@hqnicolas
Copy link

@mufeedvh I fix it with root user on docker. Because no root user causes this problem
https://github.com/hqnicolas/devika/blob/main/devika.dockerfile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants