Skip to content

fix(action-center): keep one stray 404 visit from raising a broken-link signal, and read only the candidates for a new AI platform - #1228

Merged
gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:fix/traffic-signal-noise
Oct 20, 2026
Merged

gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:fix/traffic-signal-noise

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

These are the two notes #1195's approval left as follow-ups: the single-404 signal and the nightly full-history read.

1. broken_citation_target on a single 404 visit

  • The family raised a high-impact signal for any missing page an AI visitor landed on. A single visit was enough, and the beacon is public, so a stray or made-up visit could raise it.
  • A page that AI answers cite still counts from its first visit. Its citations come from tracking, not the beacon.
  • Any other page now needs brokenLinkMinVisits (3, in config/action-engine.js).
  • When the filter drops a row, currentValue is the number of pages kept. Otherwise it stays the function's full count, as before.

2. The nightly new-platform read

  • newAiPlatformCandidates read the brand's whole merged AI traffic history before the week (ai_traffic_merged(p_from null), pages and days included), only to learn which platforms had sent a visit before.
  • It now:
    1. reads the week, as before;
    2. takes the week's candidates: known sources with 3+ visits (weekCandidates);
    3. stops when there are none, which is most nights;
    4. otherwise asks ai_traffic_platforms_seen (migration 00193) about those platforms only.
  • ai_traffic_platforms_seen returns whether the brand had any AI visit before the week, and which of the platforms sent one.
    • Each platform is an index probe on the new partial index idx_ai_traffic_logs_brand_platform_time (brand_id, source_platform, created_at) where visit_of is null. Analytics rows are daily and few.
    • A snippet visit or an Analytics session counts whatever day it fell on. For "seen before" any evidence will do; it can only make a platform less likely to read as new.

Deploy: apply 00193, then deploy the server. On a large ai_traffic_logs, build the index with create index concurrently first, as the migration notes.

Numbering: 00188–00192 are #1210, #1223, #1225, #1226 and #1227. schema.sql is built without them; whichever merges later needs build-schema.sh again.

Related issue

Follow-up to #1195 (review of 2026-10-19 17:39 UTC; the approval kept these notes for later).

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

On the dev DB, with 00193 applied, for the demo brand (its first visits per platform run from Sep 20 to Oct 10):

Call Result
ai_traffic_platforms_seen(…, '2026-10-14', {chatgpt.com, perplexity.ai, claude.ai, bing-ai, gemini.google.com}) all five seen, any_before: true (the same as ai_traffic_merged up to Oct 13)
The same with '2026-10-05' and {chatgpt.com, perplexity.ai, gemini.google.com} only gemini.google.com (first Oct 3)
A brand with no traffic seen: [], any_before: false

With seq scans off (the dev table is tiny), the per-platform probe is an Index Only Scan on the new index.

Unit tests cover:

  • traffic-platforms.test.js:
    • one week read plus one candidates read;
    • no second read without a candidate;
    • Analytics as the source;
    • a failed read costing only itself.
  • ai-traffic-alerts-family.test.js:
    • a cited page with one visit kept;
    • an uncited page with one visit dropped;
    • three visits kept;
    • nothing raised when every row is dropped.

Checklist

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

Also run:

  • server: npm run format, npm run lint, npm test (1820 passed);
  • bash supabase/build-schema.sh.

🤖 Generated with Claude Code

…nk signal, and read only the candidates for a new AI platform

broken_citation_target raised a high-impact signal for any missing page an
AI visitor landed on, a single visit included, and the beacon is public: a
stray or made-up visit was enough. A page AI answers cite still counts from
its first visit (the citations come from tracking); any other now needs
brokenLinkMinVisits (3).

The nightly new-platform check read the brand's whole merged AI traffic
history before the week, pages and days included, only to learn which
platforms had sent a visit before. It now reads the week, stops when it
has no candidate (most nights), and otherwise asks
ai_traffic_platforms_seen (00193) about those platforms only: an index
probe each on (brand_id, source_platform, created_at).

Follow-up to ansvisor#1195's review.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk This covers #1195's two remaining notes:

  • The single-404 signal: a cited page still counts from its first visit; any other page now needs 3 visits (brokenLinkMinVisits).
  • The nightly full-history read: the check reads the week first, and only for that week's candidate platforms does it ask ai_traffic_platforms_seen (00193), one index probe each, whether they sent visits before.

00193 is on the dev DB, and the PR is independent of the others.

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 19, 2026
gkhngyk
gkhngyk previously approved these changes Oct 20, 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.

The nightly candidate read and the threshold work, and 00193 is a new invoker function behind the existing RLS.

Notes for a follow-up:

  • Visits, not visitors. The threshold counts visits (IP + user agent + platform within 30 minutes), so three beacon requests from one IP with three user agents still raise broken_citation_target. Counting distinct IPs, for example as a visitors field on the broken-link rows, would stop deliberate fakes too.
  • count and rows disagree. When every listed row passes, currentValue uses broken.count, which includes the one-visit pages past p_limit. A p_min_visits parameter would keep the two consistent.
  • The new index. It is built without set lock_timeout, unlike 00186. With at most about 11k rows per brand, idx_ai_traffic_logs_brand_visits may already be enough, and every beacon insert pays for the extra index.

@gkhngyk

gkhngyk commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

@cihan-gyk I'm merging these now: I pushed a merge with main that has schema.sql rebuilt after #1227. No need to merge main forward on the open PRs in the meantime.

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

Re-approving after the merge with main (schema.sql rebuilt). 00193 is applied on prod, and the index is valid.

@gkhngyk
gkhngyk merged commit fce0bd2 into ansvisor:main Oct 20, 2026
5 checks passed
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 20, 2026
…or known

The weekly e-mail's broken-link line printed the first row's page and
redirect unconditionally, and both can be any text the public beacon
sent (00186 also picks redirects among the pages it logged). It now
reads the broken links as the broken_citation_target signal does (50
rows, cited or brokenLinkMinVisits, ansvisor#1228), asks ai_traffic_known_pages
about the top one's page and redirect along with the moved pages, and
names the page only when AI answers cite it or it's known, the redirect
only when it's known; otherwise the line gives the count.

The AI Traffic page's summary line and its Top platform card now pick
the platform that sent the most among those they can name, as the
e-mail does, so a key only the beacon sent isn't named there either.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 20, 2026
…affic digest (#1229)

* fix(traffic): name only known platforms and pages in the weekly AI Traffic digest

The digest's top changes, platform list and "sent the most" sentence named
any platform key or page path in the AI traffic data, and the snippet's
beacon is public: a caller could put any text in a customer's e-mail.

Platforms are now named only when the page can name them (platform-names
.json, old keys included). Pages are named only when a source the beacon
can't write knows them: ai_traffic_known_pages (00194) checks the week's
moved pages against the site's pages (site_pages), Google Analytics and AI
answer citations in the last 90 days, active prompts' target URLs, and the
home page.

Follow-up to #1196's review.

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

* fix(traffic): name a broken link in the digest only when it is cited or known

The weekly e-mail's broken-link line printed the first row's page and
redirect unconditionally, and both can be any text the public beacon
sent (00186 also picks redirects among the pages it logged). It now
reads the broken links as the broken_citation_target signal does (50
rows, cited or brokenLinkMinVisits, #1228), asks ai_traffic_known_pages
about the top one's page and redirect along with the moved pages, and
names the page only when AI answers cite it or it's known, the redirect
only when it's known; otherwise the line gives the count.

The AI Traffic page's summary line and its Top platform card now pick
the platform that sent the most among those they can name, as the
e-mail does, so a key only the beacon sent isn't named there either.

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

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
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