Files
patriothacks/.omo/evidence/coherence-audit/lightclock.md
T
OmO Orchestrator 93101cf237 docs: add 13-mini-app concept-execution coherence audit evidence
Full read-only audit of all 13 mini-apps against README's problem-mapping
table + each module's own doc comments. 6 COHERENT (lightclock, fairdraw,
healthpost, theclimb, sky, mentor), 7 GAP-FOUND and fixed in prior commits
(fairshare, waterwatch, tunnelsafety, housing, assembly, findfamily, farms).
2026-11-20 17:58:56 -05:00

10 KiB

Light Clock (ma-lightclock) coherence audit

Scope: src/miniapps/lightclock/ (LightClockScreen.tsx, ManualLogForm.tsx + their .module.css/.test.tsx), src/lib/lightclockSensors.ts, src/lib/lightclock.ts, src/lib/lightclockAllocatorIsolation.test.ts, src/lib/sync.ts.

Stated concept (README): "Circadian phase-response model from a manual sleep/wake log or device actigraphy (rest/activity from the motion sensor); it never claims to measure light (the Hollow has none); a personal wellness tracker only, never wired to ration anything."

Verdict: COHERENT

All six audit points check out; no gap found. This is the most honestly-engineered sensor integration in the app's mini-app set.

Evidence per point

1. Actigraphy derivation is a real computation, not fabricated

src/lib/lightclockSensors.ts:

  • motionSampleMagnitude() (L85) computes |a| = sqrt(x^2+y^2+z^2) from a real DeviceMotionEvent's acceleration/accelerationIncludingGravity vectors (vectorMagnitude(), L61-66) - standard accelerometer-magnitude actigraphy, the same primitive used by published actigraphy algorithms (e.g. Cole-Kripke/Sadeh use banded magnitude counts; this is the raw-magnitude building block). It throws rather than substituting a fabricated zero when neither field has data (L~91-97), so callers must skip the sample.
  • classifyActigraphy() (L~148-153) is a deterministic threshold vs. a documented rest-baseline calibration (DEFAULT_GRAVITY_EXCLUDED_CALIBRATION rest=0, DEFAULT_GRAVITY_INCLUSIVE_CALIBRATION rest=9.80665 i.e. standard gravity, movementThreshold=4) - no Math.random() anywhere in the file (confirmed by reading it in full).
  • subscribeToActigraphy() (L~226-256) wires this to the real window.addEventListener("devicemotion", ...) browser event, coalescing to one epoch per minute (epochMs default 60000) so a 60Hz stream becomes a manageable persisted log - not a per-sample fire-hose.
  • lightclockSensors.test.ts (L102: "delivers real, timestamped actigraphy samples (not fabricated) through the devicemotion event") exercises this path with synthetic DeviceMotionEvents, confirming classification behavior end-to-end.

Conclusion: genuine accelerometer-magnitude actigraphy, not a dressed-up random number.

2. Real circadian phase-response model, not a lookup table

src/lib/lightclock.ts is a verbatim pure-function port of the published Hannay19 macroscopic circadian model (Hannay, Booth & Forger 2019, J Biol Rhythms 34(6):658-671, DOI 10.1177/0748730419878298), citing the real circadian PyPI/GitHub package (Arcascope/circadian, models.py class Hannay19) as source for its equations and the default parameter/initial-condition values (fixtures/hannay19-model-spec.md, not re-derived per the file's own docstring).

  • hannay19Derivative() (L104-125) implements the actual 3-variable ODE (amplitude R, phase Psi, light-adaptation n) with the Hill-type saturating light-drive term lightDrive() (L80-90) and the full A1/A2 amplitude+phase coupling terms.
  • rk4Step() (L133-146) is a real explicit RK4 numerical integrator, not a static table — simulateHannay19() (L233-281) iterates it across the actual exposure time series up to MAX_SIMULATION_STEPS (bounded, not faked).
  • estimateDlmoHours() (L286-304) detects true DLMO (dim-light-melatonin-onset) phase crossings by interpolating the unwrapped Psi trajectory, and recommendLightTiming() (L340-353) turns that into phase-response-curve-consistent advice (seek/avoid light windows around projected CBTmin) — this is a genuine PRC-based model output, not a trivial if/else table.
  • hasSufficientCircadianWindow()/MIN_CIRCADIAN_WINDOW_HOURS (= tau ≈ 23.84h) explicitly forces an honest "insufficient-data" state rather than ever presenting the untouched seed state as a computed result — a real honesty safeguard baked into the model boundary, not just the UI.

Conclusion: a real, cited, numerically-integrated PRC model, not a mislabeled lookup table.

3. UI offers both paths; iOS DeviceMotionEvent permission correctly handled

LightClockScreen.tsx:

  • Initial state (dataSource === null) shows an "Enable motion sensor" button (lightclock-enable-sensor) whose onClick calls handleEnableSensor() -> startLightClockDataSource() synchronously from the click handler (gesture preserved).
  • startLightClockDataSource() (lightclockSensors.ts L372-386) calls requestMotionPermission() first; if it does not resolve "granted", it returns { kind: "manual-entry" } with no exception thrown and no silent lock-out — the UI then renders <ManualLogForm> automatically (dataSource?.kind === "manual-entry" branch, L175-181 of LightClockScreen.tsx).
  • requestMotionPermission() (lightclockSensors.ts L~300-315) correctly branches on the iOS 13+ contract: checks for DeviceMotionEvent.requestPermission as a function and awaits it (the required explicit user-gesture-triggered permission prompt), mapping its "granted"/"denied" result 1:1, catching a thrown rejection as "denied" rather than crashing. Non-iOS platforms that expose devicemotion without a separate permission step resolve "granted" directly; no window/no DeviceMotionEvent at all resolves "unavailable".
  • Both outcomes are reachable in the UI: sensor path renders lightclock-sensor-active + a "Stop recording" control; manual path renders the full ManualLogForm (hours / awake-asleep state / optional self-reported lux, with validation and an entry list) feeding buildExposureFromManualLog().
  • permissionError state (L~160-163) surfaces "Couldn't request sensor permission - try the manual log instead" if startLightClockDataSource itself throws (defensive, since it's documented to resolve rather than throw) — belt-and-braces, not a broken path.

Conclusion: both paths are real, wired, and reachable; the iOS permission gesture requirement is correctly handled (synchronous click -> immediate requestPermission() call, no intervening await before the gesture-consuming call), with denial routing cleanly to the manual-log fallback rather than a dead end.

4. No light-sensing claim anywhere

Project-wide grep across src/ for light level|brightness sensor|lux (measur|detect| sens)|ambient light sensor|AmbientLightSensor returned zero matches. The only "lux" usage is lightclockSensors.ts's ACTIVE_INFERRED_LUX/REST_INFERRED_LUX constants and the ManualLogForm's optional, user-typed "Lux estimate" field — both explicitly documented and labeled as a modeling input/user self-report, never a device measurement. lightclockSensors.ts's module docstring states this invariant outright: "does NOT claim to measure light - there is none to measure... never a fabricated light reading." The UI's own prompt copy repeats it verbatim: "It never claims to measure light - The Hollow has none" (LightClockScreen.tsx L~146).

Conclusion: no stray light-sensing claim found; the honesty boundary is stated in three independent places (lib docstring, UI copy, this audit's own grep) and all agree.

5. Genuinely never wired to ration anything

Two independent enforcement mechanisms, not just a comment:

  • src/lib/lightclockAllocatorIsolation.test.ts is a static import-graph reachability test that walks the entire src/ import graph and asserts, in both directions, that neither lib/fairshare.ts nor lib/ceeiSpike.ts (Fair Share's allocator roots) can reach lib/lightclock.ts or miniapps/lightclock/LightClockScreen.tsx, and vice versa. This is a build-enforced guarantee, re-checked on every test run, not just documentation.
  • src/lib/sync.ts (L50-51) explicitly excludes lightclock.* from its sync-push allowlist: "lightclock.* stays strictly local and NEVER pushed (purely personal, no community claim at all - see README's 'never wired to ration anything')." sync.test.ts (L122, L~140) asserts a lightclock.actigraphy event is appended locally but its type never appears in pushedTypes.
  • Project-wide grep of src/miniapps/fairshare for lightclock|Hannay|ACTIGRAPHY_EVENT_TYPE returned zero matches; a broader src/-wide grep for the same terms surfaced only the lightclock module's own files, its tests, the isolation test, and sync.ts's exclusion comment — no resource-allocation file touches it.

Conclusion: not merely "never wired" by omission — actively enforced by a dedicated static-analysis test plus an explicit sync-layer exclusion, both exercised by the test suite.

6. Claimed-but-unwired UI/feature check

None found. Every control in LightClockScreen.tsx/ManualLogForm.tsx is backed by a real function: "Enable motion sensor" -> startLightClockDataSource -> requestMotionPermission/subscribeToActigraphy; "Stop recording" -> handle.stop() (removes the real devicemotion listener); manual "Add entry"/"Compute status" -> buildExposureFromManualLog -> simulateHannay19; actigraphy persistence -> toActigraphyEvent/append() to the signed Event Log, reloaded on mount via readAll() + actigraphySamplesFromEvents() so a multi-day log survives reloads. The "local-only" disclaimer (LOCAL_ONLY_DISCLAIMER) matches sync.ts's actual exclusion behavior (point 5). No dead buttons, no TODO-stub computations, no "coming soon" state inside this mini-app.

Summary

Light Clock is the one mini-app in this codebase whose sensor claim survives full scrutiny: the actigraphy math is real accelerometer-magnitude processing with documented, non-fabricated rest/active classification; the "phase-response model" is an actual cited, numerically-integrated circadian ODE (Hannay19) with real DLMO-crossing detection, not a lookup table; both the sensor and manual-log paths are genuinely wired in the UI with correct iOS DeviceMotionEvent permission handling; there is no stray light-measurement claim anywhere in the code or copy; and the "never wired to ration anything" boundary is enforced by both a dedicated static import-graph test and an explicit sync-layer allowlist exclusion, each backed by its own test. No gap found against the README's stated concept.