Skip to content

Flaky: TestPoolDrainKillsStraggler synchronizes on QueueDepth, not on the worker being tracked #919

Open

Description

@PierrunoYT

Version / branch / commit

main @ dc15e822. The test and pool.go are unchanged since #274, so this affects every branch.

OS and environment

Observed on CI: Smoke (windows-latest), Windows Server 2025, Go per go.mod. Not OS-specific in principle — it is a scheduling race, and Windows CI is simply where the window is widest.

Steps to reproduce

go test ./internal/daemon/ -run TestPoolDrainKillsStraggler

Intermittent. It does not reproduce on an idle machine — I ran 30× normally and 200× under GOMAXPROCS=1 on Windows 11, all green. It shows up on loaded shared CI runners.

Recent occurrence: https://github.com/Gitlawb/zero/actions/runs/32013099576/job/95336704923 (on the PR #892 branch, whose diff touches only internal/config, internal/cli, and internal/tui — nothing in internal/daemon).

Expected behavior

Drain() force-kills a worker still running after KillTimeout, so straggler.killed == 1.

Actual behavior

--- FAIL: TestPoolDrainKillsStraggler (0.00s)
    pool_test.go:231: Drain must kill a straggler still running after KillTimeout
FAIL	github.com/Gitlawb/zero/internal/daemon	0.781s

Root cause

The test waits on the wrong piece of state. It gates on the slot lease, while Drain gates on the tracked worker set, and there is a window between the two.

  • internal/daemon/pool_test.go:222 — waitFor(t, func() bool { return pool.QueueDepth() == 1 })
  • internal/daemon/pool.go:169 — QueueDepth() is len(p.slots), i.e. slot-channel occupancy, set the moment Run leases a slot.
  • internal/daemon/pool.go:246 — the handle only enters p.active later, in runOnce → p.track(id, handle), after Launcher returns.
  • internal/daemon/pool.go:336 — Drain's grace loop reads len(p.active).

So waitFor can return while p.active is still empty. If Drain() runs in that window it takes the early return at pool.go:339:

if n == 0 {
    return // all workers drained gracefully
}

and never reaches the force-kill block at pool.go:344-354. straggler.killed stays 0, which is exactly the assertion that fires.

This is a test-synchronization defect, not a Drain bug — production Drain is correct for a worker that is actually tracked.

Suggested fix

Synchronize on the state Drain actually reads. WorkerStats() (pool.go:361) is built from p.active, so:

waitFor(t, func() bool { return len(pool.WorkerStats()) == 1 })

Worth a quick grep for the same QueueDepth()-as-readiness assumption in the neighbouring pool tests.

Activity

  1. self-assigned this
    on Aug 18, 2026
  2. jatmn commented on Aug 18, 2026

    @jatmn
    Collaborator

    working on this.

  3. added
    bug
    on Aug 18, 2026
  4. added 2 commits that reference this issue on Aug 19, 2026
    2e8f92f
    e382ea1
  5. added
    issue-approved
    on Aug 25, 2026
  6. gnanam1990 commented on Aug 25, 2026

    @gnanam1990
    Collaborator

    Approved. The test still waits for QueueDepth() == 1, while Drain decides from the separately populated active-worker set, leaving the reported scheduling window. Synchronizing on WorkerStats is the appropriately scoped test fix. PR #927 is already active and the issue is assigned; please coordinate there.

  7. added a commit that references this issue on Aug 27, 2026
    6975197
  8. added a commit that references this issue on Aug 27, 2026
    8c92d28
  9. added a commit that references this issue on Sep 12, 2026
    a3e8a0c
  10. added a commit that references this issue on Sep 22, 2026
    9aec673
  11. added a commit that references this issue on Oct 16, 2026
    e179f69
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugissue-approved

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions