Skip to content

Instantly share code, notes, and snippets.

View igalshilman's full-sized avatar

Igal Shilman igalshilman

View GitHub Profile
@igalshilman
igalshilman / app.ts
Last active June 25, 2026 10:36
Restate + OpenAI: durably stream structured JSON (JSONL) agent events. Each line is parsed into a typed AgentEvent and journaled via durableSource, so replay never re-calls the model.
import {
Operation,
object,
run,
} from "@restatedev/restate-sdk-gen";
import { serve } from "@restatedev/restate-sdk";
import OpenAI from "openai";
import * as utils from "./utils";
const openai = new OpenAI(); // reads OPENAI_API_KEY from the environment
@igalshilman
igalshilman / app.ts
Created June 24, 2026 19:07
Restate signal-stream example: an agent VO consuming an LLM service's output chunk-by-chunk via durable signals
import {
Operation,
object,
service,
invocation,
sendClient,
handlerRequest,
run,
} from "@restatedev/restate-sdk-gen";
import { serve, InvocationId } from "@restatedev/restate-sdk";

Effect Handlers in TypeScript

OCaml-style algebraic effects built on TypeScript generators. The fiber holds the iterator and a small state machine. The continuation is a one-shot, safety-checked handle. The handler is an async scheduler that drains synchronously-runnable work and parks while external wakers are pending.

Three pieces, each with one job:

  • Fiber<T> — iteration state machine

restate-sdk-gen internals: fibers, the scheduler, and the stack

A walkthrough of how user generators, fibers, and the scheduler interact in @restatedev/restate-sdk-gen. Aimed at JS engineers who already know Restate and durable execution; we skip framing on journals/replay and focus on the runtime model.

Source files referenced throughout:

  • src/scheduler.ts — orchestration

RocksDB SIGTRAP on Apple Silicon: Hardened libc++ vs Custom Aligned Allocators

Summary

RocksDB crashes with SIGTRAP (EXC_BREAKPOINT, brk #0x1) on Apple Silicon (aarch64-apple-darwin) when statistics are enabled. The crash occurs inside StatisticsImpl::recordTick or StatisticsImpl::recordInHistogram during normal database operations, including DB::Open.

The root cause is an incompatibility between Apple Clang's hardened libc++ bounds checking and RocksDB's custom cache-line-aligned allocator used by StatisticsData.

Symptoms

R = typing.TypeVar('R', bound=typing.Callable[..., typing.Awaitable[typing.Any]])
P = typing.ParamSpec('P'
def handler(func):
func._is_handler = True
return func
class Box:
__slots__ = ('value',)
import {
service,
serve,
type Context,
RestatePromise,
TerminalError,
} from "@restatedev/restate-sdk";
/***
* A durable async generator that persists its state across restarts.
import {
ObjectContext,
Rand,
service,
TerminalError,
type Context,
} from "@restatedev/restate-sdk";
class CircuitBreakerState {
constructor(
from fastapi import FastAPI
import restate
app = FastAPI()
@app.get("/")
async def foo():
return { "foo" : "bar" }
import { service, type Context } from "@restatedev/restate-sdk";
interface ServiceB {
greet: (ctx: Context, name: string) => Promise<string>;
}
const realServiceB = service({
name: "realServiceB",
handlers: {