fix(ai-search): return the remaining searches with the search itself - #33
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The AiSearchLog the counter reads is written with waitUntil, so it lands after the response has left. Refetching the quota on success races that write, and a lost race leaves the old count on screen for the minute the query stays fresh. The search already computed the figure, so it hands it back and the client writes it into the cache. The round trip and the count query it cost on every search go with it. Closes #22 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The word was already in the code and in no glossary. It names what is left of a Plan's cap, not the entitlement, and the distinction is the one that gets blurred. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
viclafouch
force-pushed
the
fix/ai-search-quota-counter
branch
from
August 23, 2026 09:32
1d84964 to
64c5f6b
Compare
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #22
The issue, checked
Half true, so worth stating precisely.
True:
waitUntilcarries theAiSearchLogpast the response, so the write the counter reads lands after the client already has its answer. Refetching the Quota on success races that write.False: the title.
invalidateQueriesoverridesstaleTimeand refetches immediately, so there is no systematic one minute lag. And the insert starts before the response is serialised, so it has a full HTTP round trip of head start over the refetch: in practice it wins nearly every time.What is left is a real defect on a paid counter: it is right by luck, and a lost race then sticks for the minute the query stays fresh.
The fix
The search already computed the figure. It hands it back, the client writes it into the cache with
setQueryData. The race goes, and with it a round trip and acounton every AI search: the database sleeps a little longer.buildAiSearchQuotais now the only place the cap rule lives, shared byaiSearchMemesandcheckAiSearchQuota.Proof
page.reload().Watch after deploy
Nothing schema related, nothing to migrate. If the
waitUntilwrite fails, the counter now shows one search too few until the query goes stale, against one too many before. The error is still captured in Sentry.🤖 Generated with Claude Code