Skip to content

fix(content): show an opportunity's volume as its question's, with its source - #1929

Merged
gkhngyk merged 14 commits into
ansvisor:mainfrom
cihan-gyk:fix/opportunity-volume-question
Nov 3, 2026
Merged

gkhngyk merged 14 commits into
ansvisor:mainfrom
cihan-gyk:fix/opportunity-volume-question

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

An opportunity's volume was the sum of its cluster's head terms. That came out about 5× too high, and it froze in the text: on dev, "What are the best coffee subscription services?" showed 145,000/mo, while the question itself is about 3,000. Now an opportunity's volume is its own question's volume, with its source.

Stacked on #1923 (same-question). Merge that first. With this PR, the pair #1923 merges stops showing the frozen 145,000. Customer priorities plan, P0 item 2; owner decision 2026-11-01.

What changes

  • The rule lives in web/src/lib/content/question-volume.ts:

    • The opportunity page reads the volume of the card's prompt live (getQuestionVolume), with "one of N prompts" beside it.
    • For a question of 6 or more words, a "From head terms" label is added, with the nearest measured phrase and its own estimate (e.g. "best coffee subscription 2026", 585/mo).
    • If it can't be read live, it shows the source_data.questionVolume stored at generation.
    • A cluster's old sum is never shown.
    • estAiVolume stays as the sum that the score's demand part weighs.
  • Server:

    • clusterMetrics also returns the representative question's own volume, which the generator stores as questionVolume (demo data too).
    • The volume number is removed from the generator's and the brief's instructions.
  • MCP: get_content_opportunity gains a volume field:

    • range, confidence, source (DataForSEO × AI share) and date;
    • of_prompts, from_head_terms and closest_phrase.

    The tool description is updated.

  • Places without a source badge now use the same source:

    • the Prompt Volumes chart card gets an Estimate badge;
    • Action Center's Affected tab gets a sum badge on its Volume header;
    • the topic opportunity's demand line gets a badge;
    • the Insights column is renamed "Google Vol. (head terms)", and its tip names DataForSEO.
  • Loading: lib/actions/content.ts imports the volume read only when getQuestionVolume runs, as lib/actions/tracking.ts does. Pages and tests that load content.ts don't need the service-role client.

  • Help:

    • ai-search-volume.md gets "A content opportunity's volume", and the badge places and column name are updated;
    • prompt-insights.md: the column name;
    • approved-articles.json refreshed.

Dev, before → after (open opportunities):

Question Before After
Coffee subscription (c0ffee00) 145,000 3,038
Espresso under $500 96,000 3,713
Ship internationally 26,000 1,080
Offices 21,000 855
Coffee subscription (aaaa…11) 12,400 3,038

Single-prompt opportunities don't change. Four Acme fixture opportunities with no prompt now show "—".

Left for later:

  • The score's demand part still weighs the sum; moving it to the question is a separate product call.
  • The demo brand's ready-made texts ("About X AI searches a month") and one dev fixture's frozen "Targeting 12,400/mo volume" still say the sum.

Related issue

None. Customer priorities plan, P0 item 2.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Open Content › Opportunities › "Expand the coffee subscription guide…" (Acme Coffee). Est. AI Volume shows the question's own range, with "From head terms" and the nearest measured phrase.
  2. Prompts › Insights:
    • the Prompt Volumes card shows an Estimate badge;
    • the table's column reads "Google Vol. (head terms)".
  3. An action's Affected tab: the Volume header shows the sum badge.
  4. Unit tests:
    • question-volume and use-opportunity-volume;
    • opportunity-markdown and opportunity-detail;
    • volume-estimate and affected-tab;
    • action-task-send and display;
    • MCP;
    • the server's opportunity-limits.

Checked in the browser at 1024px, light and dark: the opportunity's volume card and the Insights column. The user approved the screens.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint passes (0 errors; 7 old warnings in files this PR doesn't touch)
  • yarn typecheck passes
  • yarn format:check passes
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change)

Full checks on this branch (bd92548): web 798 files / 8298 tests pass, and yarn build passes. Server format:check and lint are clean, and 353 files / 5000 tests pass (3 skipped).

🤖 Generated with Claude Code

cihan-gyk and others added 8 commits October 31, 2026 23:27
…s into it

The basket check (CONTENT-004) only caught clusters whose prompts and AI
searches overlapped an existing opportunity by 0.6 or more, and only for
generated ones. The dev database has two open opportunities for "What are
the best coffee subscription services in 2026?" (basket overlap 0.15-0.50),
and "+ New" with a page, a prompt's Suggest content and Action Center tasks
were never checked at all.

An opportunity now also stands for its question (source_data.promptText).
When a new one would answer the question of an open one - the same words
with years, case and punctuation aside, the same prompt, or a shared
cluster - it is added to that one instead of opened:

- opportunity-same-question.js (pure): the question key, the match, which
  open one is kept (furthest along, then with work, then score, then age)
  and the merge: prompts, AI searches, keywords and cited competitors join,
  the stronger measured signal and the higher impact stay, and the merge is
  recorded on it (`merged`, the latest 20).
- The generator checks every request but Another angle before any model
  call or quota slot; a prompt's or a page's request points at the open
  one. Re-opening a done opportunity is skipped while another open one
  answers its question.
- Send to Content from a task about one prompt joins the open opportunity
  on that question, records the task there once, and says so in the
  action's History; a task's own opportunity now carries its question.
- The opportunity page notes what was added ("N more requests for the same
  question") and, on an archived duplicate, links the one it went into.
- A one-off merge for the duplicates made before this:
  scripts/merge-same-question-opportunities.js <brandId|--all> [--apply],
  a dry run by default; it keeps one per question and archives the others
  pointing at it (mergedInto). On dev it would merge exactly the pair above.

Help: "No duplicates" in Find content opportunities.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…reakdown shows

A merge kept the higher of the two scores but only a measured signal's
breakdown, so an Action Center task with a higher priority raised the
opportunity's score while its Score breakdown still showed the old
components. The score now follows the signal that stays: the incoming
one's when it is higher and measured, or when neither is; the higher
impact is still kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s source

An opportunity's volume added up its prompts' estimates, and each of those
is the median of short head terms for the prompt's category. Five prompts
on 50k head terms read as 112,500 a month, a 9-word question showed 3,038
against 585 for its closest measured phrase, and the generator and the
brief wrote the sum into their text ("Targeting 12,400/mo volume"). A
same-question merge could also keep a sum frozen months ago (145,000 on
dev). Decided 2026-11-01: the opportunity's volume is its question's.

- question-volume.ts: an opportunity's volume is its question's prompt
  estimate, "one of N prompts". A long question (6 words or more) says it
  is from head terms and names its related keyword closest to its words
  that has Google data, with that keyword's own estimate.
- The opportunity page reads it live for its prompt (getQuestionVolume);
  when it can't, it shows the question's volume kept at generation
  (source_data.questionVolume), never a group's older sum. The export says
  what the volume is of. estAiVolume stays the sum the score's demand
  weighs.
- The generator stores questionVolume, and neither it nor the brief puts a
  volume figure into the model's instructions.
- MCP get_content_opportunity adds `volume`: range, confidence, source,
  date, of_prompts, from_head_terms and closest_phrase.
- The places that showed a volume without its badge get the Estimate badge
  and its note: the Prompt Volumes chart's card, the Action Center Affected
  tab's Volume column and a topic opportunity's demand. Insights' Google
  column is labelled "(head terms)", its tip naming DataForSEO.

Help: How estimated AI search volume works (an opportunity's volume, head
terms), Prompt insights (the column's name).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ning an open opportunity

sendActionTask now says whether the task joined the open opportunity on its
question (`merged`), so the content send's expected result names it, and a
second case covers a task that joined one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…stion volume

lib/actions/content.ts imported question-volume-read.ts at the top, and it
imports the admin client, which is created at module load and needs the
service-role env. Every test that reaches content.ts, even indirectly,
failed to load with "supabaseUrl is required" (7 files, 22 tests).
getQuestionVolume now imports the reader when it runs, as tracking.ts does
for the same reason.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ume-question

# Conflicts:
#	web/messages/en.json
…ume-question

# Conflicts:
#	web/src/lib/mcp/data.ts
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged current main (c9854b5) to clear the conflicts: web/messages/en.json (kept main's chartCaption next to this PR's googleColumn/googleTip) and web/src/lib/mcp/data.ts (kept this PR's volume field next to main's withCurrentYear for source_data). Checks after the merge: format:check and typecheck pass; web MCP, content, Prompts, audit, prompts components and help tests pass (137 files / 1,450 tests); server audit and opportunity tests pass (20 files / 249 tests).

cihan-gyk and others added 6 commits November 1, 2026 23:29
…eyed by text, not an id

A topic_opportunity action keys its prompts entity by the suggestion's text, so
taskQuestion() handed that text to the prompts.id and
prompt_cluster_members.prompt_id uuid filters and Send to Content failed with
22P02 (500). It now returns null unless the entity_key is a uuid (the pattern
validate.js already uses), and such a task opens its own opportunity without a
question, as a task about several prompts does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…its own only once

An opportunity made without a cluster (Send to Content, a task) never makes
the clusters merged into it covered, since loadClusterOpportunities reads only
rows with a cluster_id. The same cluster came back every night and was merged
into the same opportunity again, adding its times searched again (N, 2N, 3N).

A cluster an open opportunity already holds (its cluster_id or one of its
related_cluster_ids) now counts as covered by it and points at it, without
merging again. The test runs two nights in a row and checks that times
searched don't grow on the second.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…count a shared cluster's searches once

The one-off merge (planSameQuestionMerges) grouped an "Another angle"
opportunity with its original, since both carry the same cluster and
prompt, and archived one of them. An opportunity with
source_data.alternativeOf is now left out of grouping, and
answersSameQuestion (so findSameQuestion too) never matches one: it is
asked for on purpose beside its original.

mergeOpportunity added up times searched even when both rows held the
same cluster, so both baskets were that cluster's and the kept row got
2N searches, written for good by the script. When the incoming row
shares a cluster with the target, a query now counts once, at the higher
of the two, the same "a cluster already held counts once" rule the
nightly path follows.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gkhngyk
gkhngyk merged commit 5c0172f into ansvisor:main Nov 3, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants