Repository navigation
fix(content): keep one open opportunity per question, merging new ones into it - #1923
Conversation
…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]>
…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]>
|
One issue before merge: |
…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]>
|
Thanks, good catch. Fixed in 9b8a44e (after merging main, 97a1c55): The test mock now returns 22P02 when a uuid column gets text, as Postgres does. New tests cover the text-keyed Checks: |
|
The uuid fix looks good. One more issue: |
…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]>
|
Thanks, good catch. In 15131c5, Separately, the one-off |
|
Two issues left, both in the one-off merge script (
|
…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.
The squash merge of #2005 (0b47e04) carried an old tree of the PR that predated the main it was merged into, so it reverted about 17,000 lines that #1923–#2004 had added: migrations 00470, 00472 and 00473, the report card, brand integrations, take-down, the model menu and more. #2008 and #2011 then merged on top. This commit carries the tree of 9cc1acc (main before #2005, what production runs) with #2005, #2008 and #2011 merged onto it again against the versions they were built on. Compared with 9cc1acc it deletes nothing, and every changed file is one of those three PRs' own or a generated snapshot. Web tsc and the chat/help/mcp suites (2,844) and the server suite (5,289) pass.
… elsewhere - A done opportunity the same run reopened was judged by its old created_at, so its need could get an angle in that run: two open opportunities on one need and a slot spent. An open opportunity now has its chance from the later of created_at and its last reopening (source_data.reopened.at, and reopenStrengthened marks the run's rows). - Angles skipped one open opportunity per question (ansvisor#1923): a need held by another open opportunity (a Send to Content or task one, through its related clusters) or whose question another open one answers no longer gets an angle. - New's dialog rounds a need's visibility as the generator does, so 19.96% counts no angle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMenyNyxsr2Doq4CaQ3
Summary
The same question could have several open opportunities, each with its own card and score. On dev, "What are the best coffee subscription services in 2026?" has two open opportunities.
Now one open opportunity stands for each question. A new request for the same question is added to that opportunity instead of opening another one. Customer priorities plan, P0 item 2 (list hygiene).
What counts as "the same question" (
opportunity-same-question.js, pure):Owner decision (2026-11-01): keep it this narrow. A cluster's other prompts don't count. Counting them would have merged four different opportunities on dev (shipping, offices, subscription) into one.
Which one is kept, and what joins it:
merged, the latest 20).Where it applies:
merged).On screen:
One-off clean-up:
server/src/scripts/merge-same-question-opportunities.js <brandId|--all> [--apply].--apply. It keeps one per question and archives the rest withmergedInto. Drafts stay with their own opportunity.Help:
content-opportunities.md, section "No duplicates" (approved-articles.jsonrefreshed).Next: "Show an opportunity's volume as its question's" (owner decision 2026-11-01) is stacked on this PR. With it, the merged pair no longer shows the frozen 145,000/mo.
For @gkhngyk:
--apply.fix/current-year-in-generated-titles(fix(content): tell generators the current year and show past years in titles as this year #1922) edits the same help article andapproved-articles.json, in other sections.Related issue
None. Customer priorities plan, P0 item 2.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
--applyand read its plan.action-task-sendwithmergedfalse and true.Checklist
yarn lintpasses (0 errors; 7 old warnings in files this PR doesn't touch)yarn typecheckpassesyarn format:checkpasseshelp/(or no user-visible change)Full checks on this branch (c62f9ce, from bf707cb; it merges cleanly with current main): web 797 files / 8,293 tests pass, and
yarn buildpasses. Serverformat:checkand lint are clean, and 353 files / 4,999 tests pass (3 skipped).🤖 Generated with Claude Code