agentleFS
CloudflareKnown publishercloudflare/workerd/src/tests/streams/compression/AGENTS.md

workerd / compression

AGENTS.md8.8k starsChanged 9 months agoApache-2.0View on GitHub

An informal specification of the two Compression Streams classes as implemented in workerd, derived from — and kept in lockstep with — the test suite in this directory. The tests are the normative artifact. Both the C++ implementation (src/workerd/api/streams/compression.{h,c++}, built on internal streams over the shared api/compression.h CodecStage) and the TypeScript implementation (src/per_isolate/webstreams/compression.ts, behind typescript_implemented_streams) are covered. The two wrap the SAME C++ zlib codec (the TS pair drives utils.newCompressionCodec handles), so codec output is parity by construction; divergences live…

Trending

Quiet since August.thin dataabout the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 2 mentionsApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 1 mentionSep 2026: 0 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the cloudflare/workerd repository that our weekly crawl found: only 12 in all, so this is a hint, not a trend. There is no adoption data for this file yet.

Who's talking about cloudflare/workerd

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

1 more on GitHub

On Hacker News · 2

The file

We split this AGENTS.md into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Eager push: write() feeds the codec and settles when the codec has consumed the chunk — no read demand needed (not the identity rendezvous, …

    line 52

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

CompressionStream and DecompressionStream

An informal specification of the two Compression Streams classes as implemented in workerd, derived from — and kept in lockstep with — the test suite in this directory. The tests are the normative artifact. Both the C++ implementation (src/workerd/api/streams/compression.{h,c++}, built on internal streams over the shared api/compression.h CodecStage) and the TypeScript implementation (src/per_isolate/webstreams/compression.ts, behind typescript_implemented_streams) are covered. The two wrap the SAME C++ zlib codec (the TS pair drives utils.newCompressionCodec handles), so codec output is parity by construction; divergences live in the stream wrappers.

The WPT compression/* tests already run against both implementations (//src/wpt:compression and //src/wpt:compression-ts), so this suite complements WPT: workerd-specific semantics (eager push, BYOB readable), exact error identities and messages, the divergences, the strict-checks flag axis, and real-HTTP body integration via the SELF loopback binding.

Interfaces

[Exposed=Worker]
interface CompressionStream {
  constructor(DOMString format);  // 'deflate' | 'gzip' | 'deflate-raw'
  readonly attribute ReadableStream readable;
  readonly attribute WritableStream writable;
};
[Exposed=Worker]
interface DecompressionStream {
  constructor(DOMString format);
  readonly attribute ReadableStream readable;
  readonly attribute WritableStream writable;
};
  • Inheritance divergence (ledger #5): C++ subclasses TransformStream; TypeScript is standalone. readable/writable placement and constructor.length (0 vs 1) follow (#5, #6).
  • The format is ToString-coerced exactly once (an object's toString runs once, both impls); a coerced string outside the three formats throws TypeError "The compression format must be either 'deflate', 'deflate-raw' or 'gzip'." — but non-string arguments diverge (#7): TypeScript coerces undefined into that same validation failure, while the C++ jsg layer rejects it at the type boundary ("constructor parameter 1 is not of type 'string'."). null coerces to "null" in both.
  • The internal codec factory (utils.newCompressionCodec) is never a JS-visible surface.

Core semantics

  • Eager push: write() feeds the codec and settles when the codec has consumed the chunk — no read demand needed (not the identity rendezvous, not the encoding suite's HWM-0 demand-driven transform). Output buffers unboundedly on the readable side (TypeScript: the readable's queue, which the sink drains the codec's output into before the write settles; C++: the codec's buffer); a parked read is served as soon as any output exists (for deflate: the 2-byte zlib header from the first write, the rest at close-time flush).
  • Delivery (#16): a default read receives a bounded piece of a write's output — at most 64 KiB under TypeScript (the size of the chunks the sink queues), the internal-stream read buffer under C++ (4 KiB; 16 KiB under the updated-auto-allocate-chunk-size autogate) — and a BYOB read fills its view in both. A write's output is never a single JS chunk, however large. Output produced before a trailing-junk error goes to the waiting reads first under TypeScript (one piece each; WPT decompression-extra-input); C++ rejects the waiting read (#17).
  • Snapshot at write: the codec consumes a copy taken synchronously inside write() (C++ adapter copy; TS strategy-size-callback snapshot). Post-write mutation/resize/detach cannot change what compresses; an already-detached chunk is a zero-byte no-op; shadowing metadata getters are never consulted.
  • Chunks: ArrayBuffer, any view (offsets honored), empty and detached inputs are accepted by both. Strings (#1) and SharedArrayBuffers incl. SAB-backed views (#2) are accepted and encoded/copied by C++ but rejected by TypeScript per spec (Web IDL BufferSource without [AllowShared]). Everything else rejects with TypeError (#3 message) — after which the C++ stream SURVIVES (later writes flow, clean close) while TypeScript errors both sides, the spec's transform-time error propagation (#4). The TypeScript pair passes WPT's bad-chunks files; the C++ configuration disables compression-bad-chunks.
  • Corrupt input (DecompressionStream): the WRITE rejects (TypeError "Decompression failed.") and both sides error, in both implementations; the failure propagates through downstream pipes to consumers.
  • strict_compression_checks (pinned): trailing bytes after the member reject the write ("Trailing bytes after end of compressed data"); close() before the member completes rejects ("Called close() on a decompression stream with incomplete data") — including close with no data at all. Closing a CompressionStream with no writes emits a valid empty member.
  • Backpressure accounting (#8): the C++ writer's desiredSize is inert (always 1); TypeScript counts the in-flight chunk against the default HWM 1 and recovers. writer.ready is settled in both (no sustained backpressure signal under eager settlement).
  • BYOB: the readable is byte-capable in both (legacy parity; WHATWG describes a default stream).
  • Termination: writer.abort(reason) errors both sides; a pending read receives the reason re-created across kj under C++ (same type/message with enhanced_error_serialization pinned, different instance) vs the original instance under TS (#9); writer.closed gets the ORIGINAL instance in both. Writes after abort: C++ closed-TypeError vs TS original reason (#10). Non-Error reasons are Error-ized by C++, delivered raw by TS (#11). The canceling reader's parked read: C++ rejects with the reason, TS resolves done (#12). readable.cancel() errors the writable under TS; C++ leaves it untouched — writer.closed stays pending (#13).
  • Reads: a second concurrent default read rejects under C++ ("single pending read request") and parks under TS (#14); the thenable check runs once per read under C++, twice under TS (#15). Under TS the first check runs inside the write delivering the chunk; a reader cancel from there stops the delivery and fails that write with the cancel reason (the writable errors per #13), where C++ has already settled the write.
  • tee(): both branches observe identical bytes; the single-branch cancel promise carries the identity suite's ledger #13 semantics (C++ immediate, TS shared composite).
  • Bodies: the four SELF-loopback tests drive compression through real HTTP serialization (close-signal propagation from JS streams into internal response-body writables) plus response-body decompression and multi-transform chains.
  • The #6061 unhandled-rejection regression (Array.fromAsync over a failing DecompressionStream) is pinned under unhandled_rejection_after_microtask_checkpoint in both cells.

Compatibility flags

The C++ cell pins every date-gated flag the implementation is subject to (see the comment in compression-cpp.wd-test); the TS cell pins only strict_compression_checks (consulted by the shared codec factory), unhandled_rejection_after_microtask_checkpoint (isolate-level event timing), and the internal-testing expose_draining_reader.

compression-cpp-pedantic.wd-test runs the full shared module set with the dateless opt-in pedantic_wpt flag added to the main C++ cell's pinned set, pinning the ABSENCE of pedantic effects: the compression classes' internal-stream implementation consults the flag nowhere, and although the pedantic-gated standard-streams machinery IS reachable from this suite's surface (the pipe tests build real TransformStream sources), every shared assertion holds unchanged — an enforced invariant against future pedantic branches shifting anything the suite pins.

Flag (enable date)SelectsUnflagged behavior tested by
strict_compression_checks (2023-08-01)DS trailing-data + incomplete-close errorslegacy-nonstrict.js
capture_async_api_throws (2022-10-31)invalid chunk rejects instead of throwing synchronouslylegacyInvalidChunkThrowsSynchronously
unhandled_rejection_after_microtask_checkpoint (2026-03-03)rejection-event timing the #6061 regression depends on—
internal-stream flags (BYOB, abort queue, getters, tags, error serialization; see config comment)generic internal-stream behaviorsidentity suite legacy cell

Divergence ledger (C++ vs TypeScript)

#AreaC++TypeScriptPinned in
1String chunksaccepted, UTF-8 encoded (the reason WPT compression-bad-chunks is disabled there)rejected TypeErrorstringChunkDiverges
2SharedArrayBuffer / SAB-backed view chunksaccepted (copied out)rejected TypeError (spec: BufferSource without [AllowShared])sharedArrayBufferChunkDiverges
3Invalid-chunk TypeError message"This TransformStream is being used as a byte stream, but received an object of non-ArrayBuffer/ArrayBufferView type on its writable side.""The provided value is not of type (ArrayBuffer or ArrayBufferView)"invalidChunkAftermathDiverges
4Invalid-chunk aftermathstream survivesboth sides error (spec)invalidChunkAftermathDiverges
5TransformStream inheritance + accessor placementsubclass; readable/writable inheritedstandalone; own accessorstransformStreamInheritance
6constructor.length01constructorSurface
7Missing/undefined formatjsg type-boundary TypeError ("not of type 'string'")ToString-coerced into format validationnonStringFormatThrows
8desiredSize accountinginert (always 1)counts in-flight chunk, recoversdesiredSizeAccounting
9Abort reason to pending readre-created (same type/message, different instance)original instanceabortReasonIdentity
10Writes after abortTypeError "This WritableStream has been closed."original abort reasonwriteAfterAbortDiverges
11Non-Error abort reasonsError-ized (string becomes message)original valuenonErrorAbortReasonSurfacing
12Canceling reader's parked readrejects with the cancel reasonresolves done (WHATWG)cancelSettlesPendingRead
13readable.cancel() → writable sideuntouched; writer.closed stays pendingerrored; closed rejects with the reasoncancelReadableWritableAftermath
14Second concurrent default readTypeError "single pending read request"parked, served in ordersecondConcurrentRead
15Thenable check per read resolutiononcetwicethenInterceptionDuringReadResolution
16Default-read piece of a large buffered outputinternal-stream read buffer (4 KiB; 16 KiB under updated-auto-allocate-chunk-size)64 KiBlargeOutputDeliveredInBoundedPieces
17Output produced before a trailing-junk error, reads waitingreads rejecteach waiting read gets a piece, later reads errortrailingJunkAfterLargeOutput

Assertion catalogue

ModuleAsserts
api-surface.jstoStringTag branding; codec factory not exposed; side stability; inheritance/placement (#5); ctor name/length/source (#6); node:stream/web re-exports are the same classes; accessor brand checks
construction.jsvalid formats; invalid format exact message (case-sensitive); one-shot ToString coercion; non-string formats (#7)
round-trip.jsall-formats round trips (compression verified smaller); parked-read service with pinned deflate bytes; shared pump/concat/readAll helpers
chunk-boundaries.jsbyte-at-a-time compression; 2-byte split decompression; all formats with 5-byte write chunks
large-payload.js400KB patterned payload, chunked writes, byte-exact round trip
empty-stream.jsclose-with-no-writes emits a valid empty member; decompressing it yields EOF
corrupt-input.jswrite-time rejection with "Decompression failed."; both-sides error; iteration rejection; bad magic bytes
strict-checks.jstrailing-data write rejection; close-with-no-data rejection; truncated-member close rejection
chunk-types.jsBufferSource acceptance incl. offsets; string (#1), SAB (#2), invalid-chunk message+aftermath (#3, #4)
buffer-lifecycle.jssnapshot-at-write: post-write mutation/detach/shrink invisible; already-detached no-op; detached/out-of-bounds typed-array and DataView views are no-ops; lying metadata getters never consulted
byob.jsBYOB reader fills a 2-byte destination with the gzip magic
backpressure.jseager write settlement without reads; desiredSize accounting (#8)
propagation.jsabort rejects pending read (reason per #9), errors both sides; cancel settles parked read (#12); write-after-abort (#10); non-Error reasons (#11); writes after a queued close reject (message per impl) without disturbing the close or output; cancel→writable aftermath (#13)
reentrancy.jsthenable-check counts (#15); a reader cancel from a read result's then getter while the write is still delivering (TS: the write rejects with the reason, the writable errors per #13; C++: the write resolves, the writable is untouched per #13); second concurrent read (#14); close from a read continuation with round-trip integrity; sibling tee cancel from a continuation
tee.jsbranches byte-identical; single-branch cancel (identity ledger #13 semantics) with survivor draining
draining-reader.jsTS only (C++ asserts absence): expectedLength undefined; a closed stream's backlog swept in ONE read with done — a small one, and a 1 MiB one as its sixteen 64 KiB pieces; lock/release
delivery-shape.jsa 4 MiB single-write output read in bounded pieces (#16), byte-exact; BYOB views filled to their size; two pending reads take consecutive pieces (C++: #14); tee branches get bounded pieces; trailing junk after a large output with two reads waiting (#17)
gc-interplay.jswriter abort after wrapper GC; decompression through collected wrapper (codec handle liveness)
pollution.jsObject.prototype members (type, autoAllocateChunkSize, expectedLength, start, size, highWaterMark) reach neither the internal dictionaries nor a native body: a gzip round trip under pollution (neither implementation reads them)
pipe-integration.jscompress→decompress chains from user and TransformStream sources; through IdentityTransformStream; bad-data propagation through both transform kinds
body-integration.jsdirect Response(cs.readable) body (same object, unlocked; byte-exact local arrayBuffer round trip); SELF-loopback HTTP: response-body decompression, multi-transform chain with completing pipeTo, compression/decompression pipelines into internal response bodies
unhandled-rejection.js#6061: no spurious unhandledrejection with Array.fromAsync
which-impl.jsimplementation detection

Legacy (unflagged) behaviors

Guarded by compression-cpp-legacy.wd-test (C++ only, generate_all_compat_flags_variant = False):

BehaviorAsserted by
Trailing bytes after the member tolerated; member content deliveredlegacyTrailingDataTolerated
close() with no data tolerated (empty output)legacyCloseWithoutDataTolerated
close() mid-member toleratedlegacyTruncatedMemberCloseTolerated
Invalid chunk throws synchronously; the stream surviveslegacyInvalidChunkThrowsSynchronously

Generic pre-flag internal-stream behaviors (BYOB in-place fills, property placement, [object Object] stringification) are guarded by the identity suite's legacy cell and not repeated here.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.