Skip to content

feat(traffic): show log senders' records against the raw cap, and why the bot report stops - #1224

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/bot-raw-cap-note
Oct 20, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/bot-raw-cap-note

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Follow-up from #1181's review: the raw cap was never returned or shown.

A Logpush job's or a Vercel drain's files count against the month's raw cap (raw_records and raw_capped_at, 00184). Past the cap they are counted but not read. No rows and no totals are added, so the bot report stops mid-month. The only note in the dialog covered the event cap ("totals still counted").

Server

  • GET /api/bots/connections/:brandId also returns usage.raw, usage.rawCappedAt and usage.rawCap (from getBotRawCap).

Web

  • BotUsage gains the three fields.
  • New helpers in lib/ai-bots.ts:
    • hasLogSender: a Logpush or drain connection;
    • logsPausedUntil: the next month's first day once the raw cap is reached, for a brand with a log sender;
    • rowsPausedUntil now shares the next-month helper.
  • The connect dialog shows, for a brand with a log sender:
    • "Log records this month: 20,000,400 of 20,000,000."
    • once the cap is reached: "Log files paused until Nov 1: this month's log records are used up, so requests from Logpush or the Vercel drain aren't counted until then."
  • The report section shows the same pause note under "By bot type", which explains a report that stops mid-month.
  • A Worker's batches don't count against the raw cap, so a Worker-only brand sees neither line.
  • New texts are in web/messages/en.json (traffic.bots.rawUsage, traffic.bots.logsPaused).

No migration.

Related issue

Follow-up to #1181 (review of 2026-10-19 14:05 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

  1. Run the branch's API with IS_CLOUD=true and set the organization to growth (raw cap 20M).
  2. Give the brand a vercel_drain connection, and a current-month ai_bot_usage row with raw_records above 20M and raw_capped_at set. Add a few ai_bot_daily rows so the report has data.
  3. Open AI Referral Traffic, then AI bots → Manage. The dialog shows the log-records line and the pause note.
  4. Scroll to AI bots reading your site. The same note is under the bot types.
  5. With only a Cloudflare Worker connection, neither line shows.

I checked this locally (API on :8082, web on :3002, temporary data removed afterwards) in light and dark mode, at 1440 and 1024 px.

Tests:

  • src/routes/bots.test.js: the route returns the raw fields.
  • lib/actions/ai-bots.test.ts: parsing.
  • lib/ai-bots.test.ts: logsPausedUntil only with a log sender and a positive cap.
  • _bots-connect.test.tsx: the dialog lines, and none for a Worker.
  • _bots-report.test.tsx: the report note.

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:

  • web: yarn test (1779 passed), and yarn build with the CI placeholder env;
  • server: npm run format, npm run lint, npm test (1818 passed).

🤖 Generated with Claude Code

… the bot report stops

A Logpush job's or a Vercel drain's files count against the month's raw
cap (00184). Past it they are counted but not read, so no rows and no
totals are added and the bot report stops mid-month, but nothing said so:
the only note covered the event cap ("totals still counted").

GET /api/bots/connections now returns the month's raw records, when the
raw cap was reached, and the cap. For a brand with a log sender, the
connect dialog shows "Log records this month: X of Y" and, once the cap is
reached, that log files are paused until the next month; the report
section shows the same note under the bot types. A Worker's batches don't
count against the raw cap, so a Worker-only brand sees neither.

Follow-up to ansvisor#1181's review.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk This covers #1181's raw-cap note.

The connections route now returns raw_records, raw_capped_at and the raw cap. For a brand with a Logpush job or a Vercel drain:

  • the dialog shows "Log records this month: X of Y" and, once the cap is reached, "Log files paused until ";
  • the report section shows the same note.

It is independent of #1222/#1223 and has no migration.

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

One small fix before merge:

The pause note keys on rawCappedAt (web/src/lib/ai-bots.ts, logsPausedUntil). 00184 sets that once a month and never clears it, but reading depends on raw < cap with today's plan:

  • Upgrade: a Growth org that hit 20M upgrades to Enterprise. Its files are read again, but the dialog and the report keep saying "paused until Nov 1".
  • Downgrade: an Enterprise org at 30M moves to Growth. Its files stop being read, but there's no note.

Use rawCap > 0 && raw >= rawCap, and add a raised-plan test.

Copy: "aren't counted" should be "aren't read" (en.json). The line above keeps counting, as the PR description says.

The pause note keyed on rawCappedAt, which 00184 sets once a month and
never clears. The server reads files while raw < cap with today's plan,
so an upgraded org kept seeing "paused until" after its files were read
again, and a downgraded one over its new cap saw no note. Read it as
the server does, and say the files aren't read (they're still counted).

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk thanks, both fixed in 5aca4ce:

  • Pause note: logsPausedUntil now reads rawCap > 0 && raw >= rawCap with today's plan, as the server does, and no longer looks at rawCappedAt. New test in ai-bots.test.ts covers both of your cases: the raised plan (Growth at 20M → Enterprise, rawCappedAt still set → no note) and the lowered one (Enterprise at 30M → Growth, no rawCappedAt → "paused until Nov 1").
  • Copy: "aren't counted" → "aren't read" in traffic.bots.logsPaused; the dialog test reads the new text.

Checked locally against a cloud-mode server with a temporary drain + usage row: Growth 20,000,400/20M shows the note, Enterprise hides it, Growth at 30M with no rawCappedAt shows it (light/dark, 1440/1024). Temp rows deleted and the demo org's plan restored. Web format, lint, typecheck, 1780 tests and build pass.

@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 pause note reads today's plan. rawCap > 0 && raw >= rawCap matches ai_bot_count_raw's v_raw < p_cap, and there are tests for both a raised and a lowered plan.
  • The copy now says the files aren't read.

This goes in first of the bot-report PRs. #1216 conflicts with it in _bots-report.tsx (the getBotConnections import and the new note) and will be resolved on top.

@gkhngyk
gkhngyk merged commit 02463af 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants