Skip to content

[Bug]: flaky test — lineage-and-scan-cache-part-03 worktree scan-cache TTL assertion is order/timing dependent #22579

Closed

Description

@nwparker

Summary

src/main/runtime/orca-runtime-tests/lineage-and-scan-cache-part-03.spec.ts:353 fails intermittently in CI with a call-count mismatch:

AssertionError: expected "vi.fn()" to be called 3 times, but got 4 times
AssertionError: expected "vi.fn()" to be called 3 times, but got 5 times

Both variants observed. It runs in the tests node 24 8/8 shard (and has also surfaced via 1/8).

The assertion

await runtime.listDetectedManagedWorktrees('id:repo-a')
await vi.advanceTimersByTimeAsync(10_000)
await runtime.listDetectedManagedWorktrees('id:repo-b')
await vi.advanceTimersByTimeAsync(20_000)
await runtime.listDetectedManagedWorktrees('id:repo-a')
await runtime.listDetectedManagedWorktrees('id:repo-b')

expect(listWorktrees).toHaveBeenCalledTimes(3)

It pins a scan-cache TTL using fake timers. Getting more calls than expected is consistent with cache entries expiring when they shouldn't — i.e. something other than the faked clock influencing TTL, or state leaking between files in the shard.

Impact

It is not tied to any particular change. I hit it across four unrelated OpenCode PRs (#22444, #22544, #22546, #22547) over a few hours; each time it cleared on a plain rerun with no code change. Because it also fails the aggregate verify check, every hit looks like a red PR and costs a diagnosis cycle before you can conclude it is noise.

Passes consistently locally: pnpm test src/main/runtime/orca-runtime.test.ts → 1294–1298 passed.

Suggested direction

Worth checking whether the runtime's scan cache reads wall-clock time (Date.now() captured outside the faked context, or a timer created before vi.useFakeTimers()) rather than the faked clock, and whether the cache is module-scoped and therefore shared with other spec files in the same shard.

Filed rather than fixed because the fix depends on how listDetectedManagedWorktrees's cache is meant to be scoped, which the runtime owners will know.

Activity

  1. AmethystLiang commented on Sep 24, 2026

    @AmethystLiang
    Contributor

    thanks for reporting. looking into it

  2. nwparker commented on Oct 22, 2026

    @nwparker
    ContributorAuthor

    Closing as completed: the reported TTL test now isolates the two sources of nondeterminism in current main (4dd97f02d5e2).

    In lineage-and-scan-cache-part-03.spec.ts, the test starts fake time at zero and uses vi.setSystemTime(10_000) / vi.setSystemTime(30_000) instead of advancing the timer queue. This changes the clock used by the TTL without running unrelated scans scheduled by earlier tests. It also stubs readRepoWorktreeAdminFingerprint to return null, so a real filesystem directory cannot short-circuit the expected rescan. Cleanup restores both the spy and real timers in finally. The assertion now checks the exact scan sequence: repo-a, repo-b, repo-a.

    That implementation is present in merged #25078, an ancestor of main, and the checked-out test matches main. Validation with ORCA_BACKGROUND_LAUNCH=1: the 11 scan-cache tests passed; a full runtime-suite run also passed this test (1,461 passed, 2 skipped). The full run had two separate existing-folder import failures involving macOS /var versus /private/var paths, so I am not claiming the whole suite passed. Neither failure was the reported TTL assertion.

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions