Repository navigation
fix(rag): atomically claim tenant task queues - #46310
mikamikasuki wants to merge 6 commits into
Conversation
Use Redis SET NX EX when routing the first tenant-isolated task so concurrent submissions cannot both bypass the per-tenant queue.
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-11-13 16:49:45.396607449 +0000
+++ /tmp/pyrefly_pr.txt 2026-11-13 16:49:30.744456001 +0000
@@ -5578,9 +5578,9 @@
ERROR Argument `() -> tuple[StartNode, Iterator[NodeRunFailedEvent]]` is not assignable to parameter `getter` with type `() -> tuple[Node[Unknown], Generator[CustomContainerRequest | IterationFrameRequest | LoopFrameRequest | NodeEvent]]` in function `services.rag_pipeline.rag_pipeline.RagPipelineService._handle_node_run_result` [bad-argument-type]
--> tests/unit_tests/services/rag_pipeline/test_rag_pipeline.py:1949:20
ERROR Argument `Literal['']` is not assignable to parameter `plan` with type `CloudPlan` in function `RagPipelineTaskProxyTestDataFactory.create_mock_features` [bad-argument-type]
- --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_task_proxy.py:579:91
+ --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_task_proxy.py:635:91
ERROR Argument `None` is not assignable to parameter `plan` with type `CloudPlan` in function `RagPipelineTaskProxyTestDataFactory.create_mock_features` [bad-argument-type]
- --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_task_proxy.py:604:91
+ --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_task_proxy.py:660:91
ERROR No matching overload found for function `typing.MutableMapping.update` called with arguments: (dict[str, object]) [no-matching-overload]
--> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_transform_service.py:29:18
ERROR No matching overload found for function `typing.MutableMapping.update` called with arguments: (dict[str, object]) [no-matching-overload]
|
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #46310 +/- ##
=======================================
Coverage 90.40% 90.40%
=======================================
Files 6332 6332
Lines 396620 396620
Branches 79708 79708
=======================================
+ Hits 358548 358550 +2
+ Misses 31962 31961 -1
+ Partials 6110 6109 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Could we make submission and completion atomic in the shared queue code, and check a unique ownership token before a worker dequeues, renews, or clears a claim? If the atomic operation touches both Redis keys, the marker and FIFO need a shared Redis Cluster hash tag so they land in the same slot. Changing the key format also needs a migration plan for existing queued jobs. Key definitions |
|
Thanks — both gaps are real on this head. The queue marker is a one-hour boolean separate from the FIFO: an enqueue can race the empty-queue handoff, and an expired worker can delete a successor's claim. I’m treating both as blockers to this fix. I’ll rework the queue handoff around atomic ownership and enqueue/completion transitions, preserve FIFO behavior, and document a safe path for existing queue keys and Redis Cluster slotting. I’ll update the PR after focused regressions cover both interleavings and the compatibility path. |
Fixes #46309
Summary
The tenant-isolated queue checked for an active task with
GETand then set its marker separately. Concurrent first submissions could both see an idle queue and dispatch directly, exceedingTENANT_ISOLATED_TASK_CONCURRENCY.Use Redis
SET NX EXas an atomic queue claim in the RAG pipeline and batch document indexing proxies. Submissions that lose the claim are appended to the existing FIFO waiting queue.A barrier-based regression test reproduces two simultaneous first submissions and verifies that only one is dispatched directly.
Screenshots
Not applicable (backend change).
Checklist
make lint && make type-check(backend) andvp staged(frontend).Focused validation: 155 relevant tests passed; Ruff check and format, targeted Pyrefly core check, and no-new-cast/no-new-test-doubles guards passed.
From Codex