Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

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

Cihan9a13cde0610e
diff --git a/supabase/migrations/00190_ai_bot_report_coverage.sql b/supabase/migrations/00190_ai_bot_report_coverage.sql
new file mode 100644
index 000000000..a298df578
--- /dev/null
+++ b/supabase/migrations/00190_ai_bot_report_coverage.sql
@@ -0,0 +1,221 @@
+-- ============================================================================
+-- 00190: the AI bot report's alert waits for 30 whole days of bot data
+-- ============================================================================
+-- Follow-ups from #1182's review (AT-011).
+--
+-- The "cited pages no search bot read in 30 days" list (ai_bot_report's
+-- `uncrawled`) only means something while the bot data covers those 30
+-- days. 00185 checked their ends: 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 as unread. The alert now also
+-- looks at every one of the 30 days: no run of more than 7 days in a row
+-- without rows. 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
+-- (its files are only counted), a Worker route taken down for a while, a
+-- Logpush job paused and resumed. Otherwise 'stale', which also pauses the
+-- cited_page_uncrawled signals (they read as unread, #1195).
+--
+-- The gate's '(other)' check scanned the brand's 30 days of rows on every
+-- read; a partial index on those rows makes it a probe. On a large
+-- ai_bot_daily, build it by hand first with `create index concurrently`,
+-- which doesn't hold back the ingest's writes; this statement then finds it
+-- in place.
+--
+-- The rest of ai_bot_report is unchanged from 00185.
+
+create index if not exists ai_bot_daily_other_idx
+ on public.ai_bot_daily (brand_id, day)
+ where page = '(other)';
+
+create or replace function public.ai_bot_report(
+ p_brand_id uuid,
+ p_since date,
+ p_until date,
+ p_limit integer default 20
+)
+returns jsonb
+language plpgsql
+stable
+security definer
+set search_path to 'public'
+as $$
+declare
+ v_first date;
+ v_last_day date;
+ v_last timestamptz;
+ v_since date;
+ v_alert text;
+ v_result jsonb;
+begin
+ if not exists (
+ select 1 from public.brands b
+ join public.profiles pf on pf.organization_id = b.organization_id
+ where b.id = p_brand_id and pf.id = auth.uid()
+ ) and auth.role() is distinct from 'service_role' then
+ return null;
+ end if;
+
+ select d.day into v_first
+ from public.ai_bot_daily d
+ where d.brand_id = p_brand_id
+ order by d.day
+ limit 1;
+ select d.day into v_last_day
+ from public.ai_bot_daily d
+ where d.brand_id = p_brand_id
+ order by d.day desc
+ limit 1;
+ select max(d.last_seen) into v_last
+ from public.ai_bot_daily d
+ where d.brand_id = p_brand_id and d.day = v_last_day;
+
+ v_since := coalesce(p_since, current_date - 89);
+
+ v_alert := case
+ when v_first is null or v_first > current_date - 29 then 'waiting'
+ when not exists (
+ select 1 from public.ai_bot_connections c
+ where c.brand_id = p_brand_id
+ and c.revoked_at is null
+ and c.last_event_at >= now() - interval '2 days'
+ ) or exists (
+ select 1 from public.ai_bot_daily d
+ where d.brand_id = p_brand_id
+ and d.bot_type = 'search'
+ and d.page = '(other)'
+ and d.day >= current_date - 29
+ ) then 'stale'
+ -- The whole 30 days, not only their ends: the longest run of days
+ -- without rows (one probe per day, then gaps and islands) is at most 7.
+ when (
+ select coalesce(max(r.days), 0)
+ from (
+ select count(*) as days
+ from (
+ select n, n - row_number() over (order by n) as run
+ from generate_series(0, 29) n
+ where not exists (
+ select 1 from public.ai_bot_daily d
+ where d.brand_id = p_brand_id and d.day = current_date - n
+ )
+ ) empty
+ group by empty.run
+ ) r
+ ) > 7 then 'stale'
+ else 'on'
+ end;
+
+ with g as (
+ -- Each bot's hits on each page in the range, added up once.
+ select
+ d.bot_type,
+ d.bot,
+ d.page,
+ sum(d.hits)::bigint as hits,
+ max(d.last_seen) as last_seen
+ from public.ai_bot_daily d
+ where d.brand_id = p_brand_id
+ and d.day >= v_since
+ and d.day <= p_until
+ group by d.bot_type, d.bot, d.page
+ ),
+ types as (
+ select
+ g.bot_type,
+ sum(g.hits)::bigint as hits,
+ count(distinct g.page) filter (where g.page <> '(other)')::bigint as pages,
+ max(g.last_seen) as last_seen,
+ array_agg(distinct g.bot order by g.bot) as bots
+ from g
+ group by g.bot_type
+ ),
+ bots as (
+ select
+ g.bot,
+ min(g.bot_type) as bot_type,
+ sum(g.hits)::bigint as hits,
+ count(*) filter (where g.page <> '(other)')::bigint as pages,
+ max(g.last_seen) as last_seen
+ from g
+ group by g.bot
+ ),
+ -- Hits folded past the month's cap ('(other)') aren't a page.
+ pages as (
+ select
+ g.page,
+ sum(g.hits)::bigint as hits,
+ max(g.last_seen) filter (where g.bot_type = 'training') as training_last,
+ max(g.last_seen) filter (where g.bot_type = 'search') as search_last,
+ max(g.last_seen) filter (where g.bot_type = 'user') as user_last
+ from g
+ where g.page <> '(other)'
+ group by g.page
+ ),
+ -- The alert reads its own 30 days, whatever the range.
+ uncrawled as (
+ select c.page, c.citations
+ from public.ai_traffic_page_citations(p_brand_id, current_date - 29, current_date) c
+ where v_alert = 'on'
+ and not exists (
+ select 1 from public.ai_bot_daily d
+ where d.brand_id = p_brand_id
+ and d.bot_type = 'search'
+ and d.page = c.page_key
+ and d.day >= current_date - 29
+ )
+ )
+ select jsonb_build_object(
+ 'first_day', v_first,
+ 'last_seen', v_last,
+ 'types', coalesce((
+ select jsonb_agg(
+ jsonb_build_object(
+ 'type', t.bot_type, 'hits', t.hits, 'pages', t.pages,
+ 'last_seen', t.last_seen, 'bots', to_jsonb(t.bots)
+ )
+ order by array_position(array['training', 'search', 'user'], t.bot_type)
+ )
+ from types t
+ ), '[]'::jsonb),
+ 'bots', coalesce((
+ select jsonb_agg(
+ jsonb_build_object(
+ 'bot', b.bot, 'type', b.bot_type, 'hits', b.hits, 'pages', b.pages,
+ 'last_seen', b.last_seen
+ )
+ order by b.hits desc, b.bot
+ )
+ from bots b
+ ), '[]'::jsonb),
+ 'page_count', (select count(*) from pages),
+ 'pages', coalesce((
+ select jsonb_agg(to_jsonb(p) order by p.hits desc, p.page)
+ from (select * from pages order by hits desc, page limit p_limit) p
+ ), '[]'::jsonb),
+ -- Null unless the bot data is whole (alert_state 'on').
+ 'uncrawled_count', case when v_alert = 'on' then (select count(*) from uncrawled) end,
+ 'uncrawled', case
+ when v_alert = 'on' then coalesce((
+ select jsonb_agg(to_jsonb(u) order by u.citations desc, u.page)
+ from (select * from uncrawled order by citations desc, page limit 10) u
+ ), '[]'::jsonb)
+ end,
+ 'alert_state', v_alert,
+ 'alert_from', case when v_first is not null then v_first + 29 end,
+ 'since', v_since
+ )
+ into v_result;
+
+ return v_result;
+end;
+$$;
+
+revoke all on function public.ai_bot_report(uuid, date, date, integer) from public, anon;
+grant execute on function public.ai_bot_report(uuid, date, date, integer)
+ to authenticated, service_role;
+
+comment on function public.ai_bot_report(uuid, date, date, integer) is
+ 'AI Traffic "AI bots reading your site" (AT-011, spec §3.7): verified AI-bot hits between two days by type (training, search, user) and by bot, the most read pages with each type''s last read, and the cited pages no search bot read in the last 30 days (null until bot data covers those 30 days: rows on 28 of them, or a live connection 29+ days old that sent in the last 2). Security definer with an organization check.';
+
+notify pgrst, 'reload schema';
diff --git a/supabase/schema.sql b/supabase/schema.sql
index dc8e48110..a81cb6bf3 100644
--- a/supabase/schema.sql
+++ b/supabase/schema.sql
@@ -26341,6 +26341,231 @@ comment on function public.ai_bot_prune(timestamptz, date, timestamptz, integer)
notify pgrst, 'reload schema';
+-- ─────────────────────────────────────────────────────────────────────────
+-- migrations/00190_ai_bot_report_coverage.sql
+-- ─────────────────────────────────────────────────────────────────────────
+-- ============================================================================
+-- 00190: the AI bot report's alert waits for 30 whole days of bot data
+-- ============================================================================
+-- Follow-ups from #1182's review (AT-011).
+--
+-- The "cited pages no search bot read in 30 days" list (ai_bot_report's
+-- `uncrawled`) only means something while the bot data covers those 30
+-- days. 00185 checked their ends: 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 as unread. The alert now also
+-- looks at every one of the 30 days: no run of more than 7 days in a row
+-- without rows. 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
+-- (its files are only counted), a Worker route taken down for a while, a
+-- Logpush job paused and resumed. Otherwise 'stale', which also pauses the
+-- cited_page_uncrawled signals (they read as unread, #1195).
+--
+-- The gate's '(other)' check scanned the brand's 30 days of rows on every
+-- read; a partial index on those rows makes it a probe. On a large
+-- ai_bot_daily, build it by hand first with `create index concurrently`,
+-- which doesn't hold back the ingest's writes; this statement then finds it
+-- in place.
+--
+-- The rest of ai_bot_report is unchanged from 00185.
+
+create index if not exists ai_bot_daily_other_idx
+ on public.ai_bot_daily (brand_id, day)
+ where page = '(other)';
+
+create or replace function public.ai_bot_report(
+ p_brand_id uuid,
+ p_since date,
+ p_until date,
+ p_limit integer default 20
+)
+returns jsonb
+language plpgsql
+stable
+security definer
+set search_path to 'public'
+as $$
+declare
+ v_first date;
+ v_last_day date;
+ v_last timestamptz;
+ v_since date;
+ v_alert text;
+ v_result jsonb;
+begin
+ if not exists (
+ select 1 from public.brands b
+ join public.profiles pf on pf.organization_id = b.organization_id
+ where b.id = p_brand_id and pf.id = auth.uid()
+ ) and auth.role() is distinct from 'service_role' then
+ return null;
+ end if;
+
+ select d.day into v_first
+ from public.ai_bot_daily d
+ where d.brand_id = p_brand_id
+ order by d.day
+ limit 1;
+ select d.day into v_last_day
+ from public.ai_bot_daily d
+ where d.brand_id = p_brand_id
+ order by d.day desc
+ limit 1;
+ select max(d.last_seen) into v_last
+ from public.ai_bot_daily d
+ where d.brand_id = p_brand_id and d.day = v_last_day;
+
+ v_since := coalesce(p_since, current_date - 89);
+
+ v_alert := case
+ when v_first is null or v_first > current_date - 29 then 'waiting'
+ when not exists (
+ select 1 from public.ai_bot_connections c
+ where c.brand_id = p_brand_id
+ and c.revoked_at is null
+ and c.last_event_at >= now() - interval '2 days'
+ ) or exists (
+ select 1 from public.ai_bot_daily d
+ where d.brand_id = p_brand_id
+ and d.bot_type = 'search'
+ and d.page = '(other)'
+ and d.day >= current_date - 29
+ ) then 'stale'
+ -- The whole 30 days, not only their ends: the longest run of days
+ -- without rows (one probe per day, then gaps and islands) is at most 7.
+ when (
+ select coalesce(max(r.days), 0)
+ from (
+ select count(*) as days
+ from (
+ select n, n - row_number() over (order by n) as run
+ from generate_series(0, 29) n
+ where not exists (
+ select 1 from public.ai_bot_daily d
+ where d.brand_id = p_brand_id and d.day = current_date - n
+ )
+ ) empty
+ group by empty.run
+ ) r
+ ) > 7 then 'stale'
+ else 'on'
+ end;
+
+ with g as (
+ -- Each bot's hits on each page in the range, added up once.
+ select
+ d.bot_type,
+ d.bot,
+ d.page,
+ sum(d.hits)::bigint as hits,
+ max(d.last_seen) as last_seen
+ from public.ai_bot_daily d
+ where d.brand_id = p_brand_id
+ and d.day >= v_since
+ and d.day <= p_until
+ group by d.bot_type, d.bot, d.page
+ ),
+ types as (
+ select
+ g.bot_type,
+ sum(g.hits)::bigint as hits,
+ count(distinct g.page) filter (where g.page <> '(other)')::bigint as pages,
+ max(g.last_seen) as last_seen,
+ array_agg(distinct g.bot order by g.bot) as bots
+ from g
+ group by g.bot_type
+ ),
+ bots as (
+ select
+ g.bot,
+ min(g.bot_type) as bot_type,
+ sum(g.hits)::bigint as hits,
+ count(*) filter (where g.page <> '(other)')::bigint as pages,
+ max(g.last_seen) as last_seen
+ from g
+ group by g.bot
+ ),
+ -- Hits folded past the month's cap ('(other)') aren't a page.
+ pages as (
+ select
+ g.page,
+ sum(g.hits)::bigint as hits,
+ max(g.last_seen) filter (where g.bot_type = 'training') as training_last,
+ max(g.last_seen) filter (where g.bot_type = 'search') as search_last,
+ max(g.last_seen) filter (where g.bot_type = 'user') as user_last
+ from g
+ where g.page <> '(other)'
+ group by g.page
+ ),
+ -- The alert reads its own 30 days, whatever the range.
+ uncrawled as (
+ select c.page, c.citations
+ from public.ai_traffic_page_citations(p_brand_id, current_date - 29, current_date) c
+ where v_alert = 'on'
+ and not exists (
+ select 1 from public.ai_bot_daily d
+ where d.brand_id = p_brand_id
+ and d.bot_type = 'search'
+ and d.page = c.page_key
+ and d.day >= current_date - 29
+ )
+ )
+ select jsonb_build_object(
+ 'first_day', v_first,
+ 'last_seen', v_last,
+ 'types', coalesce((
+ select jsonb_agg(
+ jsonb_build_object(
+ 'type', t.bot_type, 'hits', t.hits, 'pages', t.pages,
+ 'last_seen', t.last_seen, 'bots', to_jsonb(t.bots)
+ )
+ order by array_position(array['training', 'search', 'user'], t.bot_type)
+ )
+ from types t
+ ), '[]'::jsonb),
+ 'bots', coalesce((
+ select jsonb_agg(
+ jsonb_build_object(
+ 'bot', b.bot, 'type', b.bot_type, 'hits', b.hits, 'pages', b.pages,
+ 'last_seen', b.last_seen
+ )
+ order by b.hits desc, b.bot
+ )
+ from bots b
+ ), '[]'::jsonb),
+ 'page_count', (select count(*) from pages),
+ 'pages', coalesce((
+ select jsonb_agg(to_jsonb(p) order by p.hits desc, p.page)
+ from (select * from pages order by hits desc, page limit p_limit) p
+ ), '[]'::jsonb),
+ -- Null unless the bot data is whole (alert_state 'on').
+ 'uncrawled_count', case when v_alert = 'on' then (select count(*) from uncrawled) end,
+ 'uncrawled', case
+ when v_alert = 'on' then coalesce((
+ select jsonb_agg(to_jsonb(u) order by u.citations desc, u.page)
+ from (select * from uncrawled order by citations desc, page limit 10) u
+ ), '[]'::jsonb)
+ end,
+ 'alert_state', v_alert,
+ 'alert_from', case when v_first is not null then v_first + 29 end,
+ 'since', v_since
+ )
+ into v_result;
+
+ return v_result;
+end;
+$$;
+
+revoke all on function public.ai_bot_report(uuid, date, date, integer) from public, anon;
+grant execute on function public.ai_bot_report(uuid, date, date, integer)
+ to authenticated, service_role;
+
+comment on function public.ai_bot_report(uuid, date, date, integer) is
+ 'AI Traffic "AI bots reading your site" (AT-011, spec §3.7): verified AI-bot hits between two days by type (training, search, user) and by bot, the most read pages with each type''s last read, and the cited pages no search bot read in the last 30 days (null until bot data covers those 30 days: rows on 28 of them, or a live connection 29+ days old that sent in the last 2). Security definer with an organization check.';
+
+notify pgrst, 'reload schema';
+
-- ─────────────────────────────────────────────────────────────────────────
-- migrations/00192_rollup_integrity.sql
-- ─────────────────────────────────────────────────────────────────────────
diff --git a/web/messages/en.json b/web/messages/en.json
index 32d6c6a36..267f82d24 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -3632,8 +3632,9 @@
"moreUncrawled": "and {count} more",
"allCrawled": "Every page AI answers cited in the last 30 days was read by a search bot.",
"alertStarts": "The search-bot alert starts on {day}, 30 days after the first AI-bot request.",
- "alertStale": "The search-bot alert is paused: no connection has sent AI-bot requests in the last 2 days, or the month's cap was reached, so the pages search bots read aren't complete.",
- "allTimeCapped": "last 90 days"
+ "alertStale": "The search-bot alert is paused: the bot data doesn't cover the last 30 days (no connection sent in the last 2 days, or one stopped or was replaced within them), or the month's cap was reached, so the pages search bots read aren't complete.",
+ "allTimeCapped": "last 90 days",
+ "yesterdayAndToday": "yesterday and today (UTC)"
},
"gate": {
"needs": "Needs {source}",
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/traffic/_bots-connect.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/traffic/_bots-connect.test.tsx
index f292bfa06..45cd14081 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/traffic/_bots-connect.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/traffic/_bots-connect.test.tsx
@@ -126,6 +126,29 @@ describe('BotsSource', () => {
expect(getBotConnections).toHaveBeenCalledTimes(2);
});
+ // gkhngyk on #1225: a failed read after the create took the dialog down.
+ it('keeps the settings with the secret when the read after a create fails', async () => {
+ await render();
+ await act(async () => button('Connect')!.click());
+ createBotConnection.mockResolvedValue({
+ connection: { id: 'c1', kind: 'cloudflare_worker', createdAt: 't', lastEventAt: null },
+ secret: 'abot_s3cret',
+ endpoint: 'https://api.example/bots/ingest',
+ workerScript:
+ 'const ENDPOINT = "https://api.example/bots/ingest"; // env.ANSVISOR_BOT_SECRET',
+ workerSecretName: 'ANSVISOR_BOT_SECRET',
+ logpushJob: null,
+ vercelDrain: null,
+ } satisfies NewBotConnection);
+ getBotConnections.mockResolvedValue({ error: 'Server error: 502' });
+ await act(async () => button('Create connection')!.click());
+
+ expect(getBotConnections).toHaveBeenCalledTimes(2);
+ expect(card()).toContain("Cloudflare / Vercel · couldn't be read");
+ expect(page()).toContain("the secret in them isn't shown again");
+ expect(page()).toContain('abot_s3cret');
+ });
+
// gkhngyk on #1179: the secret sat in the Worker's code.
it('gives a Worker its code without the secret, and the secret to add as a Worker Secret', async () => {
await render();
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/traffic/_bots-connect.tsx b/web/src/app/[locale]/(dashboard)/dashboard/traffic/_bots-connect.tsx
index a277d111d..5b580cfa5 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/traffic/_bots-connect.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/traffic/_bots-connect.tsx
@@ -365,22 +365,44 @@ export function BotsSource({
}) {
const t = useTranslations('traffic.sources');
const tCommon = useTranslations('common');
- const [info, setInfo] = useState<BotConnections | { error: string } | null>(null);
+ // A failed read keeps the last connections read, as the report section
+ // does: the dialog reads them again after a create, and taken down it
+ // would lose the new connection's one-time secret. Kept per brand.
+ const [loaded, setLoaded] = useState<{
+ brandId: string;
+ info: BotConnections | null;
+ failed: boolean;
+ } | null>(null);
const [open, setOpen] = useState(false);
const load = useCallback(() => {
+ const done = (next: BotConnections | null) =>
+ setLoaded((prev) => ({
+ brandId,
+ info: next ?? (prev?.brandId === brandId ? prev.info : null),
+ failed: next === null,
+ }));
getBotConnections(brandId)
- .then(setInfo)
- .catch((err: Error) => setInfo({ error: err.message }));
+ .then((result) => done('error' in result ? null : result))
+ .catch(() => done(null));
}, [brandId]);
useEffect(() => {
load();
}, [load, revision]);
+ const current = loaded?.brandId === brandId ? loaded : null;
+ const info = current?.info ?? null;
const title = t('bots');
- if (!info) return <SourceCard tone="off" title={title} line={t('botsLoading')} />;
- if ('error' in info) return <SourceCard tone="off" title={title} line={t('botsFailed')} />;
+ if (!info) {
+ return (
+ <SourceCard
+ tone="off"
+ title={title}
+ line={current?.failed ? t('botsFailed') : t('botsLoading')}
+ />
+ );
+ }
const state = botsCardState(info);
const button = (label: string, primary: boolean) => (
@@ -396,7 +418,9 @@ export function BotsSource({
return (
<>
- {state === 'locked' ? (
+ {current?.failed ? (
+ <SourceCard tone="off" title={title} line={t('botsFailed')} />
+ ) : state === 'locked' ? (
<SourceCard
tone="off"
title={title}
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/traffic/_bots-report.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/traffic/_bots-report.test.tsx
index 12bd51480..f6e3784a0 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/traffic/_bots-report.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/traffic/_bots-report.test.tsx
@@ -149,6 +149,12 @@ describe('BotsReportSection', () => {
expect(getBotConnections).toHaveBeenCalledTimes(2);
expect(document.body.textContent).toContain("the secret in them isn't shown again");
expect(document.body.textContent).toContain('abot_new_secret');
+
+ // A read that fails after that keeps it up too.
+ getBotConnections.mockResolvedValue({ error: 'failed' });
+ await render(true, 2, onChanged);
+ expect(getBotConnections).toHaveBeenCalledTimes(3);
+ expect(document.body.textContent).toContain('abot_new_secret');
});
it('shows the bot types, the pages each type last read, and the search-bot alert', async () => {
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/traffic/_bots-report.tsx b/web/src/app/[locale]/(dashboard)/dashboard/traffic/_bots-report.tsx
index 58a0aafc1..4090d9286 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/traffic/_bots-report.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/traffic/_bots-report.tsx
@@ -227,6 +227,8 @@ export function BotsReportSection({
key: string;
info: BotConnections | null;
report: TrafficBots | null;
+ /** The last connections read without an error, for the dialog. */
+ lastInfo: BotConnections | null;
} | null>(null);
const [preview, setPreview] = useState(false);
const [connectOpen, setConnectOpen] = useState(false);
@@ -240,8 +242,10 @@ export function BotsReportSection({
console.error('Failed to load the AI bot report:', err);
return null;
}),
- ]).then(([info, report]) => {
- if (!cancelled) setLoaded({ key, info: 'error' in info ? null : info, report });
+ ]).then(([result, report]) => {
+ if (cancelled) return;
+ const info = 'error' in result ? null : result;
+ setLoaded((prev) => ({ key, info, report, lastInfo: info ?? prev?.lastInfo ?? null }));
});
return () => {
cancelled = true;
@@ -252,9 +256,10 @@ export function BotsReportSection({
const info = current?.info ?? null;
const report = current?.report ?? null;
// The dialog keeps the connections it was opened with while the section
- // reads again after a change it made (the page bumps `revision`): taken
- // down, it would lose the new connection's secret and settings.
- const dialogInfo = info ?? loaded?.info ?? null;
+ // reads again after a change it made (the page bumps `revision`), and when
+ // that read fails: taken down, it would lose the new connection's secret
+ // and settings.
+ const dialogInfo = info ?? loaded?.lastInfo ?? null;
const state = info ? botReportState(info, report) : null;
const pausedUntil = info ? rowsPausedUntil(info.usage) : null;
// Past the raw cap log files aren't read: the report stops mid-month.
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/traffic/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/traffic/page.tsx
index b8d21d28f..d97b06fbc 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/traffic/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/traffic/page.tsx
@@ -659,7 +659,8 @@ function TrafficPageContent({ brand }: { brand: Brand }) {
<BotsReportSection
brandId={brand.id}
dateWindow={dateWindow}
- rangeLabel={rangeSubLabel}
+ // The bot counters are by UTC day, so 24 hours read yesterday and today.
+ rangeLabel={datePreset === '24h' ? t('botReport.yesterdayAndToday') : rangeSubLabel}
canConnect={canManage}
revision={botsRevision}
onChanged={() => setBotsRevision((n) => n + 1)}