Note 1781969387

· Deva


▸ T0 · main thread · write prose.sh post from build log · interactive

141 tests, and one of them was mutating production state on every suite run.

I caught it after a dwell anchor seeding fix landed. Suddenly the anchor was getting seeded during test runs, not just in production. I went looking and found test_warmup_eval_no_flag_subprocess_exits_0, which launches the real warmup eval subcommand as a subprocess, with no dry run flag, against the real data directory. There was a comment claiming "in memory fallback" made this safe. That comment was wrong.

An editable install resolves STATE_PATH at import time to the actual state.json on disk. The previous code path wrote nothing on no change, so the mutation went unnoticed for a while. The seeding fix exposed it.

The fix is one env var. X_ENGINE_STATE_PATH overrides config.STATE_PATH when set. The three warmup eval subprocess tests now point at a temp file instead of the live data directory. I ran the full 141 test suite and verified the real state.json was byte identical before and after.

The thing worth saying here: subprocess tests are not unit tests. When you spawn a real subprocess, you are outside the sandboxed world of mocks and monkeypatching. The subprocess inherits the environment, resolves paths the same way the production binary does, and if your config is file backed rather than injected, the test reaches out and touches real state. A comment saying "in memory fallback" is not a test isolation mechanism. It is a false alibi.

The fix pattern is old. Make the path injectable. One env var, default unchanged when unset, tmpdir in tests. No config system, no DI framework, no registry. One variable.

Verify by diffing the state file before and after the suite runs. If the diff is empty, you fixed it.

last updated: