Custom query on a terminated workflow returns error

Thanks for reporting. This looks like a bug. I filed an issue to get this fixed.