Skip to content

fix(celesta): add HTTP timeout so an unreachable laser engine cannot hang startup - #643

Open
Alpaca233 wants to merge 1 commit into
masterfrom
fix/celesta-http-timeout
Open

fix(celesta): add HTTP timeout so an unreachable laser engine cannot hang startup#643
Alpaca233 wants to merge 1 commit into
masterfrom
fix/celesta-http-timeout

Conversation

@Alpaca233

Copy link
Copy Markdown
Collaborator

Problem

On a Squid with a Lumencor Celesta (USE_CELESTA_ETHERNET_CONTROL = True), startup hung after the Toupcam began streaming. The last lines in the console were the camera's frame N (CONTINUOUS) diagnostics and nothing else ever appeared.

Microscope.build_from_global_config constructs CELESTA() right after the camera. That driver's HTTP helper called urllib.request.urlopen() with no timeout, so when the Celesta is unplugged, powered off, or the PC's NIC is not on the 192.168.201.x subnet, the first GET IP request blocks indefinitely and the GUI window never opens.

Fix

control/celesta.py:

  • lumencor_httpcommand() takes a timeout= argument (default DEFAULT_TIMEOUT_S = 5.0) and passes it to urlopen(), bounding both the TCP connect and the response read.
  • CELESTA accepts a timeout= kwarg and routes every command through a single _command() helper, so the timeout applies to all requests uniformly.
  • The connection-failure log now reports the real IP and timeout instead of a hard-coded string.

No behavior change when the Celesta is reachable.

When it is not reachable, startup now fails after roughly 10 s with a clear Failed to connect to Lumencor Laser at ip: 192.168.201.200 error (the constructor's request times out, then the illumination controller's first request raises) instead of hanging. Letting the GUI come up with the laser offline is out of scope here and would be a follow-up.

Tests

New tests/control/test_celesta.py (4 tests, urlopen monkeypatched, no network):

  • default timeout is passed to urlopen
  • explicit timeout is honoured
  • a timed-out connect leaves the device marked offline (live == False)
  • the configured timeout reaches every request made during __init__
python3 -m pytest tests/control/test_celesta.py -q   # 4 passed
black --config pyproject.toml --check control/celesta.py tests/control/test_celesta.py   # clean

🤖 Generated with Claude Code

https://claude.ai/code/session_01UCmWuptseJKs9AfLrVLkRR

…cannot hang startup

CELESTA() is constructed synchronously in Microscope.build_from_global_config,
right after the camera opens. Its HTTP helper called urllib.request.urlopen()
with no timeout, so when the Celesta was unplugged, powered off, or on a
different subnet the first `GET IP` request blocked forever and the GUI never
appeared. The last thing in the log was the Toupcam frame diagnostics.

- lumencor_httpcommand() now takes timeout= (default 5 s) and passes it to
  urlopen(), bounding both TCP connect and the response read.
- CELESTA accepts a timeout= kwarg and routes every command through one
  _command() helper so the timeout applies uniformly.
- The connection-failure log reports the actual IP and timeout in use.

Behavior when the Celesta is still unreachable: startup now fails with a
logged "Failed to connect to Lumencor Laser" error instead of hanging. It does
not yet let the GUI come up without the laser.

Tests: tests/control/test_celesta.py covers the default timeout, an explicit
timeout, a timed-out connect marking the device offline, and the configured
timeout reaching every request made during init.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UCmWuptseJKs9AfLrVLkRR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

All reviewed changes are covered by focused tests with no unresolved issues.

Pull request overview

Adds bounded HTTP timeouts to prevent an unreachable Celesta laser from hanging startup.

Changes:

  • Applies configurable timeouts to all Celesta HTTP requests.
  • Improves connection-failure logging.
  • Adds timeout propagation and offline-state tests.
File summaries
File Description
software/control/celesta.py Adds configurable HTTP timeouts and centralized command dispatch.
software/tests/control/test_celesta.py Tests timeout behavior, propagation, and offline state.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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