implement a state stack for decoupled tracing of custom algs