Skip to content

feat(langgraph): stream, reconnect, continue threads and resume interrupts on Dapr workflow runs - #492

Open
CasperGN wants to merge 73 commits into
mainfrom
feat/487-token-streaming
Open

CasperGN wants to merge 73 commits into
mainfrom
feat/487-token-streaming

Conversation

@CasperGN

@CasperGN CasperGN commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Fixes #487.

A LangGraph graph run as a Dapr workflow now streams to the caller while it runs, keeps a conversation's state between runs, can be reconnected to from any replica, and can pause on interrupt() and be resumed. Before, a client got nothing until the workflow finished, every run started from scratch, and a dropped connection lost the run's output.

The README section "Streaming" in diagrid/agent/langgraph/README.md documents all of it: the API, the SSE format, the transports, reconnecting, interrupts and the limits. The headline changes:

Streaming. DaprWorkflowGraphRunner.astream() yields what native compiled.astream() yields for the messages, updates, custom, values, tasks and debug modes (checkpoints is refused with a 422). POST /agent/run with "stream": true serves the same as server-sent events: workflow_started first, the chunks, then workflow_completed, workflow_failed or workflow_interrupted. Control events (node_reset, stream_unavailable, stream_purged, stream_dropped, thread_not_saved) tell the client what the stream itself did. The golden tests in tests/agent/langgraph/test_streaming_golden*.py run the Dapr runner and native LangGraph side by side and compare chunk by chunk.

Routers run inside their node's activity. A conditional edge's function runs in the activity of the node it follows, so its tokens and custom writes land in the stream where LangGraph puts them, and a Send fan-out from a router works. If the function raises there, it runs again in an activity of its own.

Streaming across replicas, on by default. The stream transport is pluggable (stream_transport=). StateLogTransport is the default whenever the app has a state store: every activity writes its chunks to an event log in the Dapr state store and the replica serving the stream reads them back, so any replica streams any node's output. It uses the app's agent-memory store if there is one, else the store the workflows use. On Catalyst there is nothing to configure. InProcessTransport is the fallback without a store, and keeps the single-replica behaviour.

Reconnecting. Every SSE event carries an id that is a cursor into the run's log. GET /agent/run/{workflow_id}/stream with Last-Event-ID (or last_event_id) replays what the client has not seen, then the live chunks, then the final event, with nothing repeated and nothing skipped. A stream cut by its own replica going away ends with workflow_failed and workflow_still_running: true, carrying the last chunk's id, so the client reconnects from there. In Python, runner.astream_resume().

Conversations. Runs that share a caller-given thread_id continue the thread: each run starts from the state the last one ended with and applies its input through the channels' reducers, as a LangGraph checkpointer does. The state lives in the Dapr state store (DaprMemoryCheckpointer, last two checkpoints, 30-day TTL, etag-written index). A run without a thread id is stateless. continue_threads=False opts out; checkpointer= swaps the store.

Interrupts. interrupt() pauses the run durably in the workflow, in the node, in a subgraph it runs, or in its router. The stream sends the __interrupt__ chunk and ends with workflow_interrupted; GET /agent/run/{workflow_id} shows interrupted: true. POST /agent/run/{workflow_id}/resume with {"resume": value} (or Command(resume=...) in Python) resumes it, streaming or not; 422 for a missing or null value, 404 for an unknown run, 409 for one that is not waiting or that another request already resumed. Interrupt ids are stable across runs so several interrupts can be answered one at a time.

Run status. GET /agent/run/{workflow_id} returns the run's output, steps, run_status and error once it completed, not only the workflow's runtime status.

Parity fixes found along the way. Node ids, reducer defaults, Send tasks, conditional edges, defer=True, recursion_limit, pydantic and dataclass state, non-JSON state values between nodes, langgraph_* metadata on chunks, the thread_id in configurable, and AgentMiddleware with only a sync wrap_model_call or wrap_tool_call now behave as they do in LangGraph. DaprWorkflowDeepAgentRunner streams too.

Limits

Listed in full under "Limits" in the README. The ones worth knowing before deploying:

  • Without a state store only the replica serving the stream streams, nothing can be replayed, and a dropped stream cannot be resumed.
  • A replay shows a node's last attempt; the stream follows the attempt the run used.
  • Node code must not count attempts in process memory: a retry may run in another process.
  • A client disconnect does not cancel the run.
  • The three GET/POST /agent/run/{workflow_id}... endpoints answer anyone who knows the run id. Deploy behind the app's authentication.

How it was tested

uv run pytest tests -m "not integration"
  1252 passed, 1 skipped, 15 deselected, 361 subtests
uv run mypy --config-file mypy.ini          Success: no issues found in 168 source files
uv run flake8 diagrid tests --ignore=E501,F401,W503,E203,E704   clean
uv run ruff format --check                  402 files already formatted

Two independent review passes on the branch; every finding fixed.

End to end against Catalyst with two app processes behind a round-robin proxy, and again on a kind cluster with two pods per app, a Dapr sidecar each and one Redis state store. Each scenario was run from the merged head of this branch:

Scenario Result
Two pods, stream and resume through the proxy 10 of 10 checks, both directions
Pod deleted mid-stream (graceful and forced), reconnect to the surviving pod full replay, no gaps, no duplicates, equal to native astream
Thread continued on the other pod 2 of 2
Stream-log TTLs set on batches and heads 4 of 4
Interrupt on one pod, resume through the other 9 of 9 runs, live __interrupt__ chunk every time

Checklist

  • uv run ruff format (no path arguments, so examples/ is covered too)
  • uv run flake8 diagrid tests --ignore=E501,F401,W503,E203,E704
  • uv run mypy --config-file mypy.ini
  • uv run pytest tests -m "not integration"
  • New or changed behaviour has tests
  • New files under diagrid/ carry the license header
  • Commits are signed off (git commit -s)

…low runner

Activities run in worker threads, but the connection that wants their output
lives on the API's event loop. Add a StreamSinkRegistry with an in-process
sink as the hand-off between the two, a bounded buffer, and the SSE framing
used to send chunks to a client.

BaseWorkflowRunner.serve() now answers POST /agent/run with "stream": true as
an event stream for runners that opt in through _serve_stream, and publishes
the terminal result to the configured topic once the stream ends. The sink is
looked up in one place, so a cross-replica transport can replace it later.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…om node activities

Each LangGraph node runs as a Dapr workflow activity, so the caller used to
see nothing until the whole run finished. Run the node with LangGraph's own
message handler and stream writer attached, and send what they produce to the
run's sink in the shapes LangGraph's astream yields: "messages" for LLM
tokens, "updates" for each node's writes, and "custom" for get_stream_writer()
events.

DaprWorkflowGraphRunner gains astream(), which starts the workflow and yields
those chunks as they arrive, and serves "stream": true requests as SSE. The
sink registry can be injected, so tests and embedders keep runs isolated.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
A workflow can finish with status "error" or "max_steps_reached", or end
terminated, errored or with no result at all. None of these is a success, but
the stream used to end as if it were. Normalise whatever ends the run into a
single terminal event that names the workflow and thread, and keep the error
detail as a dict instead of a bare string.

astream() raises GraphRunError for a failed run, and the SSE stream ends in
workflow_failed. POST /agent/run with "stream": true now publishes the same
result shape as the non-streaming call.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…r undelivered chunks

Past the sink's buffer limit only "messages" and "custom" chunks are dropped.
"updates", node resets and the close marker always get through. The sink
counts what it dropped, logs the total when the run closes, and the terminal
event and astream() report it as stream_dropped.

An activity that finds no local sink, because it runs on another replica or
after a restart, used to stream nothing without a trace. It now logs one
warning per run, and the stream ends with stream_unavailable naming the steps
nothing arrived for. Cross-replica delivery stays a follow-up.

"stream" and "stream_mode" are now removed from the request only on the
streaming path, so a graph with a state key of that name still works.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…ive astream chunks

A caller that stopped iterating astream(), or an HTTP client that hung up,
left the run's sink registered and kept filling its buffer. Both now close the
inner stream. A streamed run's result is still published to the topic when the
client disconnects mid-run, and in the same shape a plain call publishes.

Chunks now follow native LangGraph more closely. Several threads of one node
can emit at once without losing chunks, get_stream_writer() is a no-op in a run
that is not streamed, values that are not LangChain objects are sent as plain
data, "messages" metadata carries thread_id and the other configurable values,
and control events (node_reset, stream_unavailable, stream_dropped) never
appear in a single-mode astream.

The node activity helpers are split out of the activity, and the README
documents streaming, its single-replica limit and what a disconnect does.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…nd a gateway

The stream now starts with workflow_started, which gives the client the
workflow id before anything else, so it can poll or terminate the run after a
disconnect. An idle stream sends keepalive comments, and the response sets
no-cache and no-buffering headers. A bad stream_mode is refused with a 422
before the stream starts, and only the JSON boolean true switches a request
to SSE. A chunk that cannot be encoded becomes a placeholder and is counted
as dropped instead of failing the stream.

Blocking Dapr sidecar calls move off the event loop, and a failed status poll
is retried for the LangGraph runner when the failure is transient, so a
sidecar blip no longer reports a running workflow as failed. stream_unavailable
is decided per node, node_reset and stream_unavailable number steps like
langgraph_step, and a run survives a LangGraph message handler that can no
longer be built.

A node that returns Command(goto=...) now has its goto followed, and a Send
payload that cannot be delivered is logged once per edge. Messages a node
returns, such as a ToolMessage, carry the task metadata.

astream() takes its config positionally and reads the thread id from it.
serve() documents streaming, the streaming names are exported from the
package, and the DeepAgents runner forwards the stream registry.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
… nodes as LangGraph does

The runner used to start at a single node and never read waiting edges, so a
graph with several START edges, a conditional START edge or add_edge([a, b], c)
ran fewer nodes than LangGraph and still ended completed. The graph config now
lists every START target and the waiting edges, the first step runs all the
targets, and a join fires in the step after its last source. A config written
before this has no entry_points and starts as it did, so instances in flight
replay unchanged. A step that reaches END no longer stops the other branches.

A node that returns an instance of the state schema writes its fields, a
subgraph node streams only its own output message, and a Runnable with an
async entry runs through ainvoke while a plain sync node stays on the sync
entry. The "messages" metadata lists every trigger channel of the node.

The stream helpers used by astream() move into stream_events.py, and the
poll retry is limited to gRPC statuses and errors that can pass.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…sion_limit and graph metadata

Input messages get ids that are the same on every replay of the workflow; the
orchestrator used to draw random ones, so a replay scheduled the first
activity with a different input. The first write to a reducer channel now goes
through its reducer, so add_messages assigns ids and reads (role, content)
tuples. A node's keys that are not state channels are dropped, as LangGraph
does.

astream() honours recursion_limit and refuses a config that cannot travel as
JSON up front instead of failing late. The "messages" metadata now includes
the graph's with_config metadata and tags and the metadata given to add_node.
A failed run yields its stream_dropped before its error is raised.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…state handling

A Send from a conditional edge or Command(goto=...) used to run its node once
on the whole channel state. Each Send is now an activity of its own that takes
its argument as the node input, streams under its own key with the push
trigger and path, and follows the node's outgoing edges. A router that calls an
LLM or get_stream_writer() now streams its tokens and events too, and each
conditional edge of a node streams under its own key, so one edge is no longer
mistaken for a retry of another.

State now follows LangGraph. A reducer channel nobody has written starts from
its default, message input is read in every shape add_messages takes on every
such channel, a node gets the state as its input schema shapes it, Overwrite
replaces a reducer channel's value, and a message keeps its own fields. Ids of
written messages are assigned in the activity, so replays see the recorded
ones, and a reducer that raises fails the run.

Async nodes run on one background loop that outlives the activity, so a
chat model's pooled HTTP client no longer hits a closed loop. A bound
recursion_limit and configurable apply as with LangGraph, invoke raises for a
run that failed or hit its limit, and the error is a GraphRecursionError when
it is the limit. serve(), _poll_workflow and agent_workflow are split into
helpers, and the node_reset event names the real node and path.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
… and value types

The nodes of a step ran in the order their edges were found, which changes
with the hash seed. They now run in LangGraph's task order, pull tasks by name
and then Send tasks numbered over the whole step, a task's goto Sends before
its edge Sends, and a conditional edge is evaluated once per task on that
task's own writes. A node added with defer=True runs once, when nothing else
is pending. The new order sits behind a workflow patch, so an instance already
in flight replays with the order it started under.

recursion_limit is strict: a run takes that many steps, then fails, and a
limit only the graph binds can be lowered by the runner's max_steps. A run
the orchestrator starts gets the graph's own config. Nodes and routers get
the RemainingSteps and IsLastStep managed values.

Values keep the types they were written in between nodes, through
LangGraph's serializer, while the run's output stays JSON. A subgraph's
Command(graph=PARENT) becomes its node's result, a ChatMessage reads back as
a ChatMessage, and a graph whose whole state is one channel works. A composite
node with an async step runs through ainvoke, and a node that calls sys.exit
no longer kills the shared loop.

The setup shared by invoke and run_async, the per-edge evaluation, the node
config builders and the poll retry move into helpers, the LangSmith parent
trace and the step bound get their own modules, and the comments and docstrings
that restated the code are trimmed.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…and native parity

Cover the sink and registry (ordering, backpressure, closed loops, attempt
ownership), the control events and how astream() routes them, the node
activity hooks, the public streaming names, and the run lifecycle: publishing,
disconnects, overlapping streams, failure endings, poll retries and the
request rules of the SSE route.

The golden tests run the same graphs through LangGraph's own astream and
through the runner and compare the "messages", "updates" and "custom" chunks.
They cover linear and loop graphs, ReAct agents, subgraphs, joins, Command
goto, Send, reducers and state-schema shapes. Shared helpers and the golden
harness live in streaming_helpers.py and golden_harness.py.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…runner

Pin the behaviour that makes a durable run match a native one: the order of a
step's writes and Send numbering, goto order, a router evaluated per task,
deferred nodes, the in-flight step-order patch, replay-safe message ids,
message input shapes, channel defaults, Overwrite, state shapes, root-state
graphs, value types through reducers and plain channels, managed values,
Command(graph=PARENT), async composite nodes and the shared node loop, the
step bound and the orchestrator's graph config.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
@CasperGN
CasperGN requested a review from a team as a code owner November 25, 2026 23:02
CasperGN and others added 17 commits November 26, 2026 00:28
The workflow input stored every value of a channel named "messages" as
message dicts, even when the channel has no add_messages reducer. A
plain `messages: list[str]` state then came back with its input string
as a HumanMessage dict, unlike native LangGraph, and the e2e test
test_langgraph_pure_graph_execution failed. Decide by the channel's
reducer alone, as node writes already do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Casper Nielsen <casper@diagrid.io>
…order

Native astream runs the three Send tasks concurrently, so which task's
tokens get the first normalised message id depends on thread timing.
Name each message id by its task's langgraph_path before comparing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Casper Nielsen <casper@diagrid.io>
The router golden test now compares the stream chunk by chunk with native
astream: a router's tokens and custom events come before its node's updates
chunk. New tests cover an instance from before the change (it replays the
separate condition activity), a router that raises (it falls back to that
activity, the node runs once and the consumer gets a branch node_reset), a
parallel step with two routers, a Send task's router and a path_map miss.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
LangGraph runs a conditional edge's function as a writer of its source node,
inside the node's task, so its tokens and custom events come before the node's
updates chunk. The runner ran it in a separate activity after every node of
the step had finished, so they came after that chunk, and in a parallel step
after the sibling nodes too.

Behind a new workflow patch, the workflow now hands a node's activity the
node's conditional edges. The activity evaluates them on the state the step
started from plus the task's own writes, then publishes the updates chunk, and
reports where they lead. A router that raises is not retried there: the
activity says its routes are not done and the workflow evaluates them in the
condition activity as before, so the node does not run again and the consumer
gets the existing node_reset with branch. A path_map miss or a reducer that
raises on the task's writes fails the run, as it did.

Instances started before the patch replay their recorded schedule with the
condition activity. A conditional hop also saves one activity and one stored
copy of the state.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
A conditional edge's function now runs inside its node's activity, so its
chunks come before the node's updates chunk, as in LangGraph. The node_reset
row says when a router's retry still happens: when it raised inside the node's
activity and ran again in an activity of its own.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
Golden tests against native astream for values (a sequential graph, values
between a step's chunks, a parallel step, a router loop, the final value, a
step that writes no output channel, an empty input, a run cut by its step
limit), a retried step that does not send its value twice, and values over
SSE loaded back with langchain_core.load. Tasks and debug are compared on
graphs without a checkpointer, including a router, a parallel step and Send
tasks; a failed attempt sends its start but no result. Checkpoints are
refused with a ValueError and a 422 that say why.

The golden harness takes the stream modes to compare, and the tests that
used values as an example of an unsupported mode use a bogus one.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
values: the state after step s is the input of every activity of step s+1, so
in a streamed run each of them offers it, when step s wrote an output channel,
before it runs its node; the sink keeps the first offer of a step and drops
the rest without a node_reset. The workflow hands the output channels to the
activities of a streamed run, and a START edge's activity offers the input.
The state after the last step travels on the final event of a streamed run
(a stream-only key, stripped like executed) and is sent before the closing
event when no activity sent it. A run that failed in a node or a router sends
none; a run cut by its step limit sends it, as LangGraph does.

tasks: a node's activity sends the task's start event (id, name, input,
triggers and the user metadata and tags) when it starts the node, and its
result next to its updates chunk. The id is derived from the run, step and
task, so a retry keeps it. A failed attempt sends no result. debug wraps both
with the step, a timestamp and the type, which is all native debug holds
without a checkpointer.

checkpoints is refused with a ValueError (a 422 over HTTP) that says why: the
runner keeps no LangGraph checkpoints, the workflow history is the durable
record.

Tests that compared a node's exact event list now leave out the task events.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
The Streaming section lists every mode with its chunk, says that checkpoints
is refused because the workflow history, not a LangGraph checkpoint, is the
run's durable record, and that the full state is in values, the final event
or GET /agent/run/{workflow_id}. It also says when a values chunk arrives and
what a failed run sends.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…cheduled

Signed-off-by: Casper Nielsen <casper@diagrid.io>
Signed-off-by: Casper Nielsen <casper@diagrid.io>
…s result

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…f the event loop

Signed-off-by: Casper Nielsen <casper@diagrid.io>
Signed-off-by: Casper Nielsen <casper@diagrid.io>
Signed-off-by: Casper Nielsen <casper@diagrid.io>
…ream

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…eamed or not

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…a stream drops

Signed-off-by: Casper Nielsen <casper@diagrid.io>
invoke() raised AttributeError for a Command. It now resumes the run
named by workflow_id and waits for it, and refuses any other Command, or
one without a paused run, with a ValueError. The polling loop moves out
of runner.py.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
A run without a thread_id or session_id got a generated 8-hex thread id
and still loaded and saved thread state, so stateless traffic grew the
store. Now only a thread the caller names (thread_id, session_id or
configurable thread_id) carries state; continue_threads=False turns it
off. Generated thread ids and workflow id suffixes are full UUIDs.

A graph compiled with MemorySaver no longer wins over the app's Dapr
state store: the runner keeps threads in the store and warns, and warns
too when an in-memory saver is all there is.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
DaprMemoryCheckpointer kept every run's checkpoint forever, lost index
entries when runs on one thread saved at once, and no longer read
checkpoints saved under the old langgraph-<thread>-... keys.

Checkpoints and the index now carry a TTL (30 days by default), a thread
keeps its last two checkpoints, the index is written with an etag
(first-write) and retried with backoff, and the old keys are read when
a thread has no index under the new ones. DaprStateStore gains
get_with_etag and save_with_etag.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
… saved

A save activity that failed after every node had run failed the whole
run and lost its output. The workflow now catches the failure (after the
activity's retries), returns the output with thread_saved false and
thread_error, and a stream sends a thread_not_saved control event before
its final event. GET /agent/run/{id} reports it as well.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
The final flush of a unit (its updates chunk and done head) was tried
once, so a single store error lost the node's updates. It is now tried
up to final_flush_attempts times (default 4) with a doubling backoff
before the unit is left not written.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
Every unit of a step logs that step's values chunk, and a reconnect
replayed the copies of the units it had not read, so values repeated;
the final values chunk reused the id before it, so a reconnect from it
sent it again. The SSE cursor now carries the last step whose values
the client has (a fourth, optional part), the follower skips earlier
copies, and the final values chunk gets its own id.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
A run that waited on interrupt() longer than the batch TTL lost its
first steps' chunks, and a reconnect stopped at stream_purged with
nothing live after the resume. The follower now skips a purged unit
(keeping it open for a later attempt), says stream_purged once, and
streams what is still in the log and what comes live.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
When Dapr ran a node's activity twice (a lost completion, or two at
once), the stream log kept the first attempt that finished while the
workflow could use the other one's output, so stream and state
disagreed. Now every attempt logs its batches and an end record (a late
one leaves the head alone), the activity output names its attempt, the
workflow publishes the attempt it used per unit in its custom status
and output, and the reader follows that attempt, resetting a unit it
streamed from another one.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
Two concurrent POST /resume calls for one interrupt both passed the
pending check; the workflow took the first and ignored the second, yet
its caller got the run's result. Each resume now carries an id, the
workflow publishes the id it took in its custom status, and a caller
whose resume was ignored gets ResumeConflict: a 409, before any event of
a streamed resume. invoke(Command(resume=...)) checks the same. The
test client queues raised events per key instead of keeping the last.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
The custom status listed every step's units and was rewritten each step,
and every stream read it every 200 ms. Dapr returns the custom status
only with fetch_payloads (durabletask-go's GetInstance copies it inside
the GetInputsAndOutputs branch), so the input travels with every read
and fetch_payloads=False is not an option.

The status now lists the last 128 steps (executed_from says where they
start); a reader behind that window waits for the final event, which
lists every step, so its chunks stay in order. A follower reads the
status when no known unit is still being written, and otherwise every
tenth poll.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…he run endpoints

The Conversations section recommended MemorySaver and did not say that
a run without a thread id is stateless, how resent history is handled,
how to opt out, or what happens when the state cannot be saved. The
proxy section now says the per-run endpoints answer anyone who knows a
run's id and belong behind the app's own authentication.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
… is sync-only

The runner calls a node with an async entry point through ainvoke, where
an AgentMiddleware with only wrap_model_call or wrap_tool_call raises
NotImplementedError before the wrapped call runs. A node with its own
sync function now falls back to invoke (in an executor, with the ambient
config) for that error; a composite is not retried, as its earlier steps
ran, and the README says to add the async variant there.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
A failed stream with no caller thread id reports the workflow id as its
thread, the sync fallback passes a RunnableConfig, and the resume route's
generator is typed as one.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
A Dapr bulk save is neither atomic nor ordered, so writing a batch and its
head in one save let a reader see the head first, or the head alone after a
failed batch write, and report a live run as purged. A flush now writes the
batch, then the head, and a reader looks a missing batch up once more after
a short wait before it calls the unit purged. The fake log store can land a
bulk save out of order or in part.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
Two attempts of one unit running at once both took the head at their first
flush, so the one that finished last overwrote the other's done head. The
last flush now reads the head again and leaves a done head of another
attempt alone.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…step window

A reader that knew any step below the status's window took it as caught up,
so one that knew step 0 but not steps 1..199 learned the later steps first,
and a reconnect with the id it handed out skipped the gap. The reader now
reads on only when it knows the step just below the window.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…s no other

The README said a thread's state falls back to the store the workflows use,
but the runner passed only the app's agent-memory store, so an app with just
the workflow store (the default on Catalyst) ran every named thread from
scratch. The thread store now falls back to the workflow store, as the
stream log already does.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…saves do

- A thread id holding '||' made every run fail on the old-format index key,
  which Dapr refuses. Such ids are now a 422 over HTTP (they also end up in
  the workflow id), the old keys are never read for them, and an old key the
  store cannot read is skipped with a warning.
- With keep_checkpoints=1 a concurrent save could delete the checkpoint the
  index named before the load read it, and the thread started over. A load
  that misses its checkpoint now reads the index once more, and
  keep_checkpoints must be at least 2.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…_purged

Past the heads' TTL (a day by default) nothing of a finished run is left in
the log, and a replay reported every unit as stream_unavailable with reason
write_failed. A reconnect that finds no head for any unit it reads now sends
stream_purged; a unit missing among others that are there, and a live
stream's, is still a failed write.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…s own id

A subgraph a node runs starts afresh on every run of the node, so LangGraph's
ids for its interrupts change from run to run, and its parallel nodes take
the task's resume values in whatever order they ask. An id map answering one
of two such interrupts gave its value to the wrong one and re-issued the
other under a new id.

A subgraph's interrupt is now reported under an id made of the task and the
path of node names down to it, the workflow tags each answer with that id,
and the interrupt that asks gets its own value; one left unanswered keeps its
id. Activity outputs of runs started earlier carry no path, so their replay
is unchanged. Tasks a subgraph sends to one node cannot be told apart across
runs: an id map naming only some of their interrupts is refused (422 over
HTTP, ValueError in Python), as the README says.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
The status said only which resume the run took last, so a caller that
polled after the run took another resume and paused again was told its
resume was taken. The status now keeps the winner of the last 16 interrupts,
and a loser among them always gets 409.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
… updates

- {"resume": null} raised a resume over HTTP while Command(resume=None) is
  refused in Python: both are now refused (422 over HTTP).
- Command(update=..., resume=...) resumed the run and dropped the update
  without a word: a Command that sets update or goto besides resume is now a
  ValueError.
- The README said a node's last write is retried up to four times; it is
  tried four times in all.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…m its last chunk

When the serving replica's sidecar went away mid-run, the stream ended with
workflow_failed (workflow_still_running: true) and the SSE id v1.end. A client
that reconnected with that id, as EventSource does, got only the final event
and lost the rest of the run.

A final event of a run that is still going now repeats the last chunk's
cursor (on a reconnect, before any chunk, the cursor the client sent), and the
failures raised out of a stream (StreamError) go through the same encoder
instead of being numbered per connection. The README says to treat such an
event as a lost stream and reconnect with its id.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
The log reader learns a run's units from its custom status, which it reads
only every few polls while a unit is being written, and once the run ended it
took the final event as the status. A completed run's final lists every step;
workflow_interrupted and a failed run's final list none. So when the run
paused on interrupt() before the reader had read the status since that step
started, the stream closed without reading the step: the __interrupt__
updates chunk was missing from the live stream, though a replay had it.

When the final event does not list the run's units (and the run is not still
going), the reader now reads the custom status once more and drains every unit
it names before it closes.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…1.start

workflow_started always carried v1.start, also on GET
/agent/run/{id}/stream with a Last-Event-ID. A connection that dropped right
after it made the client reconnect with v1.start and receive the whole run
again. It now carries the id the client resumed from (normalized as a cursor);
a new run still starts at v1.start.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
…not v1.start

The stream of POST /agent/run/{id}/resume carries what happens after the
resume only, but its workflow_started carried v1.start, and so did a failure
before its first chunk. A client that reconnected with either got the part of
the run streamed before the interrupt again. workflow_started now carries the
cursor of what the log held when the stream started, and a failure before the
first chunk repeats it.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
Tests that drive agent_workflow inline patch the workflow's when_all per run,
and a patch restores whatever it found when it ends. A patch that ended while
another thread's run was still going (a paused run of an earlier test whose
wait timed out) put the real when_all back under it, and that run failed with
"'dict' object has no attribute '_parent'". Which test hit it depended on
timing: adding tests made a reconnect test in test_status_size fail in the
full suite only. A session fixture now sets the inline when_all once, so every
restore restores it.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
@CasperGN CasperGN changed the title feat(langgraph): stream tokens, node updates and custom events from Dapr workflow runs feat(langgraph): stream, reconnect, continue threads and resume interrupts on Dapr workflow runs Nov 27, 2026
CasperGN and others added 2 commits November 27, 2026 08:29
…sent

The workflow_started of a resume's stream took its id from the follower
after the run had taken the resume. The follower reads the log on its own
while the run goes on, so by then it could already have read the run's
first chunks after the resume, which the stream had not yet yielded. The
id then pointed past them, and a reconnect with it missed them
(test_a_drop_right_after_workflow_started_resumes_the_rest failed in CI on
3.12). The id is now read once the follower has skipped to the end of the
log and before the resume is sent, while the paused run cannot add to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Casper Nielsen <casper@diagrid.io>
Every node activity of a streamed run wrote a values chunk (the whole
output state) and tasks/debug start events (the node's whole input) to
the stream log, whatever modes the client asked for. With the default
modes (messages, updates, custom) those three copies of the state per
activity were never read.

The run now carries its requested modes in its config. Activities write
values chunks only when the run asked for values, and task events (sent
as both tasks and debug) when it asked for either. messages, updates and
custom are always written. A run without recorded modes (started before
this change) records every mode.

A reconnect (GET /agent/run/{id}/stream, astream_resume) or a streamed
resume that asks for a mode the run did not record is refused with a 422
(ValueError in Python) naming the modes the run recorded. A resumed run
keeps the modes it was started with. The README's Streaming section says
so.

With no task event, a node that fails before its first chunk logged
nothing and wrote no head, and a replay of the run reported its log as
expired (stream_purged). A failed attempt that logged nothing now writes
its head, and a replay reports the log expired only when a unit whose
output the run used has no head either.

Signed-off-by: Casper Nielsen <casper@diagrid.io>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DaprWorkflowGraphRunner has no token streaming or per-node progress for LangGraph

1 participant