Skip to content

fix(piezo-processor): no vitals while the bed reads empty - #768

Merged
ng merged 3 commits into
sleepypod:devfrom
jasonlarue:fix/vitals-empty-bed
Oct 6, 2026
Merged

ng merged 3 commits into
sleepypod:devfrom
jasonlarue:fix/vitals-empty-bed

Conversation

@jasonlarue

@jasonlarue jasonlarue commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Strong bed vibration can pass piezo-only presence detection and produce vitals for an empty bed. This PR lets capacitance evidence from the sleep-detector veto those windows, while preserving independent piezo processing whenever capacitance presence is unknown.

The review found that the original gate could suppress an occupied cold start or a side with missing sensor input indefinitely. The producer now publishes explicit vitals_presence and per-side evidence timestamps. Absence requires a trustworthy baseline established by sustained unloading and baseline convergence; a stable initial frame alone cannot establish emptiness. Readiness survives checkpoints and adaptive-profile reuse, is cleared by reseeding, and must be paired with fresh usable readings after restart. Partial, nonfinite, missing and sentinel readings are unknown. In single-sleeper mode, absence requires valid evidence from both sides, while either side can establish presence.

The reader treats legacy or malformed checkpoints and stale per-side evidence as unknown, regardless of file modification time. Unknown leaves piezo presence in control. Before the detector observes an unloading, empty-bed vibration may still pass; this is the deliberate fallback that avoids losing a sleeper's first night.

Validation: locked Python runtime dependencies; 239 common, 87 sleep-detector, and 121 piezo tests pass. Eleven integration cases use the actual detector, checkpoint writer, reader and unmocked piezo computation. They cover occupied bootstrap, missing/lost/invalid input, trustworthy empty-bed suppression, restart and profile reuse, reseeding, and merged-side behavior. TypeScript, full ESLint, both Drizzle schema checks and 2,843 related TypeScript tests also pass. No Pod deployment was performed.

Piezo presence looks only at vibration energy and rhythm, so a prime or the
pump shaking an empty bed passed it and wrote vitals with nobody there (on a
Pod 4, ~20% of a day's vitals minutes fell outside any bed session, clustered
around the daily prime).

A side now also asks the sleep-detector, whose capacitance-based presence is
committed and saved to its state file (common/bed_presence.py): if it says
the side is empty, the window counts as absent. With one side away it asks
about the home side, where the readings are stored. A missing, unreadable or
stale state file leaves piezo presence to decide, as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vercel

vercel Bot commented Oct 2, 2026

Copy link
Copy Markdown

@jasonlarue is attempting to deploy a commit to the therealng's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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 54 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: aff8626d-595a-4b61-b25c-13f679a4051d
📥 Commits

Reviewing files that changed from the base of the PR and between 0e5d4c4 and 3b3e4b9.

📒 Files selected for processing (7)
  • docs/piezo-processor.md
  • modules/common/bed_presence.py
  • modules/common/test_bed_presence.py
  • modules/piezo-processor/main.py
  • modules/piezo-processor/test_main.py
  • modules/sleep-detector/main.py
  • modules/sleep-detector/test_main.py
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@jasonlarue
jasonlarue force-pushed the fix/vitals-empty-bed branch from 48436ea to c4233a7 Compare October 2, 2026 22:39
@ng
ng added this pull request to the merge queue Oct 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 5, 2026
@ng
ng added this pull request to the merge queue Oct 5, 2026
@ng
ng removed this pull request from the merge queue due to a manual request Oct 5, 2026
@ng
ng added this pull request to the merge queue Oct 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 5, 2026
@ng ng mentioned this pull request Oct 5, 2026
1 of 2 tasks
@ng

ng commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Scope: full branch at c4233a7ac347edc8e8f6747e679153d396a9d7b4 against dev.

Full-depth adversarial review completed with two independent Optimizers and two independent Skeptics using the inherited GPT-6 runtime (the skill’s legacy models are unavailable). Recommendation: request changes; do not merge this head.

Finding Provenance Skeptic verdict Outcome
Occupied cold bootstrap is interpreted as authoritative empty-bed absence Diff Optimizer, Codex Both Agree, Major, 97–98% Blocking
Unavailable per-side capSense evidence remains false in fresh checkpoints and indefinitely vetoes valid piezo Both Optimizers, Codex; initial severity disagreement Both confirm Major, 91–95% Blocking; severity disagreement resolved

At modules/piezo-processor/main.py:1004 / modules/common/bed_presence.py:54–66, the new gate trusts debounced_present=False without establishing a trustworthy baseline or current usable evidence for that side. The actual sleep-detector writer, checkpoint reader and unmocked piezo pipeline reproduced three cases: occupied cold startup, missing initial side input, and lost input after an empty baseline. Each produced one valid vitals row without the new gate and zero with it. A continuously refreshed checkpoint prevents the five-minute fallback from recovering.

The repair needs an explicit, persisted trustworthy-absence/readiness and per-side valid-evidence freshness contract. A non-null baseline check does not fix occupied bootstrap; last_ts is updated even for unusable observations. Include producer → checkpoint → reader → vitals regressions and restart/profile reuse. No source fix applied in this review: a reader-only patch cannot safely recover confidence absent from the producer contract.

Mechanical verification: locked uv runtime dependencies; 110 piezo and 224 common tests pass, as do exact-head CI lint, typecheck, unit tests, Python matrix and codecov/patch. These tests miss the reproduced regressions. Source build and artifact upload succeeded; the red build result is the final PR-description GraphQL permission error, not compilation. Vercel’s separate failure is deployment authorization. No Critical, additional lower-confidence blocking, or separately retained pre-existing findings. No device deployment performed.

@ng
ng enabled auto-merge October 6, 2026 02:52
@ng
ng added this pull request to the merge queue Oct 6, 2026
Merged via the queue into sleepypod:dev with commit 0aeb906 Oct 6, 2026
11 of 13 checks passed
ng added a commit that referenced this pull request Oct 8, 2026
…tions, 3D temperature Stage and experimental Base (#783)

Promote `dev` to `main`: power-off and alarm fixes, hardware recovery and diagnostics, a 24-hour time option, keeping temperature after a schedule ends, a 3D temperature Stage, hosted demo mode, and experimental adjustable-base controls.

OFF now clears the side's active firmware timer before resetting its temperature level, and reports a failure if the timer cannot be cleared (#713). This addresses the hub continuing to regulate after OFF.

## Release scope

- **Alarms:** fix snooze, the wake window and warm-up (#766, #779). A snooze is no longer lost when the firmware write that confirms a tap fails (#790).
- **Hardware:** DAC connections recover after firmware restarts (#782); pump stalls are no longer reported falsely during startup (#786); the installer separates socket discovery from hardware identity (#785).
- **Settings:** a pod-wide 12-hour / 24-hour time format, used by every clock, chart and time editor (#788). Solo bed setup is now separate from partner away mode (#767).
- **Schedules:** "After schedule ends" can keep the final temperature instead of turning the Pod off. There is a device default and a per-curve choice, and the setting is available over REST/tRPC and MCP (#789).
- **Temperature:** a 3D thermal bed, a temperature Stage view and a sweep-mode piezo waveform (#787).
- **Performance and diagnostics:** piezo vitals are suppressed while the bed reads empty; the temperature controller does less work; the firmware probe is cached; V8 and native memory counters are reported (#768, #772, #770, #773).
- **Demo:** a hosted demo mode (#765, #781).
- **Base (experimental):** controls, presets, schedules and a 3D bed view with a 2D fallback (#780, #784). Physical movement is unverified, and independent per-side movement stays locked until the firmware is validated.
- **Tests:** coverage for the Stage, ThermalBed, Base and piezo views (#790), plus automation and sensor-stream tests.

**Database migrations:**
- `0017_majestic_enchantress`
- `0018_amazing_captain_marvel`
- `0019_closed_psynapse`
- `0020_mature_puff_adder`: schedule end action, which defaults to `turn_off`
- `0021_device_time_format`: `time_format`, which defaults to `12h`

The iOS companion change for end actions is sleepypod/ios#51. It should be merged after this deploy.
ng added a commit to ng/core that referenced this pull request Oct 10, 2026
## Summary
sleepypod#769 added `system.getSensorSource` (used by `SensorSourceCard`) but no
demo handler, so `src/demo/tests/coverage.test.ts` fails on `dev` and
blocks every PR (e.g. sleepypod#779, the sleepypod#768 merge-queue run).

Adds a demo handler that reports NATS firmware with a fresh piezo frame,
reusing `FIRMWARE_LABELS` and `DEMO_UPTIME_START`.

## Test plan
- [x] `vitest run src/demo` — 77 passed (coverage + contract tests)
- [ ] CI green

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants