Skip to content

A request no worker can serve fails at once #192

Closed

Description

@V3RON

Part of #173.

Scope

After this PR a request no worker can serve fails at once with the right code instead of waiting: NO_DRIVER, UNKNOWN_MODEL, or RUNTIME_MISSING when no known worker has it, NO_CAPACITY when a capable worker exists but none takes requests, or when no worker takes requests at all. This holds on arrival and for a request already waiting when workers drain or disconnect. A busy fleet still queues.

Technical spec

File and line references are to main at 03c027f.

Modules touched

  • src/gateway/routing/serviceability.ts (new): one pure assess(request, views) that returns route-or-wait or the rejection of ADR 0009 §4, in that order. It uses request-match from the previous task. RUNTIME_MISSING carries downloadable: false, and osVersion: "default" when the request named none.
  • src/gateway/routing.ts: RoutingPolicy exposes assess beside select.
  • src/gateway/fleet-coordinator.ts: #dispatchPass (:641-659) calls assess for each waiter before select and rejects on rows 1 to 5. A candidate rejected there never enters the queue: no lease.queued, no queued progress. That one walk also runs on every view change, so a waiting request is covered.
  • src/gateway/worker-registry.ts, src/contract/schemas.ts (workerViewSchema): optional catalogReadAt. refresh sets it when the snapshot carries a catalog; connected() clears it. "Takes requests" needs it set in this session. "Known" needs a catalog on the view and a worker that is not incompatible; the view keeps the last catalog across a lost uplink, so a reconnecting worker stays known. A view also records whether it has ever held a read catalog, so a first-time worker with none is not known.
  • src/gateway/routing/stages/takes-requests.ts: also requires catalogReadAt.
  • src/gateway/worker-link.ts (:278-327): a catalog refresh that arrives while another refresh is in flight must still read the catalog. Today the queued follow-up drops includeCatalog.
  • src/bus/index.ts (:44-54): lease.rejected reason no-worker.
  • Docs: docs/CLI.md, docs/HTTP-API.md (the table, and the codes), both EVENTS.md files, docs/internal/ARCHITECTURE.md.

Contract and event changes

  • worker.list views gain optional catalogReadAt. Additive, no protocol bump.
  • lease.rejected on a gateway gains the reason no-worker for the two NO_CAPACITY rows; the other three rows use the existing unresolvable-spec. Update the rows in docs/EVENTS.md and docs/internal/EVENTS.md.

Rules in play

  • ADR 0009 §4.
  • architecture.md rule 10 (the table has one enforcement point), rule 11, rule 12 (every rejected request ends in one named state), rule 13.
  • events.md rules 3, 6, and 8.
  • safety.md rule 10.
  • testing.md rules 1 to 3.

Tests

  • One test per table row, each with and without noWait, and with and without timeoutMs.
  • A rejected requester can make a new request at once.
  • A request rejected on arrival emits no lease.queued and pushes no queued progress.
  • A waiting request fails with NO_CAPACITY when its only capable worker is drained.
  • A waiting request fails with NO_CAPACITY when its only capable worker disconnects.
  • A request only a disconnected worker lists fails with NO_CAPACITY, not UNKNOWN_MODEL, while another worker takes requests.
  • A worker connected for the first time whose catalog has not arrived causes NO_CAPACITY, not UNKNOWN_MODEL.
  • A reconnecting worker whose new catalog has not arrived is still known from its last one.
  • A catalog refresh that arrives during another refresh still reads the catalog.
  • RUNTIME_MISSING carries downloadable: false, and osVersion: "default" when the request named none.
  • With a capable worker busy, a request waits and is granted when a device frees up.
  • E2E: the first six Completion conditions of Gateway routing: staged ranking, mode-aware picks, fast failure #173.

Done when

  • Every test above passes and pnpm check is green.
  • The tests at fleet-coordinator.test.ts:543-617 and :1318, which expect a request to queue with no worker, are rewritten to the new claims.
  • The end-to-end failures return in the time of one round trip.

Out of scope

  • Retrying on another worker after a worker's own refusal: the next task.
  • Persisting views across a gateway restart.

Depends on

Approval

  • Approved for delivery

Written by an agent.

Activity

  1. added
    task:draft
    on Oct 1, 2026
  2. added
    task:ready
    and removed
    task:draft
    on Oct 2, 2026
  3. github-actions commented on Oct 2, 2026

    @github-actions
    Contributor

    Now task:ready: approved, technical spec present, #191 closed.

  4. self-assigned this
    on Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

task:ready

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions