Skip to content

test(biofeedback): golden egress replay fixture and alpha physiology check (ADR-011 PR 5) - #79

Merged
aurascoper merged 1 commit into
mainfrom
feat/biofeedback-replay
Nov 8, 2026
Merged

aurascoper merged 1 commit into
mainfrom
feat/biofeedback-replay

Conversation

@aurascoper

Copy link
Copy Markdown
Owner

Summary

Stacks on #78 (feat/biofeedback-wiring, 4726783) and closes Issue 6 (PR 5) from #76: deterministic golden-recording egress replay and eyes-closed vs eyes-open alpha physiology validation, including the committed JSON fixtures (golden_egress_v1.json and muse_validation_alpha_v1.json).

GoldenEgressReplayTests + Fixtures/golden_egress_v1.json

  • Replays Recordings/golden/golden_20260710-141352.eeg.csv through PlaybackEEGStream(.normalized(sampleRate: 256.0), pacing: .instant), EEGWindowing(windowSeconds: 2.0, strideSeconds: 1.0), and BiofeedbackCoordinator with the per-channel MindMonitorMirror and a fixed 4-mapping set covering all four HealthPolicy cases (holdLast, decayToRest, mute, passthrough).
  • Hard-pins 303 windows, 77,966 resampled samples (durationSeconds = 304.55078125), the four per-channel health tallies (TP9: 263/40, AF7: 283/20, AF8: 276/27, TP10: 280/23 healthy/saturated), and three spot windows (0, 151, 302, where window 302 has horseshoe [1, 4, 1, 1]).
  • Compares all 303 window records (bels, horseshoe, osc, midi) against Tests/BCIBiofeedbackTests/Fixtures/golden_egress_v1.json (198 KB, derived values only; zero raw EEG).

MuseValidationAlphaTests + Fixtures/muse_validation_alpha_v1.json

  • Reads each of the six Recordings/muse_validation_converted/<name>/ sessions (<name>.eeg.csv and <name>.segments.csv row-for-row using whereSeparator: \.isNewline so CRLF files from csv.writer parse cleanly) and windows each segment independently (512 samples at 256 stride -> 29 windows per 30 s segment), avoiding interpolation across the inter-segment prompt discontinuity (abs(openClosedBoundaryGap) > 1.0 s).
  • Asserts the physiological rule using the median window alpha Bels per segment (recording both median and mean in Tests/BCIBiofeedbackTests/Fixtures/muse_validation_alpha_v1.json):
    • alpha_pass: true sessions double (>= log10(2) = 0.3010 Bels) on both posterior channels (TP9, TP10) and stay below < 0.3010 Bels on both frontal channels (AF7, AF8):
      • 014223: TP9 +0.4615, TP10 +0.5651, AF7 -0.1228, AF8 +0.2033 Bels
      • 015723: TP9 +0.4277, TP10 +0.3716, AF7 -0.1500, AF8 -0.1019 Bels
    • alpha_pass: false session (013820) fails as the expected negative (TP9 +0.0616, TP10 +0.2422, AF7 -0.1217, AF8 -0.0906 Bels).

Two Build/Runtime Nits Fixed on First Run

  1. MuseValidationAlphaTests.readEEG / readSegments: changed text.split(separator: "\n") to text.split(whereSeparator: \.isNewline) because convert_muse_validation_recordings.py uses Python's csv.writer (\r\n), and Swift treats "\r\n" as a single extended grapheme cluster distinct from "\n".
  2. Updated the hard pins in GoldenEgressReplayTests.spotPins and MuseValidationAlphaTests.medianRisePins (plus abs(session.openClosedBoundaryGap) > 1.0 for 004345's -12.19 s ring-buffer overlap) to match BandPowerEstimator.swift's exact symmetric Hann (n - 1) and half-open [lowBin, highBin) bin summation.

Verification

  • GoldenEgressReplayTests: PASS (2.193 s)
  • MuseValidationAlphaTests: PASS (2.741 s)
  • BCIBiofeedbackTests total: 71/71 passed
  • Scripts/check_adr_references.py: PASS (0 warnings)

@aurascoper
aurascoper force-pushed the feat/biofeedback-replay branch from 1d7e778 to d5821b4 Compare November 8, 2026 03:23
@aurascoper
aurascoper force-pushed the feat/biofeedback-wiring branch from 4726783 to 1431c45 Compare November 8, 2026 03:23
@aurascoper
aurascoper changed the base branch from feat/biofeedback-wiring to main November 8, 2026 03:23
…check (ADR-011 PR 5)

GoldenEgressReplayTests replays Recordings/golden through PlaybackEEGStream
(.normalized 256 Hz, instant), 2 s / 1 s windowing and
BiofeedbackCoordinator with the per-channel Mind Monitor mirror and a
fixed four-mapping set, then pins what came out: 303 windows, 77,966
samples, per-channel health tallies (TP9 263/40, AF7 283/20, AF8 276/27,
TP10 280/23 healthy/saturated), three spot windows (RMS and alpha Bels),
and every window's Bels, horseshoe, OSC and MIDI in
Fixtures/golden_egress_v1.json compared with tolerances. The fixture
holds derived values only; no raw EEG is written.

MuseValidationAlphaTests reads each muse_validation_converted session's
eeg.csv and segments.csv row for row (using whereSeparator: \.isNewline
for CRLF compatibility) and windows each segment on its own, because the
protocol's inter-segment pause would otherwise be interpolated by
PlaybackEEGStream and misalign the labels. Statistic is the median
window alpha Bels per segment. Asserts a doubling (log10 2) on TP9 and
TP10 and less on AF7 and AF8 for alpha_pass: true sessions (014223,
015723), and that 013820 (alpha_pass: false) does not double on both
posterior channels. Pins the measured median rises for the three sessions
with sidecars and records all sessions in
Fixtures/muse_validation_alpha_v1.json.

Updates ADR-011 "Related implementation" and decision_registry.md entry 10
with the Principle 3 replay evidence.

Refs: ADR-011, ADR-002, PRINCIPLES.md 3 and 7, decision_registry.md
entry 10.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QapsKF5C619kjbak7vTmRK
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.

1 participant