Emil Dmitruk

Two silent bugs in an RL pipeline

Bugs that throw are easy. The expensive ones run cleanly and return plausible numbers that happen to be wrong. Two of those turned up in an empowerment-driven RL project.

The work that found them was performance work

The empowerment estimator was slow, so I memoised it on content-addressed snapshots of the agent's statistics. The environment is a deterministic gridworld, so identical (goal, outcome-count) tuples recur constantly and caching pays off. That gave roughly a 5× cut in computation cost.

The useful side effect: memoising a function forces you to write down exactly what it depends on. The first bug below fell out of that exercise; the second turned up separately.

Bug 1: a cached function that drew randomness

One of the memoised functions sampled internally. A function that draws randomness cannot be cached: on every call after the first it returns the stale first draw instead of a fresh sample. Nothing errors. The values are in range. The run completes and the curves look like curves.

The fix was to remove caching from that function. The general rule is the point: a cache key is a claim about what the output depends on, and if the claim is wrong, the failure is silent by construction.

Bug 2: a config value that never arrived

The experiment runner never forwarded two estimator settings from the config file to the estimator. Runs configured for one mode had been executing with the class defaults the whole time. The value was in the config; it just never reached the object that needed it, and a missing value fell back to a plausible default, so nothing complained.

That one is now a ValueError. A configuration key the code does not support should stop the run, not quietly select a different experiment from the one you asked for.

Knowing whether a bug mattered

Finding a bug is only half the work. In a later, team-wide audit of the same codebase, every fix was validated by re-running and checking whether the outputs changed at all. Several of the defects produced bit-identical goal and success sequences before and after, which means they had never affected a published number. Worth knowing either way, and cheap to establish.

What I took from it:

CC BY-SA 4.0 Emil Dmitruk. Last modified: November 27, 2026. Website built with Franklin.jl and the Julia programming language.