Skip to content

tools/bash: bufio.Reader streaming, no deadlock on >1MiB lines (audit #10) #658

Description

@dennisonbertram

Intent

Stop bash output streaming from deadlocking on lines larger than 1 MiB by switching from bufio.Scanner to bufio.Reader.ReadString('\n'), truncating overlong lines, and always draining to EOF.

Plan reference

Source finding

Bash streaming deadlocks on lines > 1 MiB (internal/harness/tools/bash_manager.go:107-133). bufio.Scanner (1 MiB token cap) returns false on overlong lines; the scanner goroutine exits without anyone draining io.Pipe, so the subprocess blocks forever on stdout write until the (up to 300s) tool timeout fires. Common with minified bundles, base64 dumps, find /.

Scope

  • Allowed files (test): internal/harness/tools/bash_manager_test.go (extend)
  • Allowed files (impl): internal/harness/tools/bash_manager.go
  • Dependencies: none
  • Complexity: low — Risk: low

Acceptance criteria

Use slice T11 in the plan as detailed acceptance criteria. Summary:

  • Failing test written first, compiles and fails on main.
  • Stub a subprocess that prints a single 4 MiB line followed by EOF. Today the run-loop hangs (eventually times out at 300s); assert the tool returns promptly with the line truncated to a configurable MaxLineBytes and the truncation is reported in the result, not silently swallowed.
  • Impl: replace bufio.Scanner with bufio.Reader.ReadString('\n'); on ErrBufferFull, truncate the accumulated chunk to MaxLineBytes, log "line truncated", and continue. Always drain pr to EOF before streamDone.Wait() returns. Add MaxLineBytes (default 1 MiB) to the bash tool config.
  • go test ./internal/harness/tools/... -race green; ./scripts/test-regression.sh green.

Guardrails

  • Strict TDD; failing regression test must compile and fail on main first.
  • Worktree flow; own branch, merge via verify-and-merge.sh.
  • Update .context/harness-reliability/tracker.md on pick-up and merge.
  • Deterministic tests only — in-process pipe, no real subprocess sleeps.
  • Append engineering-log entry on merge.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcorrectnessCorrectness bugs and logic errorsreliabilityReliability and resilience concernssmallSmall effort: < 4 hourswell-specifiedIssue is clear, scoped, and ready to implement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions