Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/inspect_robots/approver.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,18 @@ def rewind_reference(store: dict[str, Any], pose: npt.NDArray[np.float64]) -> No
the limiter measures subsequent deltas from the pose that actually ran.
If the limiter has not established a reference, this is a no-op.
"""
if _LAST_APPROVED_KEY in store:
if _LAST_APPROVED_KEY in store and bool(np.all(np.isfinite(pose))):
store[_LAST_APPROVED_KEY] = pose.copy()

def review(self, action: Action, store: dict[str, Any]) -> Action:
"""Limit per-step change, retaining absolute-mode history in trial state."""
data = np.asarray(action.data, dtype=np.float64)
if bool(np.isnan(data).any()):
raise SafetyAbort("DeltaLimitApprover: action contains NaN; refusing to pass it on")
if not bool(np.all(np.isfinite(data))):
raise SafetyAbort(
"DeltaLimitApprover: action contains NaN or non-finite values; "
"refusing to pass it on"
)

if self._absolute:
reference = store.get(_LAST_APPROVED_KEY)
if reference is None:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_approvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ def test_rewind_reference_uses_the_limiter_store_key() -> None:
assert np.array_equal(reference, np.array([0.3, 0.4]))


def test_delta_limit_approver_rejects_inf() -> None:
approver = DeltaLimitApprover(_abs_space(), max_delta=0.1)
store: dict[str, object] = {}
with pytest.raises(SafetyAbort, match="non-finite"):
approver.review(Action(data=np.array([float("inf"), 0.0])), store)

with pytest.raises(SafetyAbort, match="non-finite"):
approver.review(Action(data=np.array([0.0, float("-inf")])), store)


def test_substitution_rewinds_the_next_delta_reference() -> None:
held = Action(data=np.array([0.0, 0.0]))

Expand Down
Loading