Skip to content

NIS bridge worker thread, NIS monitor, and test coverage - #4

Merged
qquais merged 21 commits into
mainfrom
physarum-imaging-and-estop
Oct 17, 2026
Merged

qquais merged 21 commits into
mainfrom
physarum-imaging-and-estop

Conversation

@qquais

@qquais qquais commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Why
The first version of the NIS bridge froze NIS-Elements, because the JOBS task runs on NIS's main thread and serving there never returned (2026-10-15). There was also no way to see what Claude was sending to the microscope, and most of the hardware code had no tests that run without the scope.

What

  • Serve the bridge from a worker thread so NIS stays responsive. A second bridge on the same port is refused, because on Windows a duplicate could bind the port and needed two shutdowns.
  • Event log and live terminal monitor. Each bridge action is logged to logs/nis/ as start and then ok, failed, refused or error. The monitor shows stage, Z, objective, ND state and the e-stop, and it names the call the bridge is stuck on. The NIS MCP server opens it, so you can watch what Claude does.
  • Optical configurations. A read-only tool lists them. Selecting one from the worker thread froze NIS, so it can't be done from here.
  • Tests that need no hardware, using fake Ti2, camera, NIS and tkinter objects and a simulated agar scene. They cover the e-stop, data paths, stage positions, mosaic, time-lapse, worm_follow, the STOP panel, the harness loops and the analysis scripts.
  • CI and packaging. Real OpenCV in the test extra, a coverage floor of 90%, and scipy and scikit-image ranges so Python 3.11 can install.
  • Harness. Camera frames held inside tool_result blocks are pruned, so old images stop filling the conversation.
  • Docs. The NIS bridge results from the scope on 2026-10-15.

Testing

  • On the scope (2026-10-15): NIS stays responsive with the bridge running, reads work, XY moves work, the 1500 µm move is refused, the e-stop refuses in both the client and the bridge, and objective changes turn the turret 4x ↔ 10x.
  • Off the scope: all tests pass without hardware.
  • Known problem: capture and ND runs crashed NIS from the worker thread on 2026-10-16 (nis_ar.exe, Qt5Core.dll), after this PR was written. They are not safe to use until a follow-up PR runs them on NIS's main thread. The off-scope tests can't show whether that works in the real NIS.

qquais added 21 commits October 15, 2026 19:01
…e a second bridge on the port

A JOBS Python task runs on NIS's main thread, so the serving loop froze NIS
(step 0 of the test plan). run() now starts serve() on a worker thread and
returns. Windows SO_REUSEADDR let a re-run bind a duplicate bridge on the
same port; that is off now. Adds a read-only list of optical configurations.
Selecting one from the worker thread froze NIS, so there is no select.
Every action through the bridge client is logged to logs/nis/events-<date>.jsonl
(start, then ok/failed/refused/error). python -m acquisition.nis_monitor shows
bridge state and the action feed live, says BUSY and names the call when one
long NIS call holds the bridge, and opens by itself in its own console when
confocal-mcp-nis starts (CONFOCAL_NO_NIS_MONITOR=1 turns that off). Adds the
read-only nis_list_optical_configs tool.
launch() returns early off Windows, so the test that checks it opens one
window never saw Popen on the Linux CI runner. Patch ON_WINDOWS in the
test, and stop the server-tools test from opening a monitor window.
@qquais qquais self-assigned this Oct 16, 2026
@qquais
qquais merged commit 642c87a into main Oct 17, 2026
4 checks passed
@qquais qquais changed the title Physarum imaging and estop NIS bridge worker thread, NIS monitor, and test coverage Oct 17, 2026
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