resonate-saga-pattern-java

resonate-saga-pattern-java is a skill for Claude Code, Codex from resonatehq/resonate-skills. It costs 111 tokens per session (2,765 once invoked), scanned A, original, Apache-2.0.

A Java implementation of the saga pattern for Resonate workflows. A saga is a long-running transaction split into steps, with an undo action for each step if a later step fails.

In plain words
What is it for?
Use it for multi-step Java workflows that need consistency across failures. It shows how to track steps, handle failure with try/catch, choose compensations, and configure retries.
Why use it?
It helps coordinate work across services when one transaction cannot cover every operation. Failed workflows can reverse completed actions in the opposite order.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it for multi-step Java workflows that need consistency across failures. It shows how to track steps, handle failure with try/catch, choose compensations, and configure retries.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/resonatehq/resonate-skills/resonate-saga-pattern-java
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add resonatehq/resonate-skills --skill resonate-saga-pattern-java
Clone the repo
git clone --depth 1 https://github.com/resonatehq/resonate-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for resonate-saga-pattern-java

README.md
[![agentmods](https://agentmods.dev/badge/skills/resonatehq/resonate-skills/resonate-saga-pattern-java/github.svg)](https://agentmods.dev/skills/resonatehq/resonate-skills/resonate-saga-pattern-java)
Your own site
<a href="https://agentmods.dev/skills/resonatehq/resonate-skills/resonate-saga-pattern-java"><img src="https://agentmods.dev/badge/skills/resonatehq/resonate-skills/resonate-saga-pattern-java/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for resonate-saga-pattern-java

Your own site · 80×15
<a href="https://agentmods.dev/skills/resonatehq/resonate-skills/resonate-saga-pattern-java"><img src="https://agentmods.dev/badge/skills/resonatehq/resonate-skills/resonate-saga-pattern-java.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 111 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,765 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00111 $0.02765
Opus 5 $0.00056 $0.01383
Sonnet 5 $0.00022 $0.00553
Haiku 4.5 $0.00011 $0.00277

Measured 9d ago against content hash cd72832ea609, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

Grade A, and why

resonate-saga-pattern-java scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 9d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

resonate-saga-pattern-java/SKILL.md · 186 lines

How it starts

The opening of the file, as written. The whole thing — 186 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Resonate Saga Pattern — Java

Prerelease note. resonate-sdk-java is published on Maven Central — pin io.resonatehq:resonate-sdk-java:0.1.1. The API mirrors the Python SDK and may change before a stable 1.0. Requires Java 21+ (virtual threads, a feature generally available in Java 21). There is no Java saga example repo yet, so every code block here uses only documented SDK surface, compile-verified against 0.1.1 and cross-checked against develop/java.mdx (docs PR #230) and the SDK source.

Overview

A saga is a long-running transaction split into discrete steps, each with a compensating action. Forward steps execute top-to-bottom; on any failure, completed compensations run bottom-to-top. Because the whole workflow body re-runs on resume, the completed list is reconstructed deterministically on replay — each ctx.run short-circuits its settled durable promise in the same order, so the list is rebuilt identically before reaching the point of failure.

Java's exception model makes the saga read more like the TypeScript/Python idiom than Go's: the forward path lives in a try block, and a single catch triggers compensation — there is no per-step (T, error) check to thread by hand.

For the language-agnostic mental model — choreography vs orchestration, idempotency requirements, when not to use sagas — see resonate-saga-pattern-typescript.

When to use

  • Multi-step workflow where intermediate state is visible to other systems between steps
  • Each step is individually compensable (inventory hold, payment charge, shipment create)
  • You need "all or nothing" consistency without a distributed 2PC transaction
  • Steps span services and may take seconds to minutes each
  • Compensation logic exists and is idempotent for every committed step

Basic shape

package io.resonatehq.examples.saga;

import io.resonatehq.resonate.Context;
import io.resonatehq.resonate.Context.Opts;
import io.resonatehq.resonate.Handle.ResonateHandle;
import io.resonatehq.resonate.Resonate;
import io.resonatehq.resonate.Retry.Exponential;
import java.util.ArrayList;
import java.util.List;

public final class Saga {
    private Saga() {}

    /** The forward steps that can be committed; the enum + switch gives closed-set compensation dispatch. */
    public enum Step { INVENTORY, PAYMENT, SHIPMENT }

    public record SagaResult(String status, String orderId, List<String> compensated) {}

    /**
     * The saga orchestrator. Forward steps run in sequence inside a try; the first failure throws,
     * and the catch runs compensations in reverse. Each ctx.run is a durable checkpoint, so a
     * crash mid-saga resumes from the last settled step — committed steps do not re-execute.
     */
    public static SagaResult placeOrder(Context ctx, String orderId) {
        List<Step> completed = new ArrayList<>();
        try {
            ctx.run(Saga::reserveInventory, orderId).await();
            completed.add(Step.INVENTORY);

            ctx.run(Saga::chargePayment, orderId).await();
            completed.add(Step.PAYMENT);

            ctx.run(Saga::createShipment, orderId).await();
            completed.add(Step.SHIPMENT);

            return new SagaResult("success", orderId, List.of());
        } catch (Exception forwardErr) {
            // await() sneaky-throws the rejection, which may be unchecked OR a sneakily-rethrown
            // checked exception — catch Exception so no failure path slips past the compensator.
            return compensateAll(ctx, orderId, completed);
        }
    }

    /** Iterate completed steps in reverse, running each compensation as its own durable ctx.run. */
    public static SagaResult compensateAll(Context ctx, String orderId, List<Step> completed) {
        List<String> names = new ArrayList<>();
        for (int i = completed.size() - 1; i >= 0; i--) {
            Step step = completed.get(i);
            // A compensation that exhausts retries is a real inconsistency — give it a generous policy.
            ctx.options(new Opts().withRetryPolicy(new Exponential(1, 5, 2, 30)))
                    .run(Saga::compensate, step, orderId)
                    .await();
            names.add(step.name());
        }
        return new SagaResult("failed", orderId, names);
    }

    /** Dispatch to the correct undo action via a switch. Each branch must be idempotent. */
    public static String compensate(Context ctx, Step step, String orderId) {
        return switch (step) {
            case SHIPMENT -> "shipment-cancelled:" + orderId;   // cancelShipment(orderId)
            case PAYMENT -> "payment-refunded:" + orderId;      // refundPayment(orderId)
            case INVENTORY -> "inventory-released:" + orderId;  // releaseInventory(orderId)
        };
    }

    // Forward leaf stubs — replace with real service calls.
    public static String reserveInventory(Context ctx, String orderId) {
        return "reserved:" + orderId;
    }

    public static String chargePayment(Context ctx, String orderId) {
        return "charged:" + orderId;
    }

    public static String createShipment(Context ctx, String orderId) {
        // Simulate a transient failure to trigger compensation.
        throw new IllegalStateException("shipment service unavailable");
    }

    public static void main(String[] args) {
        Resonate r = Resonate.builder().url("http://localhost:8001").build();
        r.register(Saga::placeOrder);
        try {
            ResonateHandle<SagaResult> handle = r.run("order-1", Saga::placeOrder, "order-1");
            System.out.println(handle.result());
        } finally {
            r.stop();
        }
    }
}

Read the full file on GitHub · 186 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 9d ago First seen · 186 lines · 111 tokens per session scan A cd72832ea609

Subscribe to this mod's changes

resonate-saga-pattern-java is a skill published in the GitHub repository resonatehq/resonate-skills (6 stars, last pushed 18d ago), licensed Apache-2.0. It adds 111 tokens to every session and 2,765 once invoked, about $0.0006 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

springboot-patterns

Provides Spring Boot architecture patterns for REST APIs, layered services, JPA data access, caching, async processing, and logging. Use when working with Java Spring Boot files (.java, pom.xml) or when the user mentions Spring Boot, Spring Framework, or Java backend.

tranhieutt/software_development_department · 59 tokens

wxjava-api-contributor

A contributor guide for adding or maintaining official WeChat API support in WxJava, a Java software development kit. It covers services, request and response data objects, data conversion, HTTP handling, starter configuration, and regression tests.

binarywang/WxJava · 68 tokens

azure-communication-callautomation-java

Build call automation workflows with Azure Communication Services Call Automation Java SDK. Use when implementing IVR systems, call routing, call recording, DTMF recognition, text-to-speech, or AI-powered call flows.

microsoft/skills · 49 tokens

azure-communication-chat-java

Build real-time chat applications with Azure Communication Services Chat Java SDK. Use when implementing chat threads, messaging, participants, read receipts, typing notifications, or real-time chat features.

microsoft/skills · 41 tokens

azure-communication-common-java

Azure Communication Services common utilities for Java. Use when working with CommunicationTokenCredential, user identifiers, token refresh, or shared authentication across ACS services.

microsoft/skills · 35 tokens

azure-communication-sms-java

Send SMS messages with Azure Communication Services SMS Java SDK. Use when implementing SMS notifications, alerts, OTP delivery, bulk messaging, or delivery reports.

microsoft/skills · 36 tokens