fix(gateway): harden Honcho cache memo invalidation - #46385
Conversation
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Fixes Honcho cache memo invalidation: the cache key now includes a component that changes when the config path changes, ensuring cached values don't persist across config reloads.
Reviewed by Hermes Agent
|
Thanks for isolating this to the Honcho memo key. The current-head premise is real: Problems
Suggested changes
Automated hermes-sweeper review. |
3ff05c9 to
2a267da
Compare
|
Thanks — I pushed The memo key now includes a SHA-256 content-hash discriminator alongside I also added a regression in |
|
Closing after review against current main. The memo this hardens exists to avoid I/O on the gateway's hot agent-cache path — and adding a full SHA256 of honcho.json to the key means every lookup now reads and hashes the file, which defeats the memo's purpose. The edge it protects against (a same-size rewrite landing inside one mtime tick on a coarse-mtime filesystem) is real but vanishingly rare, and its worst outcome is one stale cache generation until the next change. If this ever bites someone in practice, the right-shaped fix is size-only: Thanks for the well-tested submission @lkz-de — the failure mode analysis was solid. |
The memo was keyed on (path, st_mtime_ns), so an edit to honcho.json landing inside one mtime tick on a coarse-mtime filesystem kept serving the previously parsed identity config. Add st_size to the key — it comes from the single stat() call the memo already makes, so any same-tick rewrite that changes the file's size is now detected at zero added I/O on this hot path (it feeds the per-turn agent-cache signature). Deliberately NOT content-hashed. An equal-size rewrite inside one mtime tick can still reuse stale parsed state for one cache generation; that edge is vanishingly rare and self-heals on the next change. Hashing the file on every lookup would defeat the memo's no-I/O purpose — this is the exact design the maintainer resolution on NousResearch#46385 declined, naming st_size as the right-shaped discriminator. A test pins the documented tradeoff so a future change that silently adds per-lookup I/O surfaces as a deliberate decision rather than an accident. Tests cover: same-mtime size-changing rewrite invalidates (verified to fail against the old key), identical stat reuses the memo without re-parsing, the equal-size edge stays memoized by design, and stat failure still returns a parsed config. Supersedes the earlier content-hash version of this branch, which also accidentally reverted NousResearch#75581's relay rename behavior via a whole-file checkout across divergent bases — this rewrite touches only the memo.
Summary
Harden the Honcho cache-busting memo key so coarse-mtime rewrites of
honcho.jsoncannot reuse stale parsed identity state.Why
On coarse-mtime filesystems, rapid rewrites of
honcho.jsoncan keep the samest_mtime_nswhile changing contents. The earlier size-only approach still missed equal-size rewrites. Using a SHA-256 content hash as a discriminator closes that remaining stale-config path.Scope
Test plan
pytest tests/gateway/test_agent_cache.pyst_mtime_ns, equal file size, changedhoncho.jsoncontent, and asserts the Honcho parse is refreshedRelated