mpfaffenberger / mpfaffenberger/code_puppy
messaging/bus.py: _event_loop never set so request/response futures are completed cross-thread unsafely; get_message/get_command busy-poll at 100Hz
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 814
- Forks
- 278
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 76
Description
File: code_puppy/messaging/bus.py
Severity: Medium (bug / performance)
-
MessageBus._event_loopis never assigned. It is declared in__init__(line 83) and read in_complete_request()(line ~394), but nothing ever sets it (grep confirms the only writes to_event_loopare inmessage_queue.py, a different class). So_complete_request()always falls through to theelsebranch and callsfuture.set_result()directly from whatever thread the UI response arrives on.asyncio.Futureis not thread-safe; setting a result from a foreign thread does not wake the awaiting loop reliably and can racefuture.done(). Either capture the loop inrequest_input/request_confirmation/request_selection(whereasyncio.get_running_loop()is already called - storeloopalongside the future, e.g.self._pending_requests[prompt_id] = (loop, future)) and always useloop.call_soon_threadsafe, or document why direct set is safe. -
Busy-wait polling in
get_message()/get_command()(lines ~415-445):while True: try get_nowait() except Empty: await asyncio.sleep(0.01)wakes 100x/sec forever, even when idle. With a renderer plus an agent command consumer this is constant background CPU churn and adds up on battery. Consider a real handoff: keep anasyncio.Queuebridged viacall_soon_threadsafe(asmessage_queue.pyalready does), or at minimum back off the sleep when idle. -
Same drop-oldest pattern duplicated in
emit()andprovide_response()- small DRY nit, extract_put_with_drop(queue, item).
Filed by Zen Reviewer B (code-puppy-60635a)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read code_puppy/messaging/bus.py, focusing on MessageBus.init, request_input/request_confirmation/request_selection, _complete_request, get_message, get_command, emit, and provide_response. Compare the handoff approach in message_queue.py, then verify request futures are completed safely across threads, idle consumers avoid constant polling, and duplicated drop-oldest behavior is addressed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100