Skip to content

fix(traffic): use a bot's range list while it is read again - #1254

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/bot-range-stale-while-refresh
Oct 20, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/bot-range-stale-while-refresh

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to gkhngyk's optional note on #1251: "once a day, when a list is older than its TTL and a refresh is under way, requests wait for that refresh even though a usable list is still in memory. Returning the stale list right away while the refresh runs would remove that wait."

rangesFor (server/src/lib/ai-bots.js) now returns the list it has (hit.prefixes) at once when that list is past its day, while the one shared read runs. Only a request with no list to use (a first read, or the 5-minute retry after a failed one) waits for that read. A failed refresh still keeps the old list for an hour.

Related issue

Follow-up to #1251.

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

ai-bots.test.js, new: a list read at 0 and asked for past its TTL, while the refresh hangs, comes back at once twice with one refresh under way. Once the refresh answers, the new list is used. On the old code the request waits for the refresh and the test times out.

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

Server: npm run format, npm run lint, npm test (1905) pass.

🤖 Generated with Claude Code

Once a day, when a range list was past its TTL, the requests that needed
it waited for the refresh even though a usable list was still in memory.
They now use that list at once while the one shared read runs; only a
request with no list to use waits for it.

Follow-up to gkhngyk's note on ansvisor#1251.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk your optional note on #1251: a list past its TTL is now returned at once while the shared refresh runs; only a request with no list waits.

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

Looks good. A list past its day is used at once while the one read runs in the background, and readRanges catches its own errors, so nothing is left unhandled. Only a request with no list waits.

@gkhngyk
gkhngyk merged commit 27e7055 into ansvisor:main Oct 20, 2026
6 checks passed
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