I have discovered what appears to be a severe bug in a development version of PostgreSQL 17 where a populated RECORD variable incorrectly fails an IS NOT NULL check.
Working as documented. You probably want to test: NOT (r IS NULL)
If the expression is row-valued, then IS NULL is true when the row expression itself is null or when all the row's fields are null, while IS NOT NULL is true when the row expression itself is non-null and all the row's fields are non-null.