golem-atomic-block-scala

Implement atomic blocks, idempotency controls, and checkpoints in Scala Golem agents.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

When building durable Golem agents in Scala, developers need to control how external side effects (HTTP calls, payments, cross-agent calls) behave across crashes and recovery. Without proper controls, a crash between two external calls can leave systems in an inconsistent state, and non-idempotent operations may be duplicated or lost.

Core Features & Use Cases

  • Atomic Blocks: Group multiple external side effects with Guards.atomically so the entire block replays together after a crash, preventing partial execution states.
  • Idempotence Mode & Keys: Control whether HTTP requests are treated as idempotent with Guards.withIdempotenceMode, and generate durable idempotency keys via HostApi.generateIdempotencyKey for exactly-once payment operations.
  • Checkpoints & Oplog Commit: Capture oplog positions with Checkpoint and revert on failure, or wait for oplog replication with HostApi.oplogCommit before proceeding.
  • Use Case: When processing an order, wrap the inventory reservation and payment charge in Guards.atomically so that if the agent crashes between them, recovery re-runs both calls together instead of leaving a reservation without a charge.

Quick Start

Show me how to wrap an inventory reservation and payment charge in an atomic block in my Scala Golem agent so both replay together after a crash.

Frequently Asked Questions about golem-atomic-block-scala

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

FAQPage Schema
How do I use atomic blocks in a Scala Golem agent?▼

Wrap external side effects in Guards.atomically with a Future-returning block. If the agent crashes mid-block, recovery re-executes the entire block from the start, so all grouped external calls replay together instead of resuming from the middle.

How do I make HTTP requests idempotent in Golem Scala?▼

Idempotence mode defaults to true, so all HTTP requests including POST are already treated as idempotent and retriable. Use Guards.withIdempotenceMode(false) only to opt out for non-idempotent calls where duplication is more harmful than missing the call.

When should I not use Guards.atomically in Golem?▼

Do not use atomically for in-memory state mutations, since oplog replay already rebuilds state deterministically. It also does not reduce oplog size or speed up recovery; use snapshot-based recovery instead for long-running agents.

How do I generate an idempotency key for payment APIs in Golem?▼

Call HostApi.generateIdempotencyKey() to create a durable idempotency key that persists across agent restarts. Pass this key to external payment APIs to ensure exactly-once processing even if the agent crashes and recovers.

What is the difference between Checkpoint tryOrRevert and runOrRevert?▼

tryOrRevert reverts to the checkpoint if the Future fails with an exception, while runOrRevert reverts if the Future resolves to a Left value. Scoped variants Checkpoint.withCheckpointTry and Checkpoint.withCheckpoint provide the same behavior within a closure.