Make mention analysis replayable: persist extracted text, recompute on brand changes#338
Open
jrhizor wants to merge 2 commits into
Open
Make mention analysis replayable: persist extracted text, recompute on brand changes#338jrhizor wants to merge 2 commits into
jrhizor wants to merge 2 commits into
Conversation
…n brand changes Fixes #329 - Add nullable prompt_runs.text_content and analyzed_at columns - Consolidate analyzeMentions/extractDomainFromUrl into packages/lib mention-analysis - Match brand/competitor names on word boundaries ("Box" no longer matches "toolbox"); domains keep substring semantics - Persist extracted answer text at write time; log + Sentry when extraction yields nothing instead of silently analyzing an empty string - Add backfill-text-content job (batched, resumable, idempotent) enqueued on worker startup - Add reanalyze-brand job that recomputes mentions and prompt system tags from text_content, enqueued when brand identity or competitors change in settings - Read path prefers text_content with extractTextContent fallback for unbackfilled rows
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Fixes #329
What
Makes mention analysis replayable instead of frozen at write time, and fixes the substring-matching false positives.
Schema (
packages/lib/src/db/schema.ts, migration0010)prompt_runs.text_content(text, nullable) — the provider-extracted answer text, now persisted instead of being re-parsed fromraw_outputon every read.prompt_runs.analyzed_at(timestamptz, nullable) — when mentions were last computed (write time or last re-analysis).Consolidated + fixed matcher
@workspace/lib/mention-analysismodule ownsanalyzeMentions()/extractDomainFromUrl()— the worker's private copy is deleted, so worker, jobs, and future backfills share one implementation.(^|\W)name(\W|$), case-insensitive): a brand named "Box" no longer matches "toolbox" or "Dropbox". Domains keep substring semantics (they're unambiguous tokens).\Winstead of\bso names like "C++" still match.isPromptBranded()intag-utils.ts(branded/unbranded system tags) gets the same fix: word-boundary for the name and domain-without-TLD, substring for the full domain.Write path
process-promptpersiststext_contentalongsideraw_outputand stampsanalyzed_at.NULL— never a silently-analyzed empty string (better text extraction error handling #106). NewtryExtractTextContent()returnsnullinstead of the human-readable failure sentinels.Backfill job (
backfill-text-content)text_contentfor historical rows fromraw_output. Batched (keyset pagination), resumable (WHERE text_content IS NULL), idempotent. Enqueued on worker startup with a singleton key, no-ops once complete.Re-analysis job (
reanalyze-brand)brand_mentioned,competitors_mentioned, and promptsystem_tagsfor all of a brand's runs fromtext_content(falling back to extraction, opportunistically backfilling), in batches.updateBrandFn,updateCompetitors,addDomainToBrandFn,addDomainToCompetitorFn,createCompetitorFromDomainFn.Read path
text_contentand only falls back toextractTextContent(raw_output)for rows the backfill hasn't reached. The fallback can be removed entirely once the backfill has completed everywhere.Acceptance criteria from the issue
reanalyze-brand, which updates historical mention data.mention-analysis.test.tsandtag-utils.test.ts).raw_outputfor backfilled rows (fallback kept until backfill completes, per spec §6).Testing
pnpm turbo test— 332 tests pass (incl. newmention-analysis.test.tsand word-boundary cases intag-utils.test.ts).pnpm turbo check-types— clean.