Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7be4a8a
feat(sleep): implement medically-grounded HMM classifier with cycle c…
Oct 25, 2026
2a03486
feat(sleep): implement medically-grounded HMM classifier with artifac…
Oct 25, 2026
06dc76c
feat(sleep): add medical disclaimer to UI
Oct 25, 2026
7a4e503
fix(review): resolve CodeRabbit critical findings for compilation and…
Oct 25, 2026
4ae36ad
fix(l10n): localize medical disclaimer
Oct 25, 2026
d990495
fix(sleep): use 10th percentile for HR baseline and refined deep slee…
Oct 25, 2026
b8a6277
fix the sleep disclaimer build error and its contrast
abdulsaheel Oct 28, 2026
6c21e6c
drop the unused sleep baseline columns
abdulsaheel Oct 28, 2026
d6e2f8a
hmm: score contact loss and implausible readings as neutral
abdulsaheel Oct 28, 2026
848c9eb
fix(l10n): resolve app_ru.arb merge leftovers from rebase
mistral-vibe Nov 1, 2026
30cb221
feat(sleep): gate experimental HMM staging behind a default-off setting
mistral-vibe Nov 1, 2026
a374246
fix(review): address CodeRabbit findings on the HMM gate (#628)
mistral-vibe Nov 1, 2026
37900d8
refactor(smart-wake): drop dead hr_min_night fallback (Option A)
mistral-vibe Nov 2, 2026
f9620c5
Merge remote-tracking branch 'origin/main' into pr-628
abdulsaheel Nov 2, 2026
93532fe
drop the smart wake changes from this pr, they belong to #630 (and re…
abdulsaheel Nov 2, 2026
e4f7ded
hmm: fix the build, decode 30 s epochs on epoch-aligned beats, keep u…
abdulsaheel Nov 2, 2026
86387e7
sleep: drop the always-on disclaimer banner (the setting row says it)…
abdulsaheel Nov 2, 2026
57d359c
test(gallery): scroll the Developer section into view before assertin…
mistral-vibe Nov 14, 2026
bb17194
ci: re-trigger test workflow after missed synchronize event (no code …
mistral-vibe Nov 14, 2026
c26979b
Merge remote-tracking branch 'origin/main' into feat/sleep-stage-plau…
mistral-vibe Nov 14, 2026
9b7d6e8
Merge branch 'main' of https://github.com/OpenStrap/edge into feat/sl…
mistral-vibe Nov 14, 2026
991cd85
fix(backup): give sleep_hmm_stages an audit policy and type
mistral-vibe Nov 14, 2026
71d66da
Merge branch 'main' of https://github.com/OpenStrap/edge into feat/sl…
mistral-vibe Nov 14, 2026
546afad
Merge main into feat/sleep-stage-plausibility
Nov 15, 2026
30fb324
sleep HMM: address the #628 review
Nov 15, 2026
f581aa3
merge main
abdulsaheel Nov 16, 2026
ba460b4
hmm stager: reload the pref in headless derives, no rr difference acr…
abdulsaheel Nov 16, 2026
d84caf7
hmm stager: repair any rem->deep boundary after the merge, re-derive …
abdulsaheel Nov 16, 2026
6a99c8b
hmm stager: rederiveDays says whether it worked, the switch logs a fa…
abdulsaheel Nov 16, 2026
259896d
hmm stager: runDays records its failed days, rederiveDays reports them
abdulsaheel Nov 16, 2026
caf26fc
hmm stager: read the failed-day count before the next await
abdulsaheel Nov 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/compute/derivation_engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3105,10 +3105,29 @@ class CompactResult {
int get freedBytes => beforeBytes > afterBytes ? beforeBytes - afterBytes : 0;
}

/// The experimental HMM sleep staging switch (Settings), default off.
const kSleepHmmStagesPref = 'sleep_hmm_stages';

class DerivationEngine {
DerivationEngine({this.log, this.background = false, this.offloadActive});
final void Function(String)? log;

/// EXPERIMENTAL, default off: re-stage the sleep window with the HMM
/// classifier inside [deriveDayBundle]. Read from the pref on every pass so
/// the foreground engine and every headless one agree, and a toggle takes
/// effect without a relaunch. Any failure reads as off.
static Future<bool> _hmmStagesOn() async {
try {
// reload(): a headless isolate caches its instance, so without it a
// toggle made in the app is not seen until that isolate restarts.
final prefs = await SharedPreferences.getInstance();
await prefs.reload();
return prefs.getBool(kSleepHmmStagesPref) ?? false;
} catch (_) {
return false;
}
}

/// True while a band offload is draining. The scheduler never STARTS a
/// derive during one, but one can start mid-pass; the raw prune checks this
/// before archiving each substrate bucket and stops for the pass, so a drain
Expand Down Expand Up @@ -3380,6 +3399,7 @@ class DerivationEngine {
..sort();
final head = [
'v${debugFingerprintAlgoVersion ?? kAlgoVersion}',
if (await _hmmStagesOn()) 'hmm',
dataNowSec,
// The edges a day is aged against (band and wearable; see
// [_agingEdgeFor]), from the pass's own memo.
Expand Down Expand Up @@ -3888,6 +3908,7 @@ class DerivationEngine {
if (days.isEmpty) return 0;
if (_running) return 0;
_running = true;
lastRunFailedDays = 0;
final startedAt = DateTime.now().millisecondsSinceEpoch;
_diag
..['running'] = true
Expand Down Expand Up @@ -3979,6 +4000,7 @@ class DerivationEngine {
// every day under the current timezone, so it clears the travel hold too.
// A partial selection deliberately does not: those days say nothing about
// the ones still held.
lastRunFailedDays = failures;
if (force && failures == 0) {
final rawDays = (await LocalDb.decodedRecTsMaxByDay()).keys.toSet();
if (rawDays.isNotEmpty && rawDays.difference(days).isEmpty) {
Expand All @@ -3999,6 +4021,7 @@ class DerivationEngine {
return done;
} catch (e, st) {
_log('derive selected ERROR: $e\n$st');
lastRunFailedDays = days.length;
return 0;
} finally {
await _runStorageHousekeeping();
Expand Down Expand Up @@ -5955,6 +5978,7 @@ class DerivationEngine {
// guess — sleep-onset latency only means what people think it means on a
// forced window.
sleepSource: day.sleepSource,
useHmmStages: await _hmmStagesOn(),
);
final withHistory = _attachHistory(input, history);

Expand Down
Loading
Loading