GeezerVison is showing github.com — feat(atlas-search): D1 hot-cache admission policy — heat, heavy-query, tenant quotas, eviction (#13103) by dezren39 · Pull Request #13132 · developing-today/code
Conversation
dezren39
commented
Nov 23, 2026
•
edited by blacksmith-sh
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Follow-on 3 of 6 under #9134 — the admission policy from §3 and §5 of the D1 tenant hot-cache design (doc/2026-11-23T08-06-00Z_design_atlas_d1_tenant_hot_cache, merged via PR #13098).
What landed
New pure policy module pkgs/atlas-search/worker/src/admission.ts — no imports from the store (follow-on 1, #13100) or the freshness evaluator (follow-on 2, #13101); its entry facts mirror the design §5 schema fields so follow-on 4 (read-path integration) wires it to whatever store lands. Sibling slices were built in parallel from main; this slice does not depend on their branches.
- Heat counters —
HeatTracker: a key becomes eligible after heatRequests requests inside heatWindowMs (defaults 2 / 10 min). In-memory per isolate; heat is evidence, not state of record.
- Heavy-query immediate admission — first request admits when source latency > 250 ms or rows-read > 10,000 (strict inequalities, per the design wording; both are config).
- Entry size cap — payloads larger than 256 KB (config) are never admitted, even when heavy or hot.
- Negative results — ride the same heat/heavy gates (a single poll is one-hit traffic) and carry the 30 s negative TTL (config) when admitted.
- Per-tenant quotas —
quotaShares: the 5% floor is reserved per active tenant off the top, the remainder splits by tier weights 1:4:16; if floors alone would exceed the budget (>20 active tenants at the default floor) the whole budget splits by weight instead. Shares always sum to the budget. A tier outside the configured weights is a RangeError, not a silent clamp.
- LRU eviction sweep —
planEvictions: quota binds only under pressure (database over its total budget); while under budget, unused quota is borrowable and nothing is evicted. Under pressure each over-share tenant sheds least-recently-hit entries, Class B/C before Class A, stopping at its share; a tenant with no share entry sheds everything.
Every threshold is a named AdmissionConfig value with the design's defaults in DEFAULT_ADMISSION_CONFIG — none hardcoded in policy code, per the issue's acceptance.
Also: test/admission.test.ts registered in the atlas-search-worker-tests workflow guard list + header enumeration, and a README shape bullet (noted as not yet wired into the read path).
Test evidence
- New suite
test/admission.test.ts: 29 tests, 64 assertions, all passing — one or more tests per rule, incl. quota-pressure eviction order, strict heavy thresholds, the window boundary, the floor guarantee, and config-override tests proving thresholds come from config. Oracles are the design §3/§5 texts, stated in the test file header.
- Sandbox runner note: the package has no
node_modules in the sandbox and this lane does not install, so the suite was run under bun's test runner (which executes the vitest-style tests directly): new file 29/29 pass; whole test/ dir 44 pass, with worker.test.ts/mcp.test.ts unloadable there because they import cloudflare:test (exists only inside the vitest-pool-workers runtime — pre-existing, untouched by this change). The package's own npm ci && npm test under vitest is CI's first run (atlas-search-worker-tests workflow, main tier).
src/admission.ts typechecks clean under tsc --strict (TypeScript 5.6.3, ES2022/bundler resolution, scoped to the new module since the full package typecheck needs the absent node_modules).
Closes #13103
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…, tenant quotas, eviction (#13103)
Follow-on 3 of 6 under #9134 (design §3, §5): a pure policy module
for the atlas-search Worker with no store or read-path wiring
(follow-on 4 owns integration).
- HeatTracker: a key is eligible after heatRequests requests
inside heatWindowMs (defaults 2 / 10 min).
- decideAdmission: the 256 KB entry size cap is absolute; heavy
queries (source latency > 250 ms or rows-read > 10,000, both
config) admit on first request; otherwise heat decides. Negative
results ride the same gates and carry the 30 s negative TTL.
- quotaShares: 5% of the budget reserved per active tenant, the
remainder split by tier weights 1:4:16; pure-weight fallback
when floors alone would exceed the budget.
- planEvictions: quota binds only under pressure (unused quota
borrowable); over-share tenants shed LRU entries, Class B/C
before Class A, stopping at their share.
Every threshold is a named AdmissionConfig value. 29 unit tests
pin each rule against the design text, incl. quota-pressure
eviction order; admission.test.ts is registered in the
atlas-search-worker-tests workflow guard list.
coderabbitai
Bot
commented
Nov 23, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Warning
Review limit reached
You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.
Next included review available in 26 minutes.
Check out review usage here.
View limit details
-
Limit details: You’ve used the included review currently available.
Learn how review limits work.
Review configuration:
Run configuration
-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: defaults
- Review profile: CHILL
- Plan: Advanced
- Run ID:
dbcbf676-f9e0-4b6c-9a26-bd289b4f6ba2
Commits
-
Reviewing files that changed from the base of the PR and between bff8a0e and 85b5ffb.
Files selected for processing: 4
-
.github/workflows/atlas-search-worker-tests.yml
pkgs/atlas-search/worker/README.md
pkgs/atlas-search/worker/src/admission.ts
pkgs/atlas-search/worker/test/admission.test.ts
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
-
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
| Review |
Status |
Commit |
Review trigger |
| 📝 Code Review |
✅ Completed 2026-11-23T08:57:44.689050Z |
8a9c431 |
PR opened |
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review" or "@codex security review".
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8a9c43174c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Comment on lines
+69
to
+72
|
|
const slot = this.slot(tenantId, cacheKey);
|
|
|
const kept = (this.hits.get(slot) ?? []).filter((ts) => nowMs - ts < this.config.heatWindowMs);
|
|
|
if (kept.length === 0) this.hits.delete(slot);
|
|
|
else this.hits.set(slot, kept);
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expire heat counters for keys that are never requested again
With long-tail, one-hit traffic, every distinct tenant/key pair remains in hits indefinitely: expiration only examines the key passed to live(), so an abandoned key is never removed after its heat window expires. A long-lived Worker isolate therefore accumulates history proportional to all distinct requests, rather than the active window, eventually creating memory pressure even though these requests never qualify for admission. Add periodic or amortized expiration of inactive keys instead of relying on another request for the same key.
Useful? React with 👍 / 👎.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Comment on lines
+153
to
+154
|
|
describe("quotaShares (§3: tier weights 1:4:16, 5% floor)", () => {
|
|
|
it("splits purely by weight when the floor is configured off", () => {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add generated tests for quota and eviction invariants
The new policy suite uses only hand-written examples, despite quota conservation, feasible tenant floors, and pressure-based eviction being invariants over varying tenant counts, budgets, and entry sizes. The repository explicitly requires property-based coverage where invariants exist and model-based coverage where a specification exists; naming §3/§5 as the oracle does not satisfy that requirement. Add generated valid inputs checked against an independent policy model, including quota conservation and eviction ordering.
AGENTS.md reference: AGENTS.md:L37-L39
Useful? React with 👍 / 👎.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Nov 23, 2026
…low test list + README bullets)
…oth README: admission + freshness bullets)
Uh oh!
There was an error while loading. Please reload this page.
|
Merged via merge commit 76a4b53 (Batch A of #13903, queue task 21622). Conflicts: (1) .github/workflows/atlas-search-worker-tests.yml header comment and test-file loop; keep-both = admission.test.ts and measurement.test.ts. (2) pkgs/atlas-search/worker/README.md bullets; keep-both = key/measurement + admission, then main's freshness bullet after a second main sync (bff8a0e). Tests: worker vitest run → 12 files, 141 tests passed; tsc --noEmit clean.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
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.
|