Ancora
A fault-tolerant runtime for durable AI workflows — kill any worker mid-run and prove nothing was lost
- Role
- Solo Developer
- Timeline
- Jul 2026 – Present
- Context
- Personal project · open source
The running system end to end — nothing mocked. Every graph is reconstructed from Temporal's real event history, and it closes by SIGKILLing a live worker mid-run and machine-checking that the run recovered correctly.
The outcome
- Chaos experiments that SIGKILL a live worker container mid-run and machine-check three invariants from Temporal history (run completed, no re-executed activities, exactly-once effects), with recovery time measured against an SLO.
- Kill detection cut from ~60s to ~6s (9.5×) by heartbeating activities under a short heartbeat timeout.
- Run DAGs reconstructed from event causality rather than timestamps: exact fan-out, live per-node state, retries collapsed, critical path highlighted.
- One unbroken OpenTelemetry trace from the API through workflow and activity to the compute call, carried across the Ray process boundary as a W3C traceparent in the payload.
- 284 passing tests, mypy --strict and ruff clean across the workspace; every subsystem ships a replay test and, where it touches failure, a chaos assertion.
- Tagged v0.1.0 and v0.1.1, with CodeQL, Dependabot and the OpenSSF Best Practices passing badge. The full stack (Temporal, Postgres, Redis, three worker replicas, scheduler, Jaeger, Prometheus, Grafana, dashboard) starts with one make up.
The challenge
A durable execution runtime for AI workflows. Temporal records every side-effecting step as an immutable event, Ray runs the heavy compute, and a pool of activity workers sits between them. If a worker dies mid-run, the workflow replays to exact state and a surviving worker finishes the job. Ancora is not an agent framework. It is the runtime that belongs underneath one.
AI pipelines lose work for boring reasons: an LLM call returns a 500, a GPU worker runs out of memory, a provider rate-limits, a pod is evicted. A multi-step, multi-dollar run disappears with no way to resume it. Durable execution fixes that in principle, but "kill a worker and the run survives" is easy to claim and hard to prove. The interesting failure is not the crash itself but whether an effect that was half-committed when the process died fires again on recovery.
The system
The FastAPI gateway starts and signals workflows on Temporal, which owns all execution state. Workflow workers poll their own queue and only decide what to schedule, because workflow code must replay deterministically; every node runs instead as a run_node activity on capability queues (cpu, io, gpu) served by three activity-worker replicas. Before a node starts, the activity asks the scheduler to admit, defer or reject it. A deferral becomes a retryable error with a backoff, so waiting work sits in Temporal history rather than in a scheduler queue, and the client fails open so a scheduler outage never halts the fleet. Side-effecting nodes reserve a key in a Postgres inbox before running, which turns at-least-once activities into exactly-once effects. Heavy compute goes to Ray, or an in-process thread pool when no cluster is configured, and long jobs use async completion so the worker's slot is freed at once. Observability is a separate, losable plane: an activity interceptor writes lifecycle events to per-run Redis Streams, the API tails them over WebSocket for the live DAG, and an event consumer projects them into Postgres while a reconciler re-derives run status from Temporal history. Losing Redis or Postgres projections costs liveness in the UI, never correctness.
The hard parts
Chaos experiments that assert instead of demonstrate
A demo that kills a worker and ends on a green checkmark proves nothing. The chaos engine asks the Docker daemon to SIGKILL a real activity-worker container mid-run, waits out the actual recovery, then checks three invariants from Temporal's own history and the inbox rows: the run completed, no completed activity ran twice, and no effect was left half-committed. Recovery time is measured against an SLO. The checkers are pure functions, so CI runs them against synthetic post-kill histories without a live cluster.
Reconstructing a run's DAG without timing heuristics
Workflows are ordinary Python that decide step by step what to schedule, so the graph is emergent and fan-out width comes from the input. Comparing timestamps to infer parallelism draws a fan-out as a plausible-looking chain. Ancora reads causality instead: every ActivityTaskScheduled event names the workflow task that commanded it, so activities sharing that id were decided together. The columns are exact, and with no layout library the graph never drifts between polls.
Temporal writes ActivityTaskStarted lazily
The started event for an attempt is only written once the attempt reaches a terminal state. An attempt running right now, including one stranded on a just-killed worker, is absent from history, so a history-only view draws it as still queued. The recovery view folds in describe().pending_activities and separates three waits that look identical from outside: queued for capacity, detecting a dead worker, and retry backoff.
Exactly-once has to survive a crash mid-effect
The inbox's unique key already makes two result rows for one effect impossible, so duplicates were never the real risk. A kill introduces the opposite case: an effect that reserved its key as pending, then lost its worker before committing the result. The chaos engine asserts every guarded effect reached done, so a half-committed effect fails the experiment instead of surfacing later as a double charge.
Durability is not liveness
Temporal keeps state safe through any worker death, but a stranded activity only finishes if some worker polls its queue, so fault tolerance had to become a pool of three replicas. Detection was the second half: without heartbeats a dead worker's activity is noticed only at start_to_close, up to 60 seconds. run_node now heartbeats every 2 seconds under a ~6 second timeout, which cut detection to about 6 seconds and exposed a policy that declared a 30-second heartbeat timeout nothing ever met. SIGKILL also skips deregistration, so a reaper prunes orphaned worker rows and a live worker re-registers if its row was reaped.
A chaos experiment: an activity worker is SIGKILLed mid-run, the run waits out detection, resumes from history, and the invariants are checked.
What I took from it
- A durability claim is worth nothing until something asserts it. Turning the demo into a test that checks invariants from history is the difference between a screenshot and a guarantee.
- Durability and liveness are separate properties. State survives any crash; progress still needs a live worker polling the queue, and a fast way to notice when one is gone.
- Read the event log's semantics before building on it. Because ActivityTaskStarted is written lazily, a history-only view got wrong exactly the stranded attempt it was built to explain.
- Give every datum one owner. Only Temporal holds execution state, so Redis, the projections and even the scheduler can fail or restart without changing what a workflow does next.
Stack
- Durability
- Temporal, Event sourcing, Deterministic replay, Idempotency inbox
- Compute
- Ray, Async activity completion, Heartbeat checkpointing
- Services
- Python 3.11, FastAPI, Pydantic v2, SQLAlchemy, Postgres, Redis Streams
- Observability
- OpenTelemetry, Jaeger, Prometheus, Grafana
- Web
- Next.js 15, React 19, React Flow, WebSocket live tail
- Quality
- pytest, mypy --strict, ruff, Playwright, CodeQL, Docker Compose
Timeline
- 21 Jul 2026
Monorepo scaffold, Compose stack, API gateway and dashboard shell.
- 22 Jul 2026
Durable core and SDK; activity workers with Ray dispatch and async completion; first worker-crash durability test.
- 23 Jul 2026
Admission scheduler, built-in node library, idempotency inbox; Chaos Lab and the recovery view.
- 26 Jul 2026
Event-sourced observability: projections, live DAG over WebSocket, OTel tracing, Prometheus/Grafana, replay and critical path.
- 27 Jul 2026
Asserting chaos experiments and fast failover via heartbeats.
- 27 Aug 2026
v0.1.0: resilient worker registration, demo walkthrough, first tagged release.
- 26 Oct 2026
v0.1.1: security release; dashboard moved to Next.js 15 and React 19, CodeQL and Dependabot added.
- Next
Kubernetes (Helm/KubeRay/KEDA), OIDC/RBAC and tenant isolation, signed third-party plugins.