Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/workflows/gotchas.md
1# Gotchas & Debugging23## Common Errors45### "Step Timeout"67**Cause:** Step execution exceeding the default or configured timeout8**Solution:** Set custom timeout with `step.do('long operation', {timeout: '30 minutes'}, async () => {...})` or increase CPU limit via `limits.cpu_ms` in wrangler.jsonc910### "waitForEvent Timeout"1112**Cause:** Event not received within timeout period (check docs for default/max)13**Solution:** Wrap in try-catch to handle timeout gracefully and proceed with default behavior1415### "Non-Deterministic Step Names"1617**Cause:** Using dynamic values like `Date.now()` in step names causes replay issues18**Solution:** Use deterministic values like `event.instanceId` for step names1920### "State Lost in Variables"2122**Cause:** Using module-level or local variables to store state which is lost on hibernation23**Solution:** Return values from `step.do()` which are automatically persisted: `const total = await step.do('step 1', async () => 10)`2425### "Non-Deterministic Conditionals"2627**Cause:** Using non-deterministic logic (like `Date.now()`) outside steps in conditionals28**Solution:** Move non-deterministic operations inside steps: `const isLate = await step.do('check', async () => Date.now() > deadline)`2930### "Large Step Returns Exceeding Limit"3132**Cause:** Returning data exceeding the per-step return size limit33**Solution:** Store large data in R2 and return only reference: `{ key: 'r2-object-key' }`. Alternatively, return a `ReadableStream<Uint8Array>` for large binary output3435### "Step Exceeded CPU Limit But Ran for a Short Time"3637**Cause:** Confusion between CPU time (active compute) and wall-clock time (includes I/O waits)38**Solution:** Network requests, database queries, and sleeps don't count toward CPU. The CPU limit refers to active processing time only3940### "Idempotency Violation"4142**Cause:** Step operations not idempotent, causing duplicate charges or actions on retry43**Solution:** Check if operation already completed before executing (e.g., check if customer already charged)4445### "Instance ID Collision"4647**Cause:** Reusing instance IDs causing conflicts48**Solution:** Use unique IDs with timestamp: `await env.MY_WORKFLOW.create({ id: \`${userId}-${Date.now()}\`, params: {} })`4950### "Instance Data Disappeared After Completion"5152**Cause:** Completed/errored instances are automatically deleted after the retention period (differs by plan)53**Solution:** Export critical data to KV/R2/D1 before workflow completes5455### "Missing await on step.do"5657**Cause:** Forgetting to await step.do() causing fire-and-forget behavior58**Solution:** Always await step operations: `await step.do('task', ...)`5960### "Provided event type is invalid"6162**Cause:** Using unsupported characters in `waitForEvent` type (e.g. `.`)63**Solution:** Type only supports letters, digits, `-`, and `_`. Pattern: `^[a-zA-Z0-9_][a-zA-Z0-9-_]*$`6465## Limits & Pricing6667Limits and pricing change over time. **Always fetch the latest values** from the official docs before citing specific numbers:6869- **Limits:** https://developers.cloudflare.com/workflows/reference/limits/70- **Pricing:** https://developers.cloudflare.com/workflows/reference/pricing/7172Key areas to check: CPU time per step, max steps per workflow, concurrent instance limits, step return size, event payload size, instance creation rate, subrequest limits, state retention period, and name/ID length constraints.7374**Behavioral notes** (stable, not subject to number changes):75- `step.sleep()` and `step.waitForEvent()` don't count toward the max steps limit76- Instances in `waiting` state (sleeping, waiting for event, waiting for retry) don't count toward the concurrent instance limit77- CPU time is active processing only — network I/O, DB queries, and sleeps are wall-clock time, not CPU time78- `waitForEvent` type and workflow/instance names follow pattern `^[a-zA-Z0-9_][a-zA-Z0-9-_]*$`7980## References8182- [Official Docs](https://developers.cloudflare.com/workflows/)83- [Get Started Guide](https://developers.cloudflare.com/workflows/get-started/guide/)84- [Workers API](https://developers.cloudflare.com/workflows/build/workers-api/)85- [REST API](https://developers.cloudflare.com/api/resources/workflows/)86- [Examples](https://developers.cloudflare.com/workflows/examples/)87- [Limits](https://developers.cloudflare.com/workflows/reference/limits/)88- [Pricing](https://developers.cloudflare.com/workflows/reference/pricing/)8990See: [README.md](./README.md), [configuration.md](./configuration.md), [api.md](./api.md), [patterns.md](./patterns.md)91