Skip to content

fix(content): the third review's open items — bounded reads (00226), My rules per site type (00227) - #1316

Merged
gkhngyk merged 11 commits into
ansvisor:mainfrom
cihan-gyk:fix/content-review-round3
Oct 21, 2026
Merged

gkhngyk merged 11 commits into
ansvisor:mainfrom
cihan-gyk:fix/content-review-round3

Conversation

@cihan-gyk

@cihan-gyk cihan-gyk commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The items @gkhngyk's third review left open on the Content stack, as listed on #1256 after the merge run. 00204–00221 are applied on production, so the reads he timed are redefined in a new migration (00226). My rules' site type is 00227, after #1315's 00224 and #1313's 00225. Items 1–4 of his #1314 review are in this PR too.

Reads (00226):

  • feat(content): check for overlapping pages before a draft is started #1287 Overlap check. content_page_overlap reads the window's answers from idx_prompt_results_brand_created_cover alone. The prompts are picked where the citations meet them (and a.prompt_id = any(p_prompt_ids) in cited), so the planner no longer combines the prompt_id index with the brand's.
  • feat(content): list the sources a draft draws on in the editor's Sources tab #1292 Sources tab. content_draft_sources:
    • takes the window's answers from the cover index, for a draft with prompts as well as one with a page, and picks the source prompts after;
    • counts each prompt's answers on that index;
    • takes "named in" from mentions_prompt_daily (00157) for the window's whole UTC days, plus the first partial day's answer rows;
    • reads fan-outs and cited pages from each prompt's latest 30 answers in the window. Those are the only answer rows fetched whole, and their citations are about a fifth of the window's.
  • feat(content): add the Content plan page #1308 Plan, 7 days. content_plan_pages (00221's 90-day copy) drops the prc.created_at bounds in page_prompts and takes the window from cur_answers.
  • feat(content): show what AI cites and what AI visits bring in on the Content plan #1309 Plan insights, 90 days. content_plan_insights:
    • takes the own ids from citation_urls' domain index first;
    • picks the own pages (the 5,000 cited most) and the top 1,000 others on the rollup's url ids;
    • joins citation_urls only for those;
    • uses force_custom_plan.

Each read was compared with its 00207–00221 version on the dev DB, with a rolled-back fixture, at 7/30/90 days. The output is the same, except the Sources fan-outs, which differ only where a prompt has more than 30 answers in the window. The index-only scans lean on #1315's daily vacuum and analyze.

App:

  • feat(content): add the Content plan page #1308 The reason reads "Citation rate −{pct}%". Start lists the page the plan named, "Optimize /page · The page your Content plan picked", first when the overlap check recommends another, so a person can come back to it. Pages match by address (pageKey).
  • feat(content): align page types with the formats www.ansvisor.com offers #1310 Collection sign. It matches whole words of the slug, so /collections/kitchen, closets, sunset-lamps, limited-edition and toothpicks are category pages. best-sellers reaches the collection sign: the best-of sign leaves it out, as it does best-practices.
  • feat(content): align page types with the formats www.ansvisor.com offers #1310 low items:
    • A title naming FAQ with a policy word ("Shipping FAQ") reads as Policy, as /pages/shipping-faq does.
    • "What is the best/difference/cost/price …", "what are the benefits/pros …" and "what is new" aren't definitions, in titles and in /what-is-… paths.
    • The How-to guide's numbered-steps rule checks a page whose H1 promises steps; otherwise it shows "Not a how-to" and isn't counted.
    • "Defined first" needs "X is/are/means/refers to" within the first eight words of the first sentence, after a subject that isn't a pronoun.
    • The writer, brief and agent prompts name the page type and its format, e.g. "Use case page: how the product serves one use case, industry or team", via server/src/lib/content-page-types.js. A test keeps it in step with PAGE_TYPES and en.json.
  • Start, when nothing overlaps. With a page from the plan, Start offers "Optimize /page" (chosen) and "Create a new page instead" under "No existing page answers these prompts".
  • "Defined first" compares words without their punctuation. It shows "English only" (not counted) when the brand's language isn't English.
  • My rules per kind of site (00227). content_rule_sets gets site_type in its key. getMyRuleSets and saveMyRuleSet use the brand's kind of site, chosen or guessed. A set saved before is copied to each kind.

From the #1314 review:

  1. A lost save's unconfirmedHash is the hash of sanitizeDraftHtml(bodyHtml), the page as the server stores it. The sanitizer is imported lazily on that path. The server also takes a stored page equal to the one being saved as its own.
  2. When the page changed while a decision was saved, redo.tr is dispatched right after it is built, before the second save.
  3. The type updates after a save and a restore match the updated_at of the version they follow.
  4. ruleSet's doc comment is back above ruleSet.

Related issue

Follow-up to the reviews on #1287, #1292, #1308, #1309, #1310 and #1314, as listed on #1256.

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

  1. Apply 00226 and 00227.
  2. Plan:
    • A page whose citations per answer fell shows "Citation rate −N%".
    • Optimize on an opportunity row whose page isn't the top overlapping page opens Start with "Optimize /page · The page your Content plan picked" selected. You can switch away and back.
  3. Sources tab: a draft's prompts show "N answers · you're named in M".
  4. Rules tab:
    • On a How-to guide titled "The Azores in winter", the steps rule reads "Not a how-to".
    • On one titled "How to pull an espresso shot" with two steps, it reads "2 of 3".
    • On a definition starting "Many people say it is great.", "Definition in the first sentence" reads "Missing".
  5. Save as my rules: the row carries the brand's kind of site.
  6. Timing on production is yours, as before. The dev DB holds too few rows to measure.

Checklist

Also run:

  • web: yarn test (2,458 tests) and yarn build.
  • server: npm run format, npm run lint and npm test (2,005 tests).
  • Migrations: bash supabase/build-schema.sh. 00226 and 00227 are applied on the dev DB. 00227 had a rolled-back dry run first, where a set saved before was copied to the three kinds of site.

No new dependencies.

🤖 Generated with Claude Code

cihan-gyk and others added 3 commits October 21, 2026 19:40
… 00226

The third review timed four content reads on production. 00204–00221 are
applied there, so 00226 redefines them:

- content_page_overlap (ansvisor#1287): the window's answers come from
  idx_prompt_results_brand_created_cover alone; the prompts are picked
  where the citations meet them.
- content_draft_sources (ansvisor#1292): the window from the cover index, each
  prompt's answers counted there, "named in" from mentions_prompt_daily
  plus the first partial day, fan-outs from each prompt's latest 30
  answers, citations from their cover index hash-joined to the answers.
- content_plan_pages (ansvisor#1308, 00221's copy): the overlap pairs take their
  window from the current answers alone, no prc.created_at bounds.
- content_plan_insights (ansvisor#1309): own ids from the domain index, rows picked
  on url ids before citation_urls is read, own list capped at 5,000,
  force_custom_plan.

Each matches its 00207–00221 version on a rolled-back dev DB fixture;
the Sources fan-outs differ only where a prompt has more than 30 answers
in the window.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
content_rule_sets was keyed by organization and page type, so a "guide"
set saved for a B2B brand also applied to the same organization's shops
and travel sites. 00227 adds site_type to the key; getMyRuleSets and
saveMyRuleSet use the brand's kind of site (chosen, or guessed). A set
saved before is copied to each kind, so it keeps applying where it did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Plan (ansvisor#1308): the reason reads "Citation rate −{pct}%"; Start lists the
  page the plan named first when the overlap check recommends another, so
  a person can come back to it (pages matched by address).
- Collection sign (ansvisor#1310): whole words of the slug, so /collections/kitchen
  or /collections/limited-edition are categories; the best-of sign leaves
  best-sellers to it.
- ansvisor#1310's low items: a title naming FAQ with a policy word reads as Policy,
  as its address does; "what is the best/difference/cost/benefits …" and
  "what is new" aren't definitions, in titles and paths; the numbered-steps
  rule checks only a how-to H1 ("Not a how-to" otherwise); "Defined first"
  needs the verb within the first eight words, after a subject that isn't
  a pronoun; the writer, brief and agent prompts name the page type and its
  format (content-page-types.js) instead of its key.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 21, 2026

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

Most of this checks out. Two fixes are left, plus items 1–2 from #1314 that you said come next here.

Timed on production, on the same brands, drafts and windows as the earlier rounds. #1315's autovacuum ran on prompt_results and prompt_result_citations at 15:58–15:59 UTC today, so the cover-index scans now make no heap fetches.

Read Before Now (00226)
content_page_overlap, biggest brand, 500 prompts, 30 d 9.1–10.6 s cold, 0.3 s warm 0.49 s first run, 0.2 s warm
content_draft_sources, 92-prompt draft, 30 d 8.3–21.7 s cold, 0.76 s warm 10.7 s first run, 0.44–0.75 s warm
content_plan_pages, largest, 7 / 30 / 90 d 15–19 s at 7 d 0.18 / 0.48 / 0.94 s
content_plan_insights, largest, 90 d 4.2 s cold 2.46 s cold, 0.95 s warm

What checks out

  • The overlap, plan-pages and insights rewrites return the same rows as before.
  • "Named in" from mentions_prompt_daily matches the raw answers exactly on prod (6,918 of 80,721 for the biggest brand's last 29 days), and the first partial day isn't counted twice.
  • Generic plans:
    • for content_plan_pages and content_plan_insights, they're no longer dangerous;
    • for content_page_overlap, the generic plan never finishes, so its force_custom_plan has to stay.
  • 00227: the key change hits content_rule_sets_pkey, the copy is a no-op on prod (no rows yet), the policies still match, and the upsert's onConflict uses the new key.
  • The page-type fixes (whole-word collections, policy-before-FAQ, the "what is …" exclusions, "Not a how-to"), the "Citation rate" label, and Start keeping the plan's page (with the www / slash / case match) all behave as described. Tests cover them.

Fixes

  1. Sources is still over 8 s on a cold first call for the biggest brand (supabase/migrations/00226_content_reads_bounded.sql:293-302).
    • cited_ids needs all 106k citations of the draft's 13.6k answers in the window. The planner probes prompt_result_citations_pkey once per answer, not the cover-index hash join the comment describes.
    • Forced onto the hash path, it reads all 672k of the brand's window entries instead: 6.3 s cold.
    • Count cited pages over the same latest-30 sample as the fan-outs (… where a.recency <= 30). That's 2,760 answers instead of 13,618, about a fifth of the reads.
  2. The plan's page can't be changed when the check finds no overlap (web/src/lib/content/overlap.ts:67-77, web/src/components/content/new-content-dialog.tsx:409, :1025).
    • Start pre-selects "Optimize /page" for the page the plan named. When the verdict is none, the box only says "No existing page answers these prompts · Safe to create" and shows no options.
    • So the person can't see that the draft will optimize that page, or switch to a new one.
    • When given is set and there are no options, return [optimizeGiven, create] and render the radio group in the none branch. Add a none case to overlap.test.ts.

Low, any time

  • definesAtOnce compares words with their punctuation attached (web/src/lib/content/rules.ts:573-581), so "Cold brew is, simply, …" reads as Missing.
  • The defined-first check is English-only. Return info when the brand's language isn't English.
  • citation_url_daily holds about 12% dead tuples. If the 90-day cold read matters later, give it 00224's autovacuum settings.

Tested on top of main: web 2,453 tests, server 2,005, tsc, lint and Prettier pass, and schema.sql rebuilds unchanged. 00226 and 00227 aren't applied on production yet. I'll apply them when this merges. Note that #1317 takes 00228.

cihan-gyk and others added 7 commits October 21, 2026 20:20
… sample

cited_ids needed every citation of the draft's window answers (106k for a
92-prompt draft on the biggest brand), read one answer at a time, and the
cold first call still took 10.7 s on prod. It now reads the citations of
the same sample as the fan-outs, each prompt's latest 30 answers (2,760
answers instead of 13,618). With the cap lifted it matches the previous
read on the dev DB fixture.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Start pre-selects the page the Content plan named, but when the overlap
check found no page, the box only said "Safe to create" and offered no
option: the person couldn't see the draft would optimize that page, or
switch to a new one. With a page from the plan and nothing overlapping,
Start now offers "Optimize /page" (chosen) and "Create a new page instead".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
When a save's answer never came back, the editor sent the hash of its raw
HTML as unconfirmedHash, but the server compares it with the stored page,
which is sanitizeDraftHtml's output. sanitize-html rewrites most real
pages (<br> to <br />, &nbsp; to U+00A0, links without target/rel, tables
without style/colgroup), so on those pages the lost save still ended in a
conflict. The editor now hashes the sanitized page, loading the sanitizer
only on that path, and the server also takes a stored page equal to the
one being saved as its own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…econd save

When the page changed while a decision was saved, redo.tr was built on the
new page, but dispatched only after the second save (the suggestions it no
longer fits going back to review). If the page changed again during that
call, dispatching threw "Applying a mismatched transaction": the person saw
the save-failed toast, and the page and the cards stayed as they were. The
redo is now dispatched right after it is built.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t follows

The type update after a save or a restore wasn't tied to that version. A
write landing between them would have its updated_at become the editor's
base, and the next autosave would go over it. Both updates now match the
version they follow (updated_at); otherwise the type catches up on the
next save, as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- The verb check compared words with their punctuation attached, so
  "Cold brew is, simply, …" read as Missing; words are compared bare now.
- The check reads English words ("is", "means", "refers to"), so for a
  brand whose language isn't English it shows "English only" and isn't
  counted. The rule context carries the brand's language.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Fixed. One commit each, in your order:

  1. Sources cold read (a4ed1a8). cited_ids reads the citations of the same sample as the fan-outs, each prompt's latest 30 answers (where a.recency <= 30). The misleading hash-join comment is gone, and the 00226 header says the cited pages and "searched N×" count that sample. With the cap lifted, it matches the previous read on the dev DB fixture. Re-applied on the dev DB.

  2. The plan's page when nothing overlaps (eedc850). overlapOptions returns [optimizeGiven, createNew] when given is set and the advice has no options. The none branch renders the radio group under "No existing page answers these prompts":

    • "Optimize /page · The page your Content plan picked", chosen;
    • "Create a new page instead".

    Tests: a none case in overlap.test.ts, and a dialog test that switches to a new page and opens it as create.

From your #1314 review:

  1. Lost-save hash (389f731). The catch hashes sanitizeDraftHtml(content.bodyHtml), imported lazily there. The server also takes currentHash === hash(bodyHtml) as its own. The new autosave test saves a page with a target/rel link and a <br>, and checks the sanitized hash is sent. A server test covers a stored page equal to the one being saved.
  2. Redo dispatched at once (671597a). redo.tr is dispatched right after it's built, before the second save. The new editor test changes the page during both saves. It fails on the previous code and passes now.
  3. Optional, done (0e44d26). The type updates after a save and after a restore match updated_at of the version they follow.
  4. Nit (bc11512). ruleSet's doc comment is back above ruleSet.

Low items (2811690): definesAtOnce compares words without their punctuation, and "Defined first" returns info ("English only") when the brand's language isn't English. The rule context now carries the brand's language. I left citation_url_daily's autovacuum for when the 90-day cold read matters.

Checked on top of main: web 2,458 tests, tsc, lint and Prettier pass, and schema.sql rebuilds. The server is unchanged since your run.

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

The fixes check out.

  • Sources now counts cited pages over the latest-30 sample. Timed on production for the biggest brand, the 92-prompt draft and 30 days:

    • first call: 7.2 s (it was 10.7 s);
    • warm: 0.28 s;
    • generic plan: 0.68 s.

    Prompts, answers, "named in", fan-outs and queries are unchanged.

  • Start with nothing overlapping: it offers the plan's page and "Create a new page instead".

  • #1314's two items are fixed: the lost-save hash is now taken over the sanitized page, and redo is dispatched before the second save. The updated_at-matched type writes and the low items are in too.

I merged main in, rebuilding schema.sql after 00224, 00228 and #1318. Tested on top of main with #1318: web 2,482 tests, server 2,006, tsc, lint and Prettier pass. 00226 and 00227 are applied on production.

@gkhngyk
gkhngyk merged commit 58007fc into ansvisor:main Oct 21, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants