Skip to content

A gateway routes an except lease by each worker's slim set and default mode #1331

Closed

Description

@V3RON

Part of #1326.

Scope

Through a gateway, a slim lease with except reaches only a worker that can serve it: one whose slim set holds every excepted name and, when the request names no mode, whose default mode is slim. When no known worker can, the gateway refuses it BAD_REQUEST at once. A worker advertises its slim set and its default mode in catalog.get (slimCategories and defaultMode on the iOS entry), so a restarting worker, whose last catalog the gateway keeps, is still known.

In short

A worker's iOS catalog entry gains slimCategories (for example ["widgets", ..., "other"]) and defaultMode (slim or full). The gateway uses them to pick a worker for an except request; a request naming a baseline is judged by the baseline's mode, as every stage already narrows it (withBaseline). It never sends such a request to a worker that would refuse it. A worker the new stage drops shows the reason cannot-keep-except ("Cannot keep these slim categories") in the waiting list.

flowchart LR
  A[fleet lease.request except] --> B["assess: any worker can? *changed*"]
  B -- none --> X[BAD_REQUEST]
  B -- yes --> C["routing: drop workers that cannot *new stage*"] --> D[warm-hit, free slot, ...] --> E["forward with except *changed*"]
Loading
Fleet Request Today After
A slims [store], B slims every category --mode slim --except mdm (no except) routed to B
A default full, B default slim --except store (no mode) (no except) routed to B
A default full, B default full --except store (no mode) (no except) BAD_REQUEST no worker can keep slim categories store (default mode is full on every worker)
A, B slim [store] --mode slim --except other (no except) BAD_REQUEST no worker slims every category in except: other
A, B slim every category --mode slim --except store (no except) routed as today; worker receives except: [store]
A holds slim baseline b, default full --baseline b --except store (no except) routed to A (the baseline's mode is slim)
A holds full baseline b --baseline b --except store (no except) BAD_REQUEST no worker can keep slim categories store (baseline "b" is full)

If this goes wrong, a request one worker could serve is refused, or a worker gets a request without except and grants a plain slim device.

Technical spec

Facts

Commit cc39ec8.

# Fact Source
F1 platformCatalogSchema has no slim field; modelWorkers is its last additive field src/contract/schemas.ts:749-779
F2 fitPlatformCatalog bounds only some fields; others pass through src/contract/schemas.ts:787-815
F3 The worker fits its catalog on the way out src/daemon/dispatcher.ts:364-366
F4 DriverCatalogEntry has no slim field; iOS listCatalog builds it src/core/driver.ts:162-171; src/drivers/ios/index.ts:1451-1472
F5 The iOS driver holds its slim config src/drivers/ios/index.ts:344
F6 A starting view keeps the last catalog src/gateway/worker-registry.ts:148-156
F7 RoutableRequest has mode? and requires?, no except src/gateway/routing/pipeline.ts:5-15
F8 routable() copies mode and requires into the routing request src/gateway/fleet-coordinator.ts:1632-1644
F9 assess's rejection codes: eight, no BAD_REQUEST src/gateway/routing/serviceability.ts:22-30
F10 requires narrows the capable views, then the table runs again: the model for this filter src/gateway/routing/serviceability.ts:111-116; stage src/gateway/routing/stages/has-capabilities.ts:3-7
F11 The stage list src/gateway/routing.ts:71-83
F12 An assess reject ends the request with no worker tried src/gateway/fleet-coordinator.ts:889-892
F13 A worker code outside CANNOT_SERVE_CODES ends the request worker-failed src/gateway/fleet-coordinator.ts:118-148, :1191-1210
F14 The gateway passes requestedDevice(input) whole, and the dispatch to the worker spreads requestedDevice({...}): once #1330 adds except there, it is forwarded with no gateway edit src/gateway/dispatcher.ts:724-727; src/gateway/fleet-coordinator.ts:1104-1107
F15 No view field holds a worker's default mode: workerViewFields keeps only downloads and lease from config.get; servesDefaultMode is a per-device flag src/contract/worker-view.ts:120-125; src/contract/schemas.ts:1258-1296; src/gateway/routing/stages/warm-hit.ts:16-21
F16 Two-worker test model src/gateway/fleet-coordinator.test.ts:3186-3222 ("requires"); src/gateway/routing/serviceability.test.ts:19-38, :408-419
F17 A starting worker's view keeps its last catalog, nothing from config.get src/gateway/worker-registry.ts:148-160
F18 The worker's default modes are wired from config.ios.defaultMode; the worker dispatcher builds catalog.get from listCatalog src/daemon/main.ts:1626-1630; src/daemon/dispatcher.ts:364-366
F19 withBaseline narrows a request to the baseline's mode before stages run src/gateway/routing/request-match.ts:55-66
F20 Waiting reasons are a closed enum, and the gateway parses handler results through it; the CLI and the console label each src/contract/schemas.ts:413-431; src/cli/commands/list.ts:62-80; ui/src/model/waiting.ts:87; website/src/content/docs/docs/gateway/fleet-console.mdx:79
F21 The gateway's client parses catalog.get with safeParse; fitPlatformCatalog runs only on the worker src/simlock-client/client.ts:1003; src/daemon/dispatcher.ts:365

Modules touched

Searches: platformCatalogSchema, listCatalog, RoutableRequest, routable(, RejectionCode, has-capabilities, CANNOT_SERVE.

flowchart LR
  ios["drivers/ios listCatalog *changed*"] --> core["core DriverCatalogEntry *changed*"]
  core --> contract["contract platformCatalogSchema, fit *changed*"]
  contract --> gw["gateway dispatcher forward *changed*"]
  gw --> fc["fleet-coordinator routable *changed*"]
  fc --> routing["routing: assess row, new stage *changed*"]
Loading
sequenceDiagram
  participant C as Client
  participant G as Gateway
  participant W as Worker B
  C->>G: lease.request except [store], no mode
  G->>G: assess over views (slimCategories, default mode)
  alt no worker can
    G-->>C: BAD_REQUEST
  else B can
    G->>W: lease.request except [store], noWait
    W-->>G: granted, device.except [store]
    G-->>C: granted
  end
Loading
  • src/core/driver.ts (DriverCatalogEntry.slimCategories?), src/drivers/ios/index.ts (listCatalog), src/core/driver-catalog.ts if it copies entries
  • src/daemon/dispatcher.ts (catalog.get adds each platform's defaultMode from the wiring of F18), src/daemon/main.ts (passes it)
  • src/contract/schemas.ts (slimCategories on the platform entry, bounded in fitPlatformCatalog), protocol.ts (+1)
  • src/gateway/fleet-coordinator.ts (routable copies except), routing/pipeline.ts (except, reason cannot-keep-except), routing/serviceability.ts (assess row), routing/stages/keeps-except.ts (new filter, after has-baseline), routing.ts (stage list), routing/AGENTS.md, aggregate.ts (fleet catalog: union of slimCategories; defaultMode dropped from the union)
  • src/contract/schemas.ts (gatewayWaitingReasonSchema gains cannot-keep-except), src/cli/commands/list.ts (GATEWAY_REASON_TEXT), ui/src/model/waiting.ts (label), website/src/content/docs/docs/gateway/fleet-console.mdx (the reasons list); docs/internal/adr/0009 is narrowed by 0066 (no edit)

Contract and event changes

This PR bumps the protocol by one.

  • catalog.get platform entry: optional slimCategories (iOS only, 0 to 32 items, each ^[a-z][a-z0-9-]{0,31}$) and optional defaultMode (slim | full). Bounded in the schema; a worker answer that breaks it fails that catalog read, as any other field does (F21).
  • Gateway waiting reason cannot-keep-except (closed enum, F20).
  • No new event. lease.requested on the gateway carries except from T3's requestedDevice; its EVENTS.md entry is T3's.

Other code on the same state

Searched the routing views' readers (routingViews, aggregate, stages) and config.get readers in the gateway:

  • The new stage reads defaultMode from the view's catalog (F15, F17), so a restarting worker keeps it.
  • The refusal memo (viewLoadKey) holds no catalog: the new stage reads the view each walk, so a worker whose slim set changes is seen at the next catalog read.
  • T3 writes except into requestedDevice; this task forwards it.

Failure modes

Call Outcome What happens Limit, counted from
assess, except no known worker slims every name BAD_REQUEST no worker slims every category in except: <names> none
assess, except, no mode every worker that slims them defaults to full BAD_REQUEST no worker can keep slim categories <names> (default mode is full on every worker) none
worker without slimCategories or defaultMode (older, or never read) dropped for an except request, reason cannot-keep-except as a worker that cannot serve it none
starting worker with a kept catalog judged by that catalog may be picked once it takes requests none
assess, except, baseline full refused BAD_REQUEST no worker can keep slim categories <names> (baseline "<name>" is full) none
forwarded request worker answers BAD_REQUEST worker-failed, as today (F13) gateway.leaseRequestTimeoutMs

Rules in play

  • ADR 0066 §5: route by slim set and default mode; assess answers BAD_REQUEST.
  • ADR 0009 §4 (narrowed by 0066): the fast-fail table's new row.
  • routing manual, "can-serve and the fleet table (assess) ask the same helpers in the same order": the stage and the assess row share one helper.
  • contract manual, protocol bump per shape change.

Tests

Seam: the gateway's FleetLeaseCoordinator with two scripted workers, modelled on fleet-coordinator.test.ts "FleetLeaseCoordinator: requires" (3186-3222), plus serviceability.test.ts for the assess row.

  • A gateway routes except by each worker's slim set and default mode: cases one worker has the set (routed there); mixed default modes, no mode (routed to the slim-default one); slim baseline on a default-full worker (routed); full baseline (BAD_REQUEST); none can (BAD_REQUEST, each message); a dropped worker's reason cannot-keep-except in status.get waiting; the chosen worker receives except.
  • A client reads catalog.get and sees the iOS slim set and default mode: cases worker with ios.slim.categories unset (every category) and set ([store]); defaultMode slim and full; the gateway's fleet catalog holds the union of its workers' slimCategories. Seam: the worker dispatcher's catalog.get (src/daemon/dispatcher.test.ts) and aggregateCatalog (src/gateway/aggregate.test.ts).

Done when

  • pnpm exec vitest run --project unit src/gateway/ src/contract/ src/drivers/ios/ passes.
  • The protocol is one above the base branch's.
  • The fleet console page lists the cannot-keep-except reason.

Out of scope

  • The worker's own refusals and grant (T3).
  • A gateway setting of its own for except.

Depends on

Written by an agent.

Activity

  1. added
    task:draftScope written; technical spec or its spec check missing.
    on Nov 5, 2026
  2. added
    task:readySpec checked. An agent may implement it once its Depends on allow.
    and removed
    task:draftScope written; technical spec or its spec check missing.
    on Nov 5, 2026
  3. self-assigned this
    on Nov 6, 2026
  4. 5 remaining items

  5. V3RON commented on Nov 6, 2026

    @V3RON
    ContributorAuthor

    Handoff

    Done: PR #1360 (draft, stacked on #1349). Built and audited. Round 1 raised 5 blocking findings and the fix run fixed them. R2, R3 and R4 were confirmed fixed by the fix-check.

    Not done: R1 is only partly fixed. The fix-check found two new blocking findings, and they are still open at the round cap:

    • R5 src/gateway/routing/serviceability.ts:116: the except BAD_REQUEST row runs after the table's NO_CAPACITY row. ADR 0066 §5 puts it before. Today a request that can never be served gets NO_CAPACITY. src/gateway/routing/AGENTS.md:25 has the same order.
    • R6 src/gateway/fleet-routing.test.ts:1299: the drained-keeper case uses noWait, so it stays green when the code is broken.

    Findings: see the ## Review ledger comment on #1360.

    Blocked on: a maintainer decides the next step. The usual one is a fix run for R5 and R6 followed by a fix-check. #1332 waits on this task.

    Written by an agent.

  6. removed
    task:readySpec checked. An agent may implement it once its Depends on allow.
    on Nov 6, 2026
  7. removed their assignment
    on Nov 6, 2026
  8. added
    task:blockedAgent stopped on a blocker in its handoff. Maintainer re-adds the label it came from.
    task:readySpec checked. An agent may implement it once its Depends on allow.
    and removed
    task:blockedAgent stopped on a blocker in its handoff. Maintainer re-adds the label it came from.
    on Nov 6, 2026
  9. self-assigned this
    on Nov 6, 2026
  10. V3RON commented on Nov 6, 2026

    @V3RON
    ContributorAuthor

    Handoff

    Done: PR #1360 has passed review after the fix-checks the maintainer approved, and it is ready in stack #1334. The gate for the whole feature (merge-pr.sh 1368) has run twice. The first run failed Fallow on #1348 (#readBack), which was fixed in 1fffd56 and checked.

    Not done: the second gate run failed Fallow on #1360: Function 'routable' has a CRAP score of 31.6 (threshold: 30) (CI run 42204614752). A Fallow gate brought in through main now fails functions over the threshold. Nothing has merged.

    Findings: see the ## Review ledger comment on #1360. The failure is deterministic.

    Blocked on: the gate's second red CI, which parks the run. Next is one fix run that splits routable in src/gateway/routing/ with no behaviour change, a coordinator fix-check, stack-sync.sh 1368, then merge-pr.sh 1368.

    Written by an agent.

  11. added a commit that references this issue on Nov 6, 2026
    57e9737
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

task:readySpec checked. An agent may implement it once its Depends on allow.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions