Skip to content

fix: race in RunWithPrompts truncates output on process exit - #64

Merged
sleipi merged 1 commit into
mainfrom
worktree-fix-prompts-race
Sep 17, 2026
Merged

sleipi merged 1 commit into
mainfrom
worktree-fix-prompts-race

Conversation

@sleipi

@sleipi sleipi commented Sep 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • test-ash (1.27) in CI (run 35203905985) fails intermittently at make examples on examples/06_prompts.clitest, missing the script's final "Created user: ..." line
  • Root cause: RunWithPrompts (internal/runner/prompts.go) called cmd.Wait() in a goroutine concurrently with the goroutine reading cmd.StdoutPipe() — a documented anti-pattern (Cmd.Wait closes the pipe as soon as the child exits, which can race a concurrent Read on the same fd and truncate the last chunk). No application code changed since May; the new golang:1.27-alpine CI matrix job just shifted timing enough to expose it
  • Fix: read the process's stdout to completion first (<-readDone), then call cmd.Wait() once, sequentially, to reap the exit code — timeout now only kills the process, it no longer races Wait

Test plan

  • go test ./internal/runner/... -run TestRunWithPrompts -race -count=50 — pass
  • make test && make e2e && make examples locally — pass
  • 40x + 30x stress loop of examples/06_prompts.clitest — 0 failures
  • Reproduced the exact CI job (make test && make e2e && make examples) inside golang:1.27-alpine via podman, including a 30x stress loop — pass

…ompts

Wait() closes the stdout pipe as soon as the child exits, racing our own
Read on the same fd and occasionally truncating the last chunk of output.
Fixes flaky examples/06_prompts.clitest under the new Go 1.27 CI matrix
(golang:1.27-alpine), reproduced and verified fixed against that exact image.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@sleipi sleipi added the bug Something isn't working label Sep 17, 2026
@sleipi
sleipi merged commit 1199f56 into main Sep 17, 2026
7 checks passed
@sleipi
sleipi deleted the worktree-fix-prompts-race branch September 17, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant