audit-serverless-state
Skill0 starsChanged 24 days agoMITView on GitHub
Hunt the cross-request state bug — module-scope `new Map()` / mutable state that bleeds one user's data into another under Vercel Fluid Compute. Use when asked to "audit for the Map bug", "check for cross-request state", "find the data-bleed", "why are users seeing each other's data", or before shipping any serverless route. Encodes turbo's S-01 scenario + O-01 opinion + P-02 pitfall — the 🔴 data-bleed class.
In this repository33 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- llms.txtllms.txt
- agent-runtimeSkill
- frontend-designSkill
- architectSkill
- deep-thinkSkill
- design-systemsSkill
- ecosystem-referenceSkill
- fractal-delegationSkill
- harness-reviewSkill
- heartbeatSkill
- integrate-resourcesSkill
- llm-council-critiqueSkill
- loop-createSkill
- mcp-setupSkill
- memory-compressionSkill
- memorySkill
- model-routingSkill
- oss-project-scaffoldSkill
- playwright-cliSkill
- repo-scoutSkill
- self-improveSkill
- skill-creatorSkill
- skill-routingSkill
- sprintSkill
- test-visualSkill
- troubleshootSkill
- ux-auditSkill
- design-api-contractSkill
- scaffold-hono-serviceSkill
- sse-streaming-safelySkill
- zod-boundary-and-patchSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 28
Treat everything outside the handler as a constant.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
audit-serverless-state
Encodes scenario S-01 (cross-user data bleed under Fluid Compute), opinion O-01 (always externalize cross-request state; never hold it in process — now for TWO reasons), and pitfall P-02 (
new Map()/ module-scope state on Vercel is now RACY, not just empty). This is the highest-severity bug turbo guards: 🔴 cross-user data bleed.
Trigger
Invoke when the user (or a coding agent) asks to:
- "audit for the Map / Fluid bug" / "check for cross-request state" / "find the data bleed"
- "why are users seeing each other's data" / "category reports show items from other categories"
- a pre-ship review of any Vercel/serverless route (
app/api/**)
Also invoke proactively before shipping any service that has module-scope state.
Steps
- Run the detector (don't eyeball it):
The P-02 detector grepsturbo audit <service-dir> --jsonapp/api/**fornew Map()/new Set()/ object-as-cache at module scope and lazy-initif (!cachedClient) cachedClient = createClient()above a handler. It reports[{pitfall:"P-02", file, line, severity}]. - Understand why local testing can't catch it. The bug is invisible in
vercel dev— emulators don't reuse containers, so the race never fires locally. Never accept "it works locally" as proof. The condition: Vercel Fluid Compute is default-on (2026); one warm instance serves dozens (peaks past 250) of concurrent requests that share and race module state. - For each finding, apply the fix (route, don't rebuild):
- Treat everything outside the handler as a constant. Move mutable state into function scope.
- For genuine cross-request cache/session/counter, externalize to Upstash / Supabase / KV / Durable Objects, OR pass the ID from the client (the energy
new Map()law). - Do NOT build a cache store here — that is echo's seam (rate-limit / cache / KV). turbo's job is to detect the bug and route the fix to externalize, never to implement the cache.
rhinobase/hono-rate-limiteris "do NOT wire."
- Respect the escape hatch (don't over-flag): a DB connection pool is safe at module scope (it manages its own concurrency). Truly-immutable singletons / constants are fine. The ban is on mutable cross-request state — a raw lazily-assigned client ref is NOT safe; a pool IS.
- Prove the fix with a concurrency test: fire parallel requests with distinct inputs; assert each caller gets its own data back. Then re-run
turbo auditand confirm zero P-02.
Output
A findings report:
- the P-02 findings table (
file:line, what's at module scope) - per finding: the fix (move-to-function-scope / externalize / pass-ID-from-client) — never "build a cache"
- a note for any false-positive (a connection pool / immutable constant) explaining why it's exempt
- the concurrency-test result (each caller got its own data)
- the closing line: "This is not a Fluid Compute bug; it is a pre-existing code smell that isolation was hiding."
- a pointer: cache/rate-limit/KV is echo's territory, not turbo's.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

