Make the external data cache typed !17

merged merged by cmc on 2026-10-24 06:18 UTC · krz/domain-dig:typed-lookup-cache into main

Discussion

cmc

Closes half of C4, and says why the other half waits.

ExternalDataService.execute was generic over CachedPayload, an enum of every payload kind, and each caller passed a four-line closure to pull its own case back out. A disagreement between the two called fatalError.

It is generic over the value now. The enum and all three extract: closures are gone, operations return their value directly instead of wrapping it in a case, and the live path runs a typed Task<T, Never> and returns its result with no cast at all — so the mismatch cannot arise, rather than being unlikely. Cached and in-flight reads still cast, and a wrong type falls through to a fetch instead of ending the process.

The other half is deliberate

LookupRuntime:282 has the identical trap with fourteen callers rather than three. It is the inspection cache — provenance, cache-source attribution, in-flight coalescing — and it has no test coverage at all, because that is W2's unfinished half. Converting it blind is exactly how the bug this change prevents gets introduced. Tests first, then the refactor; C4 stays half open in the spec rather than being marked done.

156 tests, 0 failures on iOS 18.6 and iOS 27.0.