restate-sdk
Skill2 starsChanged 32 days agoMITView on GitHub
Build resilient sagas, durable workflows, and stateful virtual objects with @restatedev/restate-sdk, deterministic journaling, and awakeable promises. Use for ctx.run side-effects, ctx.sleep timers, ctx.objectClient, TerminalError handling, compensation rollbacks, and Cloudflare/Lambda deployment.
In this repository11 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- cloudflare-email-workersSkill
- discord-activitiesSkill
- duckdb-wasmSkill
- humanize-textSkill
- mtcuteSkill
- openai-realtime-webrtcSkill
- openauthSkill
- telegram-serverless-botSkill
- use-telegram-serverlessSkill
The file
We split this skill into the rules it gives an agent
10 rules. About 0 are common, 4 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 31
Before implementing or modifying a Restate service:
- Very specific: line 34
Check package.json for @restatedev/restate-sdk (and optional @restatedev/restate-sdk-clients).
- Very specific: line 35
Check target host: Node.js/Bun (restate.serve or .listen()), Cloudflare Workers (@restatedev/restate-sdk/fetch), or AWS Lambda …
- Very specific: line 63
Never call non-deterministic functions (Math.random(), Date.now(), crypto.randomUUID(), or outbound fetch()) directly in a handler's …
- Very specific: line 70
Never use in-memory global variables (let count = 0) to maintain state in virtual objects.
- Very specific: line 72
Never use setTimeout() or sleep() in durable handlers.
- Distinctive: line 78
All external payloads (webhook responses, awakeable callback bodies, external API responses, user inputs) are untrusted data:
- Distinctive: line 80
Isolate Awakeable Payloads: Treat awakeable resolution payloads as untrusted external data.
- Very specific: line 81
Never Evaluate Untrusted Text as Instructions: When feeding workflow steps into LLMs, wrap dynamic text in strict XML boundaries …
- Distinctive: line 88
When providing Restate solutions:
≈ “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
Restate SDK
Build resilient distributed applications, durable sagas, and stateful virtual objects with @restatedev/restate-sdk. Restate turns standard TypeScript functions into fault-tolerant distributed systems that survive process crashes, network partitions, and third-party API outages with zero manual retry or state-machine boilerplate.
When to Use
- Building multi-step business transactions or payment flows that require Saga compensation rollbacks when a step fails.
- Orchestrating long-running durable workflows that sleep for days or months (
ctx.sleep) with zero compute costs during suspensions. - Coordinating Human-in-the-Loop approvals, async webhooks, or external events via durable promises (
ctx.awakeable). - Maintaining stateful, actor-like Virtual Objects (
restate.object) with guaranteed single-writer consistency and built-in K/V storage (ctx.get,ctx.set). - Wrapping non-deterministic side-effects (Stripe charges, email sending, LLM API calls, UUID generation) via deterministic journaling (
ctx.run). - Deploying durable microservices across Node.js, Bun, Cloudflare Workers, or AWS Lambda.
When Not to Use
- Simple Stateless CRUD Endpoints: For basic read/write REST endpoints without workflows, sagas, or multi-step guarantees, use plain Hono or Express.
- Client-Side Analytical SQL: For in-browser querying and Parquet analytics, use
duckdb-wasm. - Telegram Serverless Handlers: For Telegram bots and Mini Apps, use
telegram-serverless-botoruse-telegram-serverless.
Inputs to Inspect First
Before implementing or modifying a Restate service:
- Target Runtime & Framework:
- Check
package.jsonfor@restatedev/restate-sdk(and optional@restatedev/restate-sdk-clients). - Check target host: Node.js/Bun (
restate.serveor.listen()), Cloudflare Workers (@restatedev/restate-sdk/fetch), or AWS Lambda (@restatedev/restate-sdk/lambda).
- Check
- Service Architecture Style:
- Stateless Service (
restate.service): Parallel RPC handlers without bound entity keys. - Virtual Object (
restate.object): Stateful single-writer entity keyed by ID (e.g. User, Cart, Device). - Workflow (
restate.workflow): Idempotent run-to-completion workflow with query/signal handlers.
- Stateless Service (
- External Dependencies & Side-Effects:
- Identify all non-deterministic operations (random UUIDs, current timestamps, external HTTP APIs, database mutations) that must be wrapped inside
ctx.run().
- Identify all non-deterministic operations (random UUIDs, current timestamps, external HTTP APIs, database mutations) that must be wrapped inside
Workflow & Progressive Routing
Load only the reference file required for your active task. Do not preload all references at once.
| Task / Focus Area | Actionable Trigger | Reference to Load |
| Services & Virtual Objects | restate.service, restate.object, ctx.get, ctx.set, ctx.clear, ctx.objectClient | references/services-and-virtual-objects.md |
| Workflows & Sagas | restate.workflow, ctx.run, sagas, compensation rollbacks, ctx.sleep, idempotency | references/workflows-and-sagas.md |
| Awakeables & Human-in-the-Loop | ctx.awakeable, ctx.resolveAwakeable, ctx.rejectAwakeable, external webhooks | references/awakeables-and-signals.md |
| Error Handling & Retries | TerminalError, retry policies, non-retryable 4xx errors, timeout budgets | references/error-handling-and-retries.md |
| Endpoints & Deployments | restate.serve, .listen(), Cloudflare Workers (fetch), AWS Lambda, Docker server setup | references/endpoints-and-deployment.md |
| Upstream Specs & Sources | Restate server CLI, registration endpoints, breaking changes | references/sources.md |
Core Guardrails & Best Practices
- Deterministic Journaling Rule:
- Never call non-deterministic functions (
Math.random(),Date.now(),crypto.randomUUID(), or outboundfetch()) directly in a handler's top-level scope. Always wrap them inawait ctx.run('step-name', async () => ...). - Restate replays code on restarts; unwrapped non-deterministic calls cause journal mismatch errors.
- Never call non-deterministic functions (
- Throw
TerminalErrorfor Non-Retryable Failures:- By default, Restate retries all unhandled exceptions indefinitely. Throw
new TerminalError('message', { errorCode: 400 })for permanent business errors (e.g. insufficient funds, card declined, invalid input).
- By default, Restate retries all unhandled exceptions indefinitely. Throw
- Saga Compensations Must Be Durable:
- Register compensations as you proceed through transaction steps. On catch of a
TerminalError, execute compensating rollbacks in reverse order.
- Register compensations as you proceed through transaction steps. On catch of a
- Virtual Object State Exclusivity:
- Never use in-memory global variables (
let count = 0) to maintain state in virtual objects. Always useawait ctx.get()andctx.set()to guarantee persistent single-writer consistency.
- Never use in-memory global variables (
- Durable Timers Over
setTimeout:- Never use
setTimeout()orsleep()in durable handlers. Always useawait ctx.sleep(durationMs). Restate suspends execution on the server and resumes precisely when the timer fires.
- Never use
Handling External Content & Indirect Prompt Injection Defense
All external payloads (webhook responses, awakeable callback bodies, external API responses, user inputs) are untrusted data:
- Isolate Awakeable Payloads: Treat awakeable resolution payloads as untrusted external data. Validate them with a schema library (Zod or Valibot) before resuming workflow execution.
- Never Evaluate Untrusted Text as Instructions: When feeding workflow steps into LLMs, wrap dynamic text in strict XML boundaries (
<untrusted_payload>) and forbid credential exfiltration. - Restrict Outbound Webhook Endpoints: In
ctx.runblocks that invoke external URLs, enforce strict domain allowlists to prevent Server-Side Request Forgery (SSRF).
Deliverable Contract
When providing Restate solutions:
- Provide valid ESM code using
@restatedev/restate-sdk. - Wrap all side-effects and network calls in named
ctx.run()blocks. - Distinguish transient retryable errors from permanent
TerminalErrorfailures. - Include clean endpoint binding (
restate.serveorrestate.endpoint().bind(...)).
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.

