fix(update): run periodic update check in daemon so hints actually fire (#76)

* fix(update): run periodic update check in daemon so hints actually fire

The CLI spawned a detached thread to refresh ~/.bsk/update-check.json,
but the process exits as soon as the command finishes, killing the
thread before the fetch could complete — so the cache was never
written and the new-version hint never showed.

Move the periodic check into the daemon: a tokio task ticks every
30 minutes (down from 24h), refreshes the cache when missing/stale,
and logs failures at warn/info into the daemon log. The CLI path is
now read-only: it prints the hint only from a fresh cache and never
spawns threads or touches the network.

* fix(update): decouple daemon refresh window so checks truly run every 30min

The refresh decision reused the 30min tick interval as its freshness
window, and with is_fresh()'s inclusive bound a cache written just
after tick N still counted as fresh at tick N+1 — so in steady state
the daemon only refetched every other tick (~60min).

Judge staleness against DAEMON_REFRESH_WINDOW (25min = 5/6 of the
tick) instead: every 30min tick now finds the cache stale and really
refreshes, while a daemon restarted with a younger-than-25min cache
still skips its first tick. CLI hint freshness semantics
(UPDATE_CHECK_INTERVAL = 30min) are unchanged.
This commit is contained in:
BB-fat
2026-08-12 14:45:34 +08:00
committed by GitHub
parent 238a98476e
commit 89200975f3
3 changed files with 228 additions and 22 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ fn main() -> ExitCode {
if !matches!(cli.command, Command::Daemon(_)) {
init_cli_tracing(&cli.flags);
}
cli::update::maybe_spawn_background_check(&cli.flags, &cli.command);
cli::update::print_update_hint_from_cache(&cli.flags, &cli.command);
let format = if cli.flags.json {
Format::Json