Skip to content

flaky: usage-projection 'newer stored projection version' gets exit 13 (unsettled top-level await) from simlock daemon start under load #790

Closed

Description

@V3RON

Test: `e2e/usage-projection.test.ts` > usage projection > `a history.db with a newer stored projection version makes simlock daemon start fail with exit 1 and leaves the file's rows unchanged`.

Failure: `expected 13 to be 1` at the `started.code` assertion. The CLI's stderr in a failing run is Node's `Warning: Detected unsettled top-level await at dist/cli/main.js:3` (`process.exitCode = await runCli(...)`): exit 13 is Node's code for a never-settling promise, not a Simlock error code. The passing runs print `DAEMON_STARTUP_FAILED` with exit 1.

Reproduced on base commit 80cba39 (before task #774): 3 of 18 runs of that one test, 6 at a time in parallel to load the machine. Also failed in CI run 39481062187 (E2E 2/3) on PR #788, whose diff touches no CLI, launcher or history code.

Likely area: `simlock daemon start` waiting on the detached, unref'd daemon child exiting while no ref'd handle keeps the event loop alive.

Activity

  1. added
    bug:new
    flaky-test
    and removed
    bug:new
    on Oct 20, 2026
  2. self-assigned this
    on Oct 21, 2026
  3. V3RON commented on Oct 21, 2026

    @V3RON
    ContributorAuthor

    Reproduction

    Defect, confirmed. src/cli/index.test.ts > "fails a start with DAEMON_STARTUP_FAILED, exit 1, when the daemon it launched closes the socket before the CLI's hello" (branch bug/790-repro, 39b047b). A real Unix socket accepts and destroys the connection; the CLI gets it already closed.

    pnpm exec vitest run --project unit src/cli/index.test.ts -t "closes the socket before the CLI's hello"
    AssertionError: simlock daemon start still had not settled at 5000ms: expected false to be true
    

    Root cause

    src/simlock-client/wire.ts:132 subscribes to close with connection.onClose, which is socket.once("close") (src/ports/ipc.ts:107) and never fires for a socket that has already closed; then write on a closed connection resolves without sending (src/ports/ipc.ts:118). So hello (wire.ts:144) waits forever. The window: src/cli/environment.ts:233 resolves the credential (3 admin.token reads, 50 ms apart) between the socket connect and new SimlockWire. The daemon listens first, then refuses the newer projection version asynchronously and stops (src/daemon/main.ts:1503), closing that connection inside the window. The detached child is unref'd and no timer is pending, so Node's loop drains: exit 13. The 20 s startup deadline does not cover hello.

    Simplest fix

    1. SimlockWire: in the constructor, if (connection.closed) this.#die(DAEMON_CONNECTION_LOST); move the #dead check from call into #send so hello rejects too.
    2. AutoLaunchAdminConnector.connect (environment.ts:55): after a launch, a DAEMON_CONNECTION_LOST from the handshake becomes DAEMON_STARTUP_FAILED, like finishConnection does for the probe (daemon start reports DAEMON_CONNECTION_LOST for a daemon that never came up #684).

    Both together turn the test green, along with the 403 other tests in src/cli/index.test.ts, src/simlock-client and src/admin (tried locally, not pushed).

    Alternatives rejected

    Risk

    Written by an agent.

  4. removed their assignment
    on Oct 21, 2026
  5. added
    bug:ready
    and removed on Oct 21, 2026
  6. self-assigned this
    on Oct 21, 2026
  7. V3RON commented on Oct 21, 2026

    @V3RON
    ContributorAuthor

    Handoff

    Done: fix built and audited in PR #805 (head 40a3dc2); review round 1 complete, 0 blocking; review ledger and notes posted; PR is ready.

    Not done: merge. merge-pr.sh 805 refused twice: CI not green (Unit tests, so Quality).

    Findings: the only failing test is src/agent-device/gateway-front.test.ts "a download with no content-length that passes 2147483648 bytes…" (flaky-test #807). A fix run reproduced it 3/3 on both this branch and origin/main 4cc44f8 (about 2.144–2.146 GB delivered, under the 2 GiB assertion), so it is not caused by this PR. Main itself is likely red on this test.

    Blocked on: #807. Once fixed, run the gate on #805 again; no code change needed.

    Written by an agent.

  8. added
    bug:blocked
    and removed
    bug:ready
    on Oct 21, 2026
  9. removed their assignment
    on Oct 21, 2026
  10. V3RON commented on Oct 21, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #804 (#802)
    Parked: #790 — gate refused twice, red CI only from flaky-test #807 (also fails on main); PR #805 is ready and reviewed
    Waiting: #790 — on #807

    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

No one assigned

    Labels

    bug:blockedflaky-test

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions