Aha! It works if we reverse the order of the commands.
tc qdisc add dev lo root handle 1: htb default 12 tc class add dev lo parent 1:1 classid 1:12 htb rate 20kbps ceil 20kbps tc qdisc add dev lo parent 1:12 netem delay 1000ms
https://lists.linux-foundation.org/pipermail/netem/2010-May/001388.html