/lunora:lunora-performance-auditfrom Lunora
Diagnoses and fixes Lunora performance issues: full-table scans, missing indexes, expensive related traversals, OCC write conflicts (409), chatty live queries, hot shards, and sharding decisions. Uses `lunora insights` and `lunora advisor` signals.
Ships in Lunora. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Find the measured problem, route it to the matching fix below, and apply the fix to every function that touches the same table.
If traffic is modest and nothing is measured as slow, prefer simpler code. Don't introduce sharding, digest tables or document splits on speculation.
lunora insights (runtime) and lunora advisor
(static).ctx.db read and write in that flow.insights row improved after the fix has served traffic.lunora insightsNeeds a running worker that has served traffic. It reports measured problems:
lunora insights # local dev worker (http://localhost:8787)
lunora insights --shard channel:demo # one shard instead of the root
lunora insights --limit 25 --format json
LUNORA_ADMIN_TOKEN=… lunora insights --prod --url https://app.example.com
It ranks per-function write-conflict hot-spots (go to Write conflicts),
error rates, and latency outliers (usually Read amplification). The
Studio Issues panel and lunora logs give error detail once you know where to
look.
lunora advisor and @lunora/advisorNo traffic needed. The Studio Advisors tab shows the same findings live in dev.
lunora advisor # score + write lunora.advisor.map.json
lunora advisor --entry messages#send # one procedure (file#exportName)
lunora advisor --baseline # CI: fail on regression vs the committed map
Lint ids are snake_case. The performance-relevant ones:
| Lint | Meaning |
|---|---|
filter_without_index | A query filters a table with no covering index. |
unbounded_collect | .collect() with no index or filter loads every row (and re-sends it live). |
filter_on_primary_key | Filtering on _id scans; use ctx.db.get(table, id). |
unindexed_foreign_key | An FK column has no index. |
unindexed_relation_target | A many relation's target FK has no index, so with: reads scan. |
duplicate_index / empty_index | Wasted or malformed index. |
index_utilization (runtime) | A declared index nothing uses, or a hot table read with none. |
hot_shard (runtime) | One shard takes a disproportionate share of a sharded function's load. |
fan_out_breadth (runtime) | A shard set so wide a cross-shard read nears the subrequest limit. |
Symptom: a query reads the whole table to return a few rows; a latency
outlier in insights, or filter_without_index / unbounded_collect.
Fix: declare an index and read through it with .withIndex():
// (auth / org membership check on `orgId` elided — see lunora-functions)
// Scans every row, then filters in memory.
const mine = (await ctx.db.query("documents").collect()).filter((d) => d.orgId === orgId);
// schema.ts
documents: defineTable({ orgId: v.string(), createdAt: v.number() /* … */ }).index("by_org_created", ["orgId", "createdAt"]);
// Reads only the org's range.
const mine = await ctx.db
.query("documents")
.withIndex("by_org_created", (q) => q.eq("orgId", orgId))
.collect();
Put equality columns first, then the range/sort column. For a large range,
paginate instead of .collect().
Symptom: a query using ctx.db.related is slow, or one page reads far more
rows than it returns.
A traversal is one batched findMany per edge, per hop, and the frontier grows
multiplicatively. The options are bounded, and an out-of-range value is rejected
with BAD_REQUEST instead of being clamped, so a throwing traversal means the
request is too big, not that there's a bug to route around.
| Option | Default | Cap | Why |
|---|---|---|---|
depth | 1 | 4 | Past 4 hops, request time is the limit, not limit. |
limit | 50 | 200 | Nodes per page. |
| cursor offset | 0 | 10 000 | The offset is re-walked: each hop reads N + limit + 1 rows. |
Fixes, in order:
edges to the "<table>.<column>" edges the feature needs. One
unrelated v.id(...) column can double the frontier per hop.direction to "in" or "out" instead of the default "both".depth before raising limit. Hops multiply; a page is linear.WHERE fk IN (…) read
(unindexed_foreign_key).Symptom: mutations on hot rows fail under concurrency, or a function tops
the write-conflict list in insights.
ShardDO uses optimistic concurrency. When a concurrent write commits first, the
mutation throws ConflictError (code: "CONFLICT", HTTP 409). The runtime does
not retry it; a mutation body runs at most once per call, and the caller
decides what to do. On the client, check with isConflictError(error) from
@lunora/client (also exported via lunorash/client).
Not every 409 is contention. On the server, ConflictError.kind is "occ" for
real write contention, and "unique", "restrict" or "trigger" for
constraint and guard failures. The client only sees code: "CONFLICT" (kind
is not part of the error envelope), so it cannot tell them apart. insights counts only occ as a write conflict, so fix a unique
409 in the data or the insert logic, not by sharding.
Fixes, in order:
.shardBy(key). Per-user / per-tenant / per-room state
in its own Durable Object never contends across keys. This is the main
horizontal-scale lever, since most contention is one hot DO.If hot_shard fires on an already-sharded table, the key is skewed: re-shard on
a higher-cardinality key or split the hot entity's state.
Symptom: a useQuery re-runs and re-pushes to many clients on unrelated
writes.
orgId shouldn't re-run on another org's write.Symptom: read-heavy, rarely-written data is slow for distant users.
Fix: .global() replicates the table to D1 for low-latency reads from the
edge, with read-your-writes via D1 sessions. Use it only for read-mostly tables:
it adds write-path cost and its own DDL flow (lunora-migration-helper). If the
dataset outgrows D1, .global({ backend: "hyperdrive" }) serves the same
reactive contract from Postgres/MySQL (lunora-setup-hyperdrive-global).
.shardBy(key) scales writes (rows in one DO per key); .global() scales
cross-region reads. A table can't have both; the default is the single root
ShardDO. Switching an existing table's mode moves its rows, which is an
export/import, not a schema edit (see lunora-migration-helper).
ctx.db read/write.lunora insights (if there's traffic) and lunora advisor..withIndex() reads; FKs indexed.edges / direction before touching depth.occ, then writes narrowed and/or .shardBy(key) applied..global() only on read-mostly tables.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
lunora, performance-audit, database-indexing, sharding, write-conflicts
npx claudepluginhub anolilab/lunora --plugin lunora15 skills in this plugin
/lunoraRoutes general Lunora requests to the right Lunora skill and gives the shared mental model (codegen loop, generated `api`/`internal` references, review commands, add-on capabilities, the `@lunora/mcp` server). Use when the user asks which Lunora skill to use, gives an underspecified task in a project with a `lunora/` directory or `lunorash`/`@lunora/*` dependencies, asks to review or audit Lunora code, asks about an add-on without its own skill (queues, workflows, agents, AI, flags, payments, notifications), or wants to expose a deployment to an AI agent over MCP./lunora-cloudflare-auditAudits a Lunora app for Cloudflare cost and reliability risk before launch or after a surprise bill. Chains the read-only `lunora doctor`, `lunora advisor` and `lunora insights` signals, then traces what they cannot see — retry and fan-out loops, cron cadence, public routes that reach a metered product (Workers AI, Browser, Containers, Vectorize, R2, D1), preview environments with paid bindings, and missing usage alerts (`lunora cloudflare alerts`). Reports each finding with the billing meter it moves, the smallest fix, and how to verify. Use when the user asks to "audit before launch", "what could blow up our Cloudflare bill", "why did the bill spike", "is this safe to put on the public internet", or "review our cron / queue / AI / workflow cost". For a slow query or OCC conflict use `lunora-performance-audit`; for a failing deploy use `lunora-deploy`.Other plugins' skills for the same job