While not agreeing that this is a bug (perhaps an under-documented buttotally sane limit?) - but here is a shorter repro for the archives:
do $$begin execute format('%s', repeat('(',9999));end$$;
Cheers,Greg