Skip to content

fix(content): stop opportunities piling up on the same prompts - #869

Merged
gkhngyk merged 1 commit into
mainfrom
fix/opportunity-pileup
Oct 2, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/opportunity-pileup

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #837.

The nightly content-opportunity generator ranks prompts by a deterministic score (volume, visibility gap and competitor gap), so the same top prompts won every night. Only exact-title repeats were filtered, and the model rewords the same idea each run. As a result, on the largest brand:

  • one prompt held 38 open opportunities collected over 32 nights;
  • 628 of the brand's 709 prompts had none.

None of the earlier generator fixes addressed this: #735 (three per run), #442 (index leak), #369/#640 (brand language) and #63 (preserve pending).

Changes

  • Per-prompt cap. Prompts with MAX_OPEN_PER_PROMPT (3) or more open opportunities are dropped before the top-25 cut, so the run's slots go to the next prompts down. On the largest brand today 58 prompts are at the cap and 651 stay eligible, 628 of them with no opportunity yet.
  • The model sees what is open. Each remaining candidate lists its open titles as "Already suggested", and a new rule tells the model not to repeat or reword them: suggest something genuinely different, or pick another prompt.
  • Invalid indexes are dropped. An out-of-range relatedPromptIndex used to fall back to the top candidate, the most crowded prompt. It now discards the opportunity in both generators.
  • Paged reads. Open opportunities are read in pages. The previous un-paged read stopped at PostgREST's 1,000-row default, which would undercount on a brand past that.
  • Exact-title check. It stays as the last guard.
  • Shared helpers. openCountsByPrompt, belowOpenCap and relatedCandidate live in opportunity-limits.js next to the existing shared count rule, and both generators import them.

Generate button path. content-worker.js deletes a brand's open (new) opportunities before inserting the new ones, so it replaces the list rather than appending to it. The cap and the already-suggested list would have nothing to act on there, so that path gets only the index fix. The issue also proposed adding the exact-title check to it; that check would have nothing to compare against, since the list is cleared first.

Not in this PR. The existing backlog of open opportunities stays as it is. This change stops new pile-up; clearing what already accumulated is a separate data decision. #857 later replaces the per-prompt cap with per-cluster generation.

Related issue

Closes #837

Type of change

  • Bug fix

How to test

  • Unit tests cover the counting, the cap, and index resolution. Source checks confirm both generators use the shared index resolver, no longer contain the || scored[0] fallback, and that the nightly generator applies the cap and the "Already suggested" list.
  • After a nightly run, a brand's prompts that already had 3 or more open opportunities gain none, and the new ones land on other prompts.

Checklist

  • yarn lint, yarn format:check and yarn test (883 passed, 6 new) pass from server/

🤖 Generated with Claude Code

The nightly generator ranks prompts by a deterministic score, so the
same top prompts won every night and collected rewordings of one idea:
one prompt held 38 open opportunities across 32 nights, while 628 of
the brand's 709 prompts had none. Only exact-title repeats were caught.

- Prompts with 3 or more open opportunities (MAX_OPEN_PER_PROMPT) are
  skipped before the top-25 cut, so the slots go to the next prompts.
- The remaining candidates list their open titles as "Already
  suggested", and the instructions forbid repeating or rewording them.
- An out-of-range relatedPromptIndex now drops the opportunity in both
  generators instead of attaching it to the top candidate.
- Open opportunities are read in pages, past PostgREST's 1,000-row cap.

The Generate button path replaces a brand's open opportunities rather
than appending, so it needs only the index fix.

Closes #837
@gkhngyk
gkhngyk merged commit 1b02632 into main Oct 2, 2026
6 checks passed
@gkhngyk
gkhngyk deleted the fix/opportunity-pileup branch October 2, 2026 12:30
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.

fix(content): stop opportunities piling up on the same prompts

1 participant