Skip to content

A lease and its request carry a run id, set by simlock lease --run, SIMLOCK_RUN or the GitHub run #1666

Closed

Description

@V3RON

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
Loading

Rules in play

  • src/contract/AGENTS.md Shapes: 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; only Registry writes the tables, in one transaction.
  • src/gateway/AGENTS.md: the gateway sets owner and fleetRequestId only; runId is 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.md Published surfaces: the schema change reruns MCP tools/list and 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.request with a run id on a worker: 123-1 granted 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.request with 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's request; none
  • B3: simlock lease picks the run id: each row of the first Examples table; --detach; simlock status with and without a run id
  • B4: POST /v1/lease-requests with runId: dispatched and in the reply; none; run 1 (400)
  • B11: MCP lease_simulator offers no runId: the input schema; a call naming it

Done when

  • pnpm test:changed passes, with every Tests line above as a test, and the existing lease, gateway, HTTP, MCP and CLI tests pass unchanged but for the lease --help text, which gains [--run <id>] (src/cli/index-lease-requests.test.ts:859-872).
  • pnpm check passes, the protocol-bump check included: max is one above the value main holds when this lands.
  • The website build passes: pnpm --dir website install && pnpm --dir website build && node website/scripts/check-openapi.mjs.

Out of scope

Depends on

Written by an agent.

Activity

  1. added
    task:draft
    on Nov 17, 2026
  2. added
    task:ready
    and removed
    task:draft
    on Nov 17, 2026
  3. self-assigned this
    on Nov 18, 2026
  4. added 20 commits that reference this issue on Nov 18, 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