Cut a stream at every point and check what the consumer is left with.
A stream that stops early is not a rare case. A connection drops, a proxy times out, a producer dies, someone presses stop. So take the same stream, run it through your client once whole and once for every prefix of it, and ask two questions of each cut:
- Did the head change? Truncation may lose the tail. It must never alter what came before the cut.
- Does the consumer say so? A run that was cut short must not report what the same run reports when it finishes.
The second one is where things are usually wrong, and it is quiet when it is wrong, which is why a loop is better at finding it than reading the code.
npx cut-at-k demoNothing to install and nothing sent anywhere — it replays a recording that ships with the package, 48 of AG-UI's own conformance streams cut at every event boundary, and prints what the client did with each cut:
48 streams, 227 cuts, 18 streams excluded as invalid on purpose
4 cuts threw during replay
reported the same as the whole run : 154
of which something was actually lost : 54
of those, no terminal event either : 52
spread across : 34 streams
To ask the same question of a client you have installed rather than a recording,
npx cut-at-k probe lists the ones that ship with this package — AG-UI, the
Vercel AI SDK, LangGraph, Mastra, the OpenAI Node SDK, the MCP TypeScript SDK,
and the same question again in Python — and says which you can run right now and
what to install for the rest.
Each is a worked answer to everything the API below asks you to decide, against a
real SDK. probes/README.md carries what they found.
npm install cut-at-kimport { severAtEveryPoint, summarise, format } from 'cut-at-k';
const report = await severAtEveryPoint({
events, // the whole stream, in order
label: 'my-stream',
replay: async (prefix) => { // run this prefix through your client
const seen = [];
const settled = await drive(prefix, seen);
return { delivered: seen, settled, text: render(seen) };
},
});
console.log(format(summarise([report], {
lostContent: (cut, whole) => cut.text !== whole.text,
})));Nothing here knows about any protocol. You supply the events and a function that replays them; this supplies the loop and the comparison.
Three things look identical in the raw numbers and only one of them is a finding:
- A cut that lost nothing. Cutting after the last content event and before some trailing bookkeeping removes no information, so of course the consumer reports the same thing. Correct behaviour.
- A stream that is invalid on purpose. Cutting it before its deliberate error removes the error, so the whole stream delivers less than the prefix and every comparison against it is noise. Conformance corpora are full of these.
- A cut that lost content and was reported as though it had not. The finding.
So summarise reports nothing as a defect unless you pass lostContent, and it
reports excluded streams as a count rather than dropping them silently. The first
version of summarise did not make these distinctions and called 154 cuts a
problem on a corpus where 54 were. A tool that cries wolf is worse than no tool.
AG-UI ships 68 conformance fixtures — real
event streams, written by the protocol's authors, with the outcome each one requires.
Two are a single event long and have no cut point, so 66 were replayed: each through a
real HttpAgent over real HTTP/SSE — @ag-ui/[email protected] — whole and then cut at every
event boundary. Both
steps are in results/ and the recording is committed, so the block below is one
command away:
node results/run-ag-ui.mjs results/sever-results.json
Recorded again on 1.0.3, which arrived on 16 October, and committed beside it as
results/sever-results-1.0.3.json. Every line of the block below is the same on both,
and with minted ids normalised the 277 rows hash identically — so the client's behaviour
at a cut did not move between the two.
node results/run-ag-ui.mjs results/sever-results-1.0.3.json
That comparison only became possible with this run. The client mints a v4 UUID for a
message the stream never gave an id, and it lands in the recording, so re-recording the
same version twice used to differ in sixteen fields — enough to hide a real change
inside noise shaped exactly like one. record.mjs now rewrites minted ids to
<minted-N> positionally, and two recordings of one version are byte-identical.
48 streams, 227 cuts, 18 streams excluded as invalid on purpose
4 cuts threw during replay
reported the same as the whole run : 154
of which something was actually lost : 54
of those, no terminal event either : 52
spread across : 34 streams
A cut here is the specification's own definition of a truncated run: the stream ends
after k events with no further frames and no terminal event. From
/spec/1.0/basic/transports#truncation:
A consumer whose stream ends without a terminal event has a truncated run … A consumer MUST NOT synthesize a
RUN_FINISHEDfor it and MUST NOT report it as having succeeded.
The smallest case, from their conformant-run-is-quiet fixture cut after its fourth
event. What runAgent() actually resolves to, verbatim:
truncated events RUN_STARTED STEP_STARTED TEXT_MESSAGE_START TEXT_MESSAGE_CONTENT
resolved {"newMessages":[{"id":"m-1","role":"assistant","content":"Hello, "}]}
completed resolved {"newMessages":[{"id":"m-1","role":"assistant","content":"Hello, world."}]}
Both calls resolve. Neither rejects, and RunAgentResult has no field that says which
one was cut short — its result member is undefined in both, so JSON.stringify
omits it entirely. The two values are not identical: the truncated one carries less
text. But the caller has nothing to compare it against, and the message count is 1
either way, so a caller that checks whether the call succeeded, or how many messages
came back, is told the same thing by a run that finished and a run that stopped
halfway through a sentence.
Be precise about the limit of that, because it matters: a subscriber can detect
this today. onRunFinishedEvent fires on the completed run and not on the truncated
one, while onRunFinalized fires on both. So the claim is not that the client hides
the truncation everywhere — it is that the awaited call does not surface it, which is
the channel most callers use.
None of the above is a discovery. It was reported on 2026-08-03 as
ag-ui-protocol/ag-ui#2300 —
"a stream that ends without RUN_FINISHED/RUN_ERROR resolves as success" — and
#2354 has been open since
2026-08-07 with the fix: verifyEvents asserting that a terminal event arrived, so a
stream that just stops becomes an error instead of a silent success. Both were open at
the time of writing.
That is the argument for this tool rather than against it. The bug was found once, by hand, on one stream. Running the same corpus through this loop surfaces 54 cuts of that shape across 34 streams without anyone guessing where to look — and when #2354 merges, re-running the recording is how you find out which of the 54 it actually fixed.
results/run-ag-ui.mjs reproduces the table from the recorded observations, through
this library's own summary rather than separate arithmetic, so the numbers above and
the numbers the tool prints cannot drift apart.
The AG-UI run above is one protocol. probes/ asks the same question of the
Vercel AI SDK, LangGraph JS, Mastra, the OpenAI Node and Python SDKs and the MCP
TypeScript SDK, with
a self-contained script for each that prints its own verdict and refuses to run against
anything but the current release.
Five came back clean: the Vercel SDK distinguishes a cut run by reporting
finishReason: other, or by raising when no text got through at all; LangGraph's
checkpoint stops where an aborted consumer stopped and says where to resume; Mastra's
memory still holds what the consumer was shown; the OpenAI Node SDK's final response keeps
the tool call it streamed and never claims to have completed; and the OpenAI Python SDK
raises at every cut rather than returning something that looks finished.
The MCP SDK did not, and it was already reported: when the response leg of a POST dies, the request waits out its whole timeout before the caller is told, at every cut point including one where half the response had arrived. Seven asked, five clean — and both of the two that answer wrongly were found by someone else first, which is the honest account of what this is. The harness supplies the shape of a known defect, and occasionally a false positive in the fix.
chunk-invariance asks something that
sounds like this one and is not. It varies where the boundaries fall in a stream that
arrives in full, and requires a filter's concatenated streamed output to equal its
whole-input output. This harness never moves a boundary. It removes the tail, and asks
what the consumer is left with and whether it can tell.
They therefore catch different things. chunk-invariance catches a filter that acts on a
chunk before the value inside it is finished, and names the smallest split that breaks it.
It cannot catch a client that reports a run which stopped halfway as one that finished,
because in its world nothing ever stops halfway. This harness cannot catch the filter bug,
because every cut it makes is also an ending — it never delivers the rest, so a boundary
that a complete stream would have recovered from is a case it never produces.
Its own README draws the line from the other side: "It tests a filter you can call in-process. It does not test a running gateway, where the chunks are decided by an upstream model, a network and an SSE parser."
If you stream user-visible text through a filter, you want both.
It is one protocol, cut at event boundaries, and one client at one version:
@ag-ui/[email protected]. The figures move with the client, so the version is part of the
result rather than a footnote — replaying the same corpus through 0.0.58 gives
141/49/47/31, because that older client rejects four fixtures this one parses. Across the
1.0 patch line the figures above did not move — the 1.0.0 recording is committed beside
the current one as results/sever-results-1.0.0.json, so the comparison is two commands
rather than a claim.
What did move is a figure those eight lines never print. The prefix property — what a cut
delivers must be a prefix of what the whole run delivers — was broken on 14 cuts under
1.0.0 and is broken on none under 1.0.2. All 14 sit in eight -fatal fixtures, which
run-ag-ui.mjs excludes by label as invalid on purpose, which is why no count in the block
changed. The mechanism is the inversion: on 1.0.0 the whole run surfaced RUN_STARTED
and nothing else before throwing, so a shorter cut — still valid at that point — delivered
more than the whole, and the property that holds everywhere else turned upside down. On
1.0.2 both surface the valid prefix. A newer client fixing an invariant this harness
measures is the better advertisement for re-recording than the counts holding.
One limit worth naming: the recording pins the client version but not the corpus — a fixture
added to AG-UI's corpus changes the counts without changing anything here. The id that
era-0-0-45-thinking-translated mints per run is normalised rather than removed, and
<minted-N> records that two messages shared an id rather than which id it was, so a change
that altered only an id's value would not show up. Cutting inside
a frame — mid-UTF-8 sequence, mid-SSE frame, mid tool-call JSON — is covered for a single
body by probes/ag-ui-bytes.mjs, and it found nothing: of 124
seams exactly one reports what the whole body reports, and that one is byte 395 of 396, the
body minus its trailing newline, with every frame intact. It is not covered for the corpus
above, which is cut at event boundaries only. Other frameworks have no
validator of their own to use as an oracle, so for those the harness would have to
assert its own expectation, which is weaker evidence.
Findings belong in the tracker of the project that carries them, not in a scoreboard kept outside it.
Early. The core loop, the byte-level severing and the summary are tested
(npm test, 21 tests, no dependencies). The API will change.
MIT © Redouane (ROSH Company Labs)