{"record":{"id":"1e8d4358c82ac835","repo":"affaan-m/ECC","slug":"source-capacity-does-not-match-native-offsets","errorCode":null,"errorMessage":"source capacity does not match native offsets","messagePattern":"source capacity does not match native offsets","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"skills/taste-application/scripts/tasteforge/integration.py","lineNumber":256,"sourceCode":"\ndef _binding(item: Any, tracks: dict, baseline: dict, *, audio: bool = False) -> tuple:\n    _object(item, {\"media\", \"track\", \"clip_index\", \"media_frames\", \"fps\",\n                   \"source_range\", \"timeline_range\"})\n    track, index = _text(item[\"track\"]), _integer(item[\"clip_index\"])\n    if not track.startswith(\"audio\" if audio else \"video\"):\n        raise ValueError(\"wrong source/audio track kind\")\n    if track not in tracks or index >= len(tracks[track]):\n        raise ValueError(\"source binding has no native clip\")\n    clip = tracks[track][index]\n    _artifact(item[\"media\"])\n    if item[\"media\"][\"path\"] != clip[\"path\"]:\n        raise ValueError(\"source path does not match native clip\")\n    if _rate(item[\"fps\"]) != _rate(baseline[\"fps\"]):\n        raise ValueError(\"source fps/retime ambiguity\")\n    duration = clip[\"end\"] - clip[\"start\"]\n    capacity = _integer(item[\"media_frames\"], 1)\n    if capacity != clip[\"left_offset\"] + duration + clip[\"right_offset\"]:\n        raise ValueError(\"source capacity does not match native offsets\")\n    source = _range(item[\"source_range\"], [clip[\"left_offset\"], clip[\"left_offset\"] + duration])\n    target = _range(item[\"timeline_range\"], [clip[\"start\"], clip[\"end\"]])\n    mapped = [clip[\"start\"] + f - clip[\"left_offset\"] for f in source]\n    if mapped != target or (audio and target != [clip[\"start\"], clip[\"end\"]]):\n        raise ValueError(\"source/audio placement must preserve native timing\")\n    return track, index\n\n\ndef _preserved_stack(protected: Any, tracks: dict, bounds: list[int]) -> list[dict]:\n    if not isinstance(protected, list) or not protected:\n        raise ValueError(\"protected intervals must be explicit and nonempty\")\n    for item in protected:\n        _object(item, {\"range\", \"reason\"})\n        _range(item[\"range\"], bounds)\n        _text(item[\"reason\"])\n        if not any(_overlap(item[\"range\"], [c[\"start\"], c[\"end\"]])\n                   for key, clips in tracks.items() if key.startswith(\"video\") for c in clips):\n            raise ValueError(\"protected interval has no original video stack\")","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/skills/taste-application/scripts/tasteforge/integration.py#L238-L274","documentation":"Raised by _binding when the clip's total frame capacity does not equal left_offset + (end - start) + right_offset. The media_frames value in the binding must exactly account for lead-in, body, and tail frames of the native clip.","triggerScenarios":"item['media_frames'] counts only the trimmed body (end-start) while offsets are nonzero, or the snapshot offsets were edited without updating media_frames.","commonSituations":"Bindings computed from trimmed source metadata that ignores handles/offsets; snapshot regenerated with changed trim points while binding metadata is stale; rounding when media_frames was derived from seconds * fps.","solutions":["Set item['media_frames'] = clip['left_offset'] + (clip['end'] - clip['start']) + clip['right_offset'] exactly.","Regenerate binding metadata from the same snapshot that will be validated against.","Avoid float-derived frame counts; compute media_frames in integer frames only."],"exampleFix":"// before\nmedia_frames = clip['end'] - clip['start']\n// after\nmedia_frames = clip['left_offset'] + (clip['end'] - clip['start']) + clip['right_offset']","handlingStrategy":"validation","validationCode":"for item in bindings:\n    clip = snapshot['timeline_readback'][item['track']][item['clip_index']]\n    expected = clip['left_offset'] + (clip['end'] - clip['start']) + clip['right_offset']\n    assert item['media_frames'] == expected, f\"media_frames {item['media_frames']} != {expected}\"","typeGuard":"def capacity_matches(item, clip) -> bool:\n    return item['media_frames'] == clip['left_offset'] + (clip['end'] - clip['start']) + clip['right_offset']","tryCatchPattern":"try:\n    bundle = build_application_bundle(...)\nexcept ValueError as e:\n    if 'source capacity does not match native offsets' in str(e):\n        log.error('media_frames vs offsets mismatch', media_frames=item['media_frames'])\n    raise","preventionTips":["Compute media_frames from the clip's own offsets, never from trimmed seconds * fps","Regenerate bindings together with the snapshot after trim changes","Use integer frame arithmetic exclusively"],"tags":["binding","frames","validation"],"backgroundTag":"value-out-of-range","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"}