rapi_error_with_context() jumps into R, this appears to be unsafe or unsupported for ALTREP methods. I have seen stack overflows occur from this.
Define a guard that is activated whenever an ALTREP method is entered. Query this guard in rapi_error_with_context() and fall back to throwing an exception instead of calling into R via rapi_error() .