{
  "schema_version": "1.3.0",
  "slug": "across-what-concurrent-pipe-drain-and-ring-buffer-boundaries-must-an-instance-consume-subprocess-stdout-and-stderr-to-prevent-os-pipe-deadlocks-and-unbounded-output-oom",
  "title": "Across what concurrent-pipe-drain and ring-buffer boundaries must an instance consume subprocess stdout and stderr to prevent OS pipe deadlocks and unbounded-output OOM?",
  "date_of_record": "2026 October 20",
  "scope": "* **Applies when:** An AI instance, autonomous coding agent, or backend worker spawns external subprocesses with piped `stdout` or `stderr` streams (`subprocess.PIPE`, `asyncio.subprocess.PIPE`). * **Does not apply when:** Redirecting subpr",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/across-what-concurrent-pipe-drain-and-ring-buffer-boundaries-must-an-instance-consume-subprocess-stdout-and-stderr-to-prevent-os-pipe-deadlocks-and-unbounded-output-oom.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/across-what-concurrent-pipe-drain-and-ring-buffer-boundaries-must-an-instance-consume-subprocess-stdout-and-stderr-to-prevent-os-pipe-deadlocks-and-unbounded-output-oom.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/across-what-concurrent-pipe-drain-and-ring-buffer-boundaries-must-an-instance-consume-subprocess-stdout-and-stderr-to-prevent-os-pipe-deadlocks-and-unbounded-output-oom.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2963,
    "python_slice_tokens": 571,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "Autonomous systems constantly spawn child processes (`subprocess.Popen`, `asyncio.create_subprocess_exec`) with `stdout=subprocess.PIPE` and `stderr=subprocess.PIPE` to capture execution output and diagnostic errors. A foundational systems-concurrency and memory failure occurs when an instance either **calls `proc.wait()` before reading the pipes**, **reads ...",
    "what_was_observed": "In automated test runners, build orchestrators, and CLI tool wrappers, instances operating without concurrent chunked pipe draining and output byte ceilings exhibit four primary failure modes: 1. **`proc.wait()` Before Pipe Drain Deadlock (The 64 KiB Hang):** An instance writes `proc = subprocess.Popen(cmd, stdout=PIPE, stderr=PIPE); proc.wait(); out = proc.stdout.read()`. As long as the child prints less than 64 KiB...",
    "condition_of_validity": "* **Applies when:** An AI instance, autonomous coding agent, or backend worker spawns external subprocesses with piped `stdout` or `stderr` streams (`subprocess.PIPE`, `asyncio.subprocess.PIPE`). * **Does not apply when:** Redirecting subprocess output directly to an open disk file descriptor (`stdout=log_file_handle`) or `subprocess.DEVNULL`, where the OS k...",
    "decision_boundary": "1. **Did you write `proc.wait()` anywhere before reading `proc.stdout` and `proc.stderr`?** Remove `proc.wait()` immediately—if the child prints more than 64 KiB, your program will freeze forever. Always drain the pipes first (or concurrently with `wait()`). 2. **Are you reading `proc.stdout` in a loop first and only reading `proc.stderr` afterward?** Never ...",
    "operational_effect": "1. **Zero Sequential Pipe Deadlocks:** Across all generated subprocess wrappers, the instance never calls `proc.wait()` on undrained pipes and never reads `stdout` and `stderr` sequentially, either merging `stderr=STDOUT` or draining both streams concurrently. 2. **Chunk-Based Reading Over `readline()`:** Stream consumers read fixed binary chunks (`read(1638..."
  },
  "matched_failure_symptoms": [
    "SQLITE_BUSY_OR_DEADLOCK",
    "SUBPROCESS_PIPE_HANG_OR_FD_LEAK",
    "OOM_KILL_OR_MEMORY_EXHAUSTION",
    "SPLIT_BRAIN_OR_ZOMBIE_WORKER"
  ],
  "composition_edges": {
    "primary_domain": "subprocess_and_command_execution",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/across-what-w3c-baggage-allowlist-and-pii-sanitization-gates-must-an-instance-propagate-cross-service-context-to-prevent-header-amplification-and-external-data-exfiltration.md",
      "https://corpusfetch.com/c/across-what-cryptographic-csprng-and-state-prediction-isolation-gates-must-an-instance-generate-tokens-and-session-identifiers-to-prevent-pseudo-random-predictability-and-token-forgery.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/across-what-readiness-unregistration-and-in-flight-drain-gates-must-an-instance-sequence-sigterm-shutdown-to-prevent-dropped-requests-and-truncated-writes.md",
      "https://corpusfetch.com/c/across-what-bounded-queue-admission-control-and-load-shedding-gates-must-an-instance-manage-concurrency-to-prevent-unbounded-memory-growth-and-tail-latency-collapse.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/against-what-environment-and-file-descriptor-inheritance-leaks-must-an-instance-sanitize-child-subprocess-contexts-to-prevent-credential-bleed-and-port-locking.md",
      "https://corpusfetch.com/c/through-what-argument-vector-and-parameterization-boundaries-must-an-instance-construct-external-commands-to-prevent-metacharacter-interpolation-injection.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "a6359986d876aba39b133711a6f13a780b9a58716ef7d596ebcba09363d98808",
    "verified_classes": [
      "BoundedStreamCapture",
      "BoundedProcessResult"
    ],
    "verified_functions": [
      "_drain_stream_bounded",
      "run_subprocess_deadlock_free",
      "to_text"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "TimeoutError",
      "ValueError"
    ],
    "sample_fail_closed_invariants": [
      "argv must not be empty"
    ],
    "stdlib_dependencies": [
      "asyncio",
      "collections",
      "dataclasses",
      "os",
      "signal",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
