$ show temporalio/sdk-ruby
This is the official Temporal Ruby SDK (temporalio gem) for building durable workflow and activity applications on the Temporal platform. It provides a full client and worker implementation, allowing Ruby applications to start, signal, query, update, and cancel workflows, as well as define and execute activities. The SDK uses a Rust native extension (bridge) to interface with the Temporal Core SDK for performance-critical operations like polling and metric buffering, and relies on generated protobuf definitions for all API types. Architecture is library-based: users define workflow and activity classes using declarative DSL annotations, and the SDK handles lifecycle, determinism enforcement, replay, and interceptor chains for extensibility. The codebase demonstrates high craftsmanship with clean abstractions for cancellation tokens, future combinators, fiber-based deterministic scheduling, illegal call detection via TracePoint, and pluggable payload converters and codecs. It includes comprehensive test suites covering workflows, activities, versioning, OpenTelemetry tracing, and cloud integration. The SDK is actively maintained with frequent releases, CI/CD pipelines, and type signature coverage enforcement via both RBI and RBS files. While the generated protobuf code is voluminous and requires regeneration on API updates, the core Ruby code is well-structured and modular, making this a strong example of a production-grade SDK for distributed orchestration.
The LLM identified 4 files worth highlighting for reuse:
Implements a Future class with combinators (any_of, all_of, try_any_of, try_all_of) for coordinating asynchronous workflow operations. Each future wraps a Fiber that yields, and combinators create new futures that complete when any or all of their children complete. This is a clean, reusable implementation of the promise/future pattern adapted for Ruby's Fiber-based concurrency in a deterministic workflow context.
Provides a Cancellation token with parent-child derivation, callback registration, shielding (to temporarily ignore cancellation), and waiting for cancellation. The token can be cancelled with an optional reason. This is a textbook implementation of the Cancellation Token pattern, fully isolated and reusable for any Ruby application needing cooperative cancellation.
Uses Ruby's TracePoint to intercept method calls on classes like Time, Thread, Mutex, Random, and IO during workflow execution, raising errors if non-deterministic calls are made outside of allowed contexts. It provides an Unsafe escape hatch to bypass checks when needed. This is a clever, self-contained mechanism for enforcing deterministic constraints in a dynamic language, reusable for any Ruby code requiring deterministic replay.
Implements a custom Fiber::Scheduler that provides deterministic concurrency for workflow instances. It handles fiber lifecycle, wait conditions, timers, thread-blocking fiber support, and deadlock detection with timeout. The scheduler uses a priority queue for timers and a condition variable for signaling. This is a sophisticated, self-contained scheduler that could be extracted and adapted for other Ruby applications needing controlled concurrency.