fix(wiki-ingest,asynqdl): review fixups for PR #1241
- repo: drop r.db.Debug() from FindSimilarPages — it was dumping every
trigram probe's SQL+args (per-alias, per-item) into production logs.
- wiki_ingest dedup: fix Printf format string ("selected for %d new
items" had two args), and harden validMerge against un-prefixed
slugs whose strings.Index returned -1 and silently passed the type
check.
- wiki_ingest_batch: drop the duplicated loggedBatchSize/MapPar/
ReducePar assignments.
- asynqdl: record the real attempt count (retried + 1) on the dead
letter row instead of a hard-coded 0; tighten payloadProbe to the
set of field names with consistent semantics across payloads
(drop source_id/target_id/target_kb_id which differ by task type).
- asynqdl tests: update for the trimmed probe and assert FailCount=0
outside an asynq worker ctx so the semantics stay pinned.
This commit is contained in:
@@ -628,7 +628,7 @@ func (r *wikiPageRepository) FindSimilarPages(
|
||||
q := strings.ToLower(strings.TrimSpace(query))
|
||||
|
||||
var rows []types.WikiPageLite
|
||||
if err := r.db.Debug().WithContext(ctx).
|
||||
if err := r.db.WithContext(ctx).
|
||||
Model(&types.WikiPage{}).
|
||||
Select("slug, title, page_type, status, aliases, out_links, similarity(lower(title), ?) AS sim", q).
|
||||
Where("knowledge_base_id = ? AND page_type IN ? AND status <> ? AND lower(title) % ?",
|
||||
|
||||
@@ -1404,7 +1404,7 @@ func (s *wikiIngestService) deduplicateExtractedBatch(
|
||||
logger.Infof(ctx, "wiki ingest: no similar existing pages found for %d new items", len(entities)+len(concepts))
|
||||
return entities, concepts
|
||||
}
|
||||
logger.Infof(ctx, "wiki ingest: similar existing pages selected for %d new items",
|
||||
logger.Infof(ctx, "wiki ingest: %d similar existing pages selected for %d new items",
|
||||
len(candidatePages), len(entities)+len(concepts))
|
||||
|
||||
var existingBuf strings.Builder
|
||||
@@ -1461,8 +1461,19 @@ func (s *wikiIngestService) deduplicateExtractedBatch(
|
||||
logger.Warnf(ctx, "wiki ingest: dedup rejected %s → %s (target slug does not exist in candidate set)", srcSlug, dstSlug)
|
||||
return false
|
||||
}
|
||||
srcPrefix := srcSlug[:strings.Index(srcSlug, "/")+1]
|
||||
dstPrefix := dstSlug[:strings.Index(dstSlug, "/")+1]
|
||||
srcSlash := strings.Index(srcSlug, "/")
|
||||
dstSlash := strings.Index(dstSlug, "/")
|
||||
if srcSlash <= 0 || dstSlash <= 0 {
|
||||
// A type-prefixed slug must look like "entity/foo" or
|
||||
// "concept/bar". An LLM that emits an un-prefixed slug
|
||||
// here is hallucinating; reject rather than fall through
|
||||
// the prefix-equality check (which would treat both empty
|
||||
// prefixes as a match).
|
||||
logger.Warnf(ctx, "wiki ingest: dedup rejected %s → %s (missing type prefix)", srcSlug, dstSlug)
|
||||
return false
|
||||
}
|
||||
srcPrefix := srcSlug[:srcSlash+1]
|
||||
dstPrefix := dstSlug[:dstSlash+1]
|
||||
if srcPrefix != dstPrefix {
|
||||
logger.Warnf(ctx, "wiki ingest: dedup rejected %s → %s (type mismatch: %s vs %s)", srcSlug, dstSlug, srcPrefix, dstPrefix)
|
||||
return false
|
||||
|
||||
@@ -223,9 +223,6 @@ func (s *wikiIngestService) ProcessWikiIngest(ctx context.Context, t *asynq.Task
|
||||
loggedBatchSize = batchSize
|
||||
loggedMapPar = mapParallel
|
||||
loggedReducePar = reduceParallel
|
||||
loggedBatchSize = batchSize
|
||||
loggedMapPar = mapParallel
|
||||
loggedReducePar = reduceParallel
|
||||
|
||||
lang := types.LanguageNameFromContext(ctx)
|
||||
|
||||
@@ -254,9 +251,9 @@ func (s *wikiIngestService) ProcessWikiIngest(ctx context.Context, t *asynq.Task
|
||||
// callers pay only for the slugs / knowledge ids they actually
|
||||
// reach for. Cache hits keep repeat lookups within the batch free.
|
||||
var (
|
||||
fetchMu sync.Mutex
|
||||
slugTitleCache = make(map[string]string) // slug -> title; "" = known-missing
|
||||
summaryKIDCache = make(map[string]string) // kid -> content; "" = known-missing
|
||||
fetchMu sync.Mutex
|
||||
slugTitleCache = make(map[string]string) // slug -> title; "" = known-missing
|
||||
summaryKIDCache = make(map[string]string) // kid -> content; "" = known-missing
|
||||
)
|
||||
|
||||
resolveSlugs := func(ctx context.Context, slugs []string) map[string]string {
|
||||
@@ -351,7 +348,7 @@ func (s *wikiIngestService) ProcessWikiIngest(ctx context.Context, t *asynq.Task
|
||||
m := resolveSlugs(ctx, []string{slug})
|
||||
return m[slug]
|
||||
},
|
||||
SlugTitleMany: resolveSlugs,
|
||||
SlugTitleMany: resolveSlugs,
|
||||
SummaryContentByKnowledgeID: func(ctx context.Context, kid string) string {
|
||||
m := resolveSummaries(ctx, []string{kid})
|
||||
return m[kid]
|
||||
|
||||
Reference in New Issue
Block a user