Skip to content

[BUG]: exerciseEngine early-return in tracking-loss path does not update trackingLostFrames β€” counter stuck at 4 during sustained occlusionΒ #944

Description

@vipul674

πŸ“ Bug Description

The tracking-loss early return in src/services/exerciseEngine.ts does not update trackingLostFrames, visibilityBuffer, or lastValidAngles in the returned state object. On subsequent frames, the counter reads the stale value from currentState and never accurately increments, making the tracking-loss diagnostic counter unreliable during occlusion.

Bug location β€” src/services/exerciseEngine.ts:351-358 (approximate):

if (avgVisibility < 0.4 && nextTrackingLostFrames >= 5) {
  return {
    ...currentState,              // trackingLostFrames stays at previous value (e.g., 4)
    feedback: 'SENSORS BLURRED β€” POSITION BODY',
    status: 'yellow',
    isInExercisePosture: false,
    liveDepthFeedback: '',
    // MISSING: trackingLostFrames, visibilityBuffer, lastValidAngles
  };
}

The non-early-return path (lines ~738-740) correctly includes these:

return {
  ...currentState,
  // ...
  trackingLostFrames: nextTrackingLostFrames,
  visibilityBuffer: newVisibilityBuffer,
  lastValidAngles: nextLastValidAngles,
};

Steps To Reproduce

  1. Start a workout
  2. Occlude the camera so tracking is lost
  3. trackingLostFrames increments to 4 (just below threshold of 5)
  4. On the 5th frame, nextTrackingLostFrames >= 5 is true
  5. Early return fires with only ...currentState (trackingLostFrames remains 4)
  6. Counter stuck at 4 forever β€” every subsequent frame calculates nextTrackingLostFrames = 4 + 1 = 5, condition passes, early returns with trackingLostFrames: 4
  7. Counter never reflects the actual duration of tracking loss

Expected Behavior

  • Early return should override trackingLostFrames with the current nextTrackingLostFrames value
  • visibilityBuffer and lastValidAngles should also be updated to avoid stale data

Actual Behavior

  • trackingLostFrames counter stuck at 4 during sustained tracking loss
  • visibilityBuffer also never updated β€” reappends to the same 4-element stale buffer
  • No diagnostic impact on functionality (recovery still works), but diagnostic data is inaccurate

Browser

Chrome

Operating System

All

Node.js Version

v20.x

Additional Context

Impact: LOW-MEDIUM. The tracking-loss counter provides inaccurate data during sustained occlusion. Recovery is unaffected because the counter checks the condition correctly, but the returned state is stale.
Level: 1 (Beginner Friendly) β€” add missing state fields to early return

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions