Skip to content

fix(content): keep open opportunities when Generate is pressed - #870

Merged
gkhngyk merged 1 commit into
mainfrom
fix/generate-keeps-open-opportunities
Oct 2, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/generate-keeps-open-opportunities

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Pressing Generate Opportunities on the Content page deleted every open (new) opportunity the brand had, then inserted three new ones. Anyone working through the list lost it the moment they pressed the button.

This is a leftover of #63. That change moved the nightly generator (lib/opportunity-generator.js) from delete-and-replace to keep-and-append, but the queued generator behind the button (workers/content-worker.js) was never updated.

Change

  • The button path no longer deletes anything. It adds to the open list and follows the same rules the nightly run got in fix(content): stop opportunities piling up on the same prompts #869:
    • prompts at MAX_OPEN_PER_PROMPT are skipped before the top-25 cut;
    • the remaining candidates list their open titles as "Already suggested", with the matching instruction in the system prompt;
    • exact repeats (same prompt, same title) are dropped.
  • Both generators now share these pieces, so the two paths cannot drift apart again as they did after fix: preserve pending content opportunities #63:
    • lib/open-opportunities.js → loadOpenOpportunities(), the paged read of a brand's open opportunities;
    • in opportunity-limits.js: ALREADY_SUGGESTED_RULE, openTitlesByPrompt(), alreadySuggested() and opportunityKey().
  • The nightly generator is refactored onto the same helpers. Its behaviour is unchanged.

If every candidate prompt is at the cap, the button generates nothing and the existing toast reports 0. On the largest brand only 58 of 709 prompts are at the cap today.

Related issue

None. This was found while reviewing #837 / #869.

Type of change

  • Bug fix

How to test

  1. On a brand with open opportunities, press Generate Opportunities on the Content page.
  2. The existing opportunities are still listed, and up to three new ones are added.
  3. The new ones do not land on prompts that already had three open opportunities, and they do not repeat an open title.

Source tests check that both generators use the shared read, cap, rule and duplicate key, and that the worker contains no .delete(). Unit tests cover the new helpers.

Checklist

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

🤖 Generated with Claude Code

The Generate button deleted every open opportunity a brand had before
inserting three new ones, so pressing it threw away the list someone
was working through. #63 moved the nightly generator from delete-and-
replace to keep-and-append, but the button path was never updated.

The button now adds to the open list and follows the same rules as
the nightly run: prompts at the per-prompt cap are skipped, the rest
list their open titles as "Already suggested", and exact repeats are
dropped. Both generators share the open-opportunity read
(lib/open-opportunities) and the prompt-data helpers and rule
(opportunity-limits), so the two paths cannot drift apart again.
@gkhngyk
gkhngyk merged commit 178971b into main Oct 2, 2026
6 checks passed
@gkhngyk
gkhngyk deleted the fix/generate-keeps-open-opportunities branch October 2, 2026 19:56
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.

1 participant