Repository navigation
Description
Problem
All fetchers go through the TTL-based disk cache via the Fetcher trait. That makes sense for weather / github / rss (expensive I/O, safe to serve stale). It's actively wrong for clock and any widget whose value is intrinsically "right now":
ClockFetcher::fetchcomputesLocal::now()in microseconds — disk I/O for that is pure overhead.CacheEntry { refreshed_at, ttl_seconds: 60, payload }means a cache-warm invocation shows a minute-old timestamp on screen. Observably wrong on every second cd.- Future candidates have the same shape: uptime, cpu/mem instantaneous load, countdown-to-meeting.
Proposal: new RealtimeFetcher trait
Split fetchers into two categories by contract. Classification rule: if the value is "compute from wall clock / trivial local state in <1ms, always succeeds," it's realtime. Otherwise cached.
pub trait RealtimeFetcher: Send + Sync {
fn name(&self) -> &str;
fn safety(&self) -> Safety;
fn compute(&self, ctx: &FetchContext) -> Payload;
}- sync: no
async, noResult. The contract is "fast + infallible." Anything that could block or fail should beFetcher(cached). - no cache: disk cache is never consulted or written. Recomputed every frame.
Safetystays: same enum, same trust gate. Realtime widgets are almost allSafe, but that's not a guarantee baked into the type.
Runtime integration
Registryholds both kinds under one name-keyed lookup (enum variant).runtime.rssplits trust-partitioned widgets by kind:- Cached: unchanged — daemon fetches, disk cache, load in render.
- Realtime: never hit disk cache.
refresh_payloadsrecomputes them on every frame tick, and the one-shot cache-first path computes them once beforedraw_final.
daemon::fetch_and_persistignores realtime widgets (nothing to persist).
One-shot behavior
In the cache-first one-shot path (no animation, no --wait), realtime widgets still get one fresh computation before the final draw. They won't "tick" (no loop), but they also won't show a stale value from a previous invocation — which is the main win.
During the multi-frame loop (animation window or --wait), realtime widgets recompute each frame (50ms tick), so a clock with %H:%M:%S would appear to tick during that window.
Migration
ClockFetcher→RealtimeFetcher.TodayStub→RealtimeFetcher(alsoLocal::now()).- Other stubs stay on
Fetcher(they return canned data today, will become real cached fetchers later).
Why B (separate trait) over A (CachePolicy on Fetcher)
Considered adding fn cache_policy(&self) -> CachePolicy { Cached | Realtime } to the existing trait. Rejected because:
- A
Realtimefetcher that accidentally doesreqwestinsideasync fetchwould silently block the render loop. The contract "no I/O, fast" isn't enforced by the type — only by discipline. - Every frame would spawn an async future for clock. Non-issue for perf, but noise.
Separate sync trait makes the contract type-enforced and keeps the frame loop trivial.
Non-goals
- Wall-clock ticking at arbitrary granularity. Ticking cadence is
FRAME_TICK(50ms) within the existing loop window. Making splashboard run a persistent refresh loop outside the splash's "hand back to shell" lifecycle is a separate, bigger question. - Plugin-installable realtime fetchers (plugin protocol is closed, core: Plugin protocol (subprocess-based I/O spec) #5).
🤖 Generated with Claude Code
Activity