affaan-m/ECC · error · ValueError

every original audio clip must be preserved exactly once

Error message

every original audio clip must be preserved exactly once

What it means

Every clip in every audio* track of the baseline snapshot must be covered by exactly one entry in cfg['audio'], matched via _binding (track name + clip index). Duplicates, omissions, and references to non-existent track/clip indices all fail this invariant, guaranteeing the bundle provably preserves the full original audio.

Solutions

  1. Regenerate cfg['audio'] programmatically from the baseline snapshot so every (audio-track, clip) pair appears exactly once in order
  2. Remove duplicate audio entries referencing the same track/index
  3. After any baseline edit, recompute audio bindings before rebuilding the bundle
  4. Pre-validate with: keys = [(t,i) for each audio item]; assert len(set(keys))==len(keys) and set(keys)==expected from tracks

Example fix

// before (duplicate + missing)
"audio": [{"track": "audio0", "index": 0}, {"track": "audio0", "index": 0}]
// after (complete, unique)
"audio": [{"track": "audio0", "index": 0}, {"track": "audio0", "index": 1}]
Defensive patterns

Strategy: validation

Validate before calling

def audio_coverage_ok(cfg):
    tracks = {t: clips for t, clips in cfg["baseline"].items() if t.startswith("audio")}
    expected = {(t, i) for t, clips in tracks.items() for i in range(len(clips))}
    seen = [(a["track"], a["index"]) for a in cfg["audio"]]
    return len(set(seen)) == len(seen) and set(seen) == expected

Type guard

def audio_binding_valid(item):
    return isinstance(item, dict) and isinstance(item.get("track"), str) and isinstance(item.get("index"), int)

Try / catch

try:
    bundle = build_application_bundle(cfg, ci)
except ValueError as e:
    if "audio clip must be preserved exactly once" in str(e):
        cfg["audio"] = regenerate_audio_bindings(cfg["baseline"])  # derive from snapshot
        bundle = build_application_bundle(cfg, ci)
    else:
        raise

Prevention

When it happens

Trigger: cfg['audio'] missing an entry for some (audioTrack, clipIndex); two audio entries binding the same (track, index); an audio entry pointing at a track name not starting with 'audio' or an out-of-range clip index; audio tracks renamed in the baseline without updating cfg['audio'].

Common situations: Trimming or reordering baseline audio clips so indices shift; copying a config between projects with different track layouts; hand-adding audio entries and duplicating an index; deleting a clip from the baseline without deleting its preservation entry.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/7dde06e04ffb94bb. Report an issue: GitHub.

Appendix: source

Thrown at skills/taste-application/scripts/tasteforge/integration.py:367

        _object(compiled_input, {"source_video", "compiled_prompt"})
        url = urlsplit(_text(compiled_input["source_video"]))
        if url.scheme != "https" or not url.hostname or url.username or url.password:
            raise ValueError("source reference must be HTTPS without embedded credentials")
        _text(compiled_input["compiled_prompt"])
    cfg = copy.deepcopy(config)
    for key in ("audio", "candidates", "inserts", "historical_receipts"):
        cfg.setdefault(key, [])
        if not isinstance(cfg[key], list):
            raise ValueError("bundle collections must be lists")
    if local_only and (cfg["candidates"] or cfg["inserts"]):
        raise ValueError("local-only preservation cannot contain candidates or inserts")
    tracks = _snapshot(cfg["baseline"])
    _binding(cfg["source"], tracks, cfg["baseline"])
    audio_keys = [_binding(item, tracks, cfg["baseline"], audio=True) for item in cfg["audio"]]
    expected_audio = {(t, i) for t, clips in tracks.items() if t.startswith("audio")
                      for i in range(len(clips))}
    if len(set(audio_keys)) != len(audio_keys) or set(audio_keys) != expected_audio:
        raise ValueError("every original audio clip must be preserved exactly once")
    stack = _preserved_stack(cfg["protected_intervals"], tracks, cfg["baseline"]["timeline_range"])
    input_hash = None if local_only else _digest(compiled_input)
    edit_hash = _digest({key: cfg[key] for key in _REQUIRED})
    if not local_only:
        candidates = _candidates(cfg["candidates"], cfg["source"]["media"]["sha256"],
                                 input_hash, compiled_input["source_video"])
        _inserts(cfg["inserts"], candidates, cfg, input_hash, edit_hash)
    for receipt in cfg["historical_receipts"]:
        _artifact(receipt)
    result = {**cfg, "schema_version": 1, "mode": "preserve_native_timeline",
              "provider_calls": 0, "provider_execution": False, "dry_run": True, "submit": False,
              "provider_input": copy.deepcopy(compiled_input), "compiled_input_sha256": input_hash,
              "edit_context_sha256": edit_hash,
              "protected_stack": stack, "insert_policy": "new_video_track_preserve_baseline_audio",
              "evidence_scope": "verified_local_bytes_and_supplied_metadata_only"}
    if local_only:
        result = {**result, "local_only": True, "provider_input_status": "not_prepared_local_only",
                  "insert_policy": "none_preserve_baseline"}

View on GitHub (pinned to 8321021c54)