# Sprint v0.1.20 Validation Report

**Owner:** GLM via OpenCode
**Date:** 2026-04-01 (Updated)
**Baseline Session:** `a6a4cc87e493`
**Status:** IN PROGRESS - MCP Connection Timed Out

---

## Executive Summary

This sprint focused on fixing critical issues identified in v0.1.19:
1. **P1: Vocal Leak** - Vocal roles were being auto-generated despite manual-only policy
2. **P2: Anti-Loop** - Section variation was being flattened during consolidation
3. **P4: Hybrid Truth** - MIDI hook materialization failing

### CRITICAL FINDING: Anti-Loop Fix Was in WRONG Path

**Discovery:** The anti-loop fix added to `_apply_clip_consolidation()` was NOT in the active runtime path. The ACTUAL consolidation happens in:
- `_materialize_reference_audio_layers()` lines 4599-4647
- `_build_audio_pattern_positions()` lines 3784-3833

**Fix Applied:** Added anti-flattening logic to `_materialize_reference_audio_layers()` at lines 4618-4667:
- Check `section_variants` BEFORE consolidation
- Skip consolidation for music/harmonic roles with section variants
- Skip consolidation for SECTION_VARIATION_ROLES

### Changes Implemented (v0.1.20 FINAL)

#### P1: Vocal Leak Fixes (COMPLETED)

| File | Line | Change |
|------|------|--------|
| `song_generator.py` | 5880 | Removed `'vocal'` from `OPTIONAL` track budget |
| `song_generator.py` | 11741 | Removed `('VOCAL CHOP', 'vocal', ...)` from reggaeton track specs |
| `song_generator.py` | 11843 | Removed `('VOCAL CHOP', 'vocal', ...)` insert for house/tech-house/trance |
| `song_generator.py` | 11867 | Removed `('VOCAL', 'vocal', ...)` from drum-and-bass track specs |
| `song_generator.py` | 5672 | Removed `'vocal_shot'` and `'vocal_loop'` from `VARIATION_ROLES` |
| `reference_listener.py` | 5626-5632 | Added `_is_manual_recording_role()` filter in CORE_ROLES selection loop |
| `reference_listener.py` | 5874-5880 | Added `_is_manual_recording_role()` filter in OPTIONAL_ROLES selection loop |
| `reference_listener.py` | 7125-7138 | Added conditional skip for vocal_alt selection when manual-only |

#### P2: Anti-Loop Fixes (COMPLETED - IN ACTIVE PATH)

| File | Line | Change |
|------|------|--------|
| `server.py` | 4618-4667 | Added anti-flattening check BEFORE consolidation in `_materialize_reference_audio_layers()` |

**Key Code Added:**
```python
# P2: ANTI-FLATTEN - Check section_variants BEFORE consolidation
section_variants = layer.get('section_variants', {})
has_variants = bool(section_variants)

MUSIC_HARMONIC_ROLES = {"chords", "synth_loop", "pad", "lead", "pluck", "arp", "drone", "texture", "ambient"}
SECTION_VARIATION_ROLES = {"perc_loop", "top_loop", "perc_alt", "synth_peak", "atmos_fx", "fill_fx"}

should_preserve_positions = has_variants and (
    role_lower in MUSIC_HARMONIC_ROLES or role_lower in SECTION_VARIATION_ROLES
)

if should_preserve_positions:
    logger.info("[P2_ANTI_FLATTEN] Role '%s' (%s) has section_variants - preserving %d positions",
               role_lower, track_name, len(positions))
```

---

## Test Results

All tests PASS:

```
Ran 23 tests in 0.004s - OK (test_piano_forward.py)
Ran 11 tests in 1.546s - OK (test_selection_coherence.py)
```

Tests include:
- `test_sanitize_audio_layer_records_removes_manual_vocal_layers` - OK
- `test_repetition_metrics_detect_repetitive_harmonic_sections` - OK
- `test_repetition_metrics_handle_sections_with_missing_end_values` - OK (end=None bug fixed by Codex)

---

## Runtime Validation Attempt

**Status:** MCP CONNECTION TIMED OUT

Attempted to generate using:
```
generate_song(
    genre="reggaeton",
    style="perreo duro vieja escuela tipo safaera",
    reference="libreria/reggaeton/ejemplo.mp3"
)
```

Result: `MCP error -32001: Request timed out`

**Diagnosis:**
- MCP server is listening on port 9877
- Ableton is running
- But commands are timing out (both get_session_info and generate_song)
- Likely a stale connection or blocking operation

**last_generation_id remains:** `a6a4cc87e493`

---

## Baseline Session Analysis (`a6a4cc87e493`)

### Threshold Failures Found

| Threshold | Expected | Actual | Status |
|-----------|----------|--------|--------|
| `coherence_score` | ≥6.5 | 5.5 | ❌ FAIL |
| `mandatory_midi_hook.materialized` | true | false | ❌ FAIL |
| `piano_presence.piano_layer_count` | ≥1 | 0 | ❌ FAIL |
| `layer_selections.summary.total_layers` | >0 | 0 | ❌ FAIL |
| `repetition_metrics.verdict` | ≠ repetitive | N/A | ⚠️ NOT FOUND |

### Vocal Leak Confirmed

The baseline manifest showed **3 vocal tracks** auto-generated:
- AUDIO VOCAL BUILD
- AUDIO VOCAL PEAK
- AUDIO VOCAL SHOT

---

## Files Modified

1. **`AbletonMCP_AI/AbletonMCP_AI/MCP_Server/song_generator.py`**
   - Vocal removed from track budget (line 5880)
   - Vocal track specs removed for all genres (lines 11741, 11843, 11867)
   - VARIATION_ROLES cleaned (line 5672)

2. **`AbletonMCP_AI/AbletonMCP_AI/MCP_Server/reference_listener.py`**
   - Manual-only role filtering added to CORE_ROLES loop (lines 5626-5632)
   - Manual-only role filtering added to OPTIONAL_ROLES loop (lines 5874-5880)
   - Vocal_alt selection skipped for manual-only roles (lines 7125-7138)

3. **`AbletonMCP_AI/AbletonMCP_AI/MCP_Server/server.py`**
   - **CRITICAL:** Anti-flattening check added BEFORE consolidation (lines 4618-4667)
   - This is the ACTIVE runtime path, not a helper function

---

## Open Issues

### 1. MCP Connection Timeout

**Status:** Requires investigation

**Symptoms:**
- `get_session_info` times out
- `generate_song` times out
- `netstat` shows MCP listening but connections in TIME_WAIT

**Potential Causes:**
- Stale connection blocking new requests
- Previous generate request still running
- Ableton main thread blocked

### 2. Hook Materialization

**Status:** Unstable (not consistently failing)

Evidence from manifests:
- `4c697638bd3d`: hook materialized = true
- `ba306bd7575b`: hook materialized = true
- `a6a4cc87e493`: hook materialized = false

---

## Verdict

**Status: CODE COMPLETE - RUNTIME VALIDATION BLOCKED**

- ✅ P1: Vocal leak fixes implemented (all layers cleaned)
- ✅ P2: Anti-loop fix placed in ACTIVE runtime path
- ✅ Tests pass (23 + 11 = 34 tests)
- ❌ Runtime validation: MCP connection timed out

**Cannot close sprint without:**
1. New session_id persisted
2. Thresholds verified on new generation

**Recommendation:** Investigate MCP connection timeout before proceeding with P4 investigation.