[Apologies for not reply-linking this; work email is down so I'm sending from gmail.]
Based on feedback from Heikki and Tom I've reworked how I find the top-level transaction. This is in the git repo, and the changes can be viewed at: http://git.postgresql.org/gitweb?p=users/kgrittn/postgres.git;a=commitdiff;h=e29927c7966adba2443fdc4f64da9d282f95a05b -Kevin