Skip to content

scripts/wait-for-slot.sh: read-only client gate that waits for a free slot (#23) - #24

Merged
DustinTrap merged 1 commit into
mainfrom
23-wait-for-slot
Oct 4, 2026
Merged

DustinTrap merged 1 commit into
mainfrom
23-wait-for-slot

Conversation

@DustinTrap

Copy link
Copy Markdown
Owner

Closes #23.

What

A client can only count its own requests, so a fan-out cannot tell how many of the endpoint's 8 slots other consumers already hold. scripts/wait-for-slot.sh samples vllm:num_requests_running and vllm:num_requests_waiting through llama-swap and exits 0 once running + waiting + NEED <= LIMIT, or gives up after --max-wait.

  • One GET of /upstream/<model>/metrics per sample. No inference request; nothing changes on the server.
  • Key from an environment variable or a key file, passed to curl on stdin, never in argv, never printed (same as scripts/check-keys.sh).
  • Defaults: --limit 6, --need 1, sample every 5 s, give up after 600 s. The 6 is a policy choice (leave 2 slots for latency-sensitive consumers), not a measurement.
  • --check takes one sample: exit 0 room, 1 no room.
  • No answer, a 5xx or a 429 counts as "no room". 401, 403, 404 or an answer without the gauges exits 2.
  • Advisory only: two clients can take the same free slot. concurrencyLimit in llama-swap.yaml stays the hard limit.

Docs: the README lists the script and shows the call under Operations; examples/opencode/AGENTS.md runs the gate before launching more than one sub-agent; examples/opencode/README.md shows the wrapper that puts wait-for-slot on PATH.

Tested

  • Against a local mock metrics server: room, busy, wait-then-room, give-up after --max-wait, 401, 404, 500, request timeout, missing gauges, key file with CRLF, usage errors.
  • One read-only sample from the live endpoint (--check), exit 0.
  • bash -n and shellcheck pass; gitleaks passes over the tree and full history.

Not verified

No change on the box and no change to llama-swap.yaml.

🤖 Generated with Claude Code

… slot (#23)

A client can only count its own requests, so a fan-out cannot tell how many
of the endpoint's 8 slots other consumers already hold. The script samples
vllm:num_requests_running and vllm:num_requests_waiting through llama-swap
and returns once running + waiting + NEED <= LIMIT (default 6), or gives up
after --max-wait. --check takes a single sample.

One GET of /metrics per sample; no inference request, nothing changes on the
server. The key comes from an environment variable or a key file and reaches
curl on stdin, never argv. A sample with no answer counts as busy. It is
advisory: concurrencyLimit in llama-swap.yaml stays the hard limit.

README lists it and shows the call; examples/opencode/AGENTS.md runs it
before launching more than one sub-agent.

Tested against a local mock metrics server (room, busy, wait-then-room,
give-up, 401, 404, 500, timeout, missing gauges, key file with CRLF) and with
one read-only sample from the live endpoint. Not verified: the AGENTS.md line
being followed by a model in a real session.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@DustinTrap
DustinTrap merged commit f386f03 into main Oct 4, 2026
2 checks passed
@DustinTrap
DustinTrap deleted the 23-wait-for-slot branch October 4, 2026 02:32
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.

Client-side admission gate: wait for a free slot before a fan-out (scripts/wait-for-slot.sh)

1 participant