Skip to content

Swift SleepStager gravity fingerprint aliases distinct axes in detect, V1, and V2 caches #66

Closed

Description

@bhelm

Summary

The Swift Sleep stager cache fingerprint quantizes gravity as Int((x + y + z) * 1024). Distinct axis vectors with the same sum therefore share a cache key even when the staging recipes observe different motion. Android fingerprints the axes independently and does not reproduce the alias.

Affected public entry points:

  • SleepStager.detectSleep/10
  • SleepStager.stageSession/6
  • SleepStagerV2.stageSession/6

Native RED/control evidence

Tested at fork commit 6df88d0d5d3398fcb4fec62c6cb3b23da3380dae with isolated, env-gated native probes and cache-safe A→B→A sequences. Controls force uncached computation (detect trace sink; stage controls use distinct fingerprints without a cache reset hook).

Swift (SleepStagerDriftProbeTests): all three cache probes RED.

  • detect: uncached B = []; cached B incorrectly returned cached A session [1749520800,1749526199].
  • V1: uncached/control B shape = 0:180:light, 180:1200:wake; cached B incorrectly returned A shape 0:360:deep, 360:1200:light.
  • V2: uncached/control B shape = 0:1610:wake, 1610:1790:light, 1790:1800:deep; cached B incorrectly returned A shape 0:1790:light, 1790:1800:deep.

The mirrored Kotlin probes are GREEN (4/4 full probe class, including these three), BUILD SUCCESSFUL. A and B use gravity rows with equal x+y+z; V2 uses sparse (1,1,-1) samples against (0,0,1) so the nightly jerk floor remains a valid control.

Acceptance

  • Swift cache keys distinguish behaviorally distinct x/y/z gravity streams for detect, V1 stage, and V2 stage.
  • The isolated A→B→A probes pass on Swift and remain green on Kotlin.
  • Unchanged-input memo hits and bounded-cache behavior remain covered.
  • No cache reset test hook is introduced into the public production API.
  • Differential rollout for the three affected entry points remains halted until resolved.

This is separate from #43 (the quarantined V2 pad-boundary decision).

Activity

  1. bhelm commented on Aug 19, 2026

    @bhelm
    OwnerAuthor

    Resolved upstream by ryanbr#1453 () and its deduplication follow-up ryanbr#1454 (). The merged tests cover detect, V1, and V2 A→B→A cache replay with distinct gravity axes. The fork differential rollout continues under #17, but the production defect tracked here is complete.

  2. bhelm commented on Aug 19, 2026

    @bhelm
    OwnerAuthor

    Correction to the closing note: upstream merge SHAs are 9b83b8f for ryanbr#1453 and 2fe84e3 for ryanbr#1454.

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