Skip to content

Make tool position updates robust to None entries and subscriber errors - #24

Open
BrennanTM wants to merge 1 commit into
PrecisionNeuroLab:mainfrom
BrennanTM:fix/tool-positions-robustness
Open

Make tool position updates robust to None entries and subscriber errors#24
BrennanTM wants to merge 1 commit into
PrecisionNeuroLab:mainfrom
BrennanTM:fix/tool-positions-robustness

Conversation

@BrennanTM

Copy link
Copy Markdown

What broke — in Devices/:

  • ToolPositionsServer.recordNewPosition and the client receive loop both dereferenced None position entries (the publish format allows them; recordNewPosition(key, None) over RPC stores one) → AttributeError killed the client loop.
  • An exception in any subscriber to sigLatestPositionsChanged propagated out of the receive loop into asyncCreateTask's swallow-and-log wrapper → tracking froze permanently while the GUI stayed responsive.
  • Same failure mode for sigIsConnectedChanged, emitted via _updateIsConnected() from both the receive and monitor loops (CameraPanel's subscriber does a sync ZMQ request and can raise).

Fix — null-guard both comparison paths; catch, log, and continue around both emits (except Exception, so CancelledError still cancels the loop). Also stop deserializing each message twice.

NoteSignal.emit still stops at the first raising subscriber within one update, so later subscribers miss that single event; changing that would be a global Signal behavior change, so it's out of scope here — happy to follow up if you'd prefer it.

Teststests/test_Devices/test_toolPositionsRobustness.py (4): a real server/client pair over ZMQ on random localhost ports, server in its own thread. Verified on macOS / Py 3.13; not yet run on Windows.

Four related robustness fixes:
- ToolPositionsServer.recordNewPosition dereferenced a stored None
  position (the table's type and publish path both allow None values).
- ToolPositionsClient's receive loop dereferenced None entries received
  from the wire when comparing against previous positions, killing the
  loop with AttributeError. Also reuse the already-deserialized
  positions dict instead of deserializing the message a second time.
- An exception raised by any subscriber to sigLatestPositionsChanged
  propagated out of the receive loop into a task wrapper that swallows
  it, permanently freezing position updates while the GUI stayed
  responsive. Log the exception and keep the loop alive instead.
- The same failure mode existed for sigIsConnectedChanged, emitted via
  _updateIsConnected from inside both the receive and monitor loops
  (e.g. CameraPanel's subscriber performs a synchronous ZMQ request and
  can raise); guard that emit the same way.

Note: within a single update, Signal.emit still stops at the first
raising subscriber, so later-priority subscribers miss that one event;
changing per-subscriber isolation semantics in Signal.emit would be a
global behavior change and is left out of scope here.
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.

1 participant