Skip to content

Fix RCSafetyModule offline learning guard to actually raise - #134

Open
rootkiller6788 wants to merge 1 commit into
facebookresearch:mainfrom
rootkiller6788:fix-offline-safety-learning-raise
Open

Fix RCSafetyModule offline learning guard to actually raise#134
rootkiller6788 wants to merge 1 commit into
facebookresearch:mainfrom
rootkiller6788:fix-offline-safety-learning-raise

Conversation

@rootkiller6788

Copy link
Copy Markdown

What

RCSafetyModuleCostCriticContinuousAction.learn_batch is meant to reject offline safety learning with a clear error, but the AssertionError(...) was never raised:

def learn_batch(self, batch: TransitionBatch, policy_learner: PolicyLearner) -> None:
    """Don't support offline training for now."""
    AssertionError("Offline safety learning is not supported yet.")
    pass

The bare expression constructs the exception and discards it. In addition, the signature (self, batch, policy_learner) mismatches both the base class SafetyModule.learn_batch(self, batch) and the only call site PearlAgent.learn_batch (self.safety_module.learn_batch(batch)), so a user hitting the offline path gets a TypeError: learn_batch() missing 1 required positional argument: 'policy_learner' instead of the intended message.

Why

Offline safety learning is documented as unsupported, so the method should fail fast with an informative error rather than silently no-op (or crash with an unrelated TypeError).

How

  • Align the signature to (self, batch) (matches the base class, IdentitySafetyModule, RiskSensitiveSafetyModules, and the agent call site).
  • raise the AssertionError, and drop the now-resolved # pyre-fixme[14].
  • Add test/unit/with_pytorch/test_safety_module.py asserting learn_batch raises.

Verified: new test fails before the change (TypeError) and passes after; test_agent.py (agent construction) suite passes with the change.

learn_batch constructed an AssertionError without raising it, so offline
safety learning silently did nothing. The signature also mismatched the
base SafetyModule.learn_batch(batch) and the agent call site, raising a
confusing TypeError instead. Align the signature to (self, batch) and
raise the intended informative error. Add a regression test.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant