Repository navigation
Description
Part of #1633.
Scope
A lease, and the request waiting for it, can carry a run id. simlock lease sets it from --run, else SIMLOCK_RUN, else on GitHub Actions $GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT. The run id is stored on the worker, so it survives a restart. A gateway passes it to its worker and its admission command and keeps it in its lease index. lease.list, lease.get, status.get and the HTTP lease reply show it, simlock status prints it on the lease line, and POST /v1/lease-requests takes it. Nothing releases by run yet; the next task adds that.
A user would notice: a lease that loses its run id after a restart or through a gateway, a bad SIMLOCK_RUN that fails only after a lease waited, or a lease request without a run id that behaves differently from today.
Technical spec
Commit c9d82e3.
Rows
Behaviours: B1, B2, B3, B4, B11
Stored state: S1, S2, S3, S4
Interfaces: I1, I2, I3
Existing code: X1, X2, X3, X4, X5, X6, X7, X8, X9, X18 (the #1666 bump), X24 (reference/cli.mdx lease and status, its environment variables, using-devices/remote-agents.mdx lease-request body), X25, X26, X27, X28 (the runId on leaseSnapshot), X29, X30, X31, X32, X34
Facts
| # | Fact | Source |
|---|---|---|
| F1 | except and metadata are checked by object-level refinements with no path, so the refusal has the words as written |
src/contract/operations-lease-request.ts:207, src/contract/AGENTS.md (Shapes) |
| F2 | A field-level schema issue is answered with its path in front of the message | src/contract/errors.ts:661-668 |
| F3 | SIMLOCK_BASELINE is the model for an env value the CLI reads into CliEnvironment |
src/cli/environment.ts:479, src/cli/types.ts:81-82 |
| F4 | leasePayloadSchema is the reply of both the grant and GET /v1/leases/{id} |
src/http/lease-declarations.ts:62, :351 |
Modules touched
src/contract/ (operations-lease-request.ts: runId, RUN_ID_PATTERN, refuseBadRunId; lease-schemas.ts; protocol.ts bump), src/leasing/ (request options, lease-request-book.ts, waiter-outcomes.ts, lease-lifecycle.ts), src/core/ (registry-schema.ts migration, registry-rows.ts, registry.ts, domain.ts), src/gateway/ (dispatcher.ts, fleet-dispatch.ts, lease-index.ts, the fleet waiter's options), src/daemon/main.ts (leaseSnapshot), server-options.ts and dispatcher-leases.ts (the worker's lease.request options), src/gateway/fleet-grant.ts (the grant-time index entry), src/mcp/contracts.ts (the omit list), src/http/ (lease-declarations.ts, app-helpers.ts, tracker.ts), src/cli/ (commands/lease.ts, environment.ts, types.ts, format.ts), and the website pages reference/cli.mdx, using-devices/remote-agents.mdx, gateway/routing.mdx (the admission command's request names runId). Searches: idempotencyKey in src/leasing, src/daemon and src/gateway, leaseRequestFields, FleetLeaseEntry, leaseId: in waiter-outcomes.ts, LEASE_COLUMNS, leaseFromRow, requestFromRow, grantFromRow, withoutCallerIdentity, leaseSnapshot, leasePayloadSchema, buildLeasePayload, toLeaseRequestInput, requestOptions, baselineFromEnv.
flowchart LR
cli[cli: lease --run] --> contract[contract: runId]
http[http: body + reply] --> contract
contract --> leasing[leasing: options, book, grant]
leasing --> core[core: registry run_id]
gw[gateway: waiter, worker request, index] --> leasing
Rules in play
src/contract/AGENTS.mdShapes: one object-level refinement for the words (F1); Protocol version:max+ 1 in this PR.src/state/AGENTS.md,src/core/AGENTS.md: the registry owner's next migration step; onlyRegistrywrites the tables, in one transaction.src/gateway/AGENTS.md: the gateway setsownerandfleetRequestIdonly;runIdis the caller's and goes on as sent.src/http/AGENTS.md: no role check here; the body is strict.src/cli/AGENTS.md: the router loads nothing; errors as one JSON line.src/mcp/AGENTS.md: MCP serves an agent's session; no run id there (the feature's Non-goals).toolchain.mdPublished surfaces: the schema change reruns MCPtools/listand CLI help (B11, X34); Contract shapes: Through a gateway, an iOS lease goes only to a worker that serves its mode #1652 bumps first.- Documentation rule 9: the three website pages.
Tests
Seam: createLeasing and the daemon dispatcher with fake drivers and a real state.db (model: src/leasing/create-leasing-grant-and-queue.test.ts), the gateway dispatcher with a fake worker link (model: src/gateway/dispatcher*.test.ts), createApp (model: src/http/app-leases.test.ts) and runCli (models: src/cli/index-lease-requests.test.ts, src/cli/index-status-daemon-lines.test.ts).
- B1:
lease.requestwith a run id on a worker:123-1granted and listed; none; after a restart; replay with the same run id; same key, other run id (IDEMPOTENCY_CONFLICT);run 1, empty, 129 characters (BAD_REQUEST, I1's words) - B2:
lease.requestwith a run id on a gateway: forwarded to the worker; the grant-time index entry; listed; index rebuilt after a gateway restart; the admission command'srequest; none - B3:
simlock leasepicks the run id: each row of the first Examples table;--detach;simlock statuswith and without a run id - B4:
POST /v1/lease-requestswithrunId: dispatched and in the reply; none;run 1(400) - B11: MCP
lease_simulatoroffers norunId: the input schema; a call naming it
Done when
pnpm test:changedpasses, with every Tests line above as a test, and the existing lease, gateway, HTTP, MCP and CLI tests pass unchanged but for thelease --helptext, which gains[--run <id>](src/cli/index-lease-requests.test.ts:859-872).pnpm checkpasses, the protocol-bump check included:maxis one above the valuemainholds when this lands.- The website build passes:
pnpm --dir website install && pnpm --dir website build && node website/scripts/check-openapi.mjs.
Out of scope
- Releasing by run (CI runs: release every lease of a run in one call #1633's next task), the agent-device front and
@simlock/e2e(its last task).
Depends on
- Every simlock command runs against a remote farm with --url or SIMLOCK_URL and a token #1641
- A held remote simlock lease and simlock mcp reconnect and keep their lease through a network drop #1642
- Through a gateway, an iOS lease goes only to a worker that serves its mode #1652
Written by an agent.
Activity
test: a lease granted with a run id is listed with it after a daemon …
feat(core): the registry stores a lease's run id and keeps it across …
test: the same idempotency key with another run id is IDEMPOTENCY_CON…
feat(leasing): a repeat of a request under its key must carry the sam…
test: a bad run id is refused BAD_REQUEST with the run id words (#1666)
feat(contract): lease.request refuses a run id outside 1 to 128 lette…
feat(gateway): a lease request's run id goes to the worker, the admis…
feat(daemon): a gateway's lease snapshot carries each lease's run id (#…
test: a body's runId reaches the lease request and the lease reply, a…
feat(http): POST /v1/lease-requests takes a runId and the lease reply…
test: MCP lease_simulator offers no runId (#1666)
feat(mcp): lease_simulator leaves out runId (#1666)
test: simlock lease sends the run id --run, SIMLOCK_RUN or GitHub Act…
feat(cli): simlock lease --run, SIMLOCK_RUN and GitHub Actions name t…
test: simlock status prints a lease's run id on its line (#1666)
feat(cli): simlock status names a lease's run id on its line (#1666)
docs: the run id on simlock lease, status, the lease-request body and…
refactor(cli): the run id variables are read by one helper, and the r…
refactor(core): the grant row's run id goes through the same helper (#…
docs: the gateway manual stays under its size cap (#1666)
fix: a replay under a key names the run id in its conflict and is pro…
fix: the protocol minimum moves with the runId shape, and the MCP run…
feat(leasing): a lease and its request carry a run id (#1666) (#1704)