Heuristic:1broseidon Ketch Throttled Update Probe
| Knowledge Sources | |
|---|---|
| Domains | Diagnostics, Caching, Performance |
| Last Updated | 2026-10-27 00:00 GMT |
Overview
A self-throttling rule for the "newer ketch available" notice: the network probe to GitHub's releases API happens at most once per day, a failed probe enters a 6-hour backoff before retrying, and the stderr hint only appears when the cached status is recent — so an interactive run never blocks on a network check and never nags the operator about a release it already announced.
The Insight (Rule of Thumb)
- Action: `GetStatus` loads the cached `update-check.json`. If the cache is fresh (`LastCheckedAt` within `checkTTL` = 24h) it returns from cache with no network. If stale, it fetches `https://api.github.com/repos/1broseidon/ketch/releases/latest`, but only when `AllowNetwork` is set and `inFailureBackoff` (a failure within `failedRetryTT` = 6h) is not active. On success it writes the new state; on failure it records `LastCheckFailedAt` and returns the stale cache.
- Value: `ShouldNotify` suppresses the notice when the same version was already announced within `notifyTTL` (24h), so the hint appears once per day per new release, not once per invocation. `KETCH_NO_UPDATE_NOTIFIER=1` (or CI env) disables both cache access and network checks entirely.
- Trade-off: A day-old cache means the notice can lag a new release by up to 24h. The 6-hour failure backoff means a flaky network does not cause a probe on every run. Both favour "never bother the operator" over "instant notice", because the notice is a soft hint on stderr, never a gating event.
- Compatibility: A non-semver current version (`dev`, empty) short-circuits: `isVersionCheckable` returns false and the whole status is returned empty. The fetch timeout is caller-controlled via `opts.Timeout`; a `nil` ctx becomes `context.Background()`.
Reasoning
The update check runs on every interactive CLI invocation, so it must be cheap and quiet. A daily cache (`checkTTL = 24h`) means at most one network probe per day across all of an operator's `ketch` runs — the first run of the day pays the probe, the rest hit the cache. The cache is a JSON file under `UserCacheDir/ketch/update-check.json` with a `schemaVersion` so a future format change can be detected and ignored safely.
The failure backoff (`failedRetryTT = 6h`, `updatecheck/updatecheck.go:282-287`) is the defense against a dead network or a broken GitHub API: a failed probe records `LastCheckFailedAt`, and for the next 6 hours a stale cache is returned with `Source: "cache"` rather than re-probing. So an operator on a flaky connection doesn't see a 5-second hang on every `ketch search` — they see the cache and a suppressed probe.
`ShouldNotify`/`MarkNotified` (`updatecheck/updatecheck.go:173-208`) track `LastNotifiedVer` and `LastNotifiedAt` so the two-line stderr hint (`FormatNotice`) prints once per release, then goes quiet for a day. Without this, every invocation of a stale binary would re-print the hint. The notice is also gated by `Disabled()` (the `KETCH_NO_UPDATE_NOTIFIER` env var) at both `GetStatus` and `ShouldNotify`, so an operator who finds it noise can silence it permanently.
The version comparison (`compareVersions` / `parseVersion`) is strict 3-part semver; a `dev` or `v(devel)` build is treated as "not checkable" and the whole feature returns early, so development builds never trip the notice against themselves.