Diagnose and resolve the root cause of the Dramatiq worker failing to consume messages and invoke the target actor (execute_agent_task_actor or simple_task in minimal case) when launched via the dramatiq CLI within the project's tox environment.
Previous debugging steps isolated the failure to the worker process itself when run via the CLI, regardless of whether launched by subprocess.Popen, tox exec, or direct python execution within the .tox/py312 environment. The worker connects to RabbitMQ and registers as a consumer, but fails to process messages. Analysis of a python -m trace log proved difficult. A strong hypothesis points towards dependency conflicts or environment issues within the tox environment interfering with Dramatiq/Pika's event loop or message dispatch.
This plan prioritizes alternative isolation techniques over further trace log analysis.
- Goal: Directly test the hypothesis that dependency conflicts within the
.tox/py312environment are the root cause. - Action:
- Create a fresh virtual environment completely outside the project's
toxstructure (e.g.,/tmp/dramatiq_test_venv). - Install only the absolute minimum required dependencies into this venv:
python -m pip install dramatiq[rabbitmq]- (Potentially
pydanticif needed by the minimal actor, TBD)
- Copy
minimal_worker.pyandsend_test_message.pyinto a temporary directory accessible by the venv. - Ensure RabbitMQ is running (via
docker compose up -d rabbitmq). - Activate the clean venv.
- Start the worker from the clean venv using the
dramatiqCLI:python -m dramatiq minimal_worker:broker minimal_worker --verbose - Send a test message using
send_test_message.py(can be run from the project'stoxenv or the clean venv after installing necessary DB deps if the script requires them).
- Create a fresh virtual environment completely outside the project's
- Expected Outcome:
- If Worker Processes Message: Confirms the issue lies within the project's
toxenvironment dependencies. Further investigation would focus on identifying the conflicting package(s) (e.g.,locust/gevent). - If Worker Still Fails: Suggests the issue is more fundamental to Dramatiq/Pika interaction or the worker code itself, even in a minimal environment. Proceed to Step 2.
- If Worker Processes Message: Confirms the issue lies within the project's
- Goal: Isolate the core worker/actor/broker interaction from the
dramatiqCLI's environment setup, argument parsing, and process management. - Action:
- Create a new script:
start_worker_programmatically.py. - In this script:
- Import necessary components:
RabbitmqBroker,Worker, the actor function (simple_taskfromminimal_workerorexecute_agent_task_actorfromengine.py), middleware (likeAsyncIO). - Instantiate the
RabbitmqBroker. - Add required middleware to the broker.
- Declare the actor(s) on the broker instance.
- Instantiate a
Workerinstance, passing the broker and desired concurrency settings (e.g.,worker_threads=1). - Call the
worker.run()method to start the worker loop.
- Import necessary components:
- Run this script from within the standard
toxenvironment:tox exec -e py312 -- python start_worker_programmatically.py - While the programmatic worker is running, send a test message using
send_test_message.py.
- Create a new script:
- Expected Outcome:
- If Worker Processes Message: Confirms the issue is specific to the
dramatiqCLI execution path (loading, argument handling, signal handling, etc.). This would likely unblock Task 7.2, as the E2E tests could potentially be modified to start the worker programmatically. - If Worker Still Fails: Indicates a deeper issue within Dramatiq/Pika or the actor/broker interaction itself, even when bypassing the CLI. Proceed to Step 3.
- If Worker Processes Message: Confirms the issue is specific to the
- Goal: Further diagnose the failure if both the clean environment and programmatic startup fail.
- Potential Actions (Choose based on previous findings):
- Basic Pika Consumer: Write and run a simple, standalone Pika consumer script within the
.tox/py312environment to confirm basic message consumption works outside of Dramatiq. - Monkey-Patching/Library Logging: Add detailed logging/print statements directly into the installed Dramatiq or Pika library code within
.tox/py312/lib/python3.12/site-packages/to trace internal execution flow during message handling. - RabbitMQ Server Tracing: Enable and analyze message tracing on the RabbitMQ server itself to see exactly what happens to the message after the
Basic.ConsumeOk.
- Basic Pika Consumer: Write and run a simple, standalone Pika consumer script within the
- Progress and findings for these steps will be logged in a new file:
memory-bank/debugging/YYYY-MM-DD_task7.2_revised_debug.md. - This plan supersedes
PLANNING_step_7.2.6_cli_debug.md.