Add tracker description enrichment worker

Tracker descriptions were only filled on the agent-identification path,
so patterns resolved by domain, sibling, or fallback stayed without one,
and empty mapping upserts could clobber a researched description on the
shared catalog row.

Move description ownership to a dedicated, global common-pattern
enrichment worker. New catalog rows are queued on insert; the worker
researches a compliance-grade description with web search, records it on
the common pattern, and fans it out to every linked tracker pattern. The
mapping worker no longer generates descriptions and only propagates an
already-enriched one at link time.

Rename TrackerMappingConfig to TrackerAgentsConfig since the mapping and
enrichment agents now share it.

Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
Émile Ré
2026-05-29 11:48:10 +02:00
parent 29791ae775
commit 24bece6f86
12 changed files with 665 additions and 54 deletions

View File

@@ -1303,3 +1303,40 @@ WHERE
return result.RowsAffected(), nil
}
// BackfillDescriptionByCommonTrackerPatternID copies an enriched
// description onto every tracker pattern linked to the given common
// pattern that does not yet have one. It is invoked by the common-pattern
// enrichment worker, a global system process, so it is intentionally not
// tenant-scoped: a single catalog enrichment fans out to all tenants'
// linked patterns. The description = ” guard guarantees a pattern that
// already carries a description is never overwritten. Returns the number
// of patterns backfilled.
func (tps *TrackerPatterns) BackfillDescriptionByCommonTrackerPatternID(
ctx context.Context,
tx pg.Tx,
commonTrackerPatternID gid.GID,
description string,
) (int64, error) {
q := `
UPDATE tracker_patterns
SET
description = @description,
updated_at = NOW()
WHERE
common_tracker_pattern_id = @common_tracker_pattern_id
AND description = ''
`
args := pgx.StrictNamedArgs{
"common_tracker_pattern_id": commonTrackerPatternID,
"description": description,
}
result, err := tx.Exec(ctx, q, args)
if err != nil {
return 0, fmt.Errorf("cannot backfill tracker pattern descriptions: %w", err)
}
return result.RowsAffected(), nil
}