Skip to content

fix(indexing): delete vectors before catalog rows - #671

Merged
hedhoud merged 21 commits into
developfrom
fix/658-milvus-cleanup-before-catalog-delete
Jul 20, 2026
Merged

fix(indexing): delete vectors before catalog rows#671
hedhoud merged 21 commits into
developfrom
fix/658-milvus-cleanup-before-catalog-delete

Conversation

@hedhoud

@hedhoud hedhoud commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes the delete failure mode described in #658. File and partition deletes now clean the vector store before removing the catalog rows, so a Milvus cleanup failure does not leave users with a deleted catalog entry whose chunks are still queryable.

Why

The previous flow removed Postgres rows first and treated Milvus cleanup as best effort. If that cleanup failed, deleted content could remain searchable, and a reused partition name could expose stale chunks.

Validation

  • Full unit suite: 1664 passed
  • Focused service/storage tests: passed
  • Ruff check and format check: passed

Closes #658

Summary by CodeRabbit

  • New Features

    • Added filter-based deletion for vector-store chunks, enabling more targeted cleanup during file and partition removal.
    • Chunks are now stamped with an indexing task identifier to support precise downstream cleanup.
    • Added an option to prevent auto-creating missing partitions when adding a file to a partition.
  • Bug Fixes

    • Improved deletion ordering so matching vector chunks are removed before database records.
    • Active indexing tasks are cancelled prior to cleanup, with safer wait/timeout behavior.
    • Internal metadata is no longer exposed in returned chunk metadata (including searches/listing).

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The vector-store API now supports asynchronous filter-based deletion. Partition and file deletion cancel active indexing tasks, remove vectors before relational records, and perform follow-up cleanup. Indexing records task-scoped vector metadata and cleans vectors when catalog writes fail.

Changes

Cleanup and Indexing Lifecycle

Layer / File(s) Summary
Cleanup contracts and task state
openrag/core/vector_stores/vector_store.py, openrag/services/workers/task_state.py, openrag/services/workers/stages/store.py, openrag/services/storage/vector_store_searcher.py, openrag/services/orchestrators/partition_service.py
Adds filter-based deletion, active-task lookup, task-id metadata stamping, and filtering of internal metadata from returned or persisted chunk data.
Task cancellation and dispatch failures
openrag/services/workers/task_cancellation.py, openrag/services/workers/dispatcher.py, tests/unit/services/workers/test_dispatcher.py
Cancels and settles matching indexing tasks before file cleanup, handles failed submissions, and updates task state for failed or stale tasks.
Partition and file deletion ordering
openrag/services/orchestrators/partition_service.py, openrag/services/workers/dispatcher.py, openrag/services/persistence/document_repo.py, tests/unit/services/orchestrators/test_partition_service.py
Uses filter-based vector deletion before relational cleanup, performs a second sweep for race leftovers, and supports requiring an existing partition during catalog writes.
Indexing catalog and vector rollback
openrag/services/workers/indexer_actor.py, openrag/services/workers/indexer_pool.py, openrag/services/workers/stages/store.py, tests/unit/services/workers/test_indexer_worker.py
Tracks catalog-write results and removes task-scoped vectors when indexing stores vectors without writing the catalog row.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant WorkerDispatcher
  participant TaskStateManager
  participant RayTask
  participant VectorStore
  participant Repositories
  WorkerDispatcher->>TaskStateManager: find active indexing tasks
  WorkerDispatcher->>RayTask: cancel and await settlement
  WorkerDispatcher->>VectorStore: delete_by_filter(partition, file_id)
  WorkerDispatcher->>Repositories: remove file records
  WorkerDispatcher->>VectorStore: retry filter cleanup
Loading

Possibly related PRs

Suggested labels: bug

Suggested reviewers: ahmath-gadji, enjoybacon7

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.72% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: vector cleanup now happens before catalog-row deletion.
Linked Issues check ✅ Passed The PR changes file and partition deletion to delete vectors first via delete_by_filter, matching the issue’s core fix.
Out of Scope Changes check ✅ Passed The added cancellation and metadata cleanup work supports the same deletion-safety goal and does not appear unrelated.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/658-milvus-cleanup-before-catalog-delete

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/unit/services/orchestrators/test_partition_service.py`:
- Around line 116-124: Update query_chunks_by_filter to match filters using the
same row.get(key) equality logic as delete_by_filter, so rows missing a filtered
key only match when its value is None; preserve the existing filter recording
and result structure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 443b784a-fbfe-46ed-a357-63aab0365fc6

📥 Commits

Reviewing files that changed from the base of the PR and between aaa9e85 and 16d0e95.

📒 Files selected for processing (7)
  • openrag/core/vector_stores/vector_store.py
  • openrag/services/orchestrators/partition_service.py
  • openrag/services/workers/dispatcher.py
  • tests/unit/conftest.py
  • tests/unit/services/orchestrators/test_partition_service.py
  • tests/unit/services/workers/stages/test_pipeline_stages.py
  • tests/unit/services/workers/test_dispatcher.py

Comment thread tests/unit/services/orchestrators/test_partition_service.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/unit/services/orchestrators/test_partition_service.py (1)

400-401: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the redundant @pytest.mark.asyncio decorators
asyncio_mode = "auto" already covers these tests, so the markers can be dropped for consistency.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/services/orchestrators/test_partition_service.py` around lines 400
- 401, Remove the redundant `@pytest.mark.asyncio` decorators from
test_list_all_chunks_without_file_id_filters_partition_only and the async tests
at tests/unit/services/orchestrators/test_partition_service.py lines 417-418 and
425-426; asyncio_mode = "auto" already runs these tests asynchronously.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/unit/services/orchestrators/test_partition_service.py`:
- Around line 400-401: Remove the redundant `@pytest.mark.asyncio` decorators from
test_list_all_chunks_without_file_id_filters_partition_only and the async tests
at tests/unit/services/orchestrators/test_partition_service.py lines 417-418 and
425-426; asyncio_mode = "auto" already runs these tests asynchronously.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cf798b69-23ec-4dc4-8891-42e49fa9637d

📥 Commits

Reviewing files that changed from the base of the PR and between 16d0e95 and 2635df5.

📒 Files selected for processing (1)
  • tests/unit/services/orchestrators/test_partition_service.py

@hedhoud hedhoud added this to the v2.0.1 milestone Jul 15, 2026
@hedhoud
hedhoud force-pushed the fix/658-milvus-cleanup-before-catalog-delete branch from b300854 to 021aada Compare July 16, 2026 08:17

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 021aadad0d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/services/orchestrators/partition_service.py
Comment thread openrag/services/workers/dispatcher.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 81f719b9c7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/services/workers/indexer_actor.py Outdated
Comment thread openrag/services/orchestrators/partition_service.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8f4c58390c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/services/workers/task_cancellation.py
@hedhoud
hedhoud force-pushed the fix/658-milvus-cleanup-before-catalog-delete branch from af22c77 to d4955fa Compare July 16, 2026 09:28

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d4955fadcf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/services/workers/task_cancellation.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 140a054960

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/services/workers/indexer_actor.py Outdated
Comment thread openrag/services/workers/task_cancellation.py Outdated
@coderabbitai coderabbitai Bot added the fix Fix issue label Jul 16, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3592a2d5c7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/services/workers/task_cancellation.py
Comment thread openrag/services/workers/stages/store.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (1)
openrag/services/workers/task_cancellation.py (1)

32-36: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Bind structured cleanup context to the logger.

  • openrag/services/workers/task_cancellation.py#L32-L36: bind partition/file context before logging.
  • openrag/services/workers/task_cancellation.py#L57-L63: bind task and cancellation context.
  • openrag/services/workers/task_cancellation.py#L81-L86: bind pending task IDs and target context.
  • openrag/services/workers/task_cancellation.py#L127-L170: bind settlement and stale-task context.
  • openrag/services/workers/dispatcher.py#L145-L161: bind file deletion context.
  • openrag/services/orchestrators/partition_service.py#L264-L299: bind partition cleanup context.

As per coding guidelines, “Use the Loguru-based get_logger() helper and structured context via logger.bind(...) for application logging.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@openrag/services/workers/task_cancellation.py` around lines 32 - 36, Replace
direct contextual logging with the Loguru get_logger() helper and
logger.bind(...) across all identified sites: bind partition/file_id in
task_cancellation.py lines 32-36, task/cancellation context at lines 57-63,
pending-task IDs and target at lines 81-86, and settlement/stale-task context at
lines 127-170; bind file-deletion context in dispatcher.py lines 145-161 and
partition-cleanup context in partition_service.py lines 264-299 before emitting
logs.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@openrag/services/workers/dispatcher.py`:
- Around line 153-161: Persist retryable cleanup work or durable cleanup debt
when the second-sweep vector deletion fails, and do not report file deletion as
fully successful until that cleanup is guaranteed; update
openrag/services/workers/dispatcher.py lines 153-161 around the post-delete
cleanup, apply the same guarantee in
openrag/services/orchestrators/partition_service.py lines 286-294 for partition
leftovers, and update tests/unit/services/workers/test_dispatcher.py lines
518-540 to assert the durable retry or incomplete status instead of
unconditional success.
- Around line 100-122: Update the submission flow around _pool.submit.remote and
_tsm.set_object_ref.remote so that when registration fails after task is
obtained, the returned worker ref is cancelled and settled before
_mark_submit_failed and re-raising. In
tests/unit/services/workers/test_dispatcher.py lines 161-194, add coverage for
successful submission followed by set_object_ref failure and assert the worker
cancellation occurs.

In `@openrag/services/workers/task_cancellation.py`:
- Around line 29-37: Update the AttributeError handling around
task_state_manager.get_matching_active_task_refs.remote to fail closed: log the
existing warning, then abort the deletion instead of returning 0. Ensure callers
receive the established failure signal or exception used by the surrounding
task-cancellation flow, preventing cleanup from proceeding without active-task
lookup.
- Around line 41-97: Make deletion cancellation an atomic file/partition fence
rather than a snapshot: in openrag/services/workers/task_cancellation.py:41-97,
request cancellation and wait until matching tasks cannot publish refs or
execute work; in openrag/services/workers/task_cancellation.py:137-164,
coordinate ref publication and worker settlement instead of treating state-only
FAILED updates as settled; in openrag/services/workers/dispatcher.py:138-150,
hold the deletion fence through vector and catalog cleanup; and in
openrag/services/orchestrators/partition_service.py:255-274, use the same fence
to reject or cancel indexing admitted during partition deletion.

---

Nitpick comments:
In `@openrag/services/workers/task_cancellation.py`:
- Around line 32-36: Replace direct contextual logging with the Loguru
get_logger() helper and logger.bind(...) across all identified sites: bind
partition/file_id in task_cancellation.py lines 32-36, task/cancellation context
at lines 57-63, pending-task IDs and target at lines 81-86, and
settlement/stale-task context at lines 127-170; bind file-deletion context in
dispatcher.py lines 145-161 and partition-cleanup context in
partition_service.py lines 264-299 before emitting logs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 033335f3-a4c3-41aa-836e-ddcef62ee8a2

📥 Commits

Reviewing files that changed from the base of the PR and between 021aada and 3592a2d.

📒 Files selected for processing (16)
  • openrag/core/vector_stores/vector_store.py
  • openrag/di/container.py
  • openrag/services/orchestrators/partition_service.py
  • openrag/services/persistence/document_repo.py
  • openrag/services/workers/dispatcher.py
  • openrag/services/workers/indexer_actor.py
  • openrag/services/workers/indexer_pool.py
  • openrag/services/workers/stages/store.py
  • openrag/services/workers/task_cancellation.py
  • openrag/services/workers/task_state.py
  • tests/unit/conftest.py
  • tests/unit/services/orchestrators/test_partition_service.py
  • tests/unit/services/persistence/test_add_file_to_partition_user_id.py
  • tests/unit/services/workers/stages/test_pipeline_stages.py
  • tests/unit/services/workers/test_dispatcher.py
  • tests/unit/services/workers/test_indexer_worker.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/unit/conftest.py
  • openrag/core/vector_stores/vector_store.py
  • tests/unit/services/orchestrators/test_partition_service.py

Comment thread openrag/services/workers/dispatcher.py Outdated
Comment thread openrag/services/workers/dispatcher.py
Comment thread openrag/services/workers/task_cancellation.py Outdated
Comment thread openrag/services/workers/task_cancellation.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f2a70ce413

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/services/workers/task_state.py Outdated
@hedhoud
hedhoud force-pushed the fix/658-milvus-cleanup-before-catalog-delete branch from f2a70ce to 460da37 Compare July 16, 2026 12:20

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9e8dd7b5e1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/services/workers/dispatcher.py
@coderabbitai coderabbitai Bot added bug Something isn't working and removed fix Fix issue labels Jul 16, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
openrag/services/workers/task_cancellation.py (1)

41-90: 🗄️ Data Integrity & Integration | 🔴 Critical | 🏗️ Heavy lift

Make cancellation an atomic deletion fence.

The lookup only drains tasks visible at that instant. A newly admitted task can write after either sweep; additionally, a ref-less task marked FAILED can later publish its ref because set_object_ref accepts FAILED, allowing it to continue while deletion proceeds.

  • openrag/services/workers/task_cancellation.py#L41-L90: hold a partition/file cancellation fence through cleanup and mark ref-less tasks with a registration-rejecting cancellation state.
  • openrag/services/workers/task_state.py#L92-L96: ensure tasks cancelled for deletion cannot later publish an accepted worker ref.
  • openrag/services/workers/dispatcher.py#L178-L195: hold the file fence across cancellation, vector sweeps, and catalog removal; indexing admission must honor it.
  • openrag/services/orchestrators/partition_service.py#L260-L293: hold the partition fence through both vector sweeps and relational deletion.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@openrag/services/workers/task_cancellation.py` around lines 41 - 90, Make
deletion cancellation an atomic fence across all affected sites: in
openrag/services/workers/task_cancellation.py:41-90, hold the partition/file
fence through both cancellation sweeps and mark ref-less tasks with a
cancellation state that rejects registration; in
openrag/services/workers/task_state.py:92-96, update set_object_ref to reject
refs for that state; in openrag/services/workers/dispatcher.py:178-195, hold the
file fence across cancellation, vector cleanup, and catalog removal while making
indexing admission honor it; in
openrag/services/orchestrators/partition_service.py:260-293, hold the partition
fence through both vector sweeps and relational deletion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@openrag/services/workers/dispatcher.py`:
- Around line 146-176: The _cancel_submitted_task method currently returns after
cancellation errors or settlement timeouts, allowing dispatch failure to be
recorded while the worker may still run. Change the handling in
_cancel_submitted_task so cancellation and settlement must be confirmed before
returning successfully; propagate the failure or retry and fail closed when
ray.cancel fails, call_ray_actor_with_timeout times out, or settlement otherwise
cannot be confirmed.

In `@openrag/services/workers/task_cancellation.py`:
- Around line 64-89: Keep the final recheck in the surrounding cancellation flow
bounded by the original caller deadline rather than creating the independent
_STATE_UPDATE_TIMEOUT budget. Pass the remaining caller time to the final
call_ray_actor_with_timeout and _cancel_refs operations, and ensure
_mark_ref_less_tasks_failed also cannot run beyond that same absolute deadline;
preserve immediate return when no references remain.

---

Duplicate comments:
In `@openrag/services/workers/task_cancellation.py`:
- Around line 41-90: Make deletion cancellation an atomic fence across all
affected sites: in openrag/services/workers/task_cancellation.py:41-90, hold the
partition/file fence through both cancellation sweeps and mark ref-less tasks
with a cancellation state that rejects registration; in
openrag/services/workers/task_state.py:92-96, update set_object_ref to reject
refs for that state; in openrag/services/workers/dispatcher.py:178-195, hold the
file fence across cancellation, vector cleanup, and catalog removal while making
indexing admission honor it; in
openrag/services/orchestrators/partition_service.py:260-293, hold the partition
fence through both vector sweeps and relational deletion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 92216fa2-6460-48b2-824f-54ec3694ec1e

📥 Commits

Reviewing files that changed from the base of the PR and between 3592a2d and 259a333.

📒 Files selected for processing (20)
  • openrag/core/vector_stores/vector_store.py
  • openrag/di/container.py
  • openrag/services/orchestrators/partition_service.py
  • openrag/services/persistence/document_repo.py
  • openrag/services/storage/vector_store_searcher.py
  • openrag/services/workers/dispatcher.py
  • openrag/services/workers/indexer_actor.py
  • openrag/services/workers/indexer_pool.py
  • openrag/services/workers/pipeline_builder.py
  • openrag/services/workers/stages/store.py
  • openrag/services/workers/task_cancellation.py
  • openrag/services/workers/task_state.py
  • tests/unit/conftest.py
  • tests/unit/services/orchestrators/test_partition_service.py
  • tests/unit/services/persistence/test_add_file_to_partition_user_id.py
  • tests/unit/services/storage/test_vector_store_searcher.py
  • tests/unit/services/workers/stages/test_pipeline_stages.py
  • tests/unit/services/workers/test_dispatcher.py
  • tests/unit/services/workers/test_indexer_worker.py
  • tests/unit/services/workers/test_task_state.py
🚧 Files skipped from review as they are similar to previous changes (12)
  • openrag/services/workers/indexer_pool.py
  • tests/unit/conftest.py
  • openrag/services/persistence/document_repo.py
  • openrag/core/vector_stores/vector_store.py
  • openrag/services/workers/stages/store.py
  • tests/unit/services/workers/stages/test_pipeline_stages.py
  • openrag/di/container.py
  • tests/unit/services/persistence/test_add_file_to_partition_user_id.py
  • tests/unit/services/workers/test_indexer_worker.py
  • tests/unit/services/orchestrators/test_partition_service.py
  • openrag/services/workers/indexer_actor.py
  • tests/unit/services/workers/test_dispatcher.py

Comment thread openrag/services/workers/dispatcher.py Outdated
Comment thread openrag/services/workers/task_cancellation.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 259a333ab5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/services/workers/task_cancellation.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 716858bc89

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/services/orchestrators/partition_service.py Outdated
Comment thread openrag/services/workers/dispatcher.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f64a7ade27

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/services/workers/indexer_actor.py Outdated
Comment thread openrag/services/workers/stages/store.py
@hedhoud
hedhoud force-pushed the fix/658-milvus-cleanup-before-catalog-delete branch from f64a7ad to b19a96e Compare July 16, 2026 14:38

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b19a96e58b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/services/workers/indexer_actor.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1b5efc42db

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/services/workers/task_state.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f6c4d90aad

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/services/workers/pipeline_builder.py Outdated
@hedhoud
hedhoud force-pushed the fix/658-milvus-cleanup-before-catalog-delete branch from f6c4d90 to fb3cb44 Compare July 17, 2026 07:41
@hedhoud
hedhoud marked this pull request as ready for review July 20, 2026 07:38

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8daf6a2957

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/services/orchestrators/partition_service.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dca53abc39

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/services/workers/dispatcher.py
@hedhoud
hedhoud force-pushed the fix/658-milvus-cleanup-before-catalog-delete branch from dca53ab to f6b8162 Compare July 20, 2026 07:58

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f6b8162860

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/services/workers/task_state.py Outdated
@hedhoud
hedhoud force-pushed the fix/658-milvus-cleanup-before-catalog-delete branch from f6b8162 to 4649df8 Compare July 20, 2026 08:20

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4649df8ceb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/services/workers/dispatcher.py
@hedhoud
hedhoud force-pushed the fix/658-milvus-cleanup-before-catalog-delete branch from 4649df8 to 5e1dd60 Compare July 20, 2026 08:29

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5e1dd607da

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/services/persistence/partition_repo.py
@hedhoud
hedhoud force-pushed the fix/658-milvus-cleanup-before-catalog-delete branch from 5e1dd60 to 6fc790a Compare July 20, 2026 08:48

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6fc790aea8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/services/workers/dispatcher.py

@Ahmath-Gadji Ahmath-Gadji left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed end-to-end across multiple rounds as the branch evolved. Summary of what I verified directly against the code (not just bot self-reports, several of which turned out to reference commits no longer reachable after rebases):

  • Core fix (vectors deleted before catalog rows, both file and partition paths) is correct.
  • Task-id-scoped chunk stamping/cleanup for partial-failure and replace-cleanup ordering is correct — traced the row-mutation-by-reference behavior that makes cleanup work even when the pipeline raises mid-stage.
  • Internal metadata (_openrag_indexing_task_id) stripping is now centralized in core/utils/conts.py and applied consistently across all read paths.
  • The admission/delete fencing added in 6fc790ae/c9e03664 is a real fix, not cosmetic: traced the Postgres advisory lock (partition level, cross-process safe) and the TaskStateManager-based reference-counted fence (file level) through both the upload and delete code paths, confirmed the lock guard correctly reuses its held connection, and confirmed test coverage for the main failure modes.
  • Legacy-actor rolling-deploy compatibility (ac1455c1) degrades gracefully via exception-chain detection + retry, well tested.
  • CI green on c9e03664 (lint, unit, api-tests, milvus-integration).

One confirmed non-blocking finding I haven't seen addressed yet: _matching_active_task_refs_locked (task_state.py) treats every detail-less QUEUED task as a match for any delete, regardless of partition/file — this only fires in the legacy non-atomic set_state+set_details fallback path, but when it does, deleting file/partition A can spuriously delay or cancel an unrelated concurrent upload of file/partition B. Collateral-cancellation bug, not a data-integrity issue — fine as a fast follow-up rather than blocking this PR.

Approving — the primary failure mode (#658) is solidly fixed and the residual gaps are narrow, well-understood, and non-blocking.

@hedhoud
hedhoud merged commit d450f14 into develop Jul 20, 2026
6 checks passed
@hedhoud
hedhoud deleted the fix/658-milvus-cleanup-before-catalog-delete branch July 20, 2026 12:12
Ahmath-Gadji pushed a commit that referenced this pull request Jul 20, 2026
#671 and this branch each carried their own copy of
test_cancelled_state_is_not_overwritten_by_worker_transitions, with
identical assertions and different manager helpers, so reconciling the two
versions of the module kept both and ruff flagged the redefinition (F811).
Keeps #671's copy, which the rest of that file's helpers match, and moves
this branch's docstring onto it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deleted files/partitions can leave orphaned queryable chunks in Milvus; partition-name reuse can leak across tenants

4 participants