Repository navigation
feat(content): re-open finished opportunities when their signals move - #960
Merged
Merged
Conversation
The spec lets a completed opportunity come back as "New signal detected" when it later strengthens, without a duplicate being generated (#857, Phase 4). - Before writing new opportunities, generation re-checks the brand's done ones whose actions are all completed and measured. One goes back to New when its cluster's score rose 10 points since it was scored, or when the basket visibility fell below half of what its action measured afterwards. - The same row re-opens with refreshed metrics and a record of why, with the earlier actions kept as past actions. It can be sent again. - Migration 00114: the status trigger ignores actions created before the opportunity re-opened, so the new work is not shown as in progress because the old work is complete. - The list marks re-opened opportunities "New signal detected", and the detail page says what changed. Results lists past actions too.
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.
Summary
Last PR of Phase 4 in #857. The spec (§27) says: "Underlying signals keep changing. A completed opportunity that strengthens later can be re-evaluated as New Signal Detected; no duplicate opportunity should be created." A finished opportunity now goes back to New when its signals move, and keeps the same row.
When an opportunity re-opens (
lib/opportunity-reopen.js)The check runs in the nightly generation, before new opportunities are written. It only looks at opportunities that are
doneand whose actions are all completed and measured. Nothing re-opens before its result is known. One of these conditions must hold:score_roseSCORE_RISE(10) points above the opportunity's recorded score: more demand, or competitors further ahead. This is the spec's "strengthens".gain_lostGAIN_LOST_RATIO(half) of the "after" value its action measured (#956), meaning the gain did not hold.The current figures are computed the same way generation scores clusters. The measured value is the highest basket
ai_visibilityafter-value across the opportunity's actions.What re-opening does
newwith its score and metrics refreshed.source_data.reopenedrecords when, why, the previous and current score, and the measured and current visibility.source_data.pastActionsand stay visible on the Results card. The opportunity can be sent to the Action Center again.Status trigger (migration 00114)
reopened.at.UI
Tried on production data
Related issue
Part of #857. This completes Phase 4.
Type of change
feat— New featuretest— Adding or updating testsHow to test
opportunity_scorein a test database, then run generation. It returns to New with the badge and the explanation.opportunity-reopen.test.jscovers both thresholds and their edges, waiting for every action to be completed and measured, and measurements that are not basket-scoped.Checklist
yarn lint,yarn typecheck,yarn format:check,yarn test(418) andyarn buildpass (run fromweb/)yarn lint,yarn format:checkandyarn test(1008) pass (run fromserver/)supabase/schema.sqlrebuilt withbuild-schema.sh🤖 Generated with Claude Code