Skip to content

Flaky: retireExhausted > retires no more rows than the limit allows #195

Description

@phanlemanh

Seen once on main at 3c3e07a, running the full suite (bun run test) on macOS with the
Postgres from docker compose:

agent:test: error: expect(received).toBeLessThanOrEqual(expected)
agent:test: (fail) retireExhausted > retires no more rows than the limit allows

That is apps/agent/test/tasks.integration.spec.ts:183, on

expect((await retireExhausted(2)).length).toBeLessThanOrEqual(2);

I could not reproduce it: 1 failure in 6 runs. The five that passed were three
bun run --filter=agent test --force and two full bun run test --force. The one that
failed was a full-suite run, so apps/api had written its own agentTask rows first.

What I am unsure about, and why I am reporting rather than sending a patch: reading the
SQL in apps/agent/agent/lib/tasks.ts:73, the LIMIT sits inside the subquery, so a
return longer than the limit is not something foreign rows alone seem to explain. Either
the limit can leak under concurrency, or the failure is something else wearing this
test's name.

One thing that does look load-bearing: the test calls claimDue(10, RESEARCH), which
claims up to ten due rows rather than only the three it queued. On a shared database that
is whatever the previous package left behind.

I have no strong opinion on the fix. Happy to dig further if it is useful.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions