Skip to content

SleepStageVocabulary: trim newlines consistently on Swift and Kotlin #41

Closed

Description

@bhelm

Summary

SleepStageVocabulary.isWake promises to ignore surrounding whitespace, but Swift and Kotlin disagree when that whitespace contains newlines.

This is a pure, deterministic cross-platform parity bug.

Minimal reproduction

input: "\nwake\n"
Swift: false
Kotlin: true

input: "\rawake\r"
Swift: false
Kotlin: true

Cause

Swift trims only .whitespaces. Kotlin uses String.trim(), which also removes surrounding CR/LF characters.

Impact

Imported stage strings with line-ending whitespace can be classified as asleep on Swift but awake on Kotlin. isWake feeds sleep staging, hypnogram metrics, wake-motion refinement and import paths.

Proposed parity fix

Align Swift with Kotlin by trimming .whitespacesAndNewlines.

Acceptance criteria

  • Both platforms return true for the two cases above.
  • Preserve behavior for normal wake labels, case variants, spaces, tabs, empty strings and non-wake stages.
  • Add mirrored native tests and an exact differential case.

This is fully automated; no hardware testing is required.

Activity

  1. bhelm commented on Aug 19, 2026

    @bhelm
    OwnerAuthor

    Resolved and differentially verified.

    • The focused production fix was merged earlier.
    • Sleep foundations rollout Add differential parity for Sleep foundations #65 adds the exact Swift/Kotlin regression fixture for this issue.
    • The seven-function Sleep slice matched in all cases; the full native pilot matched 414/414 with zero differences.
    • Fresh coverage, stale-output rejection, both-side mutants, and independent review passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions