Skip to content

fix(cli): bound gateway pull slots per kind and the pull queue - #3030

Open
alpergundogdu wants to merge 1 commit into
mainfrom
claude/2894-gateway-pull-bounds-5c5d4e
Open

alpergundogdu wants to merge 1 commit into
mainfrom
claude/2894-gateway-pull-bounds-5c5d4e

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Closes #2894.

What changes

  • Per-kind slot cap. Manifest fills are admitted at most MAX_MANIFEST_PULLS = MAX_PULLS / 4 (4) at once, running or waiting. That is the count of full manifest buffers MANIFEST_BUFFER_BYTES holds (now defined as MAX_MANIFEST_PULLS * MAX_MANIFEST_BYTES, same 4 as before), so raw-blob and entry requests always find the other 12 slots. A manifest request past the cap is refused at once, never queued.
  • Bounded queue. PullWorker::pull takes an admission permit (MAX_PULLS + MAX_QUEUED_PULLS, with MAX_QUEUED_PULLS = 64) before it sends the job, and refuses at once (Refused::Busy) when none is free. The transport channel stays unbounded_channel: the worker drains it at once into tasks that wait on the slot semaphore, so a bound on channel depth would bound nothing. The bound sits on admitted-and-unfinished pulls instead, which is the real queue.
  • Lazy first-chunk buffer. Job carries a slotted oneshot the worker fires once the pull holds its slot. start_pull awaits it before first_chunk allocates its 256 KiB buffer, so a queued request holds no read buffer.
  • No pull deadline or byte-rate floor, as decided: large model downloads from slow holders are legitimate pulls. The MAX_PULLS doc says so.
  • A fill past the manifest buffer budget now takes the same busy refusal (it was a 502 "manifest buffer is full").
  • adr/appendix-gateway.md § Pull slots, the answers table and the refused-counter row describe the bounds and the 429.

Refusal status and the SDKs

A refusal answers 429 with Retry-After: 2 and a text body (the gateway is busy; retry the request). It counts under decdn_gateway_requests_refused_total (refused before any pull), so it does not pollute the 503 funding counter.

429 is not new to the gateway contract (pointer-lookup budget already answers it), and both SDKs already map it: @decdn/client (src/http.ts: 429: "RATE_LIMITED", Retry-After parsed into retryAfterSecs) and the decdn Python package (_http.py: same). No SDK PR is needed and neither SDK pin moves.

Tests

  • worker::tests::manifest_pulls_past_their_cap_are_refused: a held manifest pull at the cap; a second manifest pull is refused at once; a blob pull still streams; the cap frees when the held pull ends.
  • worker::tests::a_pull_past_the_queue_is_refused_at_once: slot held, queue full, the next pull is refused at once; the queued pull's slotted notice does not fire until it holds the slot.
  • tests::a_raw_blob_answers_while_manifest_pulls_hold_their_cap: through the HTTP handler, a held bundle index at the manifest cap, another bundle answers 429, a raw blob answers 200.
  • tests::a_request_past_the_queue_is_refused_at_once: every slot held and the queue at its bound, a third distinct blob answers 429 at once and lists no pull.
  • tests::a_spent_buffer_budget_fails_a_fill_fast now expects the busy 429.

cargo nextest run -p decdn-cli (1255 passed), cargo clippy --workspace --all-targets --all-features clean, cargo doc with warnings denied clean.

Follow-up worth a look

With the manifest cap at 4 and the buffer budget at 4 full buffers, the budget only bites in the window where a fill's pull has ended (permit dropped) while it still parses its buffer. It still guards that window, so it stays.

🤖 Generated with Claude Code

Manifest fills take at most a quarter of the gateway's 16 worker slots
(4, the fills the manifest buffer budget holds at full size), counted
while running or waiting, so raw-blob requests always find the other
slots. The worker admits at most 64 pulls beyond those running. A pull
past either bound, or a fill past the manifest buffer budget, is refused
at once with 429 and Retry-After: 2, and starts no pull.

A pull now allocates its 256 KiB first-chunk buffer only once the worker
reports that it holds its slot, so a queued request holds no read buffer.

A pull keeps no overall deadline and no byte-rate floor: large model
downloads from slow holders are legitimate pulls.

Closes #2894

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-code-quality

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 3750aff claude/2894-gateway-... cede1ab +/-
78% 78% 0%
View coverage of the 2 most impacted files.
File main 3750aff claude/2894-gateway-... cede1ab +/-
crates/cli/src/...ands/gateway.rs 80% 80% 0%
crates/cli/src/...teway/worker.rs 81% 82% +1%

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

This branch has not been deployed

No deployments
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.

gateway: bound queued pulls and worker-slot occupancy per request kind

1 participant