Hi Zsolt,
Thanks for the testing, both issues you reported were real; v10 (attached) fixes them.
Case 1 (plain "record" still crashed): the snapshot keyed off the variable's declared type, which is just RECORDOID for a RECORD variable, so nothing was tracked.
v10 uses the actual composite type adopted from the assigned value (er_typeid), so "r record := ROW(...)::foo" is now covered.
Case 2 (reassignment wrongly rejected): a fast path only re-checked the outermost type, so a stale nested entry survived a reassignment and caused a false positive.
v10 refreshes the snapshot on every whole-record assignment, so reassigning with fresh data after an ALTER now succeeds (matching master), while the same sequence without the reassignment still errors.
While testing, I also found a related crash the earlier versions missed: a composite reached through a container (e.g. a field of type "t_comp[]") wasn't tracked, because the recursion stopped at the array. An ALTER TYPE on the element type then crashed in record_out() and caused a connection timeout.
v10 iterates domain/array/range/multirange layers to reach the composite element.
v10 adds regression coverage for all of the above cases.