Skip to content

core: RealtimeFetcher trait for clock-like widgets (bypass disk cache) #36

Closed

Description

@unhappychoice

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::fetch computes Local::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, no Result. The contract is "fast + infallible." Anything that could block or fail should be Fetcher (cached).
  • no cache: disk cache is never consulted or written. Recomputed every frame.
  • Safety stays: same enum, same trust gate. Realtime widgets are almost all Safe, but that's not a guarantee baked into the type.

Runtime integration

  • Registry holds both kinds under one name-keyed lookup (enum variant).
  • runtime.rs splits trust-partitioned widgets by kind:
    • Cached: unchanged — daemon fetches, disk cache, load in render.
    • Realtime: never hit disk cache. refresh_payloads recomputes them on every frame tick, and the one-shot cache-first path computes them once before draw_final.
  • daemon::fetch_and_persist ignores 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 (also Local::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 Realtime fetcher that accidentally does reqwest inside async fetch would 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

  1. added
    core
    on Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    core

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions