Skip to content

flaky: gateway-handover.test.ts B10 open test sees no connected worker within 10 s on the Windows unit job #2097

Done

Description

@V3RON

What happened

src/agent-device/gateway-handover.test.ts, "the agent-device front under a handover credential, through a gateway > B10: open attaches agent-device on the handed-over lease's worker and leases nothing", failed on the Windows unit job (shard 2/3) on PR #2087, at 5f193ec, attempt 1 of the CI run (job). The same job run also failed src/report-guard.test.ts and src/agent-device/edge-allocate.test.ts. A re-run of the run (attempt 2) passed.

This one is not the 20 s test timeout. setUp() waits up to 10 s (untilRead, vi.waitFor) for the gateway's worker.list to show the worker as connected, and the wait ran out with no worker view at all:

FAIL  unit  src/agent-device/gateway-handover.test.ts > the agent-device front under a handover credential, through a gateway > B10: open attaches agent-device on the handed-over lease's worker and leases nothing
AssertionError: expected undefined to be 'connected' // Object.is equality

- Expected:
"connected"

+ Received:
undefined

 ❯ vi.waitFor.timeout src/agent-device/test-gateway.ts:359:32

What you expected

The worker is connected within 10 s, and the test passes on every run.

How to reproduce

Not reproduced locally: it runs on Windows only. Seen once, on 2026-12-03. The shard ran 384 s and three files failed, so a loaded runner is a likely cause, not a known one.

Environment

CI: windows-2025, job Unit tests (Windows) (2/3), pnpm run test:unit (20 s test timeout; the untilRead wait is 10 s).

Written by an agent.

Activity

  1. added
    bug:new
    flaky-test
    os:windows
    on Dec 3, 2026
  2. self-assigned this
    on Dec 3, 2026
  3. V3RON commented on Dec 3, 2026

    @V3RON
    ContributorAuthor

    Reproduction

    Seen on: CI log, Windows unit shard 2/3 (worker logs stay in memory, so the failed dial on CI is inferred, not read)

    When a worker's first uplink dial fails, the rig's setUp() never sees that worker. Two workers; the first dial is refused once. It fails exactly as CI did.

    src/agent-device/gateway-rig-redial.test.ts, "answers setUp with every worker connected and read when a worker's first uplink dial fails", on bug/2097-repro:

    pnpm exec vitest run --project unit src/agent-device/gateway-rig-redial.test.ts
    
    AssertionError: expected undefined to be 'connected' // Object.is equality
     ❯ vi.waitFor.timeout src/agent-device/test-gateway.ts:359:32
    

    Root cause

    Defect. untilRead (src/agent-device/test-gateway.ts:355-366) waits 10 s of real time and never moves the rig's FakeClock. When a dial fails, GatewayUplink (src/daemon/gateway-uplink.ts:143 → #scheduleRetry, line 166) schedules the redial on that clock (clock.setTimer). So the rig turns one failed handshake into a worker that never joins. On a loaded runner a dial can fail: the handshake has a real 10 s timeout (uplink-websocket.ts:51). The gateway never got a hello, so its view is undefined, as on CI. untilRedialed (line 749) already moves the clock for this; setUp does not.

    Simplest fix

    If the worker is still not connected after about 2 s of polling, move the clock while waiting, the way untilRedialed does:

     export async function untilRead(rig: Rig, member: Member): Promise<void> {
    +  let polls = 0;
       await vi.waitFor(
         async () => {
           const view = await viewOf(rig, member.label);
    +      polls += 1;
    +      if (view?.connection !== "connected" && polls > 40) await advance(rig, 1_000, 500);
    pnpm exec vitest run --project unit src/agent-device/gateway-rig-redial.test.ts src/agent-device/gateway-*.test.ts
    Test Files  9 passed (9)   Tests  99 passed (99)
    

    Alternatives rejected

    • Advancing the clock on every poll where the worker is not connected moves the clock during normal setUps too. Two gateway-front-reconnect.test.ts tests failed (expected 32000 to be 31000).
    • A longer untilRead timeout does not help: a redial on the fake clock never fires, however long the wait.
    • A startDaemon uplink-backoff option adds a daemon option only tests use.

    Risk

    • A dial still in flight after about 2 s now gets the clock moved; a test reading deadlines could fail differently.
    • The fix does not help a runner that is starved for the whole 10 s. Only the failed-dial case is fixed.

    Fast track

    • Defect: yes
    • Fix tried: yes
    • Nothing public added or broken: yes
    • No ADR or rule changed: yes
    • One fix: yes

    Written by an agent.

  4. removed their assignment
    on Dec 3, 2026
  5. added
    bug:ready
    fast-track
    and removed
    bug:new
    on Dec 3, 2026
  6. self-assigned this
    on Dec 3, 2026
  7. V3RON commented on Dec 3, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #2099 (#2097)

    Written by an agent.

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

Metadata

Metadata

Assignees

Labels

bug:readyfast-trackflaky-testos:windows

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions