CodexBar icon indicating copy to clipboard operation
CodexBar copied to clipboard

Bound subprocess output capture

Open ProspectOre opened this issue 5 months ago • 1 comments

Summary

  • Cap each subprocess stdout/stderr capture at 1 MiB while continuing to drain the pipe.
  • Keep the existing default call sites intact with an optional capture limit for tests or future callers.
  • Add regression coverage for oversized stdout and stderr.

Why

A noisy or wedged provider CLI could previously append unbounded output into memory. The status, version, credential, and login probes using this path expect small strings or JSON, so bounded diagnostics are enough; continuing to drain the pipe keeps oversized-output children from blocking.

Impact

This is a shared subprocess guardrail, not a provider-specific change. It covers the common pipe-capture path used by provider version detection, Codex login, Claude direct usage, Gemini process probes, Kiro status probing, Antigravity process/port probing, Bedrock AWS credential export, Vertex gcloud token lookup, Amp usage, and Auggie account status. Normal status, token, credential, and version outputs are small; the cap is meant to stop pathological or noisy child processes from growing CodexBar memory without bound while still draining the pipe so the child cannot deadlock.

Proof

  • swift test --filter SubprocessRunnerTests passed, 10 tests.
  • .build/lint-tools/bin/swiftformat Sources Tests --lint passed, 0/1139 files required formatting.
  • .build/lint-tools/bin/swiftlint --strict passed, 0 violations.
  • swift build --build-tests passed.
  • git diff --check passed.
  • Before/after harness compiled ProcessPipeCapture plus BoundedTaskJoin from upstream/main and this branch, then streamed 64,000,000 stdout bytes through /usr/bin/python3:
    • Before: captured 64,000,000 bytes; benchmark phys_peak=68,256,272; /usr/bin/time -l peak memory footprint 68,338,240; max RSS 72,990,720.
    • After: captured 1,048,576 bytes; benchmark phys_peak=3,342,792; /usr/bin/time -l peak memory footprint 3,441,144; max RSS 9,781,248.
  • make check local blocker: Node v25.9.0 rejects node --check docs/site.js because the file is ESM while the package is not marked as a module. upstream/main:docs/site.js starts with the same ESM import, so this is not introduced by this patch.

ProspectOre avatar Jun 16 '26 09:06 ProspectOre

Codex review: needs maintainer review before merge. Reviewed June 16, 2026, 5:55 AM ET / 09:55 UTC.

Summary The PR adds a 1 MiB default cap to ProcessPipeCapture while continuing to drain pipes, and adds oversized stdout/stderr regression tests.

Reproducibility: yes. Current main appends every non-empty pipe chunk without a cap, and the PR body gives a concrete 64 MB stdout harness showing the before/after capture size and memory behavior.

Review metrics: 2 noteworthy metrics.

  • Diff size: 2 files changed, +48/-2. The patch is narrow but touches a shared subprocess primitive plus its regression tests.
  • Default capture limit: 1 MiB per stream. This is the new compatibility boundary for every default stdout and stderr capture using the helper.

Merge readiness Overall: 🐚 platinum hermit Proof: 🦞 diamond lobster Patch quality: 🐚 platinum hermit Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Confirm or adjust the shared 1 MiB cap before marking the draft ready for merge.

Risk before merge

  • [P1] The 1 MiB default applies to every default ProcessPipeCapture(pipe:) caller, so any legitimate stdout/stderr payload above that size will be silently truncated unless the caller opts into a larger limit.

Maintainer options:

  1. Accept the shared cap
    If maintainers agree the affected subprocess outputs are small status, token, version, or diagnostic payloads, merge as-is after the draft is ready.
  2. Specialize large-output callers
    If any supported caller can legitimately emit more than 1 MiB, pass a larger maxBytes there or choose a different default before merge.

Next step before merge

  • [P2] Maintainers should decide whether the shared 1 MiB default is acceptable; there is no narrow automated repair unless they choose a different cap or caller policy.

Security Cleared: The diff only changes subprocess pipe buffering and focused tests; no dependency, CI, secret-handling, or supply-chain surface was introduced.

Review details

Best possible solution:

Land the shared capture cap with the focused regressions once maintainers accept the 1 MiB default or adjust any call site that needs a larger diagnostic payload.

Do we have a high-confidence way to reproduce the issue?

Yes. Current main appends every non-empty pipe chunk without a cap, and the PR body gives a concrete 64 MB stdout harness showing the before/after capture size and memory behavior.

Is this the best way to solve the issue?

Yes, with one compatibility decision. Bounding stored bytes inside the shared pipe capture while continuing to drain is the narrow fix, but maintainers should accept or tune the 1 MiB shared default before merge.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against ac01d73625ee.

Label changes

Label changes:

  • add P2: This is a normal-priority availability guardrail for shared subprocess probing with focused scope and tests.
  • add merge-risk: 🚨 compatibility: The PR intentionally truncates default subprocess stdout/stderr captures above 1 MiB, which could affect any legitimate large-output caller.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied terminal proof from a before/after subprocess-output harness showing the after-fix 1 MiB cap and lower peak memory, plus focused test/lint/build results.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes copied terminal proof from a before/after subprocess-output harness showing the after-fix 1 MiB cap and lower peak memory, plus focused test/lint/build results.

Label justifications:

  • P2: This is a normal-priority availability guardrail for shared subprocess probing with focused scope and tests.
  • merge-risk: 🚨 compatibility: The PR intentionally truncates default subprocess stdout/stderr captures above 1 MiB, which could affect any legitimate large-output caller.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes copied terminal proof from a before/after subprocess-output harness showing the after-fix 1 MiB cap and lower peak memory, plus focused test/lint/build results.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied terminal proof from a before/after subprocess-output harness showing the after-fix 1 MiB cap and lower peak memory, plus focused test/lint/build results.
Evidence reviewed

What I checked:

Likely related people:

  • steipete: Peter Steinberger authored the current subprocess runner snapshot and recent bounded-drain/helper-cleanup commits that define the affected shared process-capture behavior. (role: recent area contributor; confidence: high; commits: 371c7489695a, b3f74cabeb52, 3286934b8be3; files: Sources/CodexBarCore/Host/Process/ProcessPipeCapture.swift, Sources/CodexBarCore/Host/Process/SubprocessRunner.swift, Tests/CodexBarTests/SubprocessRunnerTests.swift)
  • kiranmagic7: kiranmagic7 authored the recent Kiro pipe-hang fix that touched ProcessPipeCapture, SubprocessRunner, and the subprocess regression tests. (role: adjacent contributor; confidence: medium; commits: 209b6c857fad; files: Sources/CodexBarCore/Host/Process/ProcessPipeCapture.swift, Sources/CodexBarCore/Host/Process/SubprocessRunner.swift, Tests/CodexBarTests/SubprocessRunnerTests.swift)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

clawsweeper[bot] avatar Jun 16 '26 09:06 clawsweeper[bot]

Maintainer repair pushed at 32e7087d6ba2499e6b0204ad786a1d043be1154b.

Changes:

  • Keep the contributor's 1 MiB cap per stdout/stderr stream while continuing to drain both pipes.
  • Decode captured process output lossily at the shared boundary so a cap that splits a multibyte UTF-8 scalar preserves the valid prefix instead of returning an empty string.
  • Apply that decoder to SubprocessRunner, Kiro, Codex login, Gemini helper probes, and provider version detection.
  • Add a three-byte-scalar boundary regression and simultaneous 4 MiB stdout/stderr stress coverage.
  • Add changelog credit for @ProspectOre.

Proof:

  • swift test --filter 'SubprocessRunnerTests|CodexLoginRunnerTests|ProviderVersionDetectorTests|GeminiStatusProbeAPITests|KiroStatusProbeTests' - 68 tests passed.
  • Exact process E2E: both stdout and stderr produced 4,096,000 bytes concurrently; each captured string was exactly 1,048,576 bytes and the child exited without deadlock.
  • UTF-8 E2E: a three-byte scalar split after its first byte retained the full ASCII prefix and emitted one replacement scalar at the boundary.
  • make check - format, locale, and strict lint gates passed with zero violations.
  • Full branch Codex autoreview - no accepted/actionable findings (0.83 confidence).
  • Rebased onto 421bf576; diff check clean.

steipete avatar Jun 18 '26 08:06 steipete

Post-#1572 rebase: exact candidate is now 8ba4b637616ce2cc58ae4c7bf9a1cb21182f6040.

No source conflict occurred. Diff check is clean. The earlier proof's abbreviated 32e7087d was correct, but its expanded hash was mistyped; the actual prior head was 32e7087dc25e29591a79766a5709740dc2433613.

Post-rebase focused result: all subprocess, Kiro, Codex login, and version tests passed. The combined run hit one concurrent Gemini helper flake; isolated GeminiStatusProbeAPITests immediately passed 18/18. CI restarted on the current head.

steipete avatar Jun 18 '26 08:06 steipete