{"record":{"id":"e840139a2b3d1d1b","repo":"affaan-m/ECC","slug":"reference-probe-duration-must-be-finite-and-positive","errorCode":null,"errorMessage":"reference probe duration must be finite and positive","messagePattern":"reference probe duration must be finite and positive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"skills/taste-application/scripts/tasteforge/workflow.py","lineNumber":145,"sourceCode":"    def require_finite_evidence(value: Any) -> None:\n        if isinstance(value, bool):\n            raise ValueError(  # noqa: TRY004 - one bounded invalid-media error family\n                \"reference probe numeric evidence must be finite real values\"\n            )\n        if isinstance(value, (int, float)):\n            if not math.isfinite(value):\n                raise ValueError(\"reference probe numeric evidence must be finite real values\")\n        elif isinstance(value, dict):\n            for nested in value.values():\n                require_finite_evidence(nested)\n        elif isinstance(value, list):\n            for nested in value:\n                require_finite_evidence(nested)\n\n    require_finite_evidence(measured)\n    duration = measured.get(\"duration\")\n    if not _finite_real(duration):\n        raise ValueError(\"reference probe duration must be finite and positive\")\n    duration = cast(float, duration)\n    if float(duration) <= 0:\n        raise ValueError(\"reference probe duration must be finite and positive\")\n    for field in (\"sample_times\", \"scene_changes\"):\n        values = measured.get(field, [])\n        if not isinstance(values, list) or any(\n            not _finite_real(value) or float(value) < 0 or float(value) > float(duration)\n            for value in values\n        ):\n            raise ValueError(f\"reference probe {field} must contain finite in-duration times\")\n    samples = measured.get(\"style_samples\", [])\n    if not isinstance(samples, list) or any(\n        not isinstance(sample, dict)\n        or not _finite_real(sample.get(\"time\"))\n        or float(cast(float, sample[\"time\"])) < 0\n        or float(cast(float, sample[\"time\"])) > float(duration)\n        for sample in samples\n    ):","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/skills/taste-application/scripts/tasteforge/workflow.py#L127-L163","documentation":"_validate_probe requires the probe result's \"duration\" field to be a finite, non-boolean real number strictly greater than zero. This error is raised when duration is missing (None), not a number, a bool, NaN/inf, or <= 0. Duration anchors all temporal validation (sample_times, scene_changes, style sample times must fall within it), so an invalid duration makes the entire probe payload unusable.","triggerScenarios":"run_workflow() -> _validate_probe(measured) where measured lacks \"duration\", or measured[\"duration\"] is None/0/negative/nan — e.g. a probe on an image-like or stream file where ffprobe reports no duration and probe_media's `or 0` fallback yields 0.0, or a custom probe forgets the field.","commonSituations":"Probing a still image or a live/raw stream with no duration metadata; a custom probe returning an empty dict; ffprobe output with 'duration': 'N/A' coerced through `or 0`; audio-only files where the video stream lacks duration and format.duration is also absent.","solutions":["Ensure the probe callable always returns a positive finite \"duration\"; supply a measured or fallback duration for media lacking container metadata.","Only feed video/3d media with real duration metadata into the workflow; check `ffprobe -show_format` reports a duration > 0 before running.","For still images used as references, wrap them in a container or have the custom probe return an explicit nominal duration (e.g. 1.0).","Fix custom probes/tests to include \"duration\" in the returned dict rather than omitting it.","Handle 'N/A' duration strings explicitly instead of relying on `or 0`, which silently converts them to the rejected 0.0."],"exampleFix":"// before\nvideo = {}  # image: no video stream\nduration = float(video.get(\"duration\") or payload.get(\"format\", {}).get(\"duration\") or 0)  # -> 0.0\n// after\nduration = float(video.get(\"duration\") or payload.get(\"format\", {}).get(\"duration\") or 0)\nif not math.isfinite(duration) or duration <= 0:\n    raise MediaToolUnavailable(f\"source has no measurable duration: {path}\")","handlingStrategy":"validation","validationCode":"import json, subprocess\n\ndef reference_has_positive_duration(path) -> bool:\n    out = subprocess.run(\n        [\"ffprobe\", \"-v\", \"error\", \"-show_format\", \"-of\", \"json\", str(path)],\n        capture_output=True, text=True, check=True,\n    ).stdout\n    duration = json.loads(out).get(\"format\", {}).get(\"duration\")\n    try:\n        return duration is not None and float(duration) > 0\n    except (TypeError, ValueError):\n        return False\n\n# preflight every reference in the contract before run_workflow","typeGuard":"def has_valid_duration(measured: dict) -> bool:\n    import math\n    d = measured.get(\"duration\")\n    return (\n        isinstance(d, (int, float))\n        and not isinstance(d, bool)\n        and math.isfinite(d)\n        and float(d) > 0\n    )","tryCatchPattern":"try:\n    receipt = run_workflow(\"contract.json\", \"out/\", probe=my_probe)\nexcept ValueError as e:\n    if \"duration must be finite and positive\" in str(e):\n        logger.error(\"reference has no measurable duration; supply a probe with an explicit positive duration\")\n        receipt = run_workflow(\"contract.json\", \"out/\", probe=probe_with_fallback_duration)\n    else:\n        raise","preventionTips":["Preflight each reference with ffprobe and confirm duration > 0 before running the workflow","Do not feed still images or live streams lacking duration metadata unless your probe supplies a nominal duration","Never rely on `value or 0` fallbacks for duration; treat missing metadata as a hard input error","Always include an explicit \"duration\" key in custom probe return values"],"tags":["validation","duration","media-processing","value-out-of-range"],"backgroundTag":"invalid-duration-format","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"}