One function

_state_dir in witt3rd/oh-my-hermes

The author described this change as fix(state): resolve state_dir against project_root, immune to cwd drift (Bug 2). It counts as a record because the check below fails on the code as it stood at 1b2403f0c and passes on 4d525b917, with nothing else changed between the two runs.

Fix saved2026-04-21
Sharing licenceMIT · LICENSE
Change size+16 0

What the code was meant to do, written into the code itself as a docstring

Resolve the OMH state directory to an absolute path. Resolution order (mirrors evidence_tool.py): 1. config["state_dir"] (defaults to ".omh/state"). 2. If relative, anchor against config["project_root"] if set, else against Path.cwd() at call time. 3. Resolve to absolute so subsequent cwd drift cannot redirect writes. This prevents Bug 2 (state silently landing in ~/.omh/state/ when Hermes was started from $HOME, or wherever the agent's cwd happens to be).

The change

11 def _state_dir() -> Path:
2+ """Resolve the OMH state directory to an absolute path.
3+
4+ Resolution order (mirrors evidence_tool.py):
5+ 1. config["state_dir"] (defaults to ".omh/state").
6+ 2. If relative, anchor against config["project_root"] if set,
7+ else against Path.cwd() at call time.
8+ 3. Resolve to absolute so subsequent cwd drift cannot redirect writes.
9+
10+ This prevents Bug 2 (state silently landing in ~/.omh/state/ when Hermes
11+ was started from $HOME, or wherever the agent's cwd happens to be).
12+ """
213 config = get_config()
314 p = Path(config.get("state_dir", ".omh/state"))
15+ if not p.is_absolute():
16+ project_root_cfg = config.get("project_root")
17+ base = Path(project_root_cfg).resolve() if project_root_cfg else Path.cwd().resolve()
18+ p = base / p
19+ p = p.resolve()
420 p.mkdir(parents=True, exist_ok=True)
521 _seed_dot_omh(p.parent)
622 return p

The check that tells the two apart

failpass·plugins/omh/tests/test_state.py::test_state_dir_uses_project_root_not_cwd

Check file plugins/omh/tests/test_state.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it1b2403f0c9a3aa9ccf96985cecd7dffd38d92579
Broken version dated2026-04-21
Moduleplugins.omh.omh_state
Units changed_state_dir
Fingerprinteaa6d34053e311c5
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in witt3rd/oh-my-hermes