workerd / webstreams
AGENTS.md8.8k starsChanged 9 months agoApache-2.0View on GitHub
TypeScript Streams implementation with a backend-blind reader layer and two consumer backends behind the StreamConsumer/ByteStreamConsumer fence. Authoritative docs are IN-SOURCE — read the file headers first. Parent directory conventions (primordials discipline, JSG capture trap, private-brand dispatch, no instanceof) apply here — see src/per_isolate/AGENTS.md. The spec's tee() gives each branch its own controller and queue, fed by a reader on the original. The queued backend instead has ONE queue with N consumers (cursors), one per live branch: tee() forks the stream's…
Trending
Quiet since August.thin dataabout the whole repository
Who's talking about cloudflare/workerd
- A Hacker News story“OS Workerd, Cloudflare's JavaScript/WASM Runtime”Hacker News · Sep 27, 2022 · 27 points
- withastro/astro“Cloudflare adapter returning [object Object]”GitHub · Oct 10, 2025 · 18 reactions
- supabase/supabase-js“The 'cache' field on 'RequestInitializerDict' is not implemented - Cloudflare Workers”GitHub · Mar 28, 2024 · 16 reactions
- nodejs/node“src: improve buffer.transcode performance”GitHub · Aug 1, 2024 · 13 reactions
- NixOS/nixpkgs“Package request: workerd”GitHub · Nov 12, 2024 · 12 reactions
The biggest 5 of 12 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 12
Talked about on GitHub, Bluesky and Hacker News (12 times).
On GitHub · 6
- Oct 10, 2025Cloudflare adapter returning [object Object] — withastro/astro18 reactions · 15 comments
- Mar 28, 2024The 'cache' field on 'RequestInitializerDict' is not implemented - Cloudflare Workers — supabase/supabase-js16 reactions · 24 comments
- Aug 1, 2024src: improve buffer.transcode performance — nodejs/node13 reactions · 26 comments
- Nov 12, 2024Package request: workerd — NixOS/nixpkgs12 reactions · 8 comments
- Feb 19, 2024Add Curve25519 — w3c/webcrypto9 reactions · 16 comments
1 more on GitHub
- Nov 3, 2025Optimize TextEncoder::encode — nodejs/performance7 reactions · 33 comments
On Bluesky · 4
- Mar 24, 2026workerd : le runtime JavaScript/Wasm open source de Cloudflare Workers — @news.humancoders.com4 likes and reposts
- Aug 22, 2026Current status: trying to build github.com/cloudflare/w... on various sandbox providers — @jeremymorrell.dev1 likes and repost
- Mar 24, 2026workerd : le runtime JavaScript/Wasm qui propulse Cloudflare Workers est maintenant open source. Basé sur les standards web, il permet… — @humancoders.com1 likes and repost
- Nov 5, 2024Technically workers are open source github.com/cloudflare/w... — @userops.bsky.social1 likes and repost
On Hacker News · 2
- Sep 27, 2022OS Workerd, Cloudflare's JavaScript/WASM Runtime27 points · 2 comments
- Oct 5, 2023Cloudflare workers is adopting Ada URL parser2 points
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository61 other files it gives its agents.
- AGENTS.mdAGENTS.md
- build/AGENTS.mdAGENTS.md
- src/cloudflare/AGENTS.mdAGENTS.md
- src/node/AGENTS.mdAGENTS.md
- src/per_isolate/AGENTS.mdAGENTS.md
- src/per_isolate/crypto/AGENTS.mdAGENTS.md
- src/per_isolate/webfs/AGENTS.mdAGENTS.md
- src/pyodide/AGENTS.mdAGENTS.md
- src/rust/AGENTS.mdAGENTS.md
- src/rust/cxx/AGENTS.mdAGENTS.md
- src/tests/node/AGENTS.mdAGENTS.md
- src/tests/node/http-client/AGENTS.mdAGENTS.md
- src/tests/node/http-server/AGENTS.mdAGENTS.md
- src/tests/node/net/AGENTS.mdAGENTS.md
- src/tests/node/stream/AGENTS.mdAGENTS.md
- src/tests/streams/AGENTS.mdAGENTS.md
- src/tests/streams/cache/AGENTS.mdAGENTS.md
- src/tests/streams/compression/AGENTS.mdAGENTS.md
- src/tests/streams/digest/AGENTS.mdAGENTS.md
- src/tests/streams/encoding/AGENTS.mdAGENTS.md
- src/tests/streams/formdata/AGENTS.mdAGENTS.md
- src/tests/streams/htmlrewriter/AGENTS.mdAGENTS.md
- src/tests/streams/identity/AGENTS.mdAGENTS.md
- src/tests/streams/inspect/AGENTS.mdAGENTS.md
- src/tests/streams/iocontext/AGENTS.mdAGENTS.md
- src/tests/streams/piping/AGENTS.mdAGENTS.md
- src/tests/streams/r2-patterns/AGENTS.mdAGENTS.md
- src/tests/streams/readable/AGENTS.mdAGENTS.md
- src/tests/streams/readable-byte/AGENTS.mdAGENTS.md
- src/tests/streams/scaling/AGENTS.mdAGENTS.md
- src/tests/streams/sockets/AGENTS.mdAGENTS.md
- src/tests/streams/strategies/AGENTS.mdAGENTS.md
- src/tests/streams/transform/AGENTS.mdAGENTS.md
- src/tests/streams/writable/AGENTS.mdAGENTS.md
- src/workerd/api/AGENTS.mdAGENTS.md
- src/workerd/api/crypto/AGENTS.mdAGENTS.md
- src/workerd/api/node/AGENTS.mdAGENTS.md
- src/workerd/api/streams/AGENTS.mdAGENTS.md
- src/workerd/io/AGENTS.mdAGENTS.md
- src/workerd/jsg/AGENTS.mdAGENTS.md
- src/workerd/server/AGENTS.mdAGENTS.md
- src/workerd/util/AGENTS.mdAGENTS.md
- types/AGENTS.mdAGENTS.md
- bazel-test-hygieneSkill
- commit-categoriesSkill
- dad-jokesSkill
- find-and-run-testsSkill
- identify-reviewerSkill
- investigation-notesSkill
- kj-styleSkill
- markdown-draftsSkill
- parent-project-skillsSkill
- pr-review-guideSkill
- receiving-code-reviewSkill
- rust-reviewSkill
- ts-styleSkill
- update-v8Skill
- wd-test-formatSkill
- workerd-api-reviewSkill
- workerd-safety-reviewSkill
- The first 60 shown.
The file
We split this AGENTS.md into the rules it gives an agent
3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 130
Every dictionary the implementation builds itself — the sources, sinks, strategies and transformers of the internal pairs, and the stand-in …
- Very specific: line 138
Do not port logic across the fence without checking BOTH invariant lists (queue.ts and native.ts headers).
- Very specific: line 158
Every stream instance carries an own, non-enumerable api-symbol brand (kReadableStreamBrand / kWritableStreamBrand), stamped at the very …
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
src/per_isolate/webstreams/
TypeScript Streams implementation with a backend-blind reader layer and
two consumer backends behind the StreamConsumer/ByteStreamConsumer
fence. Authoritative docs are IN-SOURCE — read the file headers first.
Parent directory conventions (primordials discipline, JSG capture trap,
private-brand dispatch, no instanceof) apply here — see
src/per_isolate/AGENTS.md.
FILE MAP
| File | Role |
ring-buffer.ts | O(1) FIFO with indexed access backing every internal queue below; leaf module |
view-extent.ts | A caller-supplied view's byte extent through captured getters; detached/out-of-bounds views (DataViews included) read as empty; leaf module |
queue.ts | QUEUED backend: single-queue/multi-cursor, JS sources; fence interfaces; invariant list |
native.ts | NATIVE backend: C++-backed pull conduit; the C++/JS contract + invariants |
readable.ts | Reader layer + queued controllers + the BACKEND-DISPATCH points (constructor, tee, chains, byte-capable gate, JS-to-C++ extraction) |
writable.ts / transform.ts / strategies.ts | WHATWG writable/transform/strategies |
identity.ts | IdentityTransformStream and FixedLengthStream (byte-capable identity transforms) |
compression.ts | CompressionStream/DecompressionStream over the C++ codec handle (utils.newCompressionCodec) |
encoding.ts | TextEncoderStream and TextDecoderStream (pure JS codec transforms) |
streams.ts | Module aggregator (user-visible classes + the flag-gated DrainingReader) |
types.d.ts | TypeScript type definitions for the streams API |
THE QUEUED TEE MODEL (deliberate spec divergence)
The spec's tee() gives each branch its own controller and queue, fed by a
reader on the original. The queued backend instead has ONE queue with N
consumers (cursors), one per live branch: tee() forks the stream's cursor
into two branch cursors, removes the original's, and leaves the original a
permanently locked, inert shell — it consumes nothing, and there is no
per-branch controller to close or error. A tee of a branch does the same to
the branch: its two branches join the queue as consumers alongside their
aunt. Consequences, all handled by the controller (readable.ts,
controllerConsumerLeaving):
- The source is cancelled only when the LAST consumer leaves the queue
(cancelled, or errored through the Node.js interop hook before the
source requested close), with the reason of every consumer that left —
one reason as is, several as an
AggregateErrorin the order they left (the spec passes[reason1, reason2]). A consumer that leaves while others remain gets a promise settled with that cancel, or withundefinedonce the source closes or errors on its own (the spec's shared cancel promise). A branch that errors alone once close is requested — through the hook, or a byte branch's fractional-element fill at close — leaves without a reason and never cancels the source (the spec never forwards a branch's error to it); if it was the last consumer, the source ends as when every consumer has drained (controllerConsumerErrored). - Erroring the source's own stream (its controller's
error(), the interop hook) errors every consumer; erroring a live branch errors that branch alone. - The source's own stream, once teed away, is closed by the source's own
events, never by the branches' progress: it closes when close is
requested (having no cursor, it has nothing to drain — so before any
branch has read, while chunks may still be buffered for them), or when
the last consumer's leaving cancels the source; it errors when the
source errors. That is what
finished()on a teed source observes (the spec's source closes once the tee's reader has drained it, or both branches have cancelled). The source itself ends later — errored, cancelled, or closed with every consumer drained — and that, not its stream's state, gates the controller'serror(): anerror()afterclose()still errors the branches that have chunks to drain, although the source's stream has already closed.addAbortSignal()on that stream, which stops listening once its stream has finished, no longer reaches them by then, and the interop hook is a no-op on it as on any stream that is no longer readable. - A branch that has itself been teed is not the controller's stream, so
none of the source's events would reach it: the tee closes it
(
closeReadableStreamHusk), and erroring it does nothing. - Consumers that are collected rather than cancelled (every branch dropped
while the source still holds its controller) leave the queue with no
consumer for good: it drops what it holds and what is enqueued later,
desiredSizereads as the high-water mark, and the controller releases the source — no more pulls, and its cancel never runs, since GC timing runs no user callback — while keeping its own state machine (close()closes the source's stream;enqueue()after it throws as ever). C++ does the same but keeps pulling (readable ledger #20). Suite:gc.jsin the readable and readable-byte suites. - Backpressure follows the SLOWEST consumer:
desiredSizeis the high-water mark minus the largest backlog among the cursors. This trades flow for bounded memory: the spec's per-branch queues keep a reading branch flowing but buffer without bound for an idle one, while here a source that enqueues only whiledesiredSize > 0stalls every branch once an idle branch's backlog reaches the high-water mark, until that branch reads or leaves. The pull trigger is unaffected: a pending read on any cursor triggers a pull regardless ofdesiredSize(apull()that itself gates ondesiredSizestalls the same way). C++ behaves the same. Suite:teeBackpressureFollowsSlowestBranchin the readable suite. - The controller's
byobRequestcovers a cursor's reads only while that cursor is the queue's only one. The exception is a released reader's head pull-into on the sole cursor attee()/detach: the controller takes it over (#releasedHead), so a request the source holds across the fork keeps working, as in the spec. Responding to it enqueues the head's bytes, old and new, for every cursor (each drops its own copy of the old ones, fromadoptReleasedBytes).enqueue(),error(), cancel and a closed-staterespond(0)retire it. Suite: readable-byte ledger #25. - Nothing walks a tree of streams: closing, cancelling and erroring act on cursors and their owners, and no stream retains another.
HANDED-OFF STREAMS
A stream whose data moves to another stream is closed at the handoff,
left locked and disturbed, and drops its controller
(closeReadableStreamHusk): a teed branch (above), the source of a
native-backed tee, and a native-backed stream whose source is extracted
(a native-to-native pipe, the C++ bridge's pumpTo) or detached (the
bridge's detach(): new Request(request), socket upgrades). The legacy
C++ streams leave the same streams locked, disturbed and closed. The
Node.js interop closed-promise settles then, and the interop error hook,
which acts only on a readable stream, cannot reach the moved source. A
queued stream detached from its source is the exception: it stays the
controller's stream, closing and erroring with the source, and the hook
on it errors the detached stream. Suites:
src/tests/node/stream/finished-and-abort.js,
src/tests/streams/sockets/socket-streams.js.
KEY RULES
- The reader layer must stay backend-blind; backend divergence is confined to the fence interface and the marked BACKEND-DISPATCH points.
- Internal code never dispatches through a user-reachable prototype
method: call the private method (
#error,#read), a module slot (controllerError), or anuncurryThiscapture taken at load time (transform.ts,encoding.ts). The public method is the brand check plus that internal entry. - Every dictionary the implementation builds itself — the sources, sinks,
strategies and transformers of the internal pairs, and the stand-in for
an omitted argument (
kEmptyDictionary) — is null-prototype, so a pollutedObject.prototypecannot supply members. Members of the C++ native source are read withdeclaresMember, which stops beforeObject.prototype. Copies of internal bytes usecloneArrayBuffer(spec CloneArrayBuffer), never the species-consultingslice. Suite guard: each suite'spollution.js. - Do not port logic across the fence without checking BOTH invariant
lists (
queue.tsandnative.tsheaders). - The native source contract (marker symbol, standard pull/cancel hooks,
byobRequest discrimination, once-per-pull delivery, per-pull abort
signal for cancellation, under-delivery = EOF signal delivering the
partial as
{done: false, value: partial}with the next read observing EOF, tee hook,expectedLengthexact-total byte contract) is specified in thenative.tsheader. The C++ implementation (ReadableStreamNativeSourceinsrc/workerd/api/js-readable-stream.{h,c++}) MUST conform to it; JS mocks in tests exercise the conduit independently. Key addition:pullreceives an extensionsignalargument — the source checkssignal.abortedbefore delivery and stashes bytes for redelivery if aborted (race buffering lives source-side; the JS conduit is uniformly bufferless). nativeStreamInternals(markers, extraction symbols, conduit construction) is module-private, consumed only by readable.ts/writable.ts and the C++ bridge via the API-symbol registry. The C++ mocks injs-readable-stream-test.c++construct realReadableStreamNativeSourceobjects; no JS-visible marker export exists.- Every stream instance carries an own, non-enumerable api-symbol brand
(
kReadableStreamBrand/kWritableStreamBrand), stamped at the very top of the constructor (before any early return). The C++ bridge'stryUnwrapTsrecognizes streams by probing it — an own-data-property read that executes no JS. That constraint is load-bearing: recognition runs during RPC deserialization, inside V8's no-JS-execution scope. Any new construction path MUST go through the constructors (or stamp the brand itself). - The C++ bridge MUST NOT dispatch into the TypeScript implementation
while JS execution is disallowed (
js.isJavascriptExecutionDisallowed(), set during RPC value deserialization):getCppExport/dispatchCall/invokeMethodassert this. Bridge operations reachable in that scope either answer from C++-side knowledge (state probes return the hydration-fresh answers; seeJsReadableStream::isDisturbed) or happen before the scope entirely (stream construction viaRpcDeserializerExternalHandler::prepare()'s externals hydration).
NODE.JS INTEROP HOOKS
ReadableStream.prototype and WritableStream.prototype carry two
non-enumerable members keyed by the well-known symbols Node's own web
streams use: a Symbol.for('nodejs.webstream.isClosedPromise') getter
(an object whose promise settles with the stream: fulfilled on close,
rejected with the stored error, created lazily and marked handled) and a
Symbol.for('nodejs.webstream.controllerErrorFunction') method (errors
the stream as its controller's error() would; a native-backed readable
also cancels its source; a queued tee branch, whose controller is shared
with its siblings, errors alone — its cursor leaves the queue as a
cancelled branch's would, until the source requests close; a branch that
has itself been teed is inert; see the tee model above). The readable method errors byte streams too, native
ones included; Node's is deliberately a no-op for byte stream controllers,
so addAbortSignal() on a Response body (a byte stream in Node) is
inert there and errors the body here. The method runs neither the sink's
abort nor the source's cancel, so on a half of a transform pair
(transform.ts, identity.ts, compression.ts; the encoding streams
are TransformStreams) the other half would never learn of it: each pair
registers an interop error hook on both halves (setInteropErrorHook in
internalsForPipe and internalsForTransform), called synchronously
after the hook has errored a half, and errors the pair as
TransformStreamDefaultController.error() would (TransformStreamError).
Node errors the one half only and the other's pending operations stay
pending. src/node's finished()/eos() (also behind
stream/promises) and addAbortSignal() rely on the hooks to observe or
error a web stream without taking its lock; nothing else in the node layer
touches them. The C++ implementation has no equivalent, and the node layer
raises ERR_WEB_STREAM_INTEROP_UNSUPPORTED there. Suite:
src/tests/node/stream/finished-and-abort.js and
abort-transform-pairs.js.
ANTI-PATTERNS
- NEVER expose internals on user-visible exports.
streams.tsexports exactly the user-visible classes plusReadableStreamDrainingReader, whichmain.tsinstalls only under the internal-testingexpose_draining_readerflag. (The Node.js interop hooks above are the one deliberate, symbol-keyed exception.)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

