fix(cache): signatures stored and compared later always hash

Review of #145651, item 3: the hook-consent signature, free-tier inventory stamp, onboarding due
stamp and skills manifest are kept and compared on a later tick or by the next process, so they use
always_digest=True like the PR's other stored signatures; a racy digest turning empty no longer
costs one recompute after a fresh write settles.
This commit is contained in:
Teknium
2026-10-27 11:47:11 -07:00
parent 6f37cc8aae
commit f09d03dfe2
5 changed files with 10 additions and 6 deletions

View File

@@ -1110,7 +1110,7 @@ def _build_skills_manifest(skills_dir: Path) -> dict[str, list[int]]:
try:
if filename in files:
st = os.stat(path)
manifest[path[prefix_len:]] = list(file_cache_version(path, st))
manifest[path[prefix_len:]] = list(file_cache_version(path, st, always_digest=True))
except OSError:
pass
return manifest

View File

@@ -41,7 +41,7 @@ _OWN_GATEWAY_PROBE_TIMEOUT_SECS = 5.0
def _stat_signature(path: Path) -> Optional[tuple]:
try:
return file_cache_version(path)
return file_cache_version(path, always_digest=True) # stored, compared on a later tick
except OSError:
return None

View File

@@ -135,7 +135,7 @@ def _config_stamp() -> tuple:
stamp = []
for name in _INVENTORY_FILES:
try:
stamp.append(file_cache_version(home / name))
stamp.append(file_cache_version(home / name, always_digest=True))
except OSError:
stamp.append(None)
return tuple(stamp)

View File

@@ -79,7 +79,7 @@ def _shared_nous_store() -> tuple[Path, ...]:
def _version(path):
from utils import file_cache_version
try:
return file_cache_version(path)
return file_cache_version(path, always_digest=True) # stamp stored, compared later
except OSError:
return None

View File

@@ -20,7 +20,7 @@ already reaches it.
| `read_config_doc(path)` | Parsed user layer (raises like `open` + `fast_safe_load`) |
| `read_config_doc_readonly(path)` | Signature-cached read; never mutate the result |
| `config_version(path)` | Change signature (the file's stat tuple) |
| `config_cache_version(path)` (`config_cache_version_or_none`) | Signature for a cache of the parse: the stat tuple plus a content digest while the mtime is younger than `utils.RACY_MTIME_WINDOW_NS` (`utils.file_cache_version` on the file backend) |
| `config_cache_version(path)` (`config_cache_version_or_none`) | Signature for a cache of the parse: the stat tuple plus a content digest while the later of mtime and ctime is younger than `utils.RACY_MTIME_WINDOW_NS` (`utils.file_cache_version` on the file backend) |
| `config_exists(path)` | Whether the layer exists |
| `probe_config_readable(path)` | Raise `OSError` while the layer cannot be read (no parse) |
| `write_config_document(path, doc)` / `write_config_key(path, key, value)` | Writes; callers normally use `atomic_config_write` / `atomic_config_replace` |
@@ -33,7 +33,11 @@ pins the older parse for the life of the process (a rotated `api_key` is the usu
Any other file a cache derives from (`auth.json`, pairing lists, `.env`, token files, the managed
overlay) keys on `utils.file_cache_version(path)`; a signature stored and compared much later (a
change detector whose false positive reconnects something, a parse-failure record) passes
`always_digest=True`, because the racy digest turns empty once the file settles. The managed scope (`/etc/hermes`) stays an overlay on top
`always_digest=True`, because the racy digest turns empty once the file settles (the skills
manifest, hook-consent, free-tier and onboarding stamps do). "Recent" is judged on ctime as well as
mtime, because `cp -p` or `rsync --inplace -t` restore an older mtime after writing. A worker bound to
a frozen config snapshot never hashes a `config.yaml`: its key stays stat-only there, so the content
check never makes such a worker open the profile file. The managed scope (`/etc/hermes`) stays an overlay on top
of whatever user layer the backend returns.
## Lints