Interesting writeup. I loath setting environment variables on long running terminal sessions exactly because it’s not obvious once they’re set.
I prefer to use a subshell for the command and set the environment variable each time:
$ ( export FOO=bar; my_cmd )