Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions website/blog/posts/2026-04-15-fork-branching-for-durable-streams.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
---
title: 'Fork — branching for Durable Streams'
description: >-
Fork is branching for Durable Streams. Branch any stream at any point with a single API call. Rewind history, fan out agents in parallel, or probe without polluting context. Live on Electric Cloud.
excerpt: >-
Fork adds branching to Durable Streams. Branch any stream at any point — rewind history, fan out agents, or probe without polluting context.
authors: [balegas, samwillis]
image: /img/blog/fork-branching-for-durable-streams/header.jpg
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a) with this image crop vertically slightly

Could you push chatgpt to generate a slightly higher quality image, more realistic, atmospheric? Here's an example image prompt that really stresses / pushes the image generation. Claude can write these well:

<style>A high-resolution macro photograph looking inside the open chamber of an experimental three-dimensional photonic computer mid-computation. 1536 by 950 pixels, 16:9 aspect ratio, mastered as a high-quality JPG. The visual register is hyperreal scientific photography fused with the precise sci-fi futurism of Tron Legacy interiors, the reactor chambers of Annihilation and Arrival, and the open photonic test rigs of advanced silicon photonics laboratories. Reference also: the cover of a Nature paper on three-dimensional photonic integration, the IBM quantum computer chandelier, free-space optical bench setups with visible laser interferometry, and the stacked die photography of Intel Foveros and TSMC CoWoS chiplet packaging. Hard sci-fi, not fantasy. Mathematical, clean, monumentally precise, three-dimensional, volumetric. Painted by light, not by hand.</style>

<setting>The entire image takes place inside the open inner chamber of a three-dimensional photonic computer. This is not a flat chip surface — it is a volumetric enclosure perhaps the size of a shoebox seen at extreme macro range, with real depth of field stretching from the immediate foreground into a soft far background several  hundred millimetres deep. The chamber is bounded above and below by stacked layers of polished dark silicon photonic dies separated by transparent glass interposers and  connected by vertical copper through-silicon vias and short fibre-coupling pillars. Multiple horizontal silicon planes are visible at different depths, each etched with  its own pattern of waveguides, each glowing faintly with cyan laser light leaking out of its edges. Between the planes, in the open volume of the chamber, free-space optical interconnects cross the air as visible coherent cyan beams, travelling vertically and diagonally between dies. The chamber walls are dark polished silicon and anodised carbon composite. The camera is positioned inside the chamber at a low three-quarter angle, looking up and across the volume so the viewer feels suspended inside the apparatus, not looking down at a board.</setting>

<agent_loop>Dominant in the central two-fifths of the frame, suspended vertically in the open volume of the chamber and presented nearly face-on to the camera so its geometry is completely unmistakable: the Durable Streams logo rendered at scale as a true static dataflow graph in coherent laser light. The form must be exactly and recognisably the Durable Streams logo from the brand assets — a perfectly circular ring composed of exactly sixteen identical wedge-shaped slices arranged radially around a small central hub, each slice the shape of a thick triangular pie segment with a flat outer rim and a sharp inner point at the hub, with a thin dark gap of empty space between each slice and the next. The slices fade gradually in opacity around the ring exactly as in the logo: brightest and most fully saturated at the top of the ring, dimming progressively around the circumference, dimmest at the bottom — this opacity gradient is itself a defining characteristic of the logo and must be obvious. The ring is large in the frame, occupying most of the vertical height of the central focal plane, and is held in space by a sculpted dark silicon mounting bracket at its hub. Each of the sixteen wedges is a discrete coherent beam of brilliant cyan laser light (hex value #75fbfd) emitted from a tiny photonic source at the central hub, projecting outward through a slot-shaped aperture in the bracket to form the wedge shape in mid-air as a volumetric beam of pure light. The wedges are sharply edged, hard volumetric, with faint coherent diffraction shimmer at their boundaries and visible flow inside their bodies. At the outer rim of the ring the sixteen beams curve through micro-mirrors mounted on a thin circular silicon halo and re-enter the next wedge along, physically closing the loop. The viewer must recognise this immediately as the Durable Streams logo at first glance.</agent_loop>

<inference_engine>Filling the depth of the chamber behind and around the agent loop, fused to it with no boundary between them: a true three-dimensional inference engine  built from stacked photonic processing elements. Multiple horizontal silicon dies are visible at progressive depths receding into the chamber, each die etched with a regular rectilinear grid of identical Mach-Zehnder interferometer cells — a chessboard of glowing diamond cells, each cell two parallel cyan waveguides meeting at a beam  splitter — extending the full surface of every die. The dies are stacked vertically in the chamber, separated by transparent glass interposers, perhaps four or five layers deep, so the lattice repeats through the volume of the computer like the floors of a tower. Cyan laser light flows horizontally across each die and vertically between dies through optical through-silicon vias, with bright nodes at every cell where beams interfere. The lattice is unmistakably a regular three-dimensional grid, not a scatter of nodes and not a curving neural network — it is a volumetric tensor core, a stacked systolic array. The depth of field falls off softly into the far layers so the deepest dies dissolve into atmospheric cyan haze, suggesting the lattice continues further than the eye can resolve.</inference_engine>

<fused_dataflow>This is the central visual thesis of the image and must be unmistakable. The cyan laser beams of the agent loop do not stop at the rim of the ring. Several wedges of the ring project their beams forward and outward into the open volume of the chamber as free-space coherent cyan beams, travelling through the air across the chamber and entering the leftmost columns of the stacked inference lattice as input beams. The beams travel through the lattice from cell to cell and from die  to die, processed in flight by interference at every Mach-Zehnder cell and routed vertically between layers through optical TSVs, and emerge from the rightmost columns of the deepest dies as new coherent cyan output beams. Those output beams curve gracefully back through the volume of the chamber along free-space return paths that arc up over the top of the lattice and back into the wedges of the loop on the opposite side of the ring, completing the cycle. There is no chamber boundary, no memory store, no mediating buffer between the loop and the lattice — it is a single continuous photonic circuit walked by one continuous flow of coherent cyan light through three-dimensional space. Discrete bright pulses travel along the beams in legible direction: brilliant cyan packets flowing outward from the loop into the lattice (spawned work), softer cyan packets flowing back from the lattice into the loop (returned results). The loop and the inference engine are two regions of one fused spatial dataflow graph and the photons cross the boundary between them as if the boundary did not exist, because it does not.</fused_dataflow>

<light_and_colour>The cyan of the laser beams (hex value #75fbfd) is the only saturated colour in the image and it is the dominant light source. The beams of the loop, the beams of the lattice, and the free-space beams crossing the chamber all glow the same precise turquoise. Cyan rim light spills onto the dark silicon dies, the glass interposers and the carbon composite chamber walls beneath every beam, casting cool reflections in the polished surfaces and modelling the etched walls of the waveguide channels in turquoise. Thin volumetric haze fills the open chamber, just enough to make the free-space beams visible as travelling shafts of light without softening their hard volumetric edges. The depth falls off into a cool blue-black ambient darkness in the deepest reaches of the chamber. A second light source is used sparingly: a very subtle warm rose-gold accent (hex value #FF8C3B) catches the very furthest right edges of a few of the lattice cells and the outermost rim of the loop's central hub, providing a single complementary warm note to anchor the otherwise entirely cool palette. The warm accent must be restrained, perhaps two or three percent of the image's total luminance, used as a counterpoint to make the cyan sing rather than as a competing colour. No other colours. No purples, no greens, no yellows. Everything else is cyan, black, and the deep cool blue-grey of polished silicon.</light_and_colour>

<material>Polished dark silicon for the photonic dies and the chamber walls. Transparent glass interposers between the dies, with subtle internal refraction of the cyan beams passing through them. Anodised carbon composite for the structural members of the chamber. Vertical copper through-silicon vias and short fibre-coupling pillars between dies. Sculpted silicon mounting brackets holding the agent loop ring face-on in the central volume. Tiny photonic components at the nodes: micro-mirrors at the rim of the loop, beam splitters at every MZI cell of the lattice, fibre-coupling fiducials at the die edges. These components are sculpted from polished silicon and rendered with the precision of an electron-microscope photograph restated in colour. The cyan beams themselves are pure coherent light: hard volumetric edges, internal flow, faint diffraction shimmer, no fuzzy bloom and no neon haze beyond a thin atmospheric carrier in the chamber air. Everything is hard-surface, clean, precise, sub-millimetre engineering visible at extreme macro range inside a real volumetric chamber.</material>

<composition>A wide three-quarter view from inside the chamber of the photonic computer, camera positioned at a low slightly elevated angle looking up and across the open volume so multiple layers of stacked silicon dies are visible at progressive depths. The Durable Streams logo ring is suspended vertically and face-on in the centre  of the frame, dominant in the central two-fifths of the image, large and unmistakably recognisable as the logo. The stacked inference lattice fills the volume behind and around the loop, receding through several layers into the far background. Free-space cyan beams cross the open chamber between the loop and the lattice and arc back over the top to close the circuit, drawing a complete three-dimensional dataflow visible at a glance. All load-bearing content lives within the inner seventy percent of the frame so the image survives a 1200 by 630 centre crop and a square crop. The upper region of the frame above the loop stays relatively clean and atmospheric — soft cool darkness with hints of distant chamber structure — because the website overlays the post title in that region. Generous breathing room on all four edges. The composition has real volumetric depth: foreground, middle-ground holding the loop, multiple receding planes of inference dies in the background.</composition>

<mood>Mathematical, precise, monumentally beautiful, quietly awe-inspiring. The viewer is suspended inside the apparatus at the moment of computation itself, at the instant the agent loop and the inference engine become one fused three-dimensional spatial dataflow graph executing in light. There are no characters. No human figures. No mood lighting beyond what the beams themselves emit. This is not a scene — it is a volumetric window into a piece of apparatus more advanced than anything that exists  today, captured with the calm descriptive clarity of a scientific photograph and the visual confidence of a master concept artist. Reverent without being theatrical.</mood>

<constraints>Absolutely no text, no numerals, no letters, no signage, no logos other than the Durable Streams sixteen-wedge ring form itself, no watermarks anywhere in the image. The Durable Streams ring must be rendered with strict geometric precision and must be immediately recognisable as the Durable Streams logo: a perfectly circular ring of exactly sixteen identical wedge-shaped beams of cyan laser light arranged radially around a central hub with a thin dark gap between each beam and the next, with a clear opacity gradient from brightest at the top to dimmest at the bottom of the ring. The ring is presented nearly face-on, large in the frame, dominant in  the composition. The inference lattice must be a regular rectilinear three-dimensional grid of identical Mach-Zehnder interferometer cells stacked across multiple silicon dies in the depth of the chamber, not a random scatter of nodes and not a neural-network-style graph of curving lines — it is a volumetric tensor-core stack. The  image must have real three-dimensional depth: it is the open chamber of a photonic computer with stacked silicon layers and free-space optical interconnects, not a single flat board surface. Absolutely no flywheels, no mechanical parts, no leather, no iron, no steampunk, no architectural framing, no robot characters, no human figures, no sky, no horizon, no buildings of any kind. The cyan must be the precise turquoise hex value #75fbfd. The warm accent, used sparingly, must be the precise rose-gold hex value #FF8C3B. Master as a high-quality JPG.</constraints>

tags: [release, durable-streams, cloud, agentic, AI]
outline: [2, 3]
post: true
published: true
---

[Durable Streams](/primitives/durable-streams) is the [data primitive for the agent loop](/blog/2026/04/08/data-primitive-agent-loop). Today we're shipping fork — a single API call that branches a stream at any point. Rewind history, fan out agents in parallel, or probe an agent without polluting its context.

A fork creates a new stream from any point in an existing one. It shares everything before the fork point with its source and evolves independently after it. One API call, two headers.

## Streams are sessions

Agent infrastructure is converging on a pattern: the session — the complete log of messages, tool calls, and decisions — lives in a durable stream that lives outside the agent itself. Anthropic's recent post on [Managed Agents](https://www.anthropic.com/engineering/managed-agents) describes exactly this architecture: an append-only session log that the harness writes to, reads from, and resumes after a crash. Durable Streams provide exactly this primitive.

A session log is linear but agent workflows aren't. An agent goes down a path that isn't working and you want to rewind a few turns. Multiple agents need to fan out from the same starting point. You want to ask an agent a question without putting it in its history. These all require the same operation that a linear log doesn't have: the ability to take the session at any point and diverge.

## Fork: branching for streams

A [Durable Stream](/primitives/durable-streams) assigns an offset to each message as it's appended. When you fork a stream, you specify a source stream and a fork offset. The system creates a new stream that inherits all messages from the source up to that offset. After the fork point, the new stream lives independently — its own URL, its own appends, its own subscribers.

Forks don't copy data. They use copy-on-write (COW): the shared history between a fork and its source is genuinely shared at the storage level, and only new writes diverge. This means forking is instant regardless of stream length — a stream with ten thousand messages forks just as quickly as one with three.

Because forks are themselves regular Durable Streams, they can be forked. This gives you trees of arbitrary depth where every node is an addressable stream with the full set of stream operations available.

### The API

Create a conversation stream and append some messages:

```http
PUT /v1/stream/{service}/chat-123
```

```http
POST /v1/stream/{service}/chat-123
Content-Type: application/json

{"role": "user", "content": "How do I deploy to prod?"}
```

```http
POST /v1/stream/{service}/chat-123
Content-Type: application/json

{"role": "assistant", "content": "Two main options: containerized with Fly or Railway, or a VM setup on EC2. The tradeoffs are..."}
```

Fork from offset `002f_0cf0` — right after the assistant's first response:

```http
PUT /v1/stream/{service}/chat-123-containers
Stream-Forked-From: /v1/stream/{service}/chat-123
Stream-Fork-Offset: 002f_0cf0
```

`chat-123-containers` now exists with the first two messages as shared history. Anything appended from here is independent. Fork again from the same offset for a second branch:

```http
PUT /v1/stream/{service}/chat-123-vms
Stream-Forked-From: /v1/stream/{service}/chat-123
Stream-Fork-Offset: 002f_0cf0
```

Clients reading any branch see a single continuous sequence — the shared prefix followed by branch-specific messages — without any special handling.

### Properties

- **Instant** — metadata operation, not a data copy. Cost doesn't scale with stream length.
- **Independent** — no lifecycle coupling between source and forks. Delete or append to one without affecting the other.
- **Transparent** — readers see one continuous sequence. The fork boundary is invisible unless you inspect stream metadata.
- **Composable** — fork a fork for trees of any depth.
- **Plain HTTP** — same protocol, same SSE, same offset-based reads. Two new headers on the PUT.

## What fork enables

### Conversation trees

ChatGPT shipped branch conversations as a user-facing feature. LangGraph added checkpoint-based forking to their agent framework. The pattern keeps showing up because agent conversations aren't linear — users want to go back, try a different direction, compare alternatives.

With Durable Streams, a conversation tree is a set of streams related by forks. The root is the original conversation. Each branch point is a fork. Every node is a regular stream with the full set of stream operations — reads, writes, real-time subscriptions. Branching lives at the data layer, not inside a specific framework's checkpoint system, so any client that can read a Durable Stream can work with forked streams without modification.

We built a demo that shows this: a chat application where users can fork any point in a conversation and explore a different direction. [Try the fork demo](https://fork-ai-chat.examples.electric-sql.com).

<div class="embed-container" style="padding-bottom: 84.4%">
<YoutubeEmbed video-id="gmkqygh9ezo" />
</div>

### Parallel paths

Conversation trees branch sequentially — a user or agent tries one direction, then goes back and tries another. Parallel paths are different: multiple agents fork from the same point and run simultaneously.

Fork the session once per agent. Each gets its own branch while the shared history exists once at the storage level. A fleet of agents can fan out from the same session to tackle a problem from different angles. A lead agent can fork when the current approach isn't working and hand the branch to a specialist. Each branch is fully isolated, but the common context is shared. Compare the results and pick the best path.

<figure>
<img src="/img/blog/fork-branching-for-durable-streams/fork-parallel-paths-diagram.svg" alt="Parallel paths: a shared session forks into three agents, each pursuing a different strategy independently" />
</figure>

### Scratch contexts

Sometimes you need to interrogate an agent without changing its state. A developer debugging a misbehaving agent wants to ask "what do you think the user wants?" without that meta-question influencing the next real turn. A harness wants to test whether the agent can answer a factual question before committing to a tool call.

Fork the session, run the side conversation in the fork, read the result. The main session is untouched — no phantom turns in the history, no context pollution. If the answer is useful, the harness can bring it forward explicitly. If not, the fork is just abandoned.


## Getting started

Fork is available now on all Durable Streams services on [Electric Cloud](/cloud). Sign up, create a stream service, and start using it.

The [protocol spec](https://github.com/durable-streams/durable-streams) covers the full fork semantics — offset behavior across forks, concurrent readers, deletion propagation. The [API docs](/docs/intro) have the reference for all stream operations including fork.

***

- [Sign up for Electric Cloud](/cloud)
- [Try the fork demo](https://fork-ai-chat.examples.electric-sql.com)
- [Read the docs](/docs/intro)
- [Join the Discord](https://discord.electric-sql.com)

<div class="actions cta-actions page-footer-actions left">
<div class="action cloud-cta">
<VPButton
href="https://dashboard.electric-sql.cloud/?intent=create&serviceType=streams"
text="Sign up"
theme="brand"
/>
&nbsp;
<VPButton
href="/docs/intro"
text="Docs"
theme="alt"
/>
&nbsp;
<VPButton
href="https://discord.electric-sql.com"
text="Discord"
theme="alt"
/>
</div>
</div>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading