fix(wiki): prevent concurrent duplicate page identities - #2850
Merged
lyingbug merged 3 commits intoAug 28, 2026
Conversation
Only exact same-title pages may overwrite a Redis identity claim. Successful Redis reads now refresh the batch-local map so concurrent batches stay aligned, citation slugs are reclaimed, and Reduce remaps onto the claimed slug before locking.
Exact title resolution was one seq-scan per extracted item, and a dirty Redis claim could split concurrent workers. Batch the lookup, memoize it per batch, overwrite invalid claims, and keep remapped Item.Slug in sync.
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
Wiki ingest allows concurrent batches for the same knowledge base and protects Reduce with per-slug locks. Two map workers can still extract the same same-type display title with different romanized slugs before either page exists. Because the reducers lock different slug keys, both pages can be created.
This change closes that window by:
(knowledge base, page type, normalized title)so concurrent batches converge before summaries and Reduce are materialized;寓言and《寓言》remain distinct identities, and keeping entity/concept namespaces separate.The claim is temporary and does not add a schema migration or change existing page data.
Type of Change
Related Issue
No linked issue.
Testing
go test ./internal/application/service -count=1go test -race ./internal/application/service -run TestWikiIdentityClaimConvergesDifferentSlugs -count=1go vet ./internal/application/servicegit diff --check origin/main...HEADThe added regression tests cover concurrent workers proposing different slugs for the same title, authoritative existing-page resolution, Lite-mode batch convergence, entity/concept separation, punctuation-sensitive work titles, and evidence preservation during coalescing.
Checklist
git diff --check origin/main...HEADpassesgolangci-lint(not installed in the development environment)Screenshots / Recordings
Not applicable; backend-only change.