Skip to content

test(api): stabilize Redis delivery and vector factory isolation - #46624

Merged
hyoban merged 2 commits into
mainfrom
fix/merge-queue-stability-20261117-2313
Nov 17, 2026
Merged

hyoban merged 2 commits into
mainfrom
fix/merge-queue-stability-20261117-2313

Conversation

@hyoban

@hyoban hyoban commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Summary

Two independent test failures removed unrelated PRs from the merge queue. Each fix has its own commit.

Wait for Redis listener delivery

The Redis pub/sub listener tests can fail unrelated merge-queue entries before the background thread has delivered its first message. This happened in run 43374058153 for #46174 and run 43707398723 for #46389, in the sharded and regular variants of test_listener_thread_normal_operation.

Both tests replaced time.sleep with a no-op, started the listener, and immediately inspected its private queue. They now assert the payload through the public receive(timeout=1) boundary, which waits for actual delivery. The test timeout is unchanged; there are no retries, fixed sleeps, or skips. Redis remains mocked at its network boundary.

The precondition is a fresh subscription with a Redis message available; the postcondition is delivery of that message's exact payload through receive(). Production subscription behavior is unchanged.

Validation

Entire api/tests/unit_tests/libs/broadcast_channel/redis/test_pubsub_channel.py, four concurrent lanes, nice -n 10, no test-name filter:

  • Original code, default Python scheduling: 0/20 failed file runs.
  • Original code, sys.setswitchinterval(0.000001) to exercise thread scheduling: 2/12 failed file runs, one in each affected test.
  • Fixed code, identical scheduling pressure: 0/12 failed file runs; 127 tests per run.
  • Ruff format/check, commit hooks, and git diff --check pass.
  • Coverage was disabled for the stress runs because concurrent independent pytest processes otherwise share the default coverage database. An initial coverage-enabled attempt hit that harness collision and is excluded from the counts above.
  • The file is already excluded from the repository's strict unit-test Pyrefly project. Forcing it through that project exposes existing annotation debt; this PR does not expand that cleanup.

Isolate cached vector factory test doubles

Dataset cleanup failed in run 42757668757 and run 42758935827, both queue entries for unrelated webhook refactoring #45912. The registry returned a fake ElasticSearchVectorFactory with no init_vector method.

test_vector_factory.py replaces backend modules with empty test classes. Its fixture cleared the registry only before a test, so restoring sys.modules afterward still left the cached fake class available to another file on the same worker. The fixture now clears the cache in finally after yielding the module, including when a case fails.

The fixture accepts an arbitrary previous cache state, starts each test with a fresh registry, and leaves no cached test factories behind. No production registry behavior changes.

Validation: four concurrent nice -n 10 lanes ran both complete files (test_vector_factory.py and test_clean_dataset_task.py), with no test-name filtering. A temporary collection-order hook placed the Elasticsearch fake lookup last in the factory file, before the cleanup file, to exercise the order a shared xdist worker can receive. This produced the exact CI error in 12/12 runs before the fix and 0/12 afterward, 89 tests per run. Ruff and commit hooks pass.

Open PR #46368 changes type annotations in the factory suite, but its diff does not clear the cache after tests and does not fix this failure. Its changes were inspected before this fix.

Other scanned failures

The scan covered 61 merge-group runs in the requested 24-hour window (17 failures, 44 successes), plus the older supplied trigger runs. Other failures are tracked separately rather than silently treated as fixed:

Screenshots

Not applicable: test synchronization only.

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've verified the change and added or updated tests where meaningful regression risk justifies coverage.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and vp staged (frontend) to appease the lint gods

Scoped checks are recorded above; full local backend checks and integration/E2E runs were intentionally left to CI.

@github-actions github-actions Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Nov 17, 2026
@hyoban hyoban changed the title test(api): await Redis listener delivery in subscription tests test(api): stabilize Redis delivery and vector factory isolation Nov 17, 2026
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 86.73% 86.74% +0.00%
Strict coverage 86.39% 86.39% +0.00%
Typed symbols 94,513 94,516 +3
Untyped symbols 14,515 14,510 -5
Modules 4618 4618 0

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-11-17 15:26:43.442465170 +0000
+++ /tmp/pyrefly_pr.txt	2026-11-17 15:26:15.453295452 +0000
@@ -5026,15 +5026,15 @@
 ERROR Object of class `Subscription` has no attribute `_start_if_needed` [missing-attribute]
    --> tests/unit_tests/libs/broadcast_channel/redis/test_pubsub_channel.py:216:13
 ERROR Argument `FakeRedisClient` is not assignable to parameter `client` with type `Redis[Unknown] | RedisCluster[Unknown]` in function `libs.broadcast_channel.redis._subscription.RedisSubscriptionBase.__init__` [bad-argument-type]
-   --> tests/unit_tests/libs/broadcast_channel/redis/test_pubsub_channel.py:693:20
+   --> tests/unit_tests/libs/broadcast_channel/redis/test_pubsub_channel.py:684:20
 ERROR Argument `FakeRedisClient` is not assignable to parameter `client` with type `Redis[Unknown] | RedisCluster[Unknown]` in function `libs.broadcast_channel.redis._subscription.RedisSubscriptionBase.__init__` [bad-argument-type]
-   --> tests/unit_tests/libs/broadcast_channel/redis/test_pubsub_channel.py:713:20
+   --> tests/unit_tests/libs/broadcast_channel/redis/test_pubsub_channel.py:704:20
 ERROR Argument `TestRedisShardedSubscription.test_get_message_uses_target_node_for_cluster_client.DummyRedisCluster` is not assignable to parameter `client` with type `Redis[Unknown] | RedisCluster[Unknown]` in function `libs.broadcast_channel.redis._subscription.RedisSubscriptionBase.__init__` [bad-argument-type]
-   --> tests/unit_tests/libs/broadcast_channel/redis/test_pubsub_channel.py:898:20
+   --> tests/unit_tests/libs/broadcast_channel/redis/test_pubsub_channel.py:882:20
 ERROR Argument `FakeRedisClient` is not assignable to parameter `client` with type `Redis[Unknown] | RedisCluster[Unknown]` in function `libs.broadcast_channel.redis._subscription.RedisSubscriptionBase.__init__` [bad-argument-type]
-    --> tests/unit_tests/libs/broadcast_channel/redis/test_pubsub_channel.py:1028:20
+    --> tests/unit_tests/libs/broadcast_channel/redis/test_pubsub_channel.py:1012:20
 ERROR Argument `FakeRedisClient` is not assignable to parameter `client` with type `Redis[Unknown] | RedisCluster[Unknown]` in function `libs.broadcast_channel.redis._subscription.RedisSubscriptionBase.__init__` [bad-argument-type]
-    --> tests/unit_tests/libs/broadcast_channel/redis/test_pubsub_channel.py:1125:24
+    --> tests/unit_tests/libs/broadcast_channel/redis/test_pubsub_channel.py:1109:24
 ERROR Class member `FailExpireRedis.expire` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
   --> tests/unit_tests/libs/broadcast_channel/redis/test_streams_channel.py:87:9
 ERROR Class member `FailXrevrangeRedis.xrevrange` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]

@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.26%. Comparing base (484404f) to head (8880273).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #46624   +/-   ##
=======================================
  Coverage   90.26%   90.26%           
=======================================
  Files        6441     6441           
  Lines      405890   405890           
  Branches    81575    81575           
=======================================
+ Hits       366377   366380    +3     
+ Misses      33112    33111    -1     
+ Partials     6401     6399    -2     
Flag Coverage Δ
api 90.03% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hyoban
hyoban marked this pull request as ready for review November 17, 2026 16:01
@hyoban
hyoban added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit b852250 Nov 17, 2026
61 of 62 checks passed
@hyoban
hyoban deleted the fix/merge-queue-stability-20261117-2313 branch November 17, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants