Review PRs and diffs for unbounded memory loading, concurrency explosions, oversized payload materialization, and missing pagination or byte caps. Use when reviewing cleanup jobs, background jobs, data imports/exports, file parsing, API fan-out, workflow execution payloads, large arrays/files, or any change that reads many rows, files, responses, logs, or external API pages into process memory.
72
88%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Use this skill when a PR or diff could load unbounded data into a Node/Bun process, especially in cron routes, background tasks, API routes, workflow execution, file parsing, cleanup jobs, migrations, import/export flows, and external API integrations.
Prove each changed path has explicit bounds for:
If any bound depends only on current production size or "probably small" data, treat it as a finding.
Read these when doing a deeper pass:
apps/sim/lib/cleanup/batch-delete.ts
chunkedBatchDelete: bounded SELECT -> optional side effect -> DELETE loop.batchDeleteByWorkspaceAndTimestamp: common workspace/timestamp cleanup wrapper.selectRowsByIdChunks: chunks large ID sets and enforces an overall row cap.chunkArray: use only after the input set itself is already bounded.apps/sim/lib/core/utils/stream-limits.ts
PayloadSizeLimitErrorassertKnownSizeWithinLimitassertContentLengthWithinLimitreadStreamToBufferWithLimitreadNodeStreamToBufferWithLimitreadResponseToBufferWithLimitreadResponseTextWithLimitapps/sim/lib/billing/cleanup-dispatcher.ts
WHERE id > afterId ORDER BY id LIMIT NworkspaceIds, retention, label) instead of one giant scopePromise.allapps/sim/app/api/files/parse/route.ts
apps/sim/connectors/utils.ts
CONNECTOR_MAX_FILE_BYTES: shared per-file cap (aligned with the manual KB upload limit)readBodyWithLimit: stream a download body to a Buffer with a hard byte cap (null on overflow)stubOrSkipBySize: listing-time skip when the reported size exceeds the capmarkSkipped / sizeLimitSkipReason: surface oversized files as failed (skipped) KB rowsConnectorFileTooLargeError: thrown mid-download when the listing under-reported sizeThe connector size pattern in apps/sim/connectors/utils.ts (CONNECTOR_MAX_FILE_BYTES + readBodyWithLimit + stubOrSkipBySize/markSkipped) exists for one risk: a knowledge-base connector downloading arbitrary, user-controlled file bytes that the source does not hard-cap. Apply it by that risk, not by the connector's name.
Use the pattern when the connector downloads file content via a stream/download_url where the user controls the size:
.vtt)For those, require all three:
readBodyWithLimit(resp, CONNECTOR_MAX_FILE_BYTES) — never raw response.text()/response.arrayBuffer()stubOrSkipBySize with the reported size) and again at fetch time (overflow -> markSkipped), since the listing size can be missing or under-reportedskippedReason, so they stay visible in the KB UI instead of vanishing from the indexSkip the pattern when the source already bounds the payload:
MAX_ROWS, Evernote ~25 MB/note) — a 100 MB cap can never fire, and wrapping a response.json()/Thrift parse in readBodyWithLimit is cargo-cultingLitmus test: "Can a user make this one fetch arbitrarily large, with nothing upstream stopping it?" Yes -> use the pattern. No (platform hard-cap, or already paginated) -> a per-file byte cap adds noise, not safety. Borderline: a user-configured/self-hosted endpoint with no platform cap (e.g. Obsidian) — bound it only if the content is genuinely unbounded.
select, findMany, Promise.all, map, filter, flatMapBuffer.concat, response.arrayBuffer(), response.text(), JSON.stringify, JSON.parsePromise.all(items.map(...)) unless items is already small and boundedLIMITid > afterId, timestamps plus unique ID), not deep OFFSETIN (...) lists are chunkedContent-Length when availableMap or Set for a platform-wide scopePromise.all over rows from an unbounded queryBuffer.concat, arrayBuffer, text, JSON.parse, or parse expansionOFFSET on a mutable or large tableselectRowsByIdChunks or chunkArray after bounding the source.chunkedBatchDelete for cleanup loops with row side effects.Promise.all with sequential chunk loops, queue concurrency, or a small limiter.Lead with concrete findings, ordered by risk:
## Findings
- **P1 Unbounded workspace load in cleanup dispatch** (`path/to/file.ts`)
The new path calls `select().from(workspace)` without a limit, then builds maps for every row before dispatch. In production this scales with all active workspaces and can exhaust the app process. Page by `workspace.id` with a fixed limit and dispatch bounded chunks.
## Good Signals
- Uses `readResponseToBufferWithLimit` for external downloads.
- Inline fallback processes chunks sequentially.
## Residual Risk
- The row cap is explicit, but no test currently proves the loop stops at the cap.Only say "good to go" when every changed source has explicit row, byte, and concurrency bounds or the boundedness is proven by a stable invariant.
6f514c1
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.