{"record":{"id":"7dde06e04ffb94bb","repo":"affaan-m/ECC","slug":"every-original-audio-clip-must-be-preserved-exactly-once","errorCode":null,"errorMessage":"every original audio clip must be preserved exactly once","messagePattern":"every original audio clip must be preserved exactly once","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"skills/taste-application/scripts/tasteforge/integration.py","lineNumber":367,"sourceCode":"        _object(compiled_input, {\"source_video\", \"compiled_prompt\"})\n        url = urlsplit(_text(compiled_input[\"source_video\"]))\n        if url.scheme != \"https\" or not url.hostname or url.username or url.password:\n            raise ValueError(\"source reference must be HTTPS without embedded credentials\")\n        _text(compiled_input[\"compiled_prompt\"])\n    cfg = copy.deepcopy(config)\n    for key in (\"audio\", \"candidates\", \"inserts\", \"historical_receipts\"):\n        cfg.setdefault(key, [])\n        if not isinstance(cfg[key], list):\n            raise ValueError(\"bundle collections must be lists\")\n    if local_only and (cfg[\"candidates\"] or cfg[\"inserts\"]):\n        raise ValueError(\"local-only preservation cannot contain candidates or inserts\")\n    tracks = _snapshot(cfg[\"baseline\"])\n    _binding(cfg[\"source\"], tracks, cfg[\"baseline\"])\n    audio_keys = [_binding(item, tracks, cfg[\"baseline\"], audio=True) for item in cfg[\"audio\"]]\n    expected_audio = {(t, i) for t, clips in tracks.items() if t.startswith(\"audio\")\n                      for i in range(len(clips))}\n    if len(set(audio_keys)) != len(audio_keys) or set(audio_keys) != expected_audio:\n        raise ValueError(\"every original audio clip must be preserved exactly once\")\n    stack = _preserved_stack(cfg[\"protected_intervals\"], tracks, cfg[\"baseline\"][\"timeline_range\"])\n    input_hash = None if local_only else _digest(compiled_input)\n    edit_hash = _digest({key: cfg[key] for key in _REQUIRED})\n    if not local_only:\n        candidates = _candidates(cfg[\"candidates\"], cfg[\"source\"][\"media\"][\"sha256\"],\n                                 input_hash, compiled_input[\"source_video\"])\n        _inserts(cfg[\"inserts\"], candidates, cfg, input_hash, edit_hash)\n    for receipt in cfg[\"historical_receipts\"]:\n        _artifact(receipt)\n    result = {**cfg, \"schema_version\": 1, \"mode\": \"preserve_native_timeline\",\n              \"provider_calls\": 0, \"provider_execution\": False, \"dry_run\": True, \"submit\": False,\n              \"provider_input\": copy.deepcopy(compiled_input), \"compiled_input_sha256\": input_hash,\n              \"edit_context_sha256\": edit_hash,\n              \"protected_stack\": stack, \"insert_policy\": \"new_video_track_preserve_baseline_audio\",\n              \"evidence_scope\": \"verified_local_bytes_and_supplied_metadata_only\"}\n    if local_only:\n        result = {**result, \"local_only\": True, \"provider_input_status\": \"not_prepared_local_only\",\n                  \"insert_policy\": \"none_preserve_baseline\"}","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/skills/taste-application/scripts/tasteforge/integration.py#L349-L385","documentation":"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.","triggerScenarios":"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'].","commonSituations":"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.","solutions":["Regenerate cfg['audio'] programmatically from the baseline snapshot so every (audio-track, clip) pair appears exactly once in order","Remove duplicate audio entries referencing the same track/index","After any baseline edit, recompute audio bindings before rebuilding the bundle","Pre-validate with: keys = [(t,i) for each audio item]; assert len(set(keys))==len(keys) and set(keys)==expected from tracks"],"exampleFix":"// before (duplicate + missing)\n\"audio\": [{\"track\": \"audio0\", \"index\": 0}, {\"track\": \"audio0\", \"index\": 0}]\n// after (complete, unique)\n\"audio\": [{\"track\": \"audio0\", \"index\": 0}, {\"track\": \"audio0\", \"index\": 1}]","handlingStrategy":"validation","validationCode":"def audio_coverage_ok(cfg):\n    tracks = {t: clips for t, clips in cfg[\"baseline\"].items() if t.startswith(\"audio\")}\n    expected = {(t, i) for t, clips in tracks.items() for i in range(len(clips))}\n    seen = [(a[\"track\"], a[\"index\"]) for a in cfg[\"audio\"]]\n    return len(set(seen)) == len(seen) and set(seen) == expected","typeGuard":"def audio_binding_valid(item):\n    return isinstance(item, dict) and isinstance(item.get(\"track\"), str) and isinstance(item.get(\"index\"), int)","tryCatchPattern":"try:\n    bundle = build_application_bundle(cfg, ci)\nexcept ValueError as e:\n    if \"audio clip must be preserved exactly once\" in str(e):\n        cfg[\"audio\"] = regenerate_audio_bindings(cfg[\"baseline\"])  # derive from snapshot\n        bundle = build_application_bundle(cfg, ci)\n    else:\n        raise","preventionTips":["Generate audio preservation entries from the baseline snapshot, never by hand","Regenerate bindings after every baseline edit","Check for duplicate (track,index) pairs in CI","Keep baseline track names stable across config versions"],"tags":["validation","audio","integrity","coverage"],"backgroundTag":"schema-validation-failed","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}