Skip to content

Tags on a worker, matched by requires, and requires with an idempotency key #1844

Done

Description

@V3RON

Part of #1832.

Scope

An operator can write "tags": ["bank-network"] in a worker's config.json. After a restart the worker lists each tag as an available capability. A lease whose requires names a tag is then granted only on a worker with that tag, both directly and through a gateway. requires can be sent with an idempotency key, which simlock lease --url and MCP farm mode always send. After this PR the programmatic client and POST /v1/lease-requests can do all of this. The CLI flag and the MCP field come in the next task.

If this task goes wrong, a lease that requires a tag lands on a worker without it, or a worker refuses a valid config, or sending a request again answers differently from the first time.

Technical spec

Commit 200afe5.

Rows

  • Behaviours: B1, B2, B3, B4, B5, B6, B9
  • Stored state: S1, S2
  • Interfaces: I1, I2, I3, I6, I7
  • Existing code: X1, X2, X3, X5, X6, X7, X8, X9, X10, X11, X12, X13, X16, X17, X18, X19, X20, X21

Facts

# Fact Source
F1 Today the refusal is tested in two places; both tests change to expect acceptance src/contract/operations-lease-device-daemon.test.ts and src/daemon/dispatcher-leases-request-outcomes.test.ts (search for cannot be combined with idempotencyKey)
F2 The worker lease handler sees leasing only through LeaseCommands, which has no read of the request book src/leasing/lease-ports.ts:21; handed over at src/daemon/worker-composition.ts:552
F3 The gateway's book comparison runs in #checkAdmission before any refusal src/gateway/fleet-admission.ts:180
F4 simlock config set tags '["bank-network"]' is refused today with Unknown config key: "tags", exit 2 ran node dist/cli/main.js config set tags '["bank-network"]' on main
F5 POST /v1/lease-requests's body is .strict() with no requires, so today a body with it is 400 src/http/lease-declarations.ts:215

Modules touched

src/core (config validators, types, defaults, registry schema and rows, domain record), src/contract (lease request refinement, config schema, protocol), src/leasing (request book, LeaseCommands, create-leasing), src/daemon (worker composition, lease handler), src/http (lease request body and its dispatch input), website reference pages. Searches: requires, capabilitySources, idempotencyKey, REQUEST_COLUMNS, configSchema.

flowchart LR
  CFG[core config: tags] --> WC[daemon worker-composition: tag sources]
  WC --> ST[status.get capabilities]
  REQ[contract lease.request: refusal lifted] --> DL[daemon dispatcher-leases: replay first]
  DL --> LB[leasing request book: stores and compares requires]
  LB --> DB[core registry: lease_requests.requires]
  ST --> GW[gateway routing: unchanged]
Loading

Rules in play

  • ADR 0091 §1–§3: tags as capabilities that are always available, and requires with an idempotency key.
  • ADR 0030 §1 and §5: the capability name pattern, and the one word users meet.
  • src/contract/AGENTS.md protocol rule: PROTOCOL_VERSION_RANGE +1, min with max (feature Decisions).
  • ADR 0036: the lease_requests column is the registry owner's next migration.
  • Documentation rule 9: configuration.mdx (a tags row), errors.mdx :51 and :57, node-client.mdx :94, concepts/workers-and-gateways.mdx, using-devices/http-api.mdx (the body table, :117).
  • src/http/AGENTS.md: no check of its own; the contract words the refusal, as for except.

Tests

Seam: the worker dispatcher (src/daemon/test-dispatcher.ts), the config loader, the gateway dispatcher (B5, and B6's gateway cases, since only dispatch runs the contract's refinement) and the HTTP app. Model them on src/daemon/dispatcher-leases-request-outcomes.test.ts, src/core/config-capabilities.test.ts, src/gateway/dispatcher-leases-label.test.ts and src/http/app-leases.test.ts.

  • B1: an operator sets tags; status.get lists each as available after the modules, in config order: no key; []; ["bank-network"]; ["bank-network","eu-west"] with one module on and one off
  • B2: bad tags are refused with the I1 message: ["Bank"]; ["1st-floor"]; 33 characters; nine names; ["a","a"]; ["stream"]; a string
  • B3: tags on a gateway warns and starts: set; absent, no warning
  • B4: a direct request with requires: ["bank-network"] granted; ["vpn-eu"] CAPABILITY_MISSING naming vpn-eu; ["bank-network","stream"] with stream off: missing stream only
  • B5: a gateway places a tag-requiring lease: tagged and untagged worker, always the tagged one; no worker tagged, CAPABILITY_MISSING; tagged worker busy, the request waits and is not sent to the untagged one
  • B6: requires with idempotencyKey: first send accepted on a worker and a gateway; same names in another order, same answer; a name added, conflict; requires then none, conflict; [] then none, same answer; worker replay after a restart, same answer; worker replay adding a name no source has, IDEMPOTENCY_CONFLICT; worker replay of a granted request after a required module turned unavailable, the first answer
  • B9: POST /v1/lease-requests with requires: ["bank-network"] forwarded; with Idempotency-Key, forwarded with the key and accepted; none, none forwarded; ["Bank"], 400 BAD_REQUEST with the contract's message

Done when

  • pnpm test:changed and pnpm typecheck pass.
  • The protocol bump check passes on push (PROTOCOL_VERSION_RANGE +1).
  • The website pages in Rules in play describe tags and the new replay comparison.

Out of scope

Depends on

#1838 changes the same configSchema object and also bumps the protocol. The seed tasks (issues 1746, 1749 and 1842) bump it too; they are not dependencies of this task, but they wait on a draft task, so they take their bump after this one.

Written by an agent.

Activity

  1. added
    task:draft
    on Nov 25, 2026
  2. added
    task:ready
    and removed
    task:draft
    on Nov 25, 2026
  3. self-assigned this
    on Nov 25, 2026
  4. added a commit that references this issue on Nov 25, 2026
    71a856e
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