Skip to content

fix(shopping): sharper "Why not you?", "What AI says" and product page, and an honest 7-day re-check (Product Visibility follow-ups, part 3) - #1667

Merged
gkhngyk merged 119 commits into
ansvisor:mainfrom
cihan-gyk:feature/pv-followups-insights
Oct 28, 2026
Merged

gkhngyk merged 119 commits into
ansvisor:mainfrom
cihan-gyk:feature/pv-followups-insights

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Product Visibility follow-ups, part 3 of 3 (insights).

Stacked on #1666. This PR's own change is its commits after #1666's: 4ec0aba, 0cc102f, a3da212, 6ec3863, 9688dba, fe4f7ff and 8843974.

  • B17: "Why not you?"
    • These words don't count toward a match: asking words (best, top, under…), numbers and single letters. A product needs two shared words, or a matching category or type.
    • Review fix fe4f7ff: audience words (men, women, kids, boys, girls, baby, unisex, adult…) can't make a product a candidate on their own, as a category, a type or a shared word. They still break a tie toward the audience asked for.
    • Example: "Men's Best Seller Tee" in "Clothing > Men" is no longer offered for "best running shoes for men under $100".
  • B18: "What AI says" looks for the product by its own name. The brand's name alone is never taken as the product's; the brand part and prefix come off the names it looks for. The server passes the product's and the cards' product_brand.
  • B19: the product page.
    • The winner is the first competitor above the product, never the brand's own product.
    • An invalid id shows "This product isn't in your catalog anymore."
    • Nothing is read while the plan locks the page.
    • Reads are narrowed:
      • the product's own cards first;
      • then the shelves of up to 60 candidate questions (asked for, where it showed, in its category, or with shared words);
      • search queries only for each shelf's latest answer.
  • B20: the 7-day re-check.
    • The re-check reads every question of a done action in chunks of 100, with 6 reads at a time. The 400-question cap is gone.
    • A category counts only its own products.
    • "not run in the 7 days after" when nothing was read after the action. "New: nothing to compare" when nothing was read before it.
    • Review fix 8843974: when a chunk reaches the 50,000-card read limit, its actions are marked partial. They show "too many answers to compare" instead of a misleading "New" or "better".

Where people see it:

  • Products › Shelf ("Why not you?");
  • the product page ("What AI says", the winner, a not-found state);
  • Categories and the product page's action results.

Related issue

Product Visibility follow-ups (PV review, items B17–B20). No GitHub issue.

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

cd web && npx vitest run src/lib/shopping/shelf.test.ts src/lib/shopping/ai-says.test.ts src/lib/shopping/product-detail.test.ts src/lib/shopping/recheck.test.ts "src/app/[locale]/(dashboard)/dashboard/shopping/_categories-table.test.tsx"

The tests cover:

  • audience words (Men, Women, Kids) and the audience tie-break;
  • The North Face / Borealis for "What AI says";
  • 450 questions and a category's own products;
  • 50,000 cards counting as partial, while 49,999 still compare.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Full checks at the top of this stack (feature/pv-followups-insights, 8843974):

  • server format, lint and npm test: 250 files, 3,392 tests passed;
  • web format, lint (0 errors; 7 warnings already on main), typecheck and vitest: 464 files, 4,473 tests passed;
  • web build: OK. The first build failed under memory load; it passed on a rerun.

A pre-push review was run, and its before-merge findings are fixed in this stack.

Browser check (local, 1024 px, light and dark):

  • Products › Shelf loads.
  • Readiness channel cards load.
  • A product page with an unknown id says "This product isn't in your catalog anymore."

Readiness still says "Google AI Overview". The shared label is renamed in #1635.

Follow-ups (later PRs):

  • B19: rank candidate questions by the channels that make shopping cards;
  • B20: a total read bound for the re-check;
  • B11: a stuck match keeping a brand in later, and a cap on concurrent matches;
  • B25: price bands scaled per currency (JPY);
  • B16: the screen-reader text for an unknown check.

🤖 Generated with Claude Code

cihan-gyk and others added 30 commits October 27, 2026 18:33
…popup and the Shelf and Products tabs (product visibility, part 1)

The first step to the Products screens in Drive › E-commerce (ECOM-spec,
ECOM-mockup): the page says what it's for, "Which of your products AI
recommends, why, and what it sells.", with "Why Ansvisor Product
Visibility?" beside the title. That opens the four steps from the AI
shelf to the sale, and offers Connect Google Analytics while GA isn't
connected (ECOM-010).

Under the title, the data sources (ECOM-009), as on AI Traffic:
- the product catalog (its products and last sync, Manage, or Connect);
- Google Analytics and Search Console, each with what it adds here;
- a Marketplaces & feeds row: Merchant Center connects as a catalog
  source, and the marketplaces show Soon until they have a connector.

The tabs read Shelf, Prompts, Products and Competitors, the one open in
the URL (?tab=products). The sidebar item is new. AI Traffic's Google
source card is shared, with an optional line for while it isn't
connected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…oduct it shows (product visibility, part 2)

Product Visibility's Shelf, Products and Categories (ECOM-005…008)
count a brand's products on the AI shelf, so each product card that is
the brand's own now records which catalog product it shows
(prompt_result_shopping_cards.catalog_product_id, and catalog_match for
how it was found; 00360).

lib/catalog/card-match.js matches in order:
- by the marketplace listing a card links (ASIN, eBay item id), to a
  variant's marketplace_item_id;
- by a GTIN the card carries, without its padding;
- by its link, to a product's or variant's page, with or without its
  query;
- else by its title: at least 0.6 of the words in common (Dice) and
  0.1 clear of the next product, the brand's name and filler words
  aside.

A key two products share matches neither.

Cards are matched as they're written, against the brand's catalog read
at most every 10 minutes. If the catalog can't be read, the cards go in
without matches. If the API runs before 00360, they go in without the
new columns rather than not at all.

After the daily catalog sweep, each brand whose catalog synced in the
last day has its own cards of the last 90 days matched again. Only the
matches that changed are written, 500 a call, through
set_shopping_card_matches (service role only).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e brand's place and its sales from AI (product visibility, part 3)

The Shelf tab (ECOM-006, Drive › E-commerce › ECOM-mockup) is
Product Visibility's overview now.

Four numbers:
- AI shelf share: the brand's share of the product slots in AI
  answers;
- Products on the shelf: its catalog products shown (00360), "41 of
  320", else distinct titles;
- AI revenue · 30d: orders from AI visits and their value against the
  30 days before, from the tracking snippet and the Shopify pixel
  (ai_traffic_events). Without a source, "Connect to see sales" links
  to AI Traffic;
- Top AI channel: by AI orders, else by the brand's slots.

Then where AI sends shoppers and resellers cheaper than the brand, as
before. Then one row per shopping question and channel: its latest
shelf in order, with photos, prices, ratings and merchant icons. The
brand's products are ringed ("2 · You", "via Amazon"), and each row
says "You: #2 · 1 of 2 shelves this week" or "You're not on this
shelf". The shelves the brand isn't on come first.

Filters:
- channel chips, which set the page's platform filter;
- a price band, from the shelf's middle price.

The platform card rate and trend charts stay below, under Trends.

The old KPI row and the Card-eligible prompts tab give way to the
Shelf. The Shelf reads on its own, so a failure there leaves the other
tabs working and says so. ChatGPT Shopping gets its name in the
platform labels.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ts, orders and readiness (product visibility, part 4)

The Products tab (ECOM-007) lists the brand's catalog when it has one.
Each product shows:
- its photo, category and price;
- the AI shelves it was on, its win rate (#1 or #2) and average place
  over the filter window, from its matched cards (00360);
- the AI visits its page got;
- the orders those visits led to, and their revenue;
- its readiness out of 100.

Visits and orders come from catalog_product_ai_stats (00361). No source
carries order line items yet (Shopify order sync, ansvisor#1267), so an order is
credited to the product whose page the AI visitor landed on first
(ai_traffic_events.first_url). A product's page is its link, else its
first variant's, matched by path. Members of the brand's organization
only.

Readiness adds up what the catalog can tell:
- a GTIN (20);
- a photo (15);
- in stock (15);
- a price (10);
- a description of 25 words or more (15);
- what the product is, in its first 40 words (10, ECOM-024);
- a category (10);
- a brand (5).
Its tip says what's missing and what each costs.

Views: All, Never shown, Shown not clicked, Clicked not bought, and Top
sellers from AI, each with its count. The table reads up to 2,000
products and says so past that. A brand with no catalog, or one that
can't be read, keeps the products AI showed by title, with a line on
connecting the catalog. Prices format in one place
(lib/shopping/price.ts).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… on it, top rival and AI revenue (product visibility, part 5)

The Categories tab (ECOM-008, between Shelf and Products) lists each
category of the brand's catalog that has live products, with:
- its shopping questions: a question is the category's when the
  category's own name is in it (its last level, plural or not:
  "Hiking backpacks" in "lightweight 30L hiking backpack for women"),
  or when one of its products was on the question's shelf (00360);
- the brand's share of the product slots on those shelves, with a bar;
- its products on a shelf, of its products;
- the rival with the most slots there: the competitor a card is
  matched to, else the card's brand, with its favicon;
- its products' AI revenue in their main currency (00361).

A category with three questions or more where the brand holds under 10%
of the slots is marked "needs attention", tinted amber. The tab reads
when it opens, once per brand and filters, and shows its count. It also
says when the catalog has no categories, or when they can't be read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…AI picked another one (product visibility, part 6)

Each product in the Products table now opens its own page,
/dashboard/shopping/products/[id] (ECOM-011, the mockup's product
detail).

Header: its photo, price, category, "On N of M shelves", its
readiness, and "View product page". Below it, its AI clicks, AI orders
and AI revenue over 30 days (00361).

"Why not your product?": for the most relevant question whose shelf it
isn't on (else the one it ranks lowest on), it stands beside the
product AI put first, row by row:
- match with the question: both BM25 scores (ansvisor#1487's), over its title
  and its description's first 40 words, with the missing words;
- price: close, or how much higher or lower;
- rating and reviews, as the answers showed them;
- what it is, in its first 40 words;
- GTIN, photo and stock in the feed;
- who sells each.
Each row is marked ✓ matches, ✕ missing, ↓ weaker, or — just what
each has. Rows we have no data for (delivery, returns, schema) are left
out rather than guessed.

"Where it shows": the questions it belongs on (its category's name in
them, the shelves it was on, or a match of 40 or more), each channel's
latest shelf, its place, its match and the missing words. Then its
readiness, check by check.

The view is its own component (_product-detail.tsx). Reading the
catalog's products is shared with the Products table. The plan's
locked note now says what Growth unlocks here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…h the work that gets it on the AI shelf (product visibility, part 7)

ECOM-013, the mockup's "Actions to get on the shelf" and "Category
actions".

A product's page lists its proposed work, from what it misses beside the
shelf's winner:
- Optimize page: rewrite it for the missing words;
- Create content: a comparison with the winner and an FAQ, else a
  buying guide;
- Get listed: the review sites AI quotes;
- Technical: GTIN and structured data.

The Categories table's "Plan actions" (filled on a category that needs
attention) opens the same for the category: the category page, a buying
guide, the "best X" lists, and its feed fields.

Each line is picked or not and set to Me or Agent. The agent can't take
a technical fix. "Send N actions to Action Center" opens one action with
a toast that links to it; a second send returns the action still open.

Server, POST /api/action-center/products (lib/action-center/
from-products.js):
- a 'shopping_product' (Growth) or 'shopping_category' (Compete) action,
  one open per product or category;
- tasks from the library: optimize_content; create_content_brief +
  create_content_draft; prepare_outreach + execute_outreach;
  fix_structured_data. Each task's mode follows Me or Agent where the
  task allows it, and the line becomes its why;
- the payload keeps the brand's own questions only. It's measured on
  them and the product's page (basket metrics), with its own priority
  subject.

The web knows both kinds' titles ("Get Ridge 30L Backpack on the shelf",
"Win “Hiking backpacks” in AI answers"). A category row keeps its
questions' ids.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…by channel and check by check (product visibility, part 8)

The Readiness tab (ECOM-015, spec §3.4 / §3.4b, the mockup's Readiness):
- the market and what it means for ChatGPT: OpenAI's product index in
  the US, Google Shopping in Europe;
- one card per AI shopping channel (ChatGPT Shopping, Google AI
  Overviews, AI Mode, Gemini, Copilot): whether it shows the brand's
  products, has its shelves tracked without them, or isn't tracked, and
  where it takes products from;
- "AI shopping readiness" scored 0–100.

The checklist lists only what Ansvisor can read:
- the catalog, and the Merchant Center feed (a fail in Europe, where it
  decides ChatGPT too);
- in the US, OpenAI's product index, and the verified seller flag as
  unknown, not scored;
- descriptions that don't say what the product is in their first 40
  words;
- feed fields complete (GTIN, photo, price, brand, category);
- feed links tagged utm_medium=feed;
- a price an AI answer shows more than 2% off the catalog's, with an
  example;
- resellers cheaper than the brand;
- Amazon's share falling sharply.

Product page schema, return policies, AI bots on product pages and
colors as separate items aren't listed until there's data for them. Each
check says where its fix starts: the Products table, or Settings ›
Integrations. OpenAI's product index card, with its direct-feed switch,
moves from Shelf to here.

The Products read keeps the prices AI answers showed for each matched
product, for the wrong price check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Products chip (product visibility, part 9)

The ECOM mockup's Action Center preview: a "From Products" chip beside
the categories, for the actions Product Visibility sends (part 7): a
product to get on the AI shelf ('shopping_product', Growth) and a
category to win ('shopping_category', Compete). They sit in different
categories, so no category filter shows them together.

- The chip shows with its count when the brand has such an action, and
  filters the list (and its CSV export) to them, whatever the category;
  a second click clears it.
- It lives in the URL (?from=products) with the page's other filters.
- FROM_PRODUCTS_KINDS in lib/action-center/registry.ts names the kinds.

The action-center guide says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nd open the product on that shelf (product visibility, part 10)

The mockup's Shelf: "When you're absent, your product shows greyed with
'Why not you? ›', which opens the product detail."

- On a shelf the brand isn't on, its product the question asks for most
  shows greyed after the shelf's own cards (the last of six gives way):
  whyNotYou in lib/shopping/shelf.ts scores the catalog's products by the
  question's words in their title, category and type, the readier one on
  a tie, none when nothing shares a word. Read from the Products table's
  rows, which load with the Shelf: no new read.
- "Why not you? ›" opens the product's page on that shelf
  (?prompt=…&platform=…): getShoppingProductDetail takes the shelf asked
  for, keeps its question whatever its match (productShelves' include) and
  explains it first (focusShelf's prefer), beside the product AI picked
  there. Without one, or when the brand leads it, the page explains its
  usual shelf.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…he product and its category (product visibility, part 11)

ECOM-018. Once an action sent from Products is completed, the product's
page and the Categories table set the shelves of its shopping questions in
the 7 days after it was done beside the 7 days before: how many the product
(or, for a category, any of the brand's products) was on. Read from the
cards already kept when the page opens: no job, nothing stored.

- lib/shopping/recheck.ts: shelfPresence, actionResult, resultTrend.
- getShoppingProductDetail reads the product's last done action beside the
  rest; one that can't be read leaves the page as it is.
- getShoppingActionResults: the categories' results, read after the table.
- Product page: an "After action #N" card with Open the action; the
  Categories table: a line under the category's name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… custom (product visibility, part 12)

ECOM-019. Plans get maxCatalogProducts: Starter 50, Growth 500,
Enterprise set per customer through plan_overrides, self-hosted no cap;
counted across the workspace's brands, like prompts.

- On the managed cloud a source's sync keeps what's left of the cap after
  the workspace's other sources (productRoom): the products already live
  first, so a tracked product stays tracked, then the new ones in the
  source's order. The rest aren't written; one in the catalog already is
  marked removed, as if gone from the source, and comes back when there's
  room. Nothing is deleted.
- The source records how many it couldn't keep and the cap (last_counts
  overLimit / limit); Settings › Product catalog says so, with Upgrade for
  admins and managers.
- A workspace without an active subscription gets the plan's own words.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…swers that showed it (product visibility, part 13)

ECOM-012, V1. A product's page gets a "What AI says" card: from the
answers of the last 30 days whose cards showed the product, the sentence
that names it (as Mentions quotes a brand: answerProse, mentionExcerpt),
the latest first, one per text, and the sources those answers cited most.
Their own words only: no AI of ours reads them, so no cost. Pros and cons
drawn from them come later.

- lib/shopping/ai-says.ts: productNames (each card title and its name
  before the variant), productQuote, productAiSays.
- getProductAiSays reads the product's cards, then the latest 8 answers'
  text and the latest 20's citations; the page reads it apart and fills the
  card when it comes, so the heavy text doesn't hold the page.
- mention-match: namesAny, the tracking match as a yes/no.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ith a Shopping filter (product visibility, part 14)

ECOM-003. A suggestion refresh now also offers the model the brand's
catalog categories, each with its live products and price band (the round
price most of them sell under), and asks for at least 5 shopping questions
from them: best-of, under a budget, for a use, which type. One that names an
offered category is kept with source 'catalog' and the category in
source_data; a category the catalog never offered stays a plain suggestion.
Brands without a catalog get the same prompt as before.

- server/src/lib/catalog-suggestions.js: composeCatalogCandidates,
  roundPrice; any read failure returns [] so a refresh never fails on it.
- 00362: 'catalog' in prompt_suggestions_source_check; schema.sql rebuilt.
- Prompt Suggestions: a "Your catalog" badge with the category on hover,
  and a Shopping source filter once the catalog gave a suggestion (or
  ?source=shopping); "Ansvisor Agents only" leaves them out.
- docs/guides/prompts.mdx: the fourth source.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The categories' re-check could filter one card read by up to 400 question
ids, a request address long enough to be refused. Reads now take 100 ids
each, side by side.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-ai-says

# Conflicts:
#	web/src/lib/actions/shopping-product-detail.test.ts
…a product's delete (00360)

`on delete set null` looks up a deleted catalog product's cards by the
product alone, which the (brand_id, catalog_product_id) index can't serve:
each delete would scan the cards. A partial index on catalog_product_id
covers it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…loop, and read every GTIN key in the sweep

A 50,000-product catalog took about 90 s to match 20,000 cards, in one
synchronous run. Now about 1 s, the longest hold under 70 ms:

- A word in more than 5% of the titles (and more than 500) finds no
  products to compare; it still counts in a title's score. A title of
  common words only is found by its rarest one. A product not compared
  can't come within the margin of the best: when one could (it would share
  only the card's common words), no title match is made. So every title
  match is one the full comparison makes too; a few it made are not.
  A catalog of 500 titles or fewer is matched exactly as before.
- matchCards matches 500 cards at a time, with a turn of the event loop
  between (the bot-log parser's nextTurn).
- The kept catalogs are capped at 200,000 products in all, not 50 brands;
  the brand read least recently goes first, and a read keeps a brand.
- The daily sweep reads a card's GTIN under gtin, gtin13, gtin12, gtin14,
  ean and upc, as matching at write time does, not under gtin alone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…'s active products first (00361)

catalog_product_ai_stats returned a row for every live product, so a
catalog past 1000 products lost the rest to PostgREST's max_rows, and the
Products table read at most the first 2000 products by id, with every
variant of the catalog.

- 00361 returns only the products with an AI visit or an order, and takes
  p_product_id for one product's row. The table reads it a page at a time
  (readAllRpcRows, by product_id).
- Past 2000 products, the table lists those on a shelf or visited from AI
  first (orders, then shelves, then visits), then the rest by id. Their
  rows, variants, photos and categories are read for those ids, 100 at a
  time; a catalog of 2000 or fewer is read by the brand, as before.
- All and Never shown count the whole catalog (the server's count), not
  the rows read; the note says which products the table holds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…f apart from the rest

Each filter change read the whole Products table with the page's other
reads, and the Shelf's rows waited for all of them.

- useKeyedRead: a read made once per brand and filters while it's wanted,
  an older answer dropped. The Shelf reads with it on its own; the
  Products table only while its tab is open, as Categories does.
- The no-catalog view says what main's CatalogNote says (with its link to
  Settings), not a second line of its own: products.noCatalog goes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ct-visibility-categories

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Categories table read catalog_product_ai_stats in one request, so a
catalog with more than 1000 products with AI visits or orders lost the rest
of its revenue to PostgREST's max_rows. It reads the pages now, as the
Products table does (readProductAiStats).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…duct-visibility-detail

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The product's page read every product's AI visits and orders to find its
own, and lost it past the first 1000 rows. It asks catalog_product_ai_stats
for its product only (p_product_id, 00361), and reads its catalog rows by
its id.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged main forward (8356ba3) through the stack; no new conflicts on this branch. Typecheck and lint pass on the chain tip.

…ing cards to the catalog

A card's link has its trailing slashes cut by a walk back rather than an
end-anchored regex, and a title match reads a card title's first 40 words
(MAX_CARD_TITLE_WORDS): each word more was compared with every product it
found.
… table

Each category added up its questions' cards by walking every card in the
window again; a big catalog's categories, each in most questions, took
seconds. The cards are now counted once per question (slots, the brand's,
each rival's), and a category adds up its questions. The rows are the same.
Counting each question's shelves once gathers a category's questions by
name first, then by its products. Its promptIds are put back in the
cards' order, so the first 50 sent to the Action Center are the same as
before.
…rk line, as the Action Center route takes them

A category with more than 50 shopping questions, or a work line over 500
characters (a long question or two long product titles), was refused whole
by POST /api/action-center/products with a 400, so nothing was sent. The
web now sends the first 50 questions and cuts the line at a word.
…uggestion categories (00371)

The variants half of 00371's read now filters by brand and live rows, as
the products half does, so catalog_variants_brand_live_idx (00281) serves
it rather than every brand's variants.

@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.

Looks good, with follow-ups.

This part needs no change of its own. The branch merges in #1665's fix, so it carries part 1's 00371 fix (the variants read filtered by brand). Merge it with parts 1 and 2.

What I checked:

  • Own change. 4ec0aba, 0cc102f, a3da212, 6ec3863, 9688dba, fe4f7ff and 8843974 (plus merge 03ca582) on top of #1666's head f4ec0fe. Web only: no server change and no migration.
  • B17, "Why not you?".
    • Asking words, numbers and single letters don't count as matches. A product needs two shared "what" words, or a category or type the question names.
    • Audience words never qualify a product on their own, as shared words, a category or a type, but they still add to the score for the tie-break.
    • The tests cover the description's example and "Clothing > Men".
  • B18, "What AI says". The brand alone is never a name. A title part that equals the brand is dropped, and a leading brand is cut ("The North Face Borealis Backpack" → "Borealis Backpack"). The name must still keep two words. Brands come from the catalog's product_brand and from the cards' own.
  • B19, product page.
    • A non-UUID product id returns null, which shows "isn't in your catalog anymore". A bad brand id still throws.
    • The winner is the first card above the product that is neither the brand's own nor this product.
    • Reads are narrowed:
      • the product's own cards (catalog_product_id = id);
      • up to 5,000 of the brand's questions;
      • shelves for up to 60 questions (detailPrompts: asked, appeared, category, then shared words);
      • search_queries only for each shelf's latest run.
    • Every read goes through the member's session and filters by brand_id, so RLS keeps it to the person's organization.
    • The page reads nothing when shopping_analytics is off.
  • B20, re-check.
    • Every question of the done actions is read, 100 ids a read and 6 at a time.
    • A category counts only its own products (catalog_product_categories, read by brand).
    • A chunk that hits 50,000 cards marks its actions partial. Reads go newest first, so the cut drops the week before.
    • resultTrend returns null for a partial action and new when nothing was read before. The card and the line say each case in words.
  • Speed. I timed productNames, productAiSays and detailPrompts on long adversarial input: 100 KB titles, runs of separators, a 100 KB brand, a 100 KB answer, 5,000 questions. The text functions finish in tens of milliseconds. detailPrompts over 5,000 long questions takes about a second on a loaded machine, once per page open, on the server. TITLE_TAIL runs on whitespace-collapsed text, so a run of spaces can't make it slow.
  • Copy. The new lines ("too many answers to compare", "not run in the 7 days after", "New: nothing to compare") are clear English with correct plurals.
  • Tests. The shopping lib, dashboard shopping and actions tests pass on this tree (100 files, 715 tests), including the PR's listed files. Web tsc is clean. eslint and prettier are clean on the touched files.
  • Merge on main (8356ba3). This part adds no conflict of its own. The stack's conflicts are the same as #1649's.

Follow-ups (none block):

  1. A total bound for the re-check (B20, already listed). The 400-question cap is gone, so the read is now bounded only per chunk: up to 50,000 cards for each 100 questions. A brand with many done actions can make one page open read millions of rows. A failure only leaves the results out, but the time and memory are still spent. Two options: read each action's own two weeks rather than the span from the oldest action to the newest, or cap the total across chunks and mark the rest partial.
  2. "Why not you?" runs per row over the whole products list. Each shelf row re-tokenizes every product's title, category and type, and this part adds the category and type checks, about three tokenizations per product per row. With the 2,000-product table, long titles and 20 rows open, that is noticeable on the main thread. Computing each product's words once per list (a useMemo keyed by the products) would make it one pass.
  3. A chunk that has exactly 50,000 cards, with nothing past them, is also marked partial. Reading one extra row would tell the two apart. Minor.
  4. Server-side plan gating: the Product Visibility server actions (getShoppingProductDetail, getProductAiSays, the Shelf and Products reads) don't check the plan themselves. The page's lock is client-side. Data stays within the person's organization through RLS, so this is plan gating, not access. It was already like this before this stack. Worth one shared check in the actions.

@gkhngyk
gkhngyk merged commit 3052f6b into ansvisor:main Oct 28, 2026
4 of 5 checks passed
@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 28, 2026
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