Skip to content

Fix flake in test_automation_listener_receives_notifications_and_processes_them - #23006

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1788272368-fix-automation-notify-listener-flake
Open

Fix flake in test_automation_listener_receives_notifications_and_processes_them#23006
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1788272368-fix-automation-notify-listener-flake

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

This PR removes a race in test_automation_listener_receives_notifications_and_processes_them, which failed on main with assert 2 == 3 (the automation__created call was missing) in this run.

The test started listen_for_automation_changes() as a task and then slept 0.1 seconds before it created the automation. Postgres sends a NOTIFY only to connections that already run LISTEN, so the notification is lost, not delayed, if the listener is not subscribed yet. On a loaded runner, the asyncpg connect plus reconcile_automations() can take more than 0.1 seconds, so the created notification was lost and the retry_asserts loop could not recover it.

The test now sends probe notifications with a random automation ID until the listener reports one. This proves the LISTEN is registered before the test makes real automation changes. The assertions filter the recorded calls by the automation ID, so a probe that arrives late cannot change the result.

Verification
  • Reproduced the CI failure locally with Postgres 14: with an added 1 second delay in the listener connection setup, the old test failed with the same missing-created assertion, and the new test passed.
  • Ran the module 20 times against Postgres: all passed.
  • Ran tests/events/server/models with --numprocesses auto --maxprocesses 6 --dist worksteal: 39 passed.

Checklist

  • This pull request references any related issue by including "closes <link to issue>"
  • If this is a complex change, a maintainer has confirmed the proposed approach on the linked issue.
  • If this pull request adds or changes functionality, it includes tests or explains why tests are not needed.
  • If this pull request changes user-facing behavior, it updates documentation or explains why documentation is not needed.
  • If this pull request removes docs files, it includes redirect settings in mint.json.
  • If this pull request adds functions or classes, it includes helpful docstrings.

Link to Devin session: https://app.devin.ai/sessions/c84ee4dd042541d7848c8a54c92cf8ea
Open in Devin Desktop: https://app.devin.ai/desktop/session/c84ee4dd042541d7848c8a54c92cf8ea?variant=devin

Wait for the listener's LISTEN to be registered before making automation
changes, since Postgres does not deliver notifications to connections that
subscribe later.

Co-Authored-By: bot_apk <apk@cognition.ai>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot added the development Tech debt, refactors, CI, tests, and other related work. label Sep 1, 2026

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

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

Labels

development Tech debt, refactors, CI, tests, and other related work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants