Skip to content

test(fake-gateway): answer a raw blob with its proven size, as the gateway does - #9

Merged
thiras merged 2 commits into
mainfrom
test/fake-gateway-sized-raw-blob
Oct 27, 2026
Merged

thiras merged 2 commits into
mainfrom
test/fake-gateway-sized-raw-blob

Conversation

@thiras

@thiras thiras commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Summary

decdn's gateway now proves a raw blob's size before it answers (decdn/decdn#2645, PR to follow): it pays for the last chunk group under the first node's size claim, and the proven size gives the response its Content-Length, one Range (206/416) and a 402 when it does not fit the allowance. A cold HEAD pays for the proof too, and is refused or fails as its GET would be. The SDK can observe the new Content-Length (it bounds a body from below), so the fake mirrors it:

  • A raw blob answers as a sized entry does (sized(), shared with entry()): length, Accept-Ranges, one range, 402 by size on a public gateway.
  • A proof charges one chunk group (16 KiB) of the allowance, once per blob; a raw blob's HEAD runs the GET's checks (402, 503, 404) unless its size is already proven, and then answers free with its length.
  • "still hashes a whole-body request the gateway answers with a window" keeps its HASH_MISMATCH check on the unsized entry, since a raw blob now has a length (its partial answer is TRUNCATED, as a sized entry's is).
  • New unit tests: a raw blob's contentLength, head() of a raw blob, and its HEAD refusals.
  • head()'s doc says a public HEAD of a raw blob may pay for a proof.

No contract-suite change: the suite also runs against the gateway floor (0.3.0) and the latest release, which do not prove sizes. The decdn PR runs this branch's contract suite against the new gateway and moves .github/sdk-typescript.sha once this lands.

No CHANGELOG entry: the package's behaviour is unchanged (test fake and one doc comment).

Test plan

  • pnpm lint
  • pnpm test (159 passed)
  • decdn gateway_sdk e2e (public + loopback) against the new gateway with this checkout

🤖 Generated with Claude Code

…teway does

decdn's gateway now proves a raw blob's size before it answers (decdn/decdn
#2645): it pays for the last chunk group under the first node's size claim,
and the proven size gives the response its Content-Length, one Range
(206/416) and a 402 when it does not fit the allowance. A cold HEAD pays for
the proof too, and is refused or fails as its GET would be.

The fake mirrors that: a raw blob answers as a sized entry does, a proof
charges one chunk group of the allowance once per blob, and a raw blob's
HEAD runs the GET's checks (402, 503, 404) unless its size is already
proven. The partial-window test keeps its hash-mismatch check on the
unsized entry, since a raw blob now has a length. head()'s doc says a
public HEAD of a raw blob may pay for a proof.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 27, 2026 22:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The fake still diverges from gateway behavior in empty-blob accounting, range admission, and site-host HEAD handling.

3 open issues
What changed in this PR

Updates the test gateway to model proven raw-blob sizes while leaving SDK runtime behavior unchanged.

Changes:

  • Adds size-proof accounting and shared sized responses for raw blobs and entries.
  • Tests raw-blob lengths, HEAD metadata and refusals, and partial-body verification.
  • Documents the possible proof cost of a public raw-blob HEAD request.
File Description
test/​unit/​client.test.ts Adds raw-blob metadata and refusal tests; adjusts partial-body expectations.
test/​fake-gateway.ts Models size proofs, sized responses, ranges, and raw-blob HEAD handling.
src/​client.ts Updates the head() doc comment to describe proof costs.

Review effort: Balanced

Comment thread test/fake-gateway.ts Resolved
Comment thread test/fake-gateway.ts Resolved
Comment thread test/fake-gateway.ts Resolved
… a window as the gateway does

- HEAD /_decdn/<hash> on a site answers through the raw-blob HEAD, as the
  gateway's head_blob does: free once the size is proven, else one proof,
  instead of a body charge.
- The empty blob is empty with no proof and no charge, as the gateway's
  empty root is.
- A window is admitted and charged by its span widened to chunk groups
  (Extent::billable), after its 416 check, instead of by the whole size.
  This also brings a sized entry's window in line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
thiras added a commit to decdn/decdn that referenced this pull request Oct 27, 2026
A raw blob that no pull on the gateway had verified streamed with no
Content-Length, ignored Range, and its HEAD had no length. A node's size
claim cannot give a length: the server stops reading a body at its length,
so a claim below the real size would end a short pull as a whole response.

- Client: Streamer::prove_size pays for the last chunk group under a size
  claim and returns the size a leg proved. Only the true size verifies a
  final chunk (ADR 039), so a claim off by less than one group proves the
  true size, and any other claim proves nothing. A claim past the cap on
  held bytes opens nothing.
- CLI fetch: BlobFetch::prove runs the proof in fetch_on and records a
  proven size with the verified sizes. A fault the following pull would
  reach again (classify: command-fatal, or a give-up) ends the fetch; any
  other leaves the size unproven. A pool replacement reruns the proof,
  which writes no byte.
- Gateway: blob() proves an unknown size first, then takes the sized path
  (length, one Range 206/416, 402 when it does not fit, capped pull). A
  cold HEAD goes through paid() and pays for its proof, refused or failed
  as its GET would be. Each proof counts PROOF_BYTES (one chunk group)
  against the allowance, a request dropped mid-proof included
  (ProofCharge). A proof that proves nothing streams unsized, as before.
- Tests: client proof cases (true, low, high, within the last group,
  past the cap, a lying source), proof error classification, gateway cold
  GET/Range/416/402/HEAD/drop/bucket/funding/loopback/retired-capability
  cases, and gateway_public opens a never-fetched blob with a Range.
- ADR appendix-gateway, CHANGELOG, and the TypeScript SDK pin
  (decdn/sdk-typescript#9: the fake answers a raw blob with its size).

Closes #2645
Closes #2616

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit 16ff1cb into main Oct 27, 2026
14 checks passed
@thiras
thiras deleted the test/fake-gateway-sized-raw-blob branch October 27, 2026 23:59
thiras added a commit to decdn/decdn that referenced this pull request Oct 28, 2026
thiras added a commit to decdn/decdn that referenced this pull request Oct 28, 2026
…2654)

* feat(gateway,client): prove a raw blob's size before its first byte

A raw blob that no pull on the gateway had verified streamed with no
Content-Length, ignored Range, and its HEAD had no length. A node's size
claim cannot give a length: the server stops reading a body at its length,
so a claim below the real size would end a short pull as a whole response.

- Client: Streamer::prove_size pays for the last chunk group under a size
  claim and returns the size a leg proved. Only the true size verifies a
  final chunk (ADR 039), so a claim off by less than one group proves the
  true size, and any other claim proves nothing. A claim past the cap on
  held bytes opens nothing.
- CLI fetch: BlobFetch::prove runs the proof in fetch_on and records a
  proven size with the verified sizes. A fault the following pull would
  reach again (classify: command-fatal, or a give-up) ends the fetch; any
  other leaves the size unproven. A pool replacement reruns the proof,
  which writes no byte.
- Gateway: blob() proves an unknown size first, then takes the sized path
  (length, one Range 206/416, 402 when it does not fit, capped pull). A
  cold HEAD goes through paid() and pays for its proof, refused or failed
  as its GET would be. Each proof counts PROOF_BYTES (one chunk group)
  against the allowance, a request dropped mid-proof included
  (ProofCharge). A proof that proves nothing streams unsized, as before.
- Tests: client proof cases (true, low, high, within the last group,
  past the cap, a lying source), proof error classification, gateway cold
  GET/Range/416/402/HEAD/drop/bucket/funding/loopback/retired-capability
  cases, and gateway_public opens a never-fetched blob with a Range.
- ADR appendix-gateway, CHANGELOG, and the TypeScript SDK pin
  (decdn/sdk-typescript#9: the fake answers a raw blob with its size).

Closes #2645
Closes #2616

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(gateway): let a proof's pool replacement reach the worker, and cap its lanes

- A size proof no longer runs its pass again on a pool replacement. The
  gateway's pool payer shares one RunFunding across fetches, and its pool
  is written once, so a rerun paid from stale funding facts, and the
  worker, which never saw the PoolReplaced, kept the retired payer for
  later requests. The replacement now ends the proof's fetch as it ends a
  pull's, and the worker rebuilds the pool payer.
- The proof runs on at most --max-sources lanes, as the stream does,
  instead of the client's default lane cap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci: pin the TypeScript SDK at its fake's site HEAD, empty-blob and window fixes

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci: pin the TypeScript SDK at its merged sized raw-blob fake (decdn/sdk-typescript#9)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

2 participants