port: the dead-press check was passing by luck -- diagnosed and fixed

Two iterations ago verify-menu-audio's bit-identity assertion began failing and I
filed three suspects in the port. It is none of them. Three IDENTICAL invocations
give two outcomes, 1.207438 s and 1.300317 s, differing by exactly 4096 samples --
one mixing buffer. The recording quantises to whole buffers and a one-buffer shift
moves the length and alignment of everything in it.

The premise -- cross-run bit-determinism -- was never guaranteed. It held while
timing sat away from a buffer boundary, and a larger export moved it onto one. A
test that passes by luck reports the luck running out as a regression in the code,
which is what it did: two iterations of suspects, and the port was never involved.

The fix keeps exact equality and no threshold, allowing the comparison to slide by
whole buffers -- the one degree of freedom the recorder has. Proved it can still
fail: ctrl against walk differs at every alignment.

Distinct from the earlier entries: this check ran and answered the right question,
resting on a property of the environment nothing verified. State what an assertion
assumes about the machine, not only what it checks.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N7FiFFFwbvG2uxdcEh8HyF
This commit is contained in:
Sylpheed port agent
2026-08-30 09:45:39 +00:00
parent 93b823eedf
commit 1cae35b43a
3 changed files with 96 additions and 11 deletions

View File

@@ -60,12 +60,42 @@ walk = dec(f"{O}/walk.wav", f"{O}/walk.raw")
ctrl = dec(f"{O}/ctrl.wav", f"{O}/ctrl.raw")
noop = dec(f"{O}/noop.wav", f"{O}/noop.raw")
# 1. A press bound to nothing must be SILENT, and silent means IDENTICAL.
# No threshold: a bar here would be a number nobody measured.
n = min(len(ctrl), len(noop))
ok_silent = ctrl[:n].tobytes() == noop[:n].tobytes()
print("no-op presses vs bed alone : %s (%d samples)"
% ("IDENTICAL -- silent" if ok_silent else "DIFFER -- the port sounds a dead press", n))
# 1. A press bound to nothing must be SILENT, and silent still means IDENTICAL --
# but aligned to a WHOLE AUDIO BUFFER, because the recording is not
# sample-deterministic across runs and never was.
#
# 🔴 This check compared the two byte streams directly and passed for weeks.
# It then began failing, and the cause is not the port: three IDENTICAL
# invocations produce two distinct outcomes, 1.207438 s and 1.300317 s,
# differing by 0.092879 s = **exactly 4096 samples**, one mixing buffer. The
# recording quantises to whole buffers and a one-buffer shift moves both the
# length and the alignment of everything inside it.
#
# So the old premise -- cross-run bit-determinism -- was never guaranteed. It
# held while the run's timing sat away from a buffer boundary, and a larger
# export (three voice streams instead of one) moved it onto one. A test that
# passes by luck reports the luck running out as a regression in the code.
#
# The fix keeps the strength that mattered: still EXACT equality, still no
# threshold to tune. It only allows the comparison to slide by whole buffers,
# which is the one degree of freedom the recorder actually has.
BUF = 4096
best = None
for k in (0, BUF, -BUF, 2*BUF, -2*BUF):
a, b = (ctrl[k:], noop) if k >= 0 else (ctrl, noop[-k:])
n = min(len(a), len(b))
if n < BUF:
continue
if a[:n].tobytes() == b[:n].tobytes():
best = (k, n)
break
if best:
print("no-op presses vs bed alone : IDENTICAL -- silent (%d samples, %+d buffer shift)"
% (best[1], best[0] // BUF))
else:
n = min(len(ctrl), len(noop))
print("no-op presses vs bed alone : DIFFER at every whole-buffer alignment "
"-- the port sounds a dead press (%d samples)" % n)
# 2. Is the RIGHT CUE on the bus? Match each EXPORTED cue wave against the
# recording by normalised cross-correlation over the whole file.