mpfaffenberger / mpfaffenberger/code_puppy
messaging: two parallel message systems (MessageQueue vs MessageBus) duplicate buffering/renderer/request-response logic and have already drifted
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 814
- Forks
- 278
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 76
Description
Files: code_puppy/messaging/message_queue.py (MessageQueue / UIMessage) vs code_puppy/messaging/bus.py (MessageBus / TextMessage et al.)
Severity: Medium (architecture / DRY - "one obvious way to do it")
The messaging package contains two parallel message systems, each with its own:
- message envelope (
UIMessagedataclass +MessageTypeenum vs the pydanticAnyMessagefamily in messages.py) - thread-safe queue with drop-oldest-on-full logic (message_queue.py
emit()~line 116 vs bus.pyemit()~line 118) - startup buffering +
_has_active_rendererflag +mark_renderer_active/inactive(both files, nearly identical method names) - sync->async bridging (
MessageQueue._process_messagesthread +call_soon_threadsafevsMessageBus.get_messagepolling) - human-input request/response correlation (
create_prompt_request/wait_for_prompt_responsewith threading.Events vsrequest_input/provide_responsewith asyncio.Futures) - module-level singleton +
emit_*convenience functions
tools/common.py consumes the queue-console flavor (get_queue_console) while the tools themselves emit through the bus (get_message_bus()), so a single tool call's output flows through both systems. Every behavior fix (buffer cap, drop policy, renderer detection) must be made twice, and they have already drifted (the bus caps its startup buffer at maxsize; the queue's _startup_buffer grows unbounded in headless mode).
Suggested fix: declare one of the two the canonical pipe (the bus appears newer and richer), port the remaining consumers of MessageQueue (queue_console, renderers) onto it, and delete or thin the other into a compatibility shim. Short of that, at least extract the shared drop-oldest/startup-buffer logic into one helper and cap the queue's startup buffer like the bus does.
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/message_queue.py and code_puppy/messaging/bus.py, then trace get_queue_console in tools/common.py and the renderers alongside get_message_bus(). Decide whether MessageBus becomes canonical or whether shared buffering logic is extracted. Done means the remaining consumers use one consistent message path, duplicate behavior is removed or shimmed, and startup-buffer limits no longer drift.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100