{"id":80596,"plugin_id":"plugin_asdk_app_6abc2a9552748191b465859a06e90da3","kind":"skill","collection_source":"plugin_package","comparison_source":null,"observed_at":"2026-11-04T12:08:22.495Z","digest":"9c2763af45c80e4a81db5cc774614d174a348261b07d494817f63326a0413f81","against":25503,"payload":{"description":"Cloudflare Workers best practices for production applications. Use when writing, reviewing, or configuring Workers.","included_files":[{"relative_path":"references/configuration.md","size_in_bytes":6722},{"relative_path":"references/platform-apis.md","size_in_bytes":3876},{"relative_path":"references/runtime-patterns.md","size_in_bytes":13872},{"relative_path":"references/skill-feedback.md","size_in_bytes":2823}],"name":"workers-best-practices","skill_md_contents":"---\nname: workers-best-practices\ndescription: Cloudflare Workers best practices for production applications. Use when writing, reviewing, or configuring Workers.\n---\n\nYour knowledge of Cloudflare Workers APIs, types, and configuration may be outdated. **Prefer retrieval over pre-training** when writing or reviewing Workers code.\n\nUse the project's installed versions, generated types, and Wrangler compatibility settings as the baseline for existing code. Retrieve relevant Cloudflare documentation to verify API, configuration, runtime behavior, and limit claims.\n\n## References\n\nRead the sections relevant to the task:\n\n| Reference | When to use it |\n|-----------|----------------|\n| [Configuration and observability](references/configuration.md) | Compatibility dates, bindings, generated types, secrets, logs, and traces |\n| [Runtime patterns](references/runtime-patterns.md) | Streaming, promise lifetime, request state, service calls, security, and runtime tests |\n| [Platform API checks](references/platform-apis.md) | Handler signatures, platform classes, binding access, and serialization |\n\nFor missing evidence, consult [Workers best practices](https://developers.cloudflare.com/workers/best-practices/workers-best-practices/index.md) or find the affected product in the [Cloudflare docs directory](https://developers.cloudflare.com/directory/index.md). Use the installed Wrangler schema for config fields. A newer type package does not supersede the project's configured target.\n\n## Keep Compatibility Dates Current\n\nUse today's date for new Workers. Encourage periodic updates for existing Workers, reviewing compatibility changes and running relevant tests. Assess existing behavior against its configured date and flags; see [compatibility guidance](references/configuration.md#keep-compatibility_date-current).\n\n## Enable Observability\n\nEnable [Workers Logs](https://developers.cloudflare.com/workers/observability/logs/workers-logs/index.md) and [Traces](https://developers.cloudflare.com/workers/observability/traces/index.md) when creating or preparing a Worker for production. Set `observability.enabled` and `observability.traces.enabled` to `true`; the top-level setting alone does not enable traces. Use structured JSON logging and configure sampling for the workload. During reviews, flag missing logs or traces. See the [configuration example](references/configuration.md#enable-workers-logs-and-traces).\n\n## Place Compute Near Regional Databases\n\nFor Workers that make multiple sequential queries to one regional database, configure explicit placement matching the database's provider and region before deployment. Ask for missing location information, preserve existing placement choices, and verify handler eligibility and deployed request duration. See [database placement](references/configuration.md#place-compute-near-regional-databases).\n\n## Anti-Patterns to Flag\n\n| Anti-pattern | Consequence and preferred pattern |\n|-------------|-----------------------------------|\n| `await response.text()` or similar buffering on unbounded data | Can exhaust Worker memory; [stream large or unbounded bodies](references/runtime-patterns.md#stream-request-and-response-bodies). |\n| Hardcoded secrets in source or config | Leaks credentials through version control; use Wrangler secrets. |\n| `Math.random()` for security-sensitive tokens or IDs | Predictable values; use `crypto.randomUUID()` or `crypto.getRandomValues()`. |\n| Async work started without awaiting, returning, or attaching it to `ctx.waitUntil()` | Work can be dropped and errors missed; tie it to the request or background-work lifetime. |\n| Module-level mutable request state | Leaks data across requests and can cause I/O ownership errors; pass request state explicitly. |\n| Cloudflare REST API calls for operations available through Worker bindings | Adds network and authentication overhead; use the available binding. |\n| `ctx.passThroughOnException()` used as general error handling | Can conceal Worker failures by forwarding to the origin; use explicit error handling and structured error responses. |\n| Hand-written `Env` that duplicates Wrangler bindings | Can drift from configuration; generate binding types with `wrangler types`. |\n| Direct string comparison of secret values | Can expose timing differences; use the [Web Crypto comparison pattern](references/runtime-patterns.md#use-web-crypto-for-secure-token-generation). |\n| Destructuring `ctx` methods, such as `const { waitUntil } = ctx` | Loses the receiver; call `ctx.waitUntil(...)`. |\n| `any` on `Env` or handler parameters | Hides binding and handler contract errors; use the project's generated and platform types. |\n| `as unknown as T` to force a platform type match | Hides incompatibilities; fix the underlying contract. |\n| `implements` used in place of extending a platform base class | Does not inherit runtime behavior, `this.ctx`, or `this.env`; use the appropriate base class. |\n| Unbound `env.X` in a platform class method | Bindings are available through `this.env.X`; see [binding access patterns](references/platform-apis.md#binding-access--the-most-common-error). |\n| Applying one serialization rule across Queues, Workflow steps, storage, and WebSockets | Can reject valid payloads or accept unsupported ones; check the [specific API and encoding](references/platform-apis.md#serialization-boundaries). |\n\n## Validation\n\nUse the project's existing checks for affected Workers behavior: type-check binding or handler contract changes, and run relevant runtime tests for behavior changes. Preserve required repository checks; a narrow edit does not require a full Workers audit.\n\n## Scope\n\nThis skill covers Workers-specific best practices and code review. For related topics:\n\n- **Durable Objects**: load the `durable-objects` skill\n- **Workflows**: see [Rules of Workflows](https://developers.cloudflare.com/workflows/build/rules-of-workflows/index.md)\n- **CLI commands**: load the `cf-cli` skill, or the `wrangler` skill in a project with a Wrangler configuration file\n\n## Skill feedback\n\nIf the user reports that this skill gave incorrect or outdated guidance, or is missing information, read [references/skill-feedback.md](references/skill-feedback.md).\n"},"changes":[{"path":"/description","type":"changed","before":"Reviews and authors Cloudflare Workers code against production best practices. Load when writing new Workers, reviewing Worker code, configuring wrangler.jsonc, or checking for common Workers anti-patterns (streaming, floating promises, global state, secrets, bindings, observability). Biases towards retrieval from Cloudflare docs over pre-trained knowledge.","after":"Cloudflare Workers best practices for production applications. Use when writing, reviewing, or configuring Workers."},{"path":"/included_files","type":"changed","before":[{"relative_path":"references/review.md","size_in_bytes":8145},{"relative_path":"references/rules.md","size_in_bytes":16483}],"after":[{"relative_path":"references/configuration.md","size_in_bytes":6722},{"relative_path":"references/platform-apis.md","size_in_bytes":3876},{"relative_path":"references/runtime-patterns.md","size_in_bytes":13872},{"relative_path":"references/skill-feedback.md","size_in_bytes":2823}]},{"path":"/skill_md_contents","type":"changed","before":"---\nname: workers-best-practices\ndescription: Reviews and authors Cloudflare Workers code against production best practices. Load when writing new Workers, reviewing Worker code, configuring wrangler.jsonc, or checking for common Workers anti-patterns (streaming, floating promises, global state, secrets, bindings, observability). Biases towards retrieval from Cloudflare docs over pre-trained knowledge.\n---\n\nYour knowledge of Cloudflare Workers APIs, types, and configuration may be outdated. **Prefer retrieval over pre-training** for any Workers code task — writing or reviewing.\n\n## Retrieval Sources\n\nFetch the **latest** versions before writing or reviewing Workers code. Do not rely on baked-in knowledge for API signatures, config fields, or binding shapes.\n\n| Source | How to retrieve | Use for |\n|--------|----------------|---------|\n| Workers best practices | Fetch `https://developers.cloudflare.com/workers/best-practices/workers-best-practices/` | Canonical rules, patterns, anti-patterns |\n| Workers types | See `references/review.md` for retrieval steps | API signatures, handler types, binding types |\n| Wrangler config schema | `node_modules/wrangler/config-schema.json` | Config fields, binding shapes, allowed values |\n| Cloudflare docs | Search tool or `https://developers.cloudflare.com/workers/` | API reference, compatibility dates/flags |\n\n## FIRST: Fetch Latest References\n\nBefore reviewing or writing Workers code, retrieve the current best practices page and relevant type definitions. If the project's `node_modules` has an older version, **prefer the latest published version**.\n\n```bash\n# Fetch latest workers types\nmkdir -p /tmp/workers-types-latest && \\\n  npm pack @cloudflare/workers-types --pack-destination /tmp/workers-types-latest && \\\n  tar -xzf /tmp/workers-types-latest/cloudflare-workers-types-*.tgz -C /tmp/workers-types-latest\n# Types at /tmp/workers-types-latest/package/index.d.ts\n```\n\n## Reference Documentation\n\n- `references/rules.md` — all best practice rules with code examples and anti-patterns\n- `references/review.md` — type validation, config validation, binding access patterns, review process\n\n## Rules Quick Reference\n\n### Configuration\n\n| Rule | Summary |\n|------|---------|\n| Compatibility date | Set `compatibility_date` to today on new projects; update periodically on existing ones |\n| nodejs_compat | Enable the `nodejs_compat` flag — many libraries depend on Node.js built-ins |\n| wrangler types | Run `wrangler types` to generate `Env` — never hand-write binding interfaces |\n| Secrets | Use `wrangler secret put`, never hardcode secrets in config or source |\n| wrangler.jsonc | Use JSONC config for non-secret settings — newer features are JSON-only |\n\n### Request & Response Handling\n\n| Rule | Summary |\n|------|---------|\n| Streaming | Stream large/unknown payloads — never `await response.text()` on unbounded data |\n| waitUntil | Use `ctx.waitUntil()` for post-response work; do not destructure `ctx` |\n\n### Architecture\n\n| Rule | Summary |\n|------|---------|\n| Bindings over REST | Use in-process bindings (KV, R2, D1, Queues) — not the Cloudflare REST API |\n| Queues & Workflows | Move async/background work off the critical path |\n| Service bindings | Use service bindings for Worker-to-Worker calls — not public HTTP |\n| Hyperdrive | Always use Hyperdrive for external PostgreSQL/MySQL connections |\n\n### Observability\n\n| Rule | Summary |\n|------|---------|\n| Logs & Traces | Enable `observability` in config with `head_sampling_rate`; use structured JSON logging |\n\n### Code Patterns\n\n| Rule | Summary |\n|------|---------|\n| No global request state | Never store request-scoped data in module-level variables |\n| Floating promises | Every Promise must be `await`ed, `return`ed, `void`ed, or passed to `ctx.waitUntil()` |\n\n### Security\n\n| Rule | Summary |\n|------|---------|\n| Web Crypto | Use `crypto.randomUUID()` / `crypto.getRandomValues()` — never `Math.random()` for security |\n| No passThroughOnException | Use explicit try/catch with structured error responses |\n\n## Anti-Patterns to Flag\n\n| Anti-pattern | Why it matters |\n|-------------|----------------|\n| `await response.text()` on unbounded data | Memory exhaustion — 128 MB limit |\n| Hardcoded secrets in source or config | Credential leak via version control |\n| `Math.random()` for tokens/IDs | Predictable, not cryptographically secure |\n| Bare `fetch()` without `await` or `waitUntil` | Floating promise — dropped result, swallowed error |\n| Module-level mutable variables for request state | Cross-request data leaks, stale state, I/O errors |\n| Cloudflare REST API from inside a Worker | Unnecessary network hop, auth overhead, added latency |\n| `ctx.passThroughOnException()` as error handling | Hides bugs, makes debugging impossible |\n| Hand-written `Env` interface | Drifts from actual wrangler config bindings |\n| Direct string comparison for secret values | Timing side-channel — use `crypto.subtle.timingSafeEqual` |\n| Destructuring `ctx` (`const { waitUntil } = ctx`) | Loses `this` binding — throws \"Illegal invocation\" at runtime |\n| `any` on `Env` or handler params | Defeats type safety for all binding access |\n| `as unknown as T` double-cast | Hides real type incompatibilities — fix the design |\n| `implements` on platform base classes (instead of `extends`) | Legacy — loses `this.ctx`, `this.env`. Applies to DurableObject, WorkerEntrypoint, Workflow |\n| `env.X` inside platform base class | Should be `this.env.X` in classes extending DurableObject, WorkerEntrypoint, etc. |\n\n## Review Workflow\n\n1. **Retrieve** — fetch latest best practices page, workers types, and wrangler schema\n2. **Read full files** — not just diffs; context matters for binding access patterns\n3. **Check types** — binding access, handler signatures, no `any`, no unsafe casts (see `references/review.md`)\n4. **Check config** — compatibility_date, nodejs_compat, observability, secrets, binding-code consistency\n5. **Check patterns** — streaming, floating promises, global state, serialization boundaries\n6. **Check security** — crypto usage, secret handling, timing-safe comparisons, error handling\n7. **Validate with tools** — `npx tsc --noEmit`, lint for `no-floating-promises`\n8. **Reference rules** — see `references/rules.md` for each rule's correct pattern\n\n## Scope\n\nThis skill covers Workers-specific best practices and code review. For related topics:\n\n- **Durable Objects**: load the `durable-objects` skill\n- **Workflows**: see [Rules of Workflows](https://developers.cloudflare.com/workflows/build/rules-of-workflows/)\n- **Wrangler CLI commands**: load the `wrangler` skill\n\n## Principles\n\n- **Be certain.** Retrieve before flagging. If unsure about an API, config field, or pattern, fetch the docs first.\n- **Provide evidence.** Reference line numbers, tool output, or docs links.\n- **Focus on what developers will copy.** Workers code in examples and docs gets pasted into production.\n- **Correctness over completeness.** A concise example that works beats a comprehensive one with errors.\n","after":"---\nname: workers-best-practices\ndescription: Cloudflare Workers best practices for production applications. Use when writing, reviewing, or configuring Workers.\n---\n\nYour knowledge of Cloudflare Workers APIs, types, and configuration may be outdated. **Prefer retrieval over pre-training** when writing or reviewing Workers code.\n\nUse the project's installed versions, generated types, and Wrangler compatibility settings as the baseline for existing code. Retrieve relevant Cloudflare documentation to verify API, configuration, runtime behavior, and limit claims.\n\n## References\n\nRead the sections relevant to the task:\n\n| Reference | When to use it |\n|-----------|----------------|\n| [Configuration and observability](references/configuration.md) | Compatibility dates, bindings, generated types, secrets, logs, and traces |\n| [Runtime patterns](references/runtime-patterns.md) | Streaming, promise lifetime, request state, service calls, security, and runtime tests |\n| [Platform API checks](references/platform-apis.md) | Handler signatures, platform classes, binding access, and serialization |\n\nFor missing evidence, consult [Workers best practices](https://developers.cloudflare.com/workers/best-practices/workers-best-practices/index.md) or find the affected product in the [Cloudflare docs directory](https://developers.cloudflare.com/directory/index.md). Use the installed Wrangler schema for config fields. A newer type package does not supersede the project's configured target.\n\n## Keep Compatibility Dates Current\n\nUse today's date for new Workers. Encourage periodic updates for existing Workers, reviewing compatibility changes and running relevant tests. Assess existing behavior against its configured date and flags; see [compatibility guidance](references/configuration.md#keep-compatibility_date-current).\n\n## Enable Observability\n\nEnable [Workers Logs](https://developers.cloudflare.com/workers/observability/logs/workers-logs/index.md) and [Traces](https://developers.cloudflare.com/workers/observability/traces/index.md) when creating or preparing a Worker for production. Set `observability.enabled` and `observability.traces.enabled` to `true`; the top-level setting alone does not enable traces. Use structured JSON logging and configure sampling for the workload. During reviews, flag missing logs or traces. See the [configuration example](references/configuration.md#enable-workers-logs-and-traces).\n\n## Place Compute Near Regional Databases\n\nFor Workers that make multiple sequential queries to one regional database, configure explicit placement matching the database's provider and region before deployment. Ask for missing location information, preserve existing placement choices, and verify handler eligibility and deployed request duration. See [database placement](references/configuration.md#place-compute-near-regional-databases).\n\n## Anti-Patterns to Flag\n\n| Anti-pattern | Consequence and preferred pattern |\n|-------------|-----------------------------------|\n| `await response.text()` or similar buffering on unbounded data | Can exhaust Worker memory; [stream large or unbounded bodies](references/runtime-patterns.md#stream-request-and-response-bodies). |\n| Hardcoded secrets in source or config | Leaks credentials through version control; use Wrangler secrets. |\n| `Math.random()` for security-sensitive tokens or IDs | Predictable values; use `crypto.randomUUID()` or `crypto.getRandomValues()`. |\n| Async work started without awaiting, returning, or attaching it to `ctx.waitUntil()` | Work can be dropped and errors missed; tie it to the request or background-work lifetime. |\n| Module-level mutable request state | Leaks data across requests and can cause I/O ownership errors; pass request state explicitly. |\n| Cloudflare REST API calls for operations available through Worker bindings | Adds network and authentication overhead; use the available binding. |\n| `ctx.passThroughOnException()` used as general error handling | Can conceal Worker failures by forwarding to the origin; use explicit error handling and structured error responses. |\n| Hand-written `Env` that duplicates Wrangler bindings | Can drift from configuration; generate binding types with `wrangler types`. |\n| Direct string comparison of secret values | Can expose timing differences; use the [Web Crypto comparison pattern](references/runtime-patterns.md#use-web-crypto-for-secure-token-generation). |\n| Destructuring `ctx` methods, such as `const { waitUntil } = ctx` | Loses the receiver; call `ctx.waitUntil(...)`. |\n| `any` on `Env` or handler parameters | Hides binding and handler contract errors; use the project's generated and platform types. |\n| `as unknown as T` to force a platform type match | Hides incompatibilities; fix the underlying contract. |\n| `implements` used in place of extending a platform base class | Does not inherit runtime behavior, `this.ctx`, or `this.env`; use the appropriate base class. |\n| Unbound `env.X` in a platform class method | Bindings are available through `this.env.X`; see [binding access patterns](references/platform-apis.md#binding-access--the-most-common-error). |\n| Applying one serialization rule across Queues, Workflow steps, storage, and WebSockets | Can reject valid payloads or accept unsupported ones; check the [specific API and encoding](references/platform-apis.md#serialization-boundaries). |\n\n## Validation\n\nUse the project's existing checks for affected Workers behavior: type-check binding or handler contract changes, and run relevant runtime tests for behavior changes. Preserve required repository checks; a narrow edit does not require a full Workers audit.\n\n## Scope\n\nThis skill covers Workers-specific best practices and code review. For related topics:\n\n- **Durable Objects**: load the `durable-objects` skill\n- **Workflows**: see [Rules of Workflows](https://developers.cloudflare.com/workflows/build/rules-of-workflows/index.md)\n- **CLI commands**: load the `cf-cli` skill, or the `wrangler` skill in a project with a Wrangler configuration file\n\n## Skill feedback\n\nIf the user reports that this skill gave incorrect or outdated guidance, or is missing information, read [references/skill-feedback.md](references/skill-feedback.md).\n"}],"summary":"Fields changed: 3. /description, /included_files, /skill_md_contents.","summary_kind":"deterministic","summary_metadata":{}}