Skip to content

fix(gateway): pull a non-manifest once, reuse verified sizes, count live spend on /_status - #2643

Merged
thiras merged 3 commits into
mainfrom
fix/gateway-batch
Oct 27, 2026
Merged

thiras merged 3 commits into
mainfrom
fix/gateway-batch

Conversation

@thiras

@thiras thiras commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Three gateway follow-ups in one PR.

#2478: a blob that is no bundle manifest is pulled once

  • NotManifests keeps up to 1024 hashes beside ManifestCache. It is checked before manifest_fill and again after taking it, as the manifest cache is.
  • The stored verdict (OverCap / Unparsed / Plain) holds no raw-blob hint. Each request renders the 404 with its own ?ns=, and the text is the same as before.
  • Only a NotManifest outcome is recorded. Allowance, funding and upstream failures still pull again.
  • Gateway::manifest is split: the pull and parse moved into pull_manifest, which returns a ManifestStop.

#2632: a pinned gateway does not re-probe for a size it verified

  • FetchHost keeps a SizeHints map of up to 4096 entries, filled only from verified whole-blob sizes, never from a node's unverified claim.
  • A hit is passed as ProbeOpts::known_size, so a --node-id gateway sends no probe for a repeat bare-hash pull.
  • The hint never reaches held_cap: only a declared size caps a fetch.
  • gateway_public e2e now asserts 0 decdn_probe_requests_total across step (3)'s repeat pulls. With the lookup reverted it fails with "probed the pinned node 4 time(s)".

#2640: /_status counts a capability's pulls in flight

  • LaneLedgers::committed_lanes() and Payer::committed_lanes() expose each live lane's committed cumulative.
  • The worker's Pools handler reads the live ledgers after the store read, and each delegate_lanes row gains spent_micro_usdc and bytes_delivered.
  • Per lane, the value is the larger of the stored watermark and the live ledger. The ledger only grows and is what the watermark is written from, so nothing is counted twice.
  • lanes, BuyerLaneSnapshot, the pool rows and GET /_capability (the SDK contract) are unchanged.
  • The dashboard's "Spent of cap" reads the new fields and shows "Live: N pulls in flight".
  • adr/appendix-gateway.md § State and § Payment and allowance describe both behaviours.

Closes #2478
Closes #2632
Closes #2640

Test plan

  • cargo nextest run -p decdn-cli -p decdn-client: 2306 passed
  • cargo clippy --workspace --all-targets --all-features -- -D warnings, cargo fmt --check, the cargo doc deny gate
  • gateway_public anvil e2e passes; a mutation check shows the new probe assertion fails without the fix
  • dashboard: pnpm lint, typecheck, test (65 passed); status fixtures regenerated with UPDATE_STATUS_FIXTURES=1
  • make -C adr check-refs, pre-commit run

🤖 Generated with Claude Code

…ive spend on /_status

- #2478: the gateway keeps up to 1024 hashes it found to be no bundle
  manifest (over the manifest cap, unparsable, or malformed), with the
  verdict but not the asker's raw-blob hint, so a repeat request answers
  the same 404 with no pull. Upstream and funding failures are not kept.
- #2632: FetchHost keeps the verified size of up to 4096 blobs pulled
  whole and passes it as ProbeOpts::known_size, so a pinned gateway's
  repeat bare-hash pull sends no probe. It never reaches held_cap. The
  gateway e2e asserts zero probes across the repeat pulls.
- #2640: each /_status delegate_lanes row gains spent_micro_usdc and
  bytes_delivered, per lane the larger of the stored watermark and the
  live ledger of a pull in flight (LaneLedgers::committed_lanes). The
  dashboard reads them and marks a capability with pulls in flight.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras thiras self-assigned this Oct 27, 2026
Copilot AI balanced review requested due to automatic review settings October 27, 2026 17:09

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

Cached diagnostics can exhaust gateway memory, and payer retirement can race with status reads and omit committed spending.

2 open issues
What changed in this PR

This PR reduces repeat gateway download costs and improves visibility into capability spending, addressing #2478, #2632, and #2640.

Changes:

  • Caches non-manifest verdicts so repeat bundle requests avoid another paid pull.
  • Reuses verified blob sizes to skip repeat probes of pinned nodes.
  • Includes live ledger spending in /_status and displays active pulls in the dashboard.
File Description
crates/​e2e/​tests/​gateway_public.rs Checks that repeat pulls send no probes.
crates/​client/​src/​ledgers.rs Exposes committed values for registered lanes.
crates/​cli/​src/​commands/​gateway/​worker/​tests.rs Tests live spending and watermark merging.
crates/​cli/​src/​commands/​gateway/​worker.rs Merges live ledger values into capability totals.
crates/​cli/​src/​commands/​gateway/​tests.rs Tests cached verdicts, retries, and namespace hints.
crates/​cli/​src/​commands/​gateway/​status/​tests.rs Updates status fixture construction.
crates/​cli/​src/​commands/​gateway.rs Adds negative caching and separates manifest pulling.
crates/​cli/​src/​commands/​fetch/​tests.rs Tests size-cache eviction and lookup precedence.
crates/​cli/​src/​commands/​fetch.rs Caches verified sizes and exposes payer ledger totals.
crates/​cli/​dashboard/​src/​view.ts Uses live spend totals and counts active pulls.
crates/​cli/​dashboard/​src/​view.test.ts Tests capability totals and active-pull counts.
crates/​cli/​dashboard/​src/​fixtures/​status-loopback.json Adds capability spend and byte totals.
crates/​cli/​dashboard/​src/​contract.test.ts Checks the new status fields.
crates/​cli/​dashboard/​src/​components/​Capabilities.tsx Displays pulls in flight.
crates/​cli/​dashboard/​src/​api.ts Defines the added capability total fields.
CHANGELOG.md Documents the three gateway fixes.
adr/​appendix-gateway.md Describes negative caching and live-spend reporting.

Review effort: Balanced

Comment thread crates/cli/src/commands/gateway.rs Resolved
@github-code-quality

github-code-quality Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main a7fd84c fix/gateway-batch 84a8357 +/-
77% 77% 0%
View coverage of the 5 most impacted files.
File main a7fd84c fix/gateway-batch 84a8357 +/-
crates/node/src/dht/publish.rs 80% 78% -2%
crates/client/src/ledgers.rs 100% 100% 0%
crates/cli/src/...ands/gateway.rs 78% 79% +1%
crates/cli/src/...mmands/fetch.rs 48% 49% +1%
crates/cli/src/...teway/worker.rs 83% 84% +1%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 27, 2026 17:48 UTC

thiras and others added 2 commits October 27, 2026 20:29
- /_status read the store before the live ledgers: a pull that ended
  during the blocking store read persisted after the snapshot and dropped
  its payer, so its key's spend dipped for one poll. The ledgers are now
  read first. DelegateLanes::include_live recomputes from the stored lanes
  (idempotent) and the struct's fields are private.
- SizeHints keeps the first size a hash records.
- Docs: no false "a ledger only grows"; the not-manifest cache is bounded
  (ADR, STE wording); ProbeOpts::known_size names the verified-size source.
- Tests: funding and allowance stops are not remembered, a mid-read cap
  stop is, a cached Unparsed verdict carries the asker's ?ns=,
  LaneLedgers::committed_lanes, the pool payer's live lanes, and the e2e
  probe check also counts shed probes.

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

- A malformed manifest's parse error quotes its publisher's paths and
  hash strings, so 1024 remembered verdicts from crafted manifests under
  the 64 MiB cap could hold gigabytes. Each verdict keeps at most
  MAX_VERDICT_TEXT (1 KiB), cut on a character boundary, from the first
  answer on.
- A worker test ends a pull, and drops its payer, during the store read;
  its spend still counts because the ledgers are read first. It fails
  with the old read order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit bce8e64 into main Oct 27, 2026
37 checks passed
@thiras
thiras deleted the fix/gateway-batch branch October 27, 2026 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants