Skip to content

Fix sleep analyzer loading only 1% of piezo data#38

Open
dallonby wants to merge 1 commit intothrowaway31265:mainfrom
dallonby:fix/cbor-empty-data-records
Open

Fix sleep analyzer loading only 1% of piezo data#38
dallonby wants to merge 1 commit intothrowaway31265:mainfrom
dallonby:fix/cbor-empty-data-records

Conversation

@dallonby
Copy link
Copy Markdown

Summary

  • Fix CBOR file reading loop exiting early when encountering records with empty data fields
  • This was causing sleep analyzer to load only ~250 records instead of ~46,000 per night

Root Cause

  1. Some RAW files contain records with data: b'' (empty byte string)
  2. When cbor2.loads(b'') is called, it raises CBORDecodeEOF
  3. CBORDecodeEOF inherits from EOFError
  4. The except EOFError: break handler catches this, exiting the loop prematurely

Fix

Skip records with empty data before attempting to decode.

Test plan

  • Verified fix loads 900 piezo-dual records (previously 6) from a single RAW file
  • Verified fix loads all expected records for a full night's data
  • Deploy to device and verify sleep detection works correctly

🤖 Generated with Claude Code

The CBOR file reading loop was exiting early when encountering records
with empty data fields. This happened because:

1. Some RAW files contain records with `data: b''` (empty byte string)
2. When `cbor2.loads(b'')` is called, it raises `CBORDecodeEOF`
3. `CBORDecodeEOF` inherits from `EOFError`
4. The `except EOFError: break` handler catches this, exiting the loop

This caused the sleep analyzer to load only ~250 records instead of
~46,000 per night, resulting in incomplete sleep detection.

The fix simply skips records with empty data before attempting to decode.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Dec 25, 2025

@dallonby is attempting to deploy a commit to the david's projects Team on Vercel.

A member of the Team first needs to authorize it.

dallonby added a commit to dallonby/free-sleep that referenced this pull request Dec 26, 2025
The same fix from PR throwaway31265#38 (19ac510) needs to be applied to stream.py.
Some RAW files contain records where 'data' is an empty byte string.
Calling cbor2.loads(b'') raises CBORDecodeEOF (inherits from EOFError),
which was caught by the EOFError handler and broke out of the read loop.

This caused the stream processor to only capture ~4 piezo records per
sleep session instead of continuous data, resulting in only 2-3 vitals
records per night instead of hundreds.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
dallonby added a commit to dallonby/free-sleep that referenced this pull request Dec 28, 2025
The same fix from PR throwaway31265#38 (19ac510) needs to be applied to stream.py.
Some RAW files contain records where 'data' is an empty byte string.
Calling cbor2.loads(b'') raises CBORDecodeEOF (inherits from EOFError),
which was caught by the EOFError handler and broke out of the read loop.

This caused the stream processor to only capture ~4 piezo records per
sleep session instead of continuous data, resulting in only 2-3 vitals
records per night instead of hundreds.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ng
Copy link
Copy Markdown

ng commented Mar 16, 2026

Nice investigation! We hit the same issue in sleepypod-core and patched it in our TypeScript CBOR reader — the fix landed in sleepypod/core#178 (merged into dev).

Our approach handles it at the byte-parsing level: readRawRecord returns null for zero-length data fields so the cbor-x decoder is never called on empty bytes. Same root cause, slightly different fix point.

Thanks for tracking this down 👍

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