Skip to content
C.W.K.
Lesson 02 of 06 · published

Unknown Is Not Zero

~12 min · optionals, staleness, observation, honest-ui

Level 0Idle Hands
0 XP0/39 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete
"Show unknown or stale measurements explicitly, including timestamps; never turn missing CPU or a repeated cached sample into an invented improvement." — Tinker architecture

Tinker Has No Sampler of Its Own

The architecture forbids Tinker from shelling out to top, ps, Spotlight or iCloud tools. Watchfire already owns those probes and their interpretation — what counts as a live simulator, how to read Spotlight's indexing state — and a second, private sampler inside Tinker would eventually disagree with it. So Tinker's worker asks Watchfire for its workspace-snapshot of this Mac, by fleet label, over the family control route, and Tinker merely projects the answer into a small struct.

Every Field Is Optional

WatchfireSnapshot has an observation time, WindowServer CPU, the number of live simulators, a Spotlight state, an iCloud state, and a problem string — and every one of them is optional. When a value is missing, the status line says unknown. (The live heading in Settings, "Current WindowServer:", says unavailable instead — a different word for the same honest gap.) It never substitutes zero, because zero is a measurement: "WindowServer 0.0%" claims the window server did nothing, which an unreachable Watchfire cannot know. Tinker's tests include one whose whole job is to check that a missing observation is never reported as zero.

Fresh, Stale, or the Same Sample Twice

Settings shows how old the reading is — "Sampled 3s ago · refreshes every 5s" — and prefixes it with Stale once the sample is more than 30 seconds old. Watchfire's timestamps may or may not carry fractional seconds; the parser accepts both, and a timestamp it cannot parse says "Sample time unavailable" rather than pretending an age. In a before/after comparison, if both sides turn out to be the same cached Watchfire sample — same observation time — the line says so: "(same cached sample)". Otherwise identical numbers would read as "hiding changed nothing" when in fact nothing was re-measured.

CPU Is an Average, Not a Verdict

The README adds two cautions that belong in any measurement UI. CPU is macOS's recent average, not an instantaneous benchmark, so a single before/after pair is weak evidence. And low CPU does not establish that iCloud has finished syncing. Tinker shows numbers; it does not draw conclusions from them, and it certainly does not let a failed observation strand a change or block emergency release.

Code

Optional everything, and 'unknown' at the edge·swift
import Foundation

/// A projection of Watchfire observations. Tinker never runs a host probe.
public struct WatchfireSnapshot: Codable, Equatable, Sendable {
  public var observedAt: String?
  public var windowServerCPU: Double?
  public var liveSimulators: Int?
  public var spotlight: String?
  public var iCloud: String?
  public var problem: String?

  public var line: String {
    let cpu = windowServerCPU.map { String(format: "%.1f%%", $0) } ?? "unknown"
    let simulators = liveSimulators.map(String.init) ?? "unknown"
    return "WindowServer \(cpu) · simulators \(simulators) · " +
           "Spotlight \(spotlight ?? "unknown") · iCloud \(iCloud ?? "unknown")"
  }
}
Saying when a comparison compared nothing·swift
public static func comparison(_ before: Self, _ after: Self) -> String {
  let beforeCPU = before.windowServerCPU.map { String(format: "%.1f%%", $0) } ?? "unknown"
  let afterCPU = after.windowServerCPU.map { String(format: "%.1f%%", $0) } ?? "unknown"
  let freshness = before.observedAt != nil && before.observedAt == after.observedAt
    ? " (same cached sample)" : ""
  return "WindowServer \(beforeCPU) → \(afterCPU)\(freshness)"
    + " · simulators \(after.liveSimulators.map(String.init) ?? "unknown")"
    + " · Spotlight \(after.spotlight ?? "unknown") · iCloud \(after.iCloud ?? "unknown")"
}
Three honest status lines·text
Final Cut editing applied (3 changes) · WindowServer 38.2% → 21.5% · simulators 0 · Spotlight idle · iCloud idle
Final Cut editing applied (3 changes) · WindowServer 21.5% → 21.5% (same cached sample) · ...
Final Cut editing applied (3 changes) · WindowServer unknown → unknown · ... · Watchfire: Watchfire unavailable: ...

(numbers invented for illustration)

External links

Exercise

Find a dashboard or status line you maintain that shows a number which can be missing. What does it show when the source is down — zero, the last value, a dash, 'unknown'? Rewrite it so a reader can always tell 'measured zero', 'not measured', and 'measured but old' apart.
Hint
Three states need three renderings: the number itself, an explicit unknown for missing, and the number plus an age (or a stale marker) for old data. The most common bug is the last-value-forever display, which looks healthy precisely when the source has died.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign in — Please sign in to comment.

No comments yet — be the first.