Repository navigation
feat(sleep-stages): store modelset-v1 manifests with stage models and flag nights staged on other vitals - #930
Merged
Merged
Conversation
… flag nights staged on other vitals Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 27 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
4 of 5 tasks
3 of 4 tasks
ng
added a commit
that referenced
this pull request
Nov 23, 2026
…it stage models (#948) Promotes `dev` to `main`. ## Changes - **Pod 5 presence fixes (#944, #947):** - A Pod 5 hub with a J57 cover on NATS firmware no longer shows the cover as disconnected while its frames are streaming. - Presence scores Pod 3-dialect capSense against its own calibration. - The sleep-detector drops capSense frames that NATS firmware republishes one second later. Before, these made an empty side read as moving. - Pod 5's whole-second frame timestamps no longer stop a side from ever learning what an empty bed looks like, so the #768 empty-bed vitals veto now runs on Pod 5. - **Alarms (#869, #923):** a single sleeper's alarm vibrates both sides, and each side's next alarm is published to Home Assistant over MQTT. - **Biometrics charts (#919, #921, #926):** - Movement is charted in 15-minute buckets of larger movements. - Breathing is drawn as a 15-minute rolling floor. - Adds 3D flow, movement and schedule charts and per-side piezo lanes. - **Local fit and stage models (#928, #929, #930, #927):** - Archived nights replay through local-fit with one pinned profile. - Fits rank by breathing error with REM/light separation. - Stage models are stored with modelset-v1 manifests (migration 0036 adds a nullable `stage_model_library.model_set` column). - Saved profiles rebase onto a new engine instead of falling back to defaults. - **Scripts and tooling (#943, #925, #946, #924, #922):** - The other boot slot is neutralized so a U-Boot fallback stays reachable and offline. - Archive pulls gain a `--curl` transport. - Slash-named branches no longer create Vercel demo previews. - Fixes saved-profile title layout. ## Test plan - [x] CI, Build & Package and Dev Release green on `dev` tip `3094a8c9` - [x] `dev` @ `3094a8c` running on pod .88 (Pod 5 J55): all four services active with 0 restarts, occupancy API 200, both sides read empty with 0 zones lit, right-side capacitance `absence_ready` flipped 0 → 1 - [x] Required checks green on this PR - [ ] After merge, wait for "Analyze & Release" on the `main` merge commit, then `sp-update main` on pod .88 and confirm `.git-info` matches the release
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Training now writes a
modelset-v1manifest next to each exported model, recording the version of every input the model was trained on. This PR handles the stage-model part of it in core.POST /api/sleep-stages/models(and the tRPCuploadModeland MCPadd_stage_model) accept an optionalmodelSetnext tomodel. The pod validates it with zod and stores it with the library entry in a newstage_model_library.model_setcolumn (migration0036). Models uploaded without a set work as before.nodes.stageis required andpinned. Itssha256must equal the model's canonical hash, itsversionmust equal the model's, and its optionalcontractmust name the model's feature contract.nodes.vitalsis optional andexpected:engineis the biometrics manifest hash andprofileis the resolved config hash.nodes.movementModelis refused with "Movement models are not supported on this pod yet". sleepypod-core-133 replaces that refusal with a check that the pinned movement model is installed.trainingandevaluationare stored as given. The whole manifest is capped at 64 KB.GET /api/sleep-stages/models?side=returns each entry'smodelSet, ornull.finite-binary64-json-v1encoding throughdataHash. That is the same encoding asconfigHash, with a budget large enough for a 1-2 MB forest;configHashstops at 20,000 values. The encoding is documented indocs/research/sleep-stage-calibration/README.md→ "Model sets" so training can reproduce it in Python. A golden hash insrc/lib/tests/stage-model-set.test.tswas computed withmodules/common/biometrics/config.py'scanonical_json.Q6 decision (owner): stage normally, flag the mismatch
When the active model's set has
nodes.vitals,getSleepStagescompares it with the vitals that actually produced the night. The night is still staged by the model, never by the rules. A difference only adds a flag:actualcomes from each vitals row's own processing run (vitals.processing_run_id→biometric_processing_runs:bundle.manifestHashandconfig_hash, live runs on the same side). The repo's vitals-summary provenance already defines configuration identity this way (vital-summary-provenance.ts)."mixed": a profile change or update mid-night, or a night only partly recorded."unknown".The receipts table records which generation was applied and when, but not the running engine, and it has no row for the default profile, so it cannot answer the engine half on its own.
A night that matches, a set without a vitals node, a model without a set, and a night staged by the rules get no flag.
GET /api/sleep-stages/modelgainsinputMismatch: the selected model's set compared with the side's latest live run. Settings → Sleep stages shows it as a note on the staging model card that does not block anything.Test plan
vitestforsrc/lib/tests/stage-model-set.test.ts: golden hash matching Python, a 1000-tree forest past theconfigHashbudget, schema bindings, refusal of a wrong sha, version or contract and of a movement node, and the mismatch rulesvitestforsrc/server/routers/tests/sleepStages.test.tsagainst migrated in-memory DBs:unknownPersonalModelCardtest for the note; MCP test thatmodelSetpasses through to the uploadpnpm tsc,pnpm lint,drizzle-kit check(both configs) andvitest related(3260 tests) pass in the pre-push hookvitest run: the only failures are in the Python/shell-environment suites (shadow build, python-installation, backtest coordinator/waveform, updateDeploy, telemetryBlocking, diagnosticCli). The same suites fail identically onorigin/dev.candidate.jsonwith aset.jsonfrom a training run viajq -n --slurpfile m candidate.json --slurpfile s set.json '{side:"left", model:$m[0], modelSet:$s[0]}' | curl -X POST -H 'content-type: application/json' -d @- http://<pod>:3000/api/sleep-stages/models, then checkGET /api/sleep-stages/models?side=leftand a night'sstagedByMigration note: this adds
0036. If another PR adds a0036first, regenerate this one withpnpm db:generateafter rebasing; do not hand-edit the journal.🤖 Generated with Claude Code
🛏️ Beam this PR onto a sleepypod ✨
Pick the snippet that matches your pod. Already-installed pods can't use the curl bootstraps below — sleepypod's egress firewall DROPs github.com, and the script that knows how to unblock WAN is the very file curl is trying to fetch. Use
sp-updateinstead; it's on disk and opens WAN as its first step.🔄 Already on a sleepypod (most common — review a PR on a running pod):
🚀 Fresh pod / first install — bootstraps from GitHub, rebuilds every push:
curl -fsSL https://raw.githubusercontent.com/sleepypod/core/feat/stage-model-set/scripts/install \ | sudo bash -s -- --branch feat/stage-model-set🎯 Pin to this exact build (run 43776866469 ·
1fd2a78) — fresh-pod path, locked to one CI artifact for reproducible review:🧊 Artifact:
sleepypod-core· self-destructs in 30 days 💥