Commit f1755c76 by PLN (Algolia)

fix(api): the live grader would score silence tier A — re-vendor, and stop

hiding the suite that said so

armada/api/engines/grade.py is a vendored copy of tools/foundry/engine/grade.py
and had fallen three fixes behind the canonical:

  * the `empty_dbfs` presence gate. Every other sub-score is undefined on
    silence — the seam between two silences is perfect, the DC of silence is
    zero, its zero crossings are trivially fine — so a silent window scored
    0.90 x perfect and came out tier A. Fourier is deployed; this is what it
    was serving.
  * the seam denominator: mean |2nd diff| collapses to ~0 on sparse material,
    so a genuinely clean dub-drum loop measured 129x the mean and read as a
    huge click. The canonical uses the 90th percentile, amplitude-floored.
  * `not empty` on the low-RMS and mono-incompatibility flags, so silence stops
    being reported as maximally mono-incompatible.

Re-vendored by copy after checking the diff both ways: the canonical is a strict
superset and the only vendored-only lines were the OLD versions of the three
changed ones, so nothing API-specific was lost. Now byte-identical, which is
what the drift guard actually wants.

The drift guard was not broken. It had been failing, in-repo, unseen — because
of the second half of this commit.

armada/api needs FastAPI, which lives in ~/.virtualenvs/fourier. Run `pytest`
from the repo root with the plain interpreter and its seven test modules raise
ModuleNotFoundError during collection, which pytest reports as "Interrupted: 7
errors during collection" and then runs NOTHING — not the api suite, and not
the other 890 tests either. The natural response is `--ignore=armada/api`,
after which the api suite has no verdict at the root at all and can sit red
indefinitely. It sat red long enough for the grader to drift.

So conftest.py now skips that tree when fastapi is absent and prints the exact
command to run it properly. An unrunnable suite should say it is being skipped
and say how to run it; an error that stops everything only teaches you to pass
a flag that hides it.

  plain python3 at root      892 passed,  2 skipped   (was: 0 run, 7 errors)
  fourier venv at root       993 passed,  2 skipped   — the whole workspace
  armada/api in its venv     101 passed,  0 failed    (was: 1 failed)
parent 8dd2b710
......@@ -40,6 +40,14 @@ THRESH = {
"rms_lo_dbfs": -28.0, # A-profile moderate-level band …
"rms_hi_dbfs": -12.0, # … RMS in here is ideal
"clip_dbfs": -0.1, # peak at/above this ⇒ clipping
# Peak below this ⇒ there is no audio here. NOT a taste threshold: every other
# sub-score is undefined on silence (the seam between two silences is perfect, the
# DC of silence is zero, the zero crossings are trivially fine), so a silent window
# scores 0.90 × perfect + 0.10 × nothing and comes out tier A. Measured on Fred
# again..'s pack: 24 of 153 cut loops were digital silence at -104…-75 dBFS peak,
# graded 0.707-0.896, and the next file up was -47.1 — a 28 dB empty gap, so the
# floor is placed inside it rather than tuned.
"empty_dbfs": -60.0,
"bars": (1, 2, 4, 8), # B-rule bar interpretations to test
"beats_per_bar": 4,
"tempo_lo": 60.0,
......@@ -123,7 +131,17 @@ def seam_score(mono: np.ndarray) -> tuple[float, float]:
return 1.0, -60.0
# curvature at the wrap: the sequence is … x[-2], x[-1], x[0], x[1] …
jerk = abs(float(mono[0]) - 2.0 * float(mono[-1]) + float(mono[-2]))
typical = float(np.mean(np.abs(np.diff(mono, n=2)))) + _EPS # typical |2nd diff|
# Reference = the loop's TYPICAL curvature. The mean |2nd diff| collapses to ≈0
# on sparse material (dub drums: mostly silence, a few hits) — any real wrap
# curvature then reads as a huge click (a genuinely clean sparse loop measured
# 129× the mean, a false positive). The 90th percentile of |2nd diff| tracks the
# signal's active-region curvature and stays finite on sparse input (2–3× on the
# same loop). Floor it to a fraction of peak amplitude so a near-silent slice
# can't make the denominator vanish either.
d2 = np.abs(np.diff(mono, n=2))
peak = float(np.max(np.abs(mono))) + _EPS
typical = max(float(np.percentile(d2, 90)) if d2.size else 0.0,
1e-3 * peak) + _EPS # 90th-pct curvature, amplitude-floored
click_db = _db(jerk / typical)
clean, click = THRESH["seam_db_clean"], THRESH["seam_db_click"]
# ≤ clean dB (jerk ≈ natural curvature) ⇒ 1.0 ; ≥ click dB (audible) ⇒ 0
......@@ -246,6 +264,19 @@ def grade_array(y: np.ndarray, sr: int, *, path: str = "<array>",
grade = sum(w[k] * sub[k] for k in w)
flags: list[str] = []
# Presence is a PRECONDITION, not a weighted term. Everything above is a measure of
# how cleanly this audio loops, and all of it is vacuously true of silence — so the
# composite has a degenerate optimum at "nothing", which the finder duly walked into.
# A loop nobody can hear is not an A-grade loop whatever its seam looks like.
# Measured on the CHANNELS, not the mono sum: a deliberately wide stereo file can
# have almost no mono content — an anti-phase pair sums to exact zero — and calling
# that "empty" would both mis-report it and suppress the mono-incompatible flag that
# is the actually useful thing to say about it.
file_peak_db = float(20 * np.log10(float(np.max(np.abs(y))) + _EPS))
empty = file_peak_db < THRESH["empty_dbfs"]
if empty:
flags.append("empty")
grade = 0.0
if one_shot:
flags.append("one-shot")
if abs(dc) > THRESH["dc_ok"]:
......@@ -256,9 +287,15 @@ def grade_array(y: np.ndarray, sr: int, *, path: str = "<array>",
flags.append("off-grid")
if clipped:
flags.append("clipping")
if rms_db < -45:
if rms_db < -45 and not empty:
# RMS this low with a real peak means SPARSE, not silent — a hat loop with peaks
# at -14.7 reads -48.8 RMS because RMS measures how much silence it contains
# (`feedback_right_lens_per_control`). Advisory; `empty` is the blocking one.
flags.append("near-silent")
if (role == "bass" or y.ndim > 1) and corr < 0.2:
if (role == "bass" or y.ndim > 1) and corr < 0.2 and not empty:
# Interchannel correlation of two independent noise floors is ~0, so silence
# reads as maximally mono-incompatible; 4 of MAREA's flagged vox loops were
# just empty.
flags.append("mono-incompatible")
metrics = {
......
"""Root pytest config.
The only job here is to stop one suite from being invisible.
`armada/api/` (Fourier) needs FastAPI and friends, which live in a separate
interpreter — `~/.virtualenvs/fourier`, per armada/api/README.md. Run from the
repo root with the plain interpreter, its seven test modules raised
ModuleNotFoundError during COLLECTION, which pytest reports as
!!!! Interrupted: 7 errors during collection !!!!
and then runs NOTHING AT ALL — not the api suite, not the other 890 tests. So
the habit becomes `pytest --ignore=armada/api`, the api suite's verdict is
never seen from the root, and it can go red for weeks. It had: its vendored
copy of the loop grader had drifted from the Foundry canonical and was missing
the presence gate, so the live API would have graded silence as tier A.
An unrunnable suite should SAY it is being skipped and say how to run it — an
error that stops everything teaches you to pass a flag that hides it.
"""
import importlib.util
collect_ignore_glob: list[str] = []
if importlib.util.find_spec("fastapi") is None:
collect_ignore_glob.append("armada/api/tests/*")
def pytest_report_header(config):
if collect_ignore_glob:
return [
"armada/api SKIPPED — fastapi not in this interpreter.",
" run it with: cd armada/api && "
"~/.virtualenvs/fourier/bin/python -m pytest tests/ -q",
]
return []
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment