{"record":{"id":"6d7c58be61dd40b0","repo":"abhigyanpatwari/GitNexus","slug":"capture-stdout-bytes-must-be-positive-when-supplie","errorCode":null,"errorMessage":"capture_stdout_bytes must be positive when supplied","messagePattern":"capture_stdout_bytes must be positive when supplied","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"eval/workflow_bench/process_control.py","lineNumber":430,"sourceCode":"    *,\n    cwd: Path | str | None = None,\n    env: Mapping[str, str] | None = None,\n    shell: bool = False,\n    timeout: float,\n    terminate_grace: float = DEFAULT_TERMINATE_GRACE,\n    tail_bytes: int = MAX_TAIL_BYTES,\n    require_pid_namespace: bool = False,\n    stdin_data: bytes | None = None,\n    capture_stdout_bytes: int | None = None,\n    _ownership_slot: list[tuple[subprocess.Popen[bytes], _WindowsJob | None, int | None]],\n) -> ManagedProcessResult:\n    \"\"\"Implementation registered with an outer post-spawn ownership guard.\"\"\"\n\n    started = time.monotonic()\n    if timeout <= 0 or terminate_grace < 0 or tail_bytes <= 0:\n        raise ValueError(\"timeout and tail_bytes must be positive; terminate_grace must be non-negative\")\n    if capture_stdout_bytes is not None and capture_stdout_bytes <= 0:\n        raise ValueError(\"capture_stdout_bytes must be positive when supplied\")\n    if require_pid_namespace:\n        if os.name == \"nt\":\n            return _empty_result(\"ownership-failure\", started, \"PID-namespace execution is not supported on Windows\")\n        if not _pid_namespace_wrapper(command, shell):\n            return _empty_result(\n                \"ownership-failure\",\n                started,\n                \"required Bubblewrap --unshare-pid/--die-with-parent ownership is absent\",\n            )\n\n    try:\n        process, job, ownership = _spawn(\n            command,\n            cwd=cwd,\n            env=env,\n            shell=shell,\n            pipe_stdin=stdin_data is not None,\n            ownership_slot=_ownership_slot,","sourceCodeStart":412,"sourceCodeEnd":448,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/eval/workflow_bench/process_control.py#L412-L448","documentation":"Companion validator in _run_managed_inner: when capture_stdout_bytes is supplied (not None) it must be strictly positive, because a zero-byte bounded capture is meaningless and a negative one is impossible. The check fires before any subprocess is spawned.","triggerScenarios":"Calling run_managed with capture_stdout_bytes=0 or negative. Typically a code path that sets the kwarg unconditionally from an optional config without gating on None.","commonSituations":"Reading capture_stdout_bytes from config that returns 0 for 'unset'; arithmetic that subtracts into the negatives; copy-paste from another call site that legitimately omitted the kwarg.","solutions":["Omit capture_stdout_bytes entirely when full capture is not needed (the default None is correct).","If driven by config, convert 0 / negative to None before the call: `cap or None`.","Add an assertion at the call site: `assert capture_stdout_bytes is None or capture_stdout_bytes > 0`.","Write a unit test that exercises both None and a positive value."],"exampleFix":"// before\nrun_managed(cmd, timeout=60, capture_stdout_bytes=config.get('cap', 0))\n// after\ncap = config.get('cap') or None\nrun_managed(cmd, timeout=60, capture_stdout_bytes=cap)","handlingStrategy":"validation","validationCode":"def normalize_capture(capture_stdout_bytes: int | None) -> int | None:\n    if capture_stdout_bytes is None:\n        return None\n    if capture_stdout_bytes <= 0:\n        raise ValueError('capture_stdout_bytes must be > 0 when supplied')\n    return capture_stdout_bytes\n\n# run_managed(..., capture_stdout_bytes=normalize_capture(cfg.get('cap')))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Convert unset config (0 / falsy) to None before passing capture_stdout_bytes.","Omit the kwarg entirely when full capture is not needed.","Document that 0 is invalid for capture_stdout_bytes at every call site."],"tags":["validation","process-control","precondition","numeric"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}