Skip to content

fix(traffic): hold the uncrawled-pages alert until bot data covers its 30 days - #1225

Merged
gkhngyk merged 5 commits into
ansvisor:mainfrom
cihan-gyk:fix/bot-report-followups
Oct 20, 2026
Merged

gkhngyk merged 5 commits into
ansvisor:mainfrom
cihan-gyk:fix/bot-report-followups

Conversation

@cihan-gyk

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

Copy link
Copy Markdown
Collaborator

Summary

These are the four notes left from #1182's review: 30-day coverage, the dialog unmount, the (other) index and the 24h range.

1. 30-day coverage (migration 00190, ai_bot_report redefined; the rest is unchanged from 00185)

  • The "cited pages no search bot read in 30 days" gate checked only its window's ends:
    • v_first 30 days back;
    • a live connection that sent in the last 2 days.
  • A connection revoked on day −25, with a new one made yesterday, passed both. Every page crawled less often than once in the new data's one day was then listed.
  • The gate now also looks at every one of the 30 days: the longest run of days without rows must be at most 7. A site bots read once a week still passes; a hole of weeks doesn't, however old the connection (a sender past the month's raw cap, a Worker route taken down, a Logpush job paused and resumed). The first version's exception for a live connection made 29+ days ago is gone (review of 2026-10-20).
  • Otherwise it reads 'stale'. That also keeps cited_page_uncrawled signals as unread rather than resolving them (feat(action-center): raise AI Traffic alerts as signals: weekly drop, new platform, broken links, unread cited pages #1195).
  • The day check is 30 probes of (brand_id, day), not a scan; the runs come from those probes (gaps and islands).
  • The alertStale text now names the gap case.

2. Dialog unmount

  • If the refetch's getBotConnections failed, loaded.info became null and the dialog still unmounted with the new secret.
  • The section now keeps lastInfo, the last connections read without an error, through a functional state update. The dialog falls back to it.
  • I checked that the new test fails with the old line and passes with this one.
  • The sources strip's AI bots card (BotsSource) does the same now: a failed read keeps the last connections read (per brand), the card says "couldn't be read", and the dialog stays up with the secret. Its new test also fails on the old code.

3. The (other) index

  • New partial index ai_bot_daily_other_idx (brand_id, day) where page = '(other)'.
  • With 20,000 rows of realistic data on the dev DB (rolled back), the gate's exists uses it (Index Scan, 1 row).
  • On a large table, build it with create index concurrently first, as 00158/00164 note.

4. The 24h range

  • The counters are by UTC day, so 24h reads yesterday and today.
  • The section's range tag now says "yesterday and today (UTC)" instead of "last 24 hours". Reading exact hours would need ai_bot_events, which stops at the event cap.

Deploy: apply 00190 (web only otherwise). Numbering: 00188 is #1210's and 00189 is #1223's. schema.sql here is built without them; whichever merges later needs build-schema.sh again.

Related issue

Follow-up to #1182 (review of 2026-10-19 17:39 UTC).

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

I applied 00190 to the dev DB and ran ai_bot_report as the service role. Each case was in a transaction, rolled back:

Case alert_state
Rows on days −40…−26, plus today and yesterday; the old connection revoked on day −25, a new one made yesterday stale (00185 said on)
The same, plus rows on every day in between on
With a live connection made 60 days ago that sent an hour ago (the old exception made all of these on):
Raw cap reached on day −23, reading back on day −2: rows on 9 of 30 days, a 21-day hole stale
A Worker route down three weeks stale
Rows every 3rd day; once a week (6-day gaps); a 7-day gap on
An 8-day gap stale

In the browser (web on :3002 with the branch's API on :8082):

  1. Open AI Referral Traffic and pick 24h.
  2. AI bots reading your site shows "yesterday and today (UTC)" while the other sections say "last 24 hours".

I checked it in light and dark mode, at 1440 and 1024 px.

Unit tests: _bots-report.test.tsx and _bots-connect.test.tsx. After a failed refetch, the dialog still shows the new secret. In the browser I also blocked the reads right after a create: the card said "couldn't be read" and the dialog kept the Vercel drain's header with the secret.

Checklist

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

Also run:

  • yarn test (1776 passed);
  • yarn build with the CI placeholder env;
  • bash supabase/build-schema.sh.

🤖 Generated with Claude Code

…s 30 days

The "cited pages no search bot read in 30 days" list checked only the
ends of its window: the first bot day 30 days back, and a live connection
that sent in the last 2 days. A connection revoked on day -25 with a new
one made yesterday passed both, and every page crawled less often than the
new data's one day was listed. 00190 redefines ai_bot_report so the alert
also needs rows on 28 of the 30 days, or a live connection made 29+ days
ago that still sends (a site bots don't read every day); otherwise it is
'stale', which also pauses the cited_page_uncrawled signals. A partial
index on the '(other)' rows makes the gate's other check a probe.

The connect dialog kept the last connections only while a read was in
flight; a read that failed after a change took it down with the new
secret. The section now keeps the last connections read without an error.

The bot counters are by UTC day, so the 24h range reads yesterday and
today; the section says so instead of "last 24 hours".

Follow-up to ansvisor#1182's review.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk This covers #1182's four remaining notes:

  • Coverage gate: rows on 28 of the 30 days, or a live connection 29+ days old that still sends.
  • The dialog: it keeps the last connections read without an error.
  • The (other) index: a partial index on (brand_id, day) for those rows.
  • 24h: the section now says "yesterday and today (UTC)".

Migration 00190 is on the dev DB, and it is independent of #1222–#1224. One choice to check: for 24h I relabelled instead of reading ai_bot_events, since that table stops at the event cap.

@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 (other) index and the 24h label are done, and the report section keeps its last good info.

One change before merge, plus one smaller fix:

1. The connection-age exception reopens the gap (00190, the not exists (... created_at <= now() - interval '29 days' ...) branch). Any live connection over 29 days old that sent in the last two days skips the 28-of-30 check, and that is every long-lived connection.

  • A drain made in August hits the raw cap on Oct 10. Its files are then only counted: no ai_bot_daily rows, and last_event_at stops.
  • On Nov 1 reading resumes. The brand has rows on 9 of the last 30 days, but the exception makes the gate on.
  • uncrawled then lists every cited page not read on those 9 days, and the signals raise cited_page_uncrawled for them.
  • The same happens with a Worker route removed for three weeks, or a Logpush job paused and resumed.

The new alertStale copy promises this case is caught. Instead of the exception, use the same 30 probes to find the longest run of empty days, and read stale when it is longer than a few days (3–7). Sparse sites still pass, and multi-week holes don't. Please add both cases to the dev-DB check.

2. The sources strip still loses the secret (_bots-connect.tsx, BotsSource). A failed refetch after create sets info to {error} and returns before the <BotsDialog>, so the dialog unmounts with the one-time secret. Keep the last good info there too, as BotsReportSection now does.

…bot data

00190's exception for a live connection made 29+ days ago let every
long-lived connection skip the 28-of-30 check, so a sender past the
month's raw cap, a Worker route taken down for weeks or a paused Logpush
job reopened the gap the gate was meant to close. The gate now finds the
longest run of days without rows over the same 30 probes and reads
'stale' past 7: a site bots read once a week still passes, a hole of
weeks doesn't.

The sources strip's AI bots card also keeps the last connections it
read when a later read fails, as the report section does, so a failed
read after a create no longer takes down the dialog with the new
connection's one-time secret.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk thanks, both fixed in 65f3913:

1. The connection-age exception is gone (00190). The gate now takes the same 30 probes, finds the longest run of days without rows (gaps and islands over them), and reads stale when it is longer than 7 days. I took the top of your 3–7 range so a site bots read once a week still passes; a hole of weeks doesn't, however old the connection. The header comment and the PR description say so. Re-applied on the dev DB and checked as the service role, each case rolled back, all with a live connection made 60 days ago that sent an hour ago (the old exception made every one of them on):

Case alert_state
Raw cap reached on day −23, reading back on day −2 (rows on 9 of 30, a 21-day hole) stale
A Worker route down three weeks stale
Rows every 3rd day / once a week (6-day gaps) / a 7-day gap on
An 8-day gap stale
Every day on

2. The sources strip keeps the secret (_bots-connect.tsx, BotsSource). A failed read now keeps the last connections read (per brand, so another brand's never show): the card says "couldn't be read" and the dialog stays up. The new test in _bots-connect.test.tsx fails on the old code and passes now. In the browser I blocked every read right after a create: the dialog kept the Vercel drain's header with the secret.

schema.sql rebuilt; web format, lint, typecheck, 1792 tests and build pass. I didn't merge main in, as you asked during your merge runs; the PR is still MERGEABLE.

ansvisor#1252 and this branch each added a test to _bots-connect.test.tsx at the
same place: both are kept, and this branch's failed-read test takes
ansvisor#1252's connection shape (workerSecretName, a Worker without the secret).

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

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

Thanks, both points are fixed:

  • The gate. It now finds the longest run of empty days and reads 'stale' past 7, whatever the connection's age.
  • The dialog. BotsSource keeps the last good connections, so a failed read after a create keeps the dialog and its secret. The new test covers it.

I checked 00190 on production in a rolled-back transaction, on the largest citation brand, with a live connection and synthetic bot rows:

  • Weekly crawl: rows every 7th day give a longest gap of 6, so the alert stays on.
  • Hole: dropping two of those days leaves a 20-day hole, and the alert reads stale.
  • Speed, as an org member: the report takes 1.97 s cold over 30 days, with 73 uncrawled pages, and 0.23 s over all time.
  • Another org: a member of another organization gets null.

00190 is now applied to production. Your merge of main resolves _bots-connect.test.tsx the same way I did; it only changes the order of the two tests.

Nit for a follow-up: the comment on function text still describes the old rule ("rows on 28 of them, or a live connection 29+ days old"). It should say no run of more than 7 empty days.

#1216 conflicts with this in _bots-report.tsx. I'll resolve that on top and keep lastInfo.

@gkhngyk
gkhngyk merged commit 9a13cde into ansvisor:main Oct 20, 2026
5 checks passed
gkhngyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 20, 2026
Resolves _bots-report.tsx against ansvisor#1224 and ansvisor#1225: the connections keep
their own read, and they keep ansvisor#1225's lastInfo so a failed read after a
create doesn't close the dialog and lose the new secret. ansvisor#1224's
logsPausedUntil import stays.

Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
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