improvement(knowledge): cache admitted usage checks on the search path - #7989
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
There was a problem hiding this comment.
All reported issues were addressed across 9 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 9 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
f44f14c to
f59978f
Compare
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
Summary
checkAttributedUsageLimits, which sums the payer'susage_logrows for the whole billing period. For a large organization that is a scan of over a million rows per search,usage_admissionsat at a median of ~378ms per search, and the sum is one of the top database consumers overallcheckSearchUsageLimits, which serves a cached admission for up to 60s and always re-reads a refusal. Staleness only fails open: a payer who crosses their limit can keep searching for at most a minute, and a payer who raises their limit or upgrades is never held behind a cached blockcoalesceLocallycollapses concurrent misses and bounds a hung read at its settle deadline; the cache is anLRUCachecapped at 10k entriesingestion-usage-gate.ts→usage-gate-cache.ts): one key, one LRU, one coalescer, two entry points.checkIngestionUsageLimitsbehaves as before (serves cached refusals too); search serves only cached admissions, so it never sees a refusal ingestion cachedworkspaceId, which the check never reads, so every workspace of one payer shares an entry/api/v1/knowledge/search(its own inline gate, not the search use case), and every other caller keep the fresh read. No invalidator: usage and limit changes land in other processes, so the TTL is the real boundType of Change
Testing
check:audits(47), andcheck:api-validationpassChecklist