Wire shared getLatestVersionCached into CC and Codex session-start hooks#70
Wire shared getLatestVersionCached into CC and Codex session-start hooks#70
Conversation
…ck (1h cache) The cached helper has existed in src/hooks/version-check.ts since it was written, with full test coverage, but was never wired into production. All three session-start hooks (CC session-start, CC session-start-setup, codex session-start-setup) were still calling the uncached getLatestVersion() — meaning they hit raw.githubusercontent.com on every session start. Now all three use getLatestVersionCached, which caches the fetched 'latest' version at ~/.deeplake/.version-check.json with a 1h TTL (falls back to cached value on fetch failure). Reduces per-host per-day GitHub fetches from once-per-session to at most once-per-hour, matches the openclaw plugin's wiring in PR #69, and eliminates the 'we hit GitHub on every session' disclosure gap. Test isolation: hooks now respect process.env.HIVEMIND_VERSION_CACHE_PATH if set. Session-start and session-start-setup tests use mkdtempSync to give each test a unique cache path, so the cache doesn't bleed between tests (or into the user's real ~/.deeplake/.version-check.json). Exported GITHUB_RAW_PKG from src/utils/version-check.ts so call sites pass the URL to the cached helper explicitly. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Claude finished @kaghni's task in 2m 35s —— View job Review
One issue found and posted as an inline comment: the Everything else looks clean: test isolation with per-test tmp dirs is correct, |
Coverage ReportScope: files changed in this PR. Enforced threshold: 90% per metric (per file via
File Coverage — 4 files changed
Generated for commit 2e10e34. |
| } catch { | ||
| const latest = stale?.latest ?? null; | ||
| writeVersionCache({ | ||
| checkedAt: nowMs, | ||
| latest, | ||
| url: opts.url | ||
| }, cachePath); | ||
| return latest; | ||
| } |
There was a problem hiding this comment.
Writing checkedAt: nowMs in the catch block resets the full 1h TTL on any transient fetch failure (timeout, DNS hiccup). A brand-new install with a brief network blip will cache null and skip version checks for an entire hour. The same issue exists in the !res.ok branch (line 503) — a non-200 response also silently extends the TTL.
Skip the cache write on error and just return the stale value; retrying next session is preferable to a guaranteed 1h blackout. Fix should be applied in src/hooks/version-check.ts (the bundle is generated):
| } catch { | |
| const latest = stale?.latest ?? null; | |
| writeVersionCache({ | |
| checkedAt: nowMs, | |
| latest, | |
| url: opts.url | |
| }, cachePath); | |
| return latest; | |
| } | |
| } catch { | |
| return stale?.latest ?? null; | |
| } |
|
Closing without merge. The per-session fetch is the current and preferred behavior. Caching was the bot-suggested alternative to the disclosure fix; now that openclaw's docs (PR #69) accurately name both network destinations, the caching mitigation isn't needed. Context: the |
Summary
Completes the version-check caching work started in PR #69 (which wired openclaw). The cached helper
getLatestVersionCachedhas existed insrc/hooks/version-check.tsfor a while — written, exported, fully unit-tested — but was never wired into production. All three Claude Code and Codex session-start hooks were still calling the uncachedgetLatestVersion(), meaning each session fires araw.githubusercontent.comrequest.This PR switches them to the cached version. Same helper that PR #69 uses for openclaw.
What changes
src/hooks/session-start.ts— CC session-startsrc/hooks/session-start-setup.ts— CC async setupsrc/hooks/codex/session-start-setup.ts— codex async setupAll three now call:
~/.deeplake/.version-check.jsonwith a 1h TTLHIVEMIND_VERSION_CACHE_PATHenv override for test isolationGITHUB_RAW_PKGis now exported fromsrc/utils/version-check.tsso callers reference the canonical URL.Test isolation
Previously, the session-start tests mocked global
fetchbut let the cache helper write to the user's real~/.deeplake/.version-check.json. Between tests, cached state would bleed into fetch-mock assertions. This PR:mkdtempSync+HIVEMIND_VERSION_CACHE_PATHafterEachTest plan
npm run typecheckcleannpm run build— all bundles rebuiltnpm test— 918/918 passing across 41 filesFollow-up
After merge, the full caching story lines up across all three hosts:
Network-destinations disclosure (in the README and SKILL.md) can then honestly say "contacts
raw.githubusercontent.comat most once per hour."🤖 Generated with Claude Code