Skip to content

capture-compaction idle-broadcast test is flaky on Windows: winner indeterminacy + fixed-sleep completion race #117

Closed

Description

@abogartz

The flake

test/capture-compaction.test.ts → cooldown shared across setup() registrations (#108) → an idle broadcast reaches every live subscription, and pays exactly ONE model call failed test-windows on #114's run https://github.com/abogartz/opencode-self-improvement/actions/runs/40357282402 (job 121693027113):

expect((await loadAll()).filter(isActive).length).toBe(2);
Expected: 2
Received: 1        # capture-compaction.test.ts:385

The test landed with #113 and is flaky on main — any branch that rebases over main can catch it.

Two independent race legs

  1. Winner indeterminacy. The harness bus gives each event.subscribe its own queue (test/harness.ts:72-75), so both setups receive the broadcast; whichever loop reaches the shared cooldown first pays the model call. Setup a carries a FRESH response, setup b carries DUP_CONTENT — the byte-identical twin of the seeded row, which the write gate collapses without appending (gates.ts, dedup_collapse). If b wins, the store legitimately holds 1 row and the store assertion goes red on correct code. The in-line comment claims "seed + ONE row, whichever loop got there first" — only true if either winner would append.

  2. Fixed-sleep completion. waitFor(() => calls.length > 0) unblocks when the mocked generate is initiated; everything downstream — parse, runWriteGate (near-dup scan + append under lock), evidence record — is real async fs bounded only by sleep(150). On a loaded Windows runner the append can take longer; the assertion races it. The compaction twin test is immune because it waits on the evidence line, which is recorded after the gate returns.

Suggested fix

  • Give both setups distinct FRESH responses: the dedup leg belongs to the gate's own tests; the cooldown test should pass no matter which loop wins.
  • Replace the naked sleep(150) + immediate store assert with waitFor(() => evidence().some((l) => String(l.ev).startsWith("auto_capture_"))) (evidence lands after the append — deterministic completion), THEN assert calls === 1, then keep a short post-completion sleep window and re-assert calls === 1 so the "no second fire" check stays honest.

Evidence this is not hypothetical

  • Windows red: run above.
  • macOS sighting: two full-suite runs on a busy machine showed the same lone red that vanished on three reruns — consistent with leg 1 under load.

Activity

  1. added
    test-integrity
    on Oct 26, 2026
  2. added 2 commits that reference this issue on Oct 26, 2026
  3. abogartz-opencode-self-improvement commented on Oct 26, 2026

    @abogartz-opencode-self-improvement

    🎉 This issue has been resolved in version 0.14.6 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    releasedtest-integrity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions