Skip to content

Fix AttributeError in health_reporter from dict iteration and missing Connection attributes#1

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-service-metrics-error
Draft

Fix AttributeError in health_reporter from dict iteration and missing Connection attributes#1
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-service-metrics-error

Conversation

Copilot AI commented Jan 5, 2026

Copy link
Copy Markdown

The health reporter crashed with AttributeError: 'str' object has no attribute 'port_id' when collecting service metrics because it iterated over dict keys instead of values, and the Connection dataclass was missing bytes_read/bytes_written attributes.

Changes

  • Added byte counters to Connection dataclass (serial_manager.py)

    • Added bytes_read and bytes_written fields (default 0)
    • Incremented counters in _read_continuously(), read_from_port(), and write_to_port()
  • Fixed dict iteration

    • Changed for conn in active_connectionsfor conn in active_connections.values() in health_reporter.py and api/connections.py
    • get_active_connections() returns Dict[str, Connection]; iterating directly loops over keys (strings), not Connection objects
  • Added tests (test_connection_bytes_tracking.py)

    • Verifies Connection has byte tracking attributes
    • Validates health reporter handles dict of connections correctly

Example

Before:

for conn in active_connections:  # conn is a string (port_id)
    print(conn.port_id)  # AttributeError: 'str' object has no attribute 'port_id'

After:

for conn in active_connections.values():  # conn is a Connection object
    print(conn.port_id)  # Works correctly
    print(conn.bytes_read)  # Now tracked
Original prompt

{"timestamp": "2026-01-05T17:32:15.680384+00:00", "level": "ERROR", "module": "src.health_reporter", "event": null, "message": "Error collecting service metrics: 'str' object has no attribute 'port_id'", "exc_info": "Traceback (most recent call last):\n File "/home/hyperloop/rpi-hub-server/src/health_reporter.py", line 219, in _collect_service_metrics\n "port_id": conn.port_id,\n ^^^^^^^^^^^^\nAttributeError: 'str' object has no attribute 'port_id'", "taskName": "Task-11"}

Created from VS Code.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 5, 2026 17:40
…nection and fixing dict iteration

Co-authored-by: WesP10 <97987799+WesP10@users.noreply.github.com>
…ion fix

Co-authored-by: WesP10 <97987799+WesP10@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error collecting service metrics due to incorrect data type Fix AttributeError in health_reporter from dict iteration and missing Connection attributes Jan 5, 2026
Copilot AI requested a review from WesP10 January 5, 2026 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants