Repository navigation
fix(knowledge): reconcile segment indexes on repeated status requests - #45239
Open
Zhi-Xiang-Guo wants to merge 2 commits into
Open
Zhi-Xiang-Guo wants to merge 2 commits into
Zhi-Xiang-Guo wants to merge 2 commits into
Conversation
1 of 2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
A Console segment enable/disable request commits its status before Celery publication. After a broker failure, a retry previously skipped the segment because its persisted status already matched, leaving the index unchanged.
Dispatch reconciliation for all eligible explicitly requested segments, including those whose desired status is already persisted. Update status fields only for actual transitions, preserving the original disabled_at/disabled_by on retries. Keep document/segment indexing guards and tenant/resource scoping.
Related Issues
Fixes #45238. Related #43865 covers a different enabled-only Service API path.
Module(s) Affected
api/services/knowledge/segments/application.pyapi/tests/unit_tests/services/knowledge/segments/test_adapters.pyTesting
Four failure/retry cases cover enable and disable for both single-segment and mixed batches (already at the target state plus a segment requiring a transition). All four fail on the original baseline and pass with the fix. The mixed batch retries must dispatch both eligible segments, exclude foreign-tenant segments, and preserve existing disable audit metadata. Three additional cases exercise repeated batch-enable tasks for disabled, archived, and incomplete documents; the existing non-COMPLETED-segment test also passes. Expanded service/adapter/worker suite: 144 passed, 6 warnings. Real API + worker fault injection restored keyword retrieval from 0 to 1; symmetric disable retry removed stale keywords. Test assertions also preserve disable audit metadata and exclude foreign-tenant segments.
main@4c521a3c0a1f60607c8a7bcf90792f34adcf18d0; branchfix/segment-status-dispatch-recovery; commit56e35fee231b6fc46dc3c2a544e9af06adbbba2b.git diff --checkpassed. Import linter: 78 contracts kept, 0 broken. Response contract lint: 762 valid, 0 mismatch, 378 unknown (not a claim of full coverage).Latest test-only update: local
ba500552a6e323adb56de3462549f51a32a07e32, remoteed365091de039abd7c4cf3830e9c56a435044f82(identical source trees). Production logic is unchanged; the real application before/after evidence above comes from the original implementation validation, not a new deployment run.Validation for this update:
uv run --project api --no-sync pytest -o addopts="" api/tests/unit_tests/services/knowledge/segments/test_adapters.py api/tests/unit_tests/services/knowledge/segments/test_application.py api/tests/unit_tests/tasks/test_enable_segments_to_index_task.py -q— 144 passed. Ruff check/format, the no-new-test-doubles guard, andgit diff --checkpassed. Targeted Pyrefly reports one existingcontextmanager/Iteratordeprecation warning in the worker test helper; the unchanged pre-update files produce the same warning. No new type diagnostics.Checklist
Additional Notes
AI-assisted implementation and validation. This is explicit retry recovery, not an Outbox: it does not autonomously retry a lost dispatch, resolve opposite-action ordering, or guarantee exactly-once delivery. Repeated successful requests can enqueue redundant work; existing vector writes/keyword updates remain responsible for repeat execution semantics. The real deployment verification used economy indexing, not every vector backend.