Skip to content

test(worker): fix races in the reconnect test - #940

Merged
jlav merged 1 commit into
mainfrom
jl/fix-flaky-worker-reconnect-test
Nov 5, 2026
Merged

jlav merged 1 commit into
mainfrom
jl/fix-flaky-worker-reconnect-test

Conversation

@jlav

@jlav jlav commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

  • A human has tested these changes.

AGENT:


Why

test_the_worker_reconnects_after_the_server_drops_it is flaky. It failed CI three times today: twice on main and once on #898.

The test had two races:

  1. It deferred the second job right after pg_terminate_backend. If the NOTIFY fired before the worker had run LISTEN on its new connection, the job waited for the next poll. The test polls every 60s and waits 20s, so it timed out. All three CI failures were this one.
  2. run_one_job returns as soon as the job body runs. The worker then still records the job as done and fetches the next one. If the connections drop during that fetch, procrastinate raises ConnectorException out of the worker loop and the worker exits. This one shows up locally under pytest -n 8.

Summary

  • Before it drops the connections, the test waits until a fetch finds no job, so no worker query is in flight.
  • Before it defers the second job, the test waits for an idle LISTEN connection that opened after the admin connection.

Issue Number

How to Test

Run the reconnect test many times in parallel, for example through a wrapper test parametrized with range(60) and uv run pytest -n 8. On main that gives a few failures per 60 runs. On this branch it passes every time, also with a 1s delay forced into procrastinate's LISTEN reconnect.

Video/Screenshots

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

The worker exiting on a failed query is procrastinate behavior in 3.10.0, the latest release. So the test now covers a connection drop while the worker is idle. In production, a failover that hits an in-flight worker query still stops the worker process, and the container restarts it.


Enterprise server image for this PR:

ghcr.io/openhands/enterprise-server:sha-4561f5c

@github-actions github-actions Bot added the type: test Adding or fixing tests label Oct 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

This PR does not seem to contain any modification to coverable code.

@jlav
jlav merged commit 97a6fdd into main Nov 5, 2026
18 checks passed
@jlav
jlav deleted the jl/fix-flaky-worker-reconnect-test branch November 5, 2026 19:37
@openhands-release-bot openhands-release-bot Bot added the released: 1.87.0 Shipped in 1.87.0 label Nov 5, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.87.0.

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

Labels

released: 1.87.0 Shipped in 1.87.0 type: test Adding or fixing tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants