Skip to content

aitools: fix flaky TestRunAgentCmdTimeoutStopsDescendants on macOS - #8208

Merged
pietern merged 4 commits into
mainfrom
pietern/installer-timeout-flake
Nov 30, 2026
Merged

pietern merged 4 commits into
mainfrom
pietern/installer-timeout-flake

Conversation

@pietern

@pietern pietern commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Changes

Fix the flaky TestRunAgentCmdTimeoutStopsDescendants (libs/aitools/installer) on macOS. Test-only change.

The test gave the shell a 100ms timeout, so the process-group SIGTERM often landed while sh was still starting and forking its background sleep. On macOS a child forked at that moment can miss the group signal; it then holds the output pipes until the 10s grace period ends. Every macOS failure took 10.1s or more; Linux never failed.

The shell now records its child's PID before the deadline expires (then runs wait, which forks nothing), and the test expires the deadline by hand through a parent context that reports context.DeadlineExceeded, so runAgentCmd still returns its timeout error. This matches how the sibling tests in libs/process/group_unix_test.go wait for the child before cancelling.

Dashboard

  • error/3798: "<N>s" is not less than "5s", macOS only, 5 flaky runs in 14 days on unrelated PRs.

Tests

  • 50/50 runs with -race on Linux.
  • Mutation check: with the group signal changed to target only the leader, the test still fails (10.0s), so it keeps catching the bug it guards.

Gaps and risks

  • No macOS machine was available, so the race was not reproduced directly; the macOS unit-test jobs on this PR are the real check.
  • Production gap left as is: a real timeout that lands exactly while an agent CLI is forking can wait up to the 10s grace period before the kill. With the real 20s/60s timeouts this is rare.
  • Risk: low (test-only).

🤖 AI agent (opus5.5, isaac_claude)

This pull request and its description were written by Isaac.

…er the shell is ready

The test gave the shell a 100ms timeout, so the group SIGTERM often landed
while sh was still starting and forking its background sleep. On macOS a
child forked at that moment can miss the group signal; it then holds the
output pipes until the 10s grace period ends (every macOS failure took
10.1s or more; Linux never failed).

The shell now records its child before the deadline expires, and the test
expires the deadline by hand through a parent context, so the command still
reports an agentCmdTimeoutError. With the group signal changed to target
only the leader, the test still fails (10.0s).

Co-authored-by: Isaac <no-reply@databricks.com>
@github-actions github-actions Bot added aitools AI tools (databricks aitools) related changes test-only-fix PRs that update failing of flaky tests without changing CLI code. labels Nov 30, 2026
@pietern

pietern commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

🤖 /trigger all

AI agent (opus5.5, isaac_claude)

Co-authored-by: Isaac <no-reply@databricks.com>
@pietern

pietern commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

🤖 /trigger all

AI agent (opus5.5, isaac_claude)

@pietern
pietern marked this pull request as ready for review November 30, 2026 15:49
@pietern
pietern requested review from a team and lennartkats-db as code owners November 30, 2026 15:49

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Automated review at 0dd0550. Each finding was verified against the code.

No blocking issues found. 2 non-blocking comment(s) below.

This PR fixes the flaky macOS TestRunAgentCmdTimeoutStopsDescendants. The test now waits for the shell to record its child's PID, then expires the deadline by hand through a parent context that reports DeadlineExceeded. The approach is sound and still covers the group kill and the timeout classification. Two test gaps remain: the test no longer covers runAgentCmd's own timeout argument, and a failed wait leaves the shell running after the test returns.

…test failure

TestRunAgentCmdTimeoutStopsDescendants takes its deadline from the parent
context, so it no longer runs a real process into runAgentCmd's own
timeout. TestRunAgentCmdTimeoutFires does, with a command that forks
nothing, so it cannot hit the macOS fork race.

The descendants test now also expires its deadline from t.Cleanup, so a
failed wait for the ready file still stops the shell and its sleep.

Co-authored-by: Isaac <no-reply@databricks.com>
@pietern

pietern commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

🤖 /trigger all

AI agent (opus5.5, isaac_claude)

@pietern
pietern requested a review from andrewnester November 30, 2026 16:29
Co-authored-by: Isaac <no-reply@databricks.com>
@pietern

pietern commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

🤖 /trigger all

AI agent (opus5.5, isaac_claude)

@pietern
pietern added this pull request to the merge queue Nov 30, 2026
Merged via the queue into main with commit ca57cb8 Nov 30, 2026
23 checks passed
@pietern
pietern deleted the pietern/installer-timeout-flake branch November 30, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aitools AI tools (databricks aitools) related changes factory-generated test-only-fix PRs that update failing of flaky tests without changing CLI code.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants