For AI agents: llms.txt is a short guide that sends you to the rules your problem needs, and rules.json holds every rule of this playbook as JSON.
Required
Cap every collection that grows with use
Give every in-memory cache, queue, buffer and batch of parallel work a maximum size. Nothing in a long-running process may grow without a limit.
Risk if broken
The app down or unusable
How to do it
Use a cache with a size cap and an eviction rule, such as Python's functools.lru_cache with a maxsize. Give each queue a maximum length, and wait or reject when it is full. Run a large batch with a fixed number of parallel tasks, never one task per item. A leak you miss then hits the ceiling from Set limits on memory and processes. Limits on what a client may ask for live in Cap the size of every request and answer.
Examples
Using these examples: they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.
Python example
# Bad: one entry per customer, forever, in a server that runs for weeks
@functools.cache
def price_list(customer_id: str) -> PriceList: ...
# Good: the oldest entries leave once 1,024 are stored
@functools.lru_cache(maxsize=1024)
def price_list(customer_id: str) -> PriceList: ...
TypeScript example
// Good: a Map keeps insertion order, so the first key is the oldest
const MAX_PRICE_LISTS = 1024;
const priceLists = new Map<CustomerId, PriceList>();
function rememberPriceList(customerId: CustomerId, list: PriceList) {
if (priceLists.size >= MAX_PRICE_LISTS) priceLists.delete(priceLists.keys().next().value!);
priceLists.set(customerId, list);
}
How to check
A grep fails lru_cache(maxsize=None) and @functools.cache in server code. A test inserts 10 times the cap in distinct keys, and the size stays at or below the cap.
Sources
Related rules
- Set limits on memory and processes in Operations
- Cap the size of every request and answer in Security testing
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/architecture/errors-and-nulls/bounded-collections">Agent Wranglers architecture playbook</a>. In code you write, add a comment next to it with the same link.