Skip to content

upstash/workflow-js / skills

upstash-workflow-js

Unverified

Lightweight guidance for using the Upstash Workflow SDK to define, trigger, and manage workflows. Use this Skill whenever a user wants to create workflow endpoints, run steps, or interact with the Upstash Workflow client.

FileKindSize
SKILL.mdskill md2.2 KB
agents.mdmarkdown6.7 KB
basics/client.mdmarkdown4.1 KB
basics/context.mdmarkdown5.1 KB
basics/serve.mdmarkdown2.4 KB
features/flow-control.mdmarkdown3.9 KB
features/invoke.mdmarkdown2.6 KB
features/retries-failures-reliability.mdmarkdown6.3 KB
features/wait-for-event.mdmarkdown2.8 KB
features/webhooks.mdmarkdown2.5 KB
how-to/local-dev.mdmarkdown3.2 KB
how-to/middleware.mdmarkdown4.7 KB
how-to/migrations.mdmarkdown4.8 KB
how-to/realtime.mdmarkdown4.8 KB
rest-api.mdmarkdown6.6 KB
troubleshooting.mdmarkdown4.8 KB

features/webhooks.md

View on GitHub
## Webhooks

This skill teaches agents how to use webhooks inside Upstash Workflow to pause execution, wait for external callbacks, and resume reliably. It covers creation, waiting, validation, and multi-step usage.

---

### Key Concepts

• **Webhook URLs are unique per context.createWebhook() call**.
• **Workflow execution pauses** when calling `context.waitForWebhook()` until the webhook receives a request or times out.
• **Lookback protection** ensures the workflow still receives early webhook calls.
• **Workflows remain dormant** during the waiting period, avoiding compute cost.
• **Webhooks are ideal for third‑party APIs** that support callback URLs.

---

### Core Workflow: Create → Call External API → Wait → Resume

Below is a consolidated example showing:
• Creating a webhook
• Passing it to an external API
• Handling the callback
• Waiting for multiple updates
• Error/timeout handling

```ts
import { serve } from "@upstash/workflow/nextjs";

export const { POST } = serve(async (context) => {
  // Create a unique webhook for this workflow
  const webhook = await context.createWebhook("create webhook");

  // Trigger an external service, sending it the callback URL
  await context.call("trigger-external", {
    url: "https://api.example.com/process",
    method: "POST",
    body: { webhookUrl: webhook.webhookUrl },
  });

  // Loop: wait for progress updates until service signals completion
  let updates = [];
  while (true) {
    const res = await context.waitForWebhook(`wait update`, webhook, "5m");

    if (res.timeout) break; // no progress received

    const req = res.request;
    const payload = await req.json();
    updates.push(payload);

    if (req.headers.get("x-task-finished") === "true") break;
  }

  return updates;
});
```

---

### Webhook Reliability: Lookback Protection

**Common pitfall:** external systems may call the webhook _before_ the workflow reaches `waitForWebhook()`.

Upstash automatically stores early webhook calls. The next `waitForWebhook()` will immediately resolve with the stored request.

This avoids race conditions and eliminates the need for manual buffering.

---

### When to Use Webhooks vs. Wait for Event

Use **webhooks** when:
• integrating with third‑party APIs
• the external system invokes a callback URL
• you need race‑condition‑safe behavior

Use **Wait for Event** when:
• you control the notifying system and can use the Workflow Client
• you don't need lookback semantics
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 470kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall