Skip to content

Fix flaky Windows CI: widen post-exit wait bound for output draining - #4207

Open
lox wants to merge 1 commit into
mainfrom
fix-windows-ci-hook-flake
Open

Fix flaky Windows CI: widen post-exit wait bound for output draining#4207
lox wants to merge 1 commit into
mainfrom
fix-windows-ci-hook-flake

Conversation

@lox

@lox lox commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

What

Widens the post-exit WaitDelay buffer from 1s to 30s, and adds a per-process WaitDelay override so tests that intentionally leak the output pipe can keep a short delay and stay fast.

Why

Windows AMD64 CI on main has been flaking on lifecycle hook tests (TestAgentStartupHook, TestAgentShutdownHook, TestBuildCancel) with missing log output, e.g. an expected [info] hello world line never appearing.

#4141 introduced a 1s Cmd.WaitDelay buffer that starts once the process exits. When it expires, os/exec force-closes the stdout/stderr pipes — discarding output that was written but not yet drained. On slow Windows CI workers, 1s is sometimes not enough, so hook output gets truncated and the assertions fail.

This is reproducible deterministically: shrinking the buffer to 1ms on Linux produces exactly the missing-output diffs seen in CI.

How

  • waitDelayBuffer goes from 1s to 30s. This buffer only delays completion when a child process has leaked a copy of the output pipe's write end (the case Bound Cmd.Wait so a leaked stdout/stderr pipe can't hang hooks #4141 addressed); a clean exit with closed pipes still completes immediately, so normal jobs see no slowdown.
  • process.Config.WaitDelay allows overriding the buffer per process, with test-only plumbing in internal/shell so the leaked-pipe tests run with ~2s instead of 30s.

Note: main also shows a separate, rarer Windows flake (GetExitCodeProcess: The handle is invalid) that first appeared with the Go 1.26.5 bump (#4134) and matches the Cmd.Wait races in golang/go#78046. That is not addressed here — it's handled by downgrading Go until a released Go contains the upstream fixes (see companion PR).

@lox
lox requested review from a team as code owners August 8, 2026 10:05
@lox lox added the bug label Aug 8, 2026

@buildsworth-bk-app buildsworth-bk-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found no code issues in this pass. This changes shared subprocess wait and exit-status semantics, including the deliberate false-success trade-off for unreadable Windows statuses, so it needs human review.

Want to dig deeper?

Paste this into your agent to explore the findings from this review's Buildkite build:

Download the buildsworth logs from build 13142, then answer my questions about the findings.

Install the reading-buildsworth-logs skill to run this.

About buildsworth

Model: gpt-5.6-sol with xhigh thinking.

How to request a review: Comment @buildsworth-bk review on the PR, or request buildsworth-bk as a reviewer.

Risk labels (how buildsworth classifies risk) — buildsworth classifies risk itself from the diff. To let it approve, grant L2 approval by mentioning @buildsworth-bk (see L2 approval grant):

  • L1 — Low risk (dep bumps, docs/copy, lockfiles, small presentational fixes). buildsworth may approve by default.
  • L2 — Standard risk (new UI, additive API fields, refactors). Approved only with an L2 grant; otherwise comment-only.
  • L3 — High risk (auth, migrations, payments, secrets, perf-critical paths). Human review always required.

@lox
lox force-pushed the fix-windows-ci-hook-flake branch from 1166849 to 4cce25f Compare August 8, 2026 11:11
@lox lox changed the title Fix flaky Windows CI: widen post-exit wait bound, tolerate exit-status read race Fix flaky Windows CI: widen post-exit wait bound for output draining Aug 8, 2026

@buildsworth-bk-app buildsworth-bk-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found no code issues in this revision. This changes the shared non-PTY subprocess wait path used by hooks and jobs, so it needs human review. The current agent build is failing, but its job logs weren't available to me.

Want to dig deeper?

Paste this into your agent to explore the findings from this review's Buildkite build:

Download the buildsworth logs from build 13145, then answer my questions about the findings.

Install the reading-buildsworth-logs skill to run this.

PR #4141 added a 1s WaitDelay buffer after a process exits, after which
os/exec force-closes the output pipes. On slow Windows CI workers, 1s is
sometimes not enough to finish draining hook output that was already
written, causing lifecycle hook tests (TestAgentStartupHook etc.) to
flake with missing log lines.

Widen the post-exit buffer to 30s (it only delays completion when a
child process leaked the output pipe; a clean exit with closed pipes
still completes immediately), and add a per-process WaitDelay override
so the leaked-pipe tests can keep a short delay and stay fast.

Amp-Thread-ID: https://ampcode.com/threads/T-019fe0a2-982c-74fa-830c-5aa0c249369e
Co-authored-by: Lachlan Donald <lachlan@buildkite.com>
@lox
lox force-pushed the fix-windows-ci-hook-flake branch from 4cce25f to d10bf0c Compare August 8, 2026 11:31

@buildsworth-bk-app buildsworth-bk-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found no code issues in this revision. It changes the shared non-PTY subprocess wait path used by hooks and jobs, so it still warrants human review. Focused process/shell tests and vet passed locally; the agent CI build is still running.

Want to dig deeper?

Paste this into your agent to explore the findings from this review's Buildkite build:

Download the buildsworth logs from build 13150, then answer my questions about the findings.

Install the reading-buildsworth-logs skill to run this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants