golem-add-transactions-scala

Implements saga-pattern transactions with compensation logic in Scala Golem agents.

1.5k|212|Updated Nov 24, 2023
One-click install
npx skills add https://github.com/golemcloud/golem --skill golem-add-transactions-scala
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golem-add-transactions-scala
Source: https://github.com/golemcloud/golem/tree/main/golem-skills/skills/scala/golem-add-transactions-scala
Command: npx skills add https://github.com/golemcloud/golem --skill golem-add-transactions-scala

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Multi-step operations in distributed agents need undo logic when a step fails partway through. This Skill shows how to add saga-pattern transactions to a Scala Golem agent so completed steps are automatically compensated in reverse order on failure.

Core Features & Use Cases

  • Operation Definition: Create operations with async execute and compensate functions returning Future[Either[Err, Out]], including correct conversion of JS Promises via FutureInterop.fromPromise.
  • Fallible Transactions: Use Transactions.fallibleTransaction to compensate completed steps and return the error when failure is an acceptable outcome.
  • Infallible Transactions: Use Transactions.infallibleTransaction to compensate and retry the entire transaction until it succeeds.
  • Use Case: Build an order-processing agent that reserves inventory and then charges payment; if charging fails, the inventory reservation is automatically rolled back.

Quick Start

Add a saga transaction to my Scala Golem agent that reserves inventory and charges a payment with automatic compensation on failure.

Frequently Asked Questions about golem-add-transactions-scala

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add transactions to a Scala Golem agent?

Define operations with Transactions.operation, providing an async execute function and an async compensate function. Then run them inside Transactions.fallibleTransaction or Transactions.infallibleTransaction using tx.execute for each step.

What is the difference between fallible and infallible transactions in Golem?

A fallible transaction compensates completed steps and returns the error when a step fails. An infallible transaction compensates completed steps and then retries the entire transaction until it eventually succeeds.

How do I use JavaScript Promises inside Golem transaction operations?

Convert the JS Promise to a Scala Future with FutureInterop.fromPromise and chain it with map or flatMap. Never fire a Promise and ignore the result, because that breaks operation ordering and compensation determinism.

Why must compensation logic be idempotent in saga transactions?

Compensation functions may be called more than once, especially when infallible transactions retry. Writing idempotent compensation ensures repeated undo calls do not corrupt state or cause additional failures.

When should I use the saga pattern instead of a single atomic operation?

Use sagas when an operation spans multiple independent steps or external services that cannot share one atomic commit. Each step gets its own compensation action, and completed steps are undone in reverse order if a later step fails.