fix(eiger): finish on_complete when JFJoch is Idle but wait_till_done errors
CI for csaxs_bec / test (push) Successful in 3m42s

After a collection that ends with a broker error (e.g. "Missing packets in
data collection; reduce frame rate"), JFJoch's /wait_till_done answers
HTTP 500 with that message on every call although the broker is already
Idle. wait_for_idle() then always returned False, so on_complete spun
(logging one error per call) until _wait_for_on_complete and raised a
TimeoutError. The missing-packet tolerance was never reached, and the scan
failed even with raise_on_missing_packets=False (S00985, 2026-11-11, with
10/10 images written).

Now a failing wait_for_idle is followed by a broker-state check: if the
broker is Idle, the usual message and frame-count checks decide the
outcome. While it is still busy, the loop waits 0.2 s between attempts
instead of retrying immediately.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
menzelandClaude Opus 5.5 authored and x12sa committed 2026-11-11 09:55:52 +01:00
1 parent 15a8773c95
commit 09d201b470
2 files changed
+73 -2

No files matched your search

+12 -1
View File
@@ -572,7 +572,18 @@ class Eiger(PSIDeviceBase):
f"Device {self.name} is in ERROR state during acquisition. Broker status: "
f"{yaml.dump(self.jfj_client.jfj_status.to_dict(), indent=4)}"
)
if self.jfj_client.wait_for_idle(timeout=1, raise_on_timeout=False):
# NOTE JFJoch's /wait_till_done answers HTTP 500 carrying the broker message
# when the last collection ended with an error (e.g. missing packets), even
# though the broker is already Idle, and keeps doing so on every call. So
# wait_for_idle returning False does not mean "not finished yet": check the
# broker state too, and let the message checks below decide. Without this,
# such a scan spun here (logging an error per call) until the timeout.
finished = self.jfj_client.wait_for_idle(timeout=1, raise_on_timeout=False)
if not finished:
finished = self.jfj_client.detector_state == DetectorState.IDLE
if not finished:
time.sleep(0.2) # wait_for_idle can fail immediately; don't spin
if finished:
# Call API endpoints to get broker status
broker_status = self.jfj_client.jfj_status
if broker_status.message_severity not in [
+61 -1
View File
@@ -401,7 +401,11 @@ def test_eiger_on_complete(eiger_1_5m, raise_timeout):
mock.patch.object(
eiger.jfj_client.api,
"status_get",
return_value=BrokerStatus(state="Idle", message_severity="info"),
# A broker that reports Idle counts as finished even if wait_for_idle fails,
# so the timeout case needs one that is still measuring.
return_value=BrokerStatus(
state="Measuring" if raise_timeout else "Idle", message_severity="info"
),
),
mock.patch.object(eiger.jfj_client, "wait_for_idle", side_effect=mock_wait_for_idle),
mock.patch.object(
@@ -781,6 +785,62 @@ def test_eiger_tolerance_does_not_hide_a_short_acquisition(eiger_1_5m):
_run_on_complete(eiger, _missing_packets_status(), images_collected=9)
def _run_on_complete_wait_till_done_failing(eiger, broker_status, images_collected=10):
"""Like _run_on_complete, but as JFJoch behaves after a collection that ended in an
error: /wait_till_done answers HTTP 500 on every call, so wait_for_idle always
returns False, while the broker itself already reports Idle (seen 2026-11-11, S00985).
"""
eiger._wait_for_on_complete = 2
with (
mock.patch.object(eiger.jfj_client.api, "status_get", return_value=broker_status),
mock.patch.object(eiger.jfj_client, "wait_for_idle", return_value=False),
mock.patch.object(
eiger.jfj_client.api,
"statistics_data_collection_get",
return_value=MeasurementStatistics(run_number=1, images_collected=images_collected),
),
):
status = eiger.complete()
status.wait(timeout=5)
return status
def test_eiger_tolerates_missing_packets_when_wait_till_done_errors(eiger_1_5m):
"""The tolerance must apply although /wait_till_done keeps failing -- before the fix
this case spun until the on_complete timeout and raised TimeoutError instead."""
eiger = eiger_1_5m
eiger.set_raise_on_missing_packets(False)
eiger._num_triggers = 10
start = time.time()
status = _run_on_complete_wait_till_done_failing(eiger, _missing_packets_status())
assert status.done is True
assert status.success is True
assert eiger.get_missing_packet_events() == 1
assert time.time() - start < 1.5 # resolved on the first pass, not by the timeout
def test_eiger_raises_eiger_error_not_timeout_when_wait_till_done_errors(eiger_1_5m):
"""With the tolerance off the scan still fails -- with the broker error, promptly."""
eiger = eiger_1_5m
eiger.set_raise_on_missing_packets(True)
with pytest.raises(EigerError, match="error status from JungfrauJoch broker"):
_run_on_complete_wait_till_done_failing(eiger, _missing_packets_status())
def test_eiger_still_waits_while_measuring_when_wait_till_done_errors(eiger_1_5m):
"""A failing wait_till_done must not count as finished while the broker is busy."""
eiger = eiger_1_5m
eiger.set_raise_on_missing_packets(False)
with pytest.raises(TimeoutError):
_run_on_complete_wait_till_done_failing(
eiger, BrokerStatus(state="Measuring", message_severity="info", message="")
)
def test_eiger_missing_packet_tolerance_is_switchable_at_runtime(eiger_1_5m):
"""The flag is reachable from the client, so a beamtime can change its mind."""
eiger = eiger_1_5m