Skip to content

Conversation

@JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Dec 18, 2025

fixes

2025-12-18 07:25:09.371 - core - ovos_bus_client.session:from_message:509 - WARNING - No session context in message:recognizer_loop:utterance
2025-12-18 07:25:09.373 - core - ovos_bus_client.session:from_message:510 - DEBUG - Update ovos-bus-client or add `session` to `message.context` where emitted. context={}
2025-12-18 07:25:09.374 - core - hivemind_core.protocol:handle_bus_message:568 - WARNING - Client tried to inject 'default' session message, action only allowed for administrators!
2025-12-18 07:25:09.383 - core - hivemind_core.protocol:update_last_seen:295 - DEBUG - updated last seen timestamp: c57e6e41d3a627c2ef4cb3461c4d437f - 1766042709.38148
2025-12-18 07:25:09.390 - core - hivemind_websocket_protocol:on_close:235 - INFO - disconnecting client: HiveMessageBusClientV0.0.1::1::HiveMind-Node-0::b9ab5e76-1413-4e59-a09e-34949c05b9a5

Summary by CodeRabbit

  • New Features

    • Added an interactive example chat script demonstrating persistent user input, message emission, and response handling.
  • Enhancements

    • Payload handling now accepts and normalizes multiple input types for more flexible assignment.
    • Added explanatory docstrings to improve clarity of message emission and payload semantics.
  • Refactor

    • Optimized internal message context update flow to reduce intermediate object creation and improve efficiency.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions github-actions bot added the fix label Dec 18, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 18, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds an interactive example CLI at examples/chat.py to emit BUS utterances and await handled events, refactors client.emit to update payload.context in-place during BUS routing, and introduces a HiveMessage.payload setter to normalize Message/HiveMessage inputs and document getters.

Changes

Cohort / File(s) Summary
New example script
examples/chat.py
New interactive chat example: connects a HiveMessageBusClient, registers handle_speak and utt_handled handlers, reads user input, emits BUS messages with recognizer_loop:utterance payloads, and waits for an ovos.utterance.handled event before continuing.
Client emit refactor
hivemind_bus_client/client.py
Adjusted BUS routing in emit to update payload.context in-place instead of creating a shallow copy; expanded/added docstring describing emit behavior.
HiveMessage payload setter
hivemind_bus_client/message.py
Added a payload setter on HiveMessage that accepts HiveMessage, Message, dict, or bytes and normalizes Message/HiveMessage instances to their dict representation; added docstrings to payload getter and bin_type. Minor tweak to remove_target_peer behavior.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ChatScript as examples/chat.py
    participant Client as HiveMessageBusClient
    participant InternalBus as InternalBus
    participant RemotePeers as WebSocket/Peers

    User->>ChatScript: type utterance (stdin)
    ChatScript->>ChatScript: clear Event
    ChatScript->>Client: emit BUS message (recognizer_loop:utterance)
    Client->>InternalBus: deliver internal BUS payload (in-place context update)
    Client->>RemotePeers: send payload over WebSocket
    RemotePeers-->>InternalBus: (optional) emit 'speak' event
    InternalBus-->>ChatScript: invoke 'speak' handler (handle_speak)
    RemotePeers-->>Client: send 'ovos.utterance.handled'
    Client-->>ChatScript: deliver 'ovos.utterance.handled' -> ChatScript sets Event
    ChatScript-->>User: prompt for next utterance
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Focus areas:
    • examples/chat.py: threading.Event synchronization, async handler registration (on_mycroft) and ack/wait semantics.
    • hivemind_bus_client/client.py: verify in-place payload.context updates don't produce unintended shared-state mutations.
    • hivemind_bus_client/message.py: validate payload setter normalization across Message/HiveMessage/dict/bytes and serialization invariants.

Possibly related PRs

Poem

🐰
I hopped a message through the wire,
Listened close as handlers conspire.
Context tucked neatly in place,
Payloads dance, then leave no trace—
Hoppity hops — another chat, another chase! 💬✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: payload context update' directly reflects the main changes in the PR, particularly the context injection improvements in client.py and payload setter enhancements in message.py.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%.

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c0c0f90 and 7b3c139.

📒 Files selected for processing (1)
  • hivemind_bus_client/message.py (3 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 18, 2025

Note

Docstrings generation - SUCCESS
Generated docstrings for this pull request at #74

@github-actions github-actions bot added fix and removed fix labels Dec 18, 2025
coderabbitai bot added a commit that referenced this pull request Dec 18, 2025
Docstrings generation was requested by @JarbasAl.

* #73 (comment)

The following files were modified:

* `examples/chat.py`
* `hivemind_bus_client/client.py`
* `hivemind_bus_client/message.py`
@github-actions github-actions bot removed the fix label Dec 18, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
examples/chat.py (3)

18-19: Acknowledge unused parameter (minor).

The message parameter is unused in the utt_handled function. While this is flagged by static analysis, it's acceptable here since the event handler signature requires this parameter. You can optionally prefix it with an underscore to signal the intent:

🔎 Optional: Signal unused parameter with underscore:
-def utt_handled(message: Message):
+def utt_handled(_message: Message):
     answered.set()

25-30: Consider adding error handling and cleanup (optional).

The example would benefit from basic error handling and cleanup to demonstrate best practices:

  1. Handle potential connection failures
  2. Catch KeyboardInterrupt for graceful exit
  3. Show proper client disconnection
🔎 Optional: Add error handling and cleanup:
+try:
     while True:
         utt = input("> ")
         answered.clear()
         client.emit(HiveMessage(HiveMessageType.BUS,
                                 Message("recognizer_loop:utterance", {"utterances": [utt]})))
         answered.wait()
+except KeyboardInterrupt:
+    print("\nDisconnecting...")
+finally:
+    client.close()

9-10: Add connection error handling.

The example doesn't handle potential connection failures. Consider wrapping the connection attempt in a try-except block to provide helpful feedback if the identity file is missing or the connection fails.

🔎 Add error handling for connection:
+try:
     client = HiveMessageBusClient()
-    client.connect() # establish a secure end-to-end encrypted connection
+    client.connect()  # establish a secure end-to-end encrypted connection
+except RuntimeError as e:
+    print(f"Connection failed: {e}")
+    print("Tip: Run 'hivemind-client set-identity' to configure credentials")
+    exit(1)
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a4caf18 and 13ed28f.

📒 Files selected for processing (3)
  • examples/chat.py (1 hunks)
  • hivemind_bus_client/client.py (1 hunks)
  • hivemind_bus_client/message.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
hivemind_bus_client/client.py (2)
hivemind_bus_client/message.py (2)
  • payload (125-135)
  • payload (138-144)
hivemind_bus_client/identity.py (2)
  • site_id (109-116)
  • site_id (119-121)
examples/chat.py (2)
hivemind_bus_client/message.py (2)
  • HiveMessage (44-245)
  • HiveMessageType (9-29)
hivemind_bus_client/client.py (5)
  • HiveMessageBusClient (93-522)
  • connect (193-213)
  • on_mycroft (403-405)
  • emit (336-397)
  • wait (64-75)
🪛 Ruff (0.14.8)
examples/chat.py

18-18: Unused function argument: message

(ARG001)

@github-actions github-actions bot added the fix label Dec 18, 2025
coderabbitai bot and others added 2 commits December 18, 2025 07:54
* 📝 Add docstrings to `fix/payload_context`

Docstrings generation was requested by @JarbasAl.

* #73 (comment)

The following files were modified:

* `examples/chat.py`
* `hivemind_bus_client/client.py`
* `hivemind_bus_client/message.py`

* Update client.py

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: JarbasAI <[email protected]>
@github-actions github-actions bot added fix and removed fix labels Dec 18, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
hivemind_bus_client/message.py (1)

145-158: Fix Message.as_dict to use serialize() method.

This issue was flagged in a previous review and remains unresolved. Line 154 calls payload.as_dict, but the ovos_bus_client.Message class does not expose an as_dict property. The codebase consistently uses serialize() for Message objects (see lines 178, and util.py references in past review).

🔎 Apply this diff to fix the setter:
 @payload.setter
 def payload(self, payload: Union['HiveMessage', Message, dict, bytes]):
     """
     Set the message payload, normalizing Message or HiveMessage inputs to their dictionary representations.
     
     Parameters:
         payload (HiveMessage | Message | dict | bytes): New payload to assign. If a `Message` or `HiveMessage` is provided, its dict representation is stored; otherwise the value is stored as given.
     """
     if isinstance(payload, Message):
-        self._payload = payload.as_dict
+        self._payload = json.loads(payload.serialize())
     elif isinstance(payload, HiveMessage):
         self._payload = payload.as_dict
     else:
         self._payload = payload
🧹 Nitpick comments (1)
examples/chat.py (1)

1-42: Clean example demonstrating HiveMessageBusClient usage.

The interactive chat script effectively demonstrates connecting to HiveMind, registering handlers, and sending BUS messages. The structure is clear and the handlers are correctly implemented.

Consider adding a timeout to answered.wait() on line 42 to prevent indefinite hangs if the utterance handling fails:

if not answered.wait(timeout=30):
    print("Timeout waiting for response")

This would make the example more robust, though the current implementation is acceptable for demonstration purposes.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 13ed28f and c0c0f90.

📒 Files selected for processing (3)
  • examples/chat.py (1 hunks)
  • hivemind_bus_client/client.py (2 hunks)
  • hivemind_bus_client/message.py (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
hivemind_bus_client/client.py (2)
hivemind_bus_client/message.py (2)
  • payload (125-143)
  • payload (146-158)
hivemind_bus_client/identity.py (2)
  • site_id (109-116)
  • site_id (119-121)
🪛 Ruff (0.14.8)
examples/chat.py

24-24: Unused function argument: message

(ARG001)

🔇 Additional comments (2)
hivemind_bus_client/client.py (2)

338-351: Good documentation for the emit method.

The added docstring clearly explains the method's purpose, parameters, behavior, and error conditions.


368-379: Context injection now uses consistent references.

The refactored code correctly uses updated_payload.context for all reads and writes, addressing the issue flagged in the previous review. However, line 379 (message.payload = updated_payload) depends on the payload setter working correctly, which currently has a bug (see comment on message.py lines 145-158).

Please verify that the payload setter bug is fixed before merging, as this code will fail at runtime when attempting to assign a Message back to message.payload.

@JarbasAl JarbasAl merged commit 989888a into dev Dec 18, 2025
1 check passed
@github-actions github-actions bot added fix and removed fix labels Dec 18, 2025
JarbasAl added a commit that referenced this pull request Dec 18, 2025
* Update README.md

* fix: defensive check for potential missing key (#69)

* fix: payload context update (#73)

* fix: payload context update

* 📝 Add docstrings to `fix/payload_context` (#74)

* 📝 Add docstrings to `fix/payload_context`

Docstrings generation was requested by @JarbasAl.

* #73 (comment)

The following files were modified:

* `examples/chat.py`
* `hivemind_bus_client/client.py`
* `hivemind_bus_client/message.py`

* Update client.py

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: JarbasAI <[email protected]>

* fix: payload context update

* fix: payload context update

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Increment Version to 0.4.4a1

* Update Changelog

---------

Co-authored-by: JarbasAI <[email protected]>
Co-authored-by: Mike <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: JarbasAl <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants