Repository navigation
Description
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]
Rules in play
- ADR 0091 §1–§3: tags as capabilities that are always available, and
requireswith an idempotency key. - ADR 0030 §1 and §5: the capability name pattern, and the one word users meet.
src/contract/AGENTS.mdprotocol rule:PROTOCOL_VERSION_RANGE+1,minwithmax(feature Decisions).- ADR 0036: the
lease_requestscolumn is the registry owner's next migration. - Documentation rule 9: configuration.mdx (a
tagsrow), errors.mdx:51and: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 forexcept.
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.getlists each asavailableafter 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:
tagson a gateway warns and starts: set; absent, no warning - B4: a direct request with
requires:["bank-network"]granted;["vpn-eu"]CAPABILITY_MISSINGnamingvpn-eu;["bank-network","stream"]with stream off: missingstreamonly - 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:
requireswithidempotencyKey: first send accepted on a worker and a gateway; same names in another order, same answer; a name added, conflict;requiresthen 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-requestswithrequires:["bank-network"]forwarded; withIdempotency-Key, forwarded with the key and accepted; none, none forwarded;["Bank"], 400BAD_REQUESTwith the contract's message
Done when
pnpm test:changedandpnpm typecheckpass.- The protocol bump check passes on push (
PROTOCOL_VERSION_RANGE+1). - The website pages in Rules in play describe
tagsand the new replay comparison.
Out of scope
simlock lease --requiresand the MCPrequiresfield: the next task.- Tags on single devices (Devices on one worker cannot be tagged by the network they can reach #1542).
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
test: bad tags are refused with the message naming the rule (#1844)
feat(core): the config loader refuses tags that break a name rule (#1844
test: tags on a gateway warn and start (#1844)
test: status.get lists each tag as available after the modules, in co…
test: lease.request accepts requires with an idempotencyKey (#1844)
test: a worker replays requires with an idempotency key, or refuses a…
feat(leasing): a worker stores and compares requires, and answers a r…
test: a gateway places a tag-requiring lease on the tagged worker and…
test: POST /v1/lease-requests forwards requires, also with an Idempot…
feat(http): POST /v1/lease-requests takes requires (#1844)
refactor(leasing): the request book's optional fields in one helper (#…
test: probes found gaps: a non-string tag, a replay key of another re…
test(core): a version-9 state.db migrates to 10 and stores a request'…
docs(adr): merge leaves one 0091 row (#1844)
fix(core): tag names reuse the contract's capabilityNameSchema (#1844)
feat(daemon): tags on a worker, matched by requires, and requires wit…