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.
Intent
Stop bash output streaming from deadlocking on lines larger than 1 MiB by switching from
bufio.Scannertobufio.Reader.ReadString('\n'), truncating overlong lines, and always draining to EOF.Plan reference
docs/plans/2026-06-24-harness-reliability-plan.md— slice T11Source 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 drainingio.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
internal/harness/tools/bash_manager_test.go(extend)internal/harness/tools/bash_manager.goAcceptance criteria
Use slice T11 in the plan as detailed acceptance criteria. Summary:
main.EOF. Today the run-loop hangs (eventually times out at 300s); assert the tool returns promptly with the line truncated to a configurableMaxLineBytesand the truncation is reported in the result, not silently swallowed.bufio.Scannerwithbufio.Reader.ReadString('\n'); onErrBufferFull, truncate the accumulated chunk toMaxLineBytes, log "line truncated", and continue. Always drainprto EOF beforestreamDone.Wait()returns. AddMaxLineBytes(default 1 MiB) to the bash tool config.go test ./internal/harness/tools/... -racegreen;./scripts/test-regression.shgreen.Guardrails
mainfirst.verify-and-merge.sh..context/harness-reliability/tracker.mdon pick-up and merge.