Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0330399
test: a lease requested with a label carries it in the grant and ever…
V3RON Nov 19, 2026
f5056b3
feat(leasing): a lease carries the label it was requested with (#1755)
V3RON Nov 19, 2026
55a512c
test: a bad label is refused BAD_REQUEST with the same words (#1755)
V3RON Nov 19, 2026
cb88da3
feat(contract): lease.request refuses a bad label (#1755)
V3RON Nov 19, 2026
ab35349
test: an idempotent repeat conflicts when the label differs (#1755)
V3RON Nov 19, 2026
7ad9d25
feat(leasing): a repeat with another label is an idempotency conflict…
V3RON Nov 19, 2026
c5cdd46
test: a label reaches the grant and reads on every device kind (#1755)
V3RON Nov 19, 2026
ecc3f93
test: a labelled lease keeps its label after state.db is reopened and…
V3RON Nov 19, 2026
80a2c15
test: simlock status prints a lease's label after its run id (#1755)
V3RON Nov 19, 2026
305a353
feat(cli): simlock status prints a lease's label (#1755)
V3RON Nov 19, 2026
9a353b8
test: simlock lease --label sends the label and the daemon checks it …
V3RON Nov 19, 2026
8d6bcff
feat(cli): simlock lease --label names the lease (#1755)
V3RON Nov 19, 2026
3127b91
test: MCP lease_simulator sends the label it is given (#1755)
V3RON Nov 19, 2026
252b600
test: POST /v1/lease-requests carries a label to the lease and refuse…
V3RON Nov 19, 2026
c44e8b5
feat(http): POST /v1/lease-requests accepts a label and the lease vie…
V3RON Nov 19, 2026
45610cf
test: a gateway forwards the label and its reads carry the worker's l…
V3RON Nov 19, 2026
92cf0d7
feat(gateway): a gateway forwards a lease request's label to the work…
V3RON Nov 19, 2026
1d82091
docs: simlock lease --label and the label field on the lease request …
V3RON Nov 19, 2026
f8d8380
test: the lease usage text lists --label (#1755)
V3RON Nov 19, 2026
81c249c
refactor(core): lease and request records share one presentFields hel…
V3RON Nov 19, 2026
72cb1ac
fix(leasing): the idempotency-conflict message and docs name the labe…
V3RON Nov 19, 2026
68b430c
Merge remote-tracking branch 'origin/main' into HEAD
V3RON Nov 19, 2026
2ea7dfb
Merge remote-tracking branch 'origin/main' into HEAD
V3RON Nov 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/cli/commands/lease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ async function runLease(
help: { type: "boolean", short: "h" },
"image-tag": { type: "string" },
"lease-id": { type: "string" },
label: { type: "string" },
meta: { type: "string", multiple: true },
mode: { type: "string" },
"no-wait": { type: "boolean" },
Expand All @@ -93,7 +94,7 @@ async function runLease(
" [--except <category,...>] [--baseline <name>]\n" +
" [--timeout <duration>] [--lease-id <id>] [--physical]\n" +
" [--no-wait] [--detach] [--ttl <duration>] [--allow-download]\n" +
" [--run <id>] [--meta <key=value>]... [--export-env] [--bind-pid <pid>]\n",
" [--run <id>] [--label <text>] [--meta <key=value>]... [--export-env] [--bind-pid <pid>]\n",
);
return 0;
}
Expand Down Expand Up @@ -323,6 +324,7 @@ async function runLease(
...(baseline === undefined ? {} : { baseline }),
...(runId === undefined ? {} : { runId }),
...(typeof values["lease-id"] === "string" ? { leaseId: values["lease-id"] } : {}),
...(typeof values.label === "string" ? { label: values.label } : {}),
...(metadata === undefined ? {} : { metadata }),
...(timeoutMs === undefined ? {} : { timeoutMs }),
...(ttlMs === undefined ? {} : { ttlMs }),
Expand Down
2 changes: 1 addition & 1 deletion src/cli/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export function formatStatus(status: StatusGetOutput, now: number, cliVersion?:
});
const leaseLines = leases.map(
(lease) =>
`Lease ${esc(lease.id)}: ${esc(lease.requesterId)}${lease.workerId === undefined ? "" : ` on ${esc(lease.workerId)}`}${lease.runId === undefined ? "" : `, run ${esc(lease.runId)}`} since ${lease.grantedAt}, last renewed ${lease.lastRenewedAt}`,
`Lease ${esc(lease.id)}: ${esc(lease.requesterId)}${lease.workerId === undefined ? "" : ` on ${esc(lease.workerId)}`}${lease.runId === undefined ? "" : `, run ${esc(lease.runId)}`}${lease.label === undefined ? "" : `, label ${esc(lease.label)}`} since ${lease.grantedAt}, last renewed ${lease.lastRenewedAt}`,
);
return [
...daemonLines(daemon, cliVersion),
Expand Down
83 changes: 83 additions & 0 deletions src/cli/index-lease-label.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { describe, expect, it } from "vitest";
import { SimlockError } from "../contract/index.js";
import { runCli } from "./index.js";
import { fakeClient, outputCapture } from "./test-index.js";

const grant = {
device: {
physical: false,
driverDeviceId: "dev_1",
id: "dev_1",
mode: "full" as const,
spec: { physical: false, model: "iPhone 17", osVersion: "26.5", platform: "ios" as const },
},
environment: {},
lease: {
deviceId: "dev_1",
grantedAt: 0,
id: "lse_1",
lastRenewedAt: 0,
idChosenByRequester: false,
ownerId: "test-requester",
requesterId: "test-requester",
ttlDeadline: 60_000,
ttlMs: 60_000,
},
timing: {
estimatedBootMs: 0,
estimatedProvisionMs: 0,
estimatedReadyMs: 0,
estimatedReclaimMs: 0,
},
};

describe("simlock lease: the label a lease carries", () => {
it("sends --label as given, sends none without it, and prints the daemon's refusal of a bad one instead of a local usage error", async () => {
const sentWith = async (flags: readonly string[]) => {
let sent: Record<string, unknown> | undefined;
const exitCode = await runCli(
["lease", "--platform", "ios", "--detach", ...flags],
outputCapture().environmentWith({
connectAdmin: async () =>
fakeClient({
requestLease: (input) => {
sent = input as unknown as Record<string, unknown>;
return Promise.resolve(grant);
},
}),
}),
);
return { exitCode, sent };
};

const labelled = await sentWith(["--label", "feature-x", "--run", "nightly-7"]);
expect(labelled.exitCode).toBe(0);
expect(labelled.sent).toMatchObject({ label: "feature-x", runId: "nightly-7" });
const plain = await sentWith([]);
expect(plain.exitCode).toBe(0);
expect(plain.sent).not.toHaveProperty("label");

const refusal = "label must be 1 to 64 characters";
let sent: Record<string, unknown> | undefined;
const output = outputCapture();
const exitCode = await runCli(
["lease", "--platform", "ios", "--detach", "--label", ""],
output.environmentWith({
connectAdmin: async () =>
fakeClient({
requestLease: (input) => {
sent = input as unknown as Record<string, unknown>;
return Promise.reject(
new SimlockError("BAD_REQUEST", "protocol", refusal, {} as never),
);
},
}),
}),
);
expect(sent).toMatchObject({ label: "" });
expect(exitCode).toBe(2);
expect(output.stderr).toContain(refusal);
expect(output.stderr).toContain("BAD_REQUEST");
expect(output.stderr).not.toContain("USAGE");
});
});
2 changes: 1 addition & 1 deletion src/cli/index-lease-requests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ describe("simlock lease: a request names a model, a class, or nothing", () => {
" [--except <category,...>] [--baseline <name>]\n" +
" [--timeout <duration>] [--lease-id <id>] [--physical]\n" +
" [--no-wait] [--detach] [--ttl <duration>] [--allow-download]\n" +
" [--run <id>] [--meta <key=value>]... [--export-env] [--bind-pid <pid>]\n",
" [--run <id>] [--label <text>] [--meta <key=value>]... [--export-env] [--bind-pid <pid>]\n",
);
});

Expand Down
15 changes: 14 additions & 1 deletion src/cli/index-status-daemon-lines.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ describe("CLI: status renders the fleet a gateway reports (ADR 0005 §20)", () =
expect(output.stdout).toContain("Install android 35 on wrk_1: waiting for 0s, 3 waiters\n");
});

it("prints a lease's run id after its worker on the lease line, and the line as before for a lease with none", async () => {
it("prints a lease's run id after its worker and its label after the run id on the lease line, and the line as before for a lease with neither", async () => {
const output = outputCapture();
const lease = {
deviceId: "dev_1",
Expand All @@ -461,6 +461,9 @@ describe("CLI: status renders the fleet a gateway reports (ADR 0005 §20)", () =
leases: [
{ ...lease, id: "lse_run", runId: "123-1", workerId: "w1" },
{ ...lease, id: "lse_local", runId: "123-1" },
{ ...lease, id: "lse_labelled", label: "feature-x", runId: "123-1", workerId: "w1" },
{ ...lease, id: "lse_label_only", label: "feature-x" },
{ ...lease, id: "lse_escaped", label: "a\u001b[31mb" },
{ ...lease, id: "lse_plain" },
],
};
Expand All @@ -478,6 +481,16 @@ describe("CLI: status renders the fleet a gateway reports (ADR 0005 §20)", () =
expect(output.stdout).toContain(
"Lease lse_local: ci-job-42, run 123-1 since 100, last renewed 200\n",
);
expect(output.stdout).toContain(
"Lease lse_labelled: ci-job-42 on w1, run 123-1, label feature-x since 100, last renewed 200\n",
);
expect(output.stdout).toContain(
"Lease lse_label_only: ci-job-42, label feature-x since 100, last renewed 200\n",
);
expect(output.stdout).toContain(
"Lease lse_escaped: ci-job-42, label a\\u001b[31mb since 100, last renewed 200\n",
);
expect(output.stdout).not.toContain("\u001b");
expect(output.stdout).toContain("Lease lse_plain: ci-job-42 since 100, last renewed 200\n");
});

Expand Down
1 change: 1 addition & 0 deletions src/contract/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Shapes:
- `config.get` carries a driver's own keys under `ios` and `android`, and a module's under `capabilities`, as sent: a new one is no shape change.
- `lease.request` holds `except` (a slim iOS simulator lease keeping slim categories running, ADR 0066) to one object-level refinement with no path (`exceptRefusal`, `operations-lease-request.ts`), so every transport answers `BAD_REQUEST` with the message as written: 1 to 16 names matching `EXCEPT_NAME_PATTERN`, none twice, never with `physical`, a platform but iOS or `mode: full`. The worker's default mode and a baseline's mode are checked in leasing.
- `lease.request`'s `runId` is held to `RUN_ID_PATTERN` by one object-level refinement with no path (`refuseBadRunId`), and the HTTP body by the same one: the same words on every transport. A gateway hands it on as sent; MCP's `lease_simulator` leaves it out.
- `lease.request`'s `label` (1 to 64 UTF-16 units, no `Cc` character, U+2028 or U+2029) is held the same way (`refuseBadLabel`), the HTTP body by the same one. A gateway hands it on as sent, and MCP's `lease_simulator` keeps it.
- `lease.request`'s `metadata` (ADR 0074 §3) is held to one object-level refinement too (`refuseBadMetadata`): the same words on every transport. A gateway hands it to its admission command alone; nothing else may read it.
- Wire input is a claim: every field a gateway parses from a worker is bounded here (`fit*`, `CONSOLE_URL_MAX_LENGTH`, `relay.ts`).
- One OS grammar (`os-range.ts`), one duration parser (`duration.ts`), one usage window (`usageWindow`, `usage-window.ts`), one events page query (`eventsPageQuery`, `events-page.ts`). Nobody else parses.
Expand Down
5 changes: 2 additions & 3 deletions src/contract/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ export interface ErrorDetailsMap {
QUEUE_TIMEOUT: { readonly requestId: string };
PROVISION_FAILED: Record<string, never>;
REQUESTER_ALREADY_LEASED: { readonly requesterId: string; readonly existingLeaseId?: string };
/** `lease.request` repeated an `idempotencyKey` its requester already used for a different
* device or a different `leaseId` (a missing one on either side counts as different). The
* stored request is untouched; a new request needs a new key. */
/** why: a missing `leaseId`, `runId` or `label` on either side counts as different, so a retry
* that adds or drops one conflicts instead of replaying. */
IDEMPOTENCY_CONFLICT: Record<string, never>;
/** `lease.request` named a `leaseId` an active lease or a waiting request already holds
* (ADR 0020). The daemon stores nothing for it; a gateway can also meet it after storing the
Expand Down
1 change: 1 addition & 0 deletions src/contract/lease-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const leaseRecordSchema = z.object({
lastRenewedAt: z.number(),
idChosenByRequester: z.boolean(),
runId: z.string().max(128).optional(),
label: z.string().max(64).optional(),
worker: z.object({ id: z.string(), label: z.string().optional() }).optional(),
});

Expand Down
21 changes: 21 additions & 0 deletions src/contract/operations-lease-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ const leaseRequestBaseSchema = z
idempotencyKey: z.string().min(1).max(200).optional(),
// why: A plain string, bounded by `refuseBadRunId` as the one object-level check, like `osVersion`: a refined field would be checked by the MCP SDK before the handler.
runId: z.string().optional(),
// why: A plain string, bounded by `refuseBadLabel` as the one object-level check, like `runId`: a refined field would be checked by the MCP SDK before the handler.
label: z.string().optional(),
leaseId: leaseIdSchema.optional(),
fleetRequestId: z.string().min(1).max(200).optional(),
// why: A plain record of plain strings, bounded by `refuseBadMetadata` as one object-level check, like `except`: a bound on the field itself would be checked by the MCP SDK before the handler.
Expand Down Expand Up @@ -251,6 +253,24 @@ export function refuseBadRunId(): <T extends { readonly runId?: string | undefin
};
}

const LABEL_LENGTH_REFUSAL = "label must be 1 to 64 characters";
const LABEL_CONTROL_REFUSAL = "label must not contain control characters";

export function refuseBadLabel(): <T extends { readonly label?: string | undefined }>(
input: T,
context: z.RefinementCtx,
) => void {
return (input, context) => {
const { label } = input;
if (label === undefined) return;
if (label.length < 1 || label.length > 64) {
context.addIssue({ code: "custom", message: LABEL_LENGTH_REFUSAL });
} else if (/[\p{Cc}\u2028\u2029]/u.test(label)) {
context.addIssue({ code: "custom", message: LABEL_CONTROL_REFUSAL });
}
};
}

function refuseBadOsVersion(): <T extends { readonly osVersion?: string | undefined }>(
input: T,
context: z.RefinementCtx,
Expand Down Expand Up @@ -288,6 +308,7 @@ const leaseRequestInputSchema = leaseRequestBaseSchema
.superRefine(refuseBadExcept())
.superRefine(refuseBadMetadata())
.superRefine(refuseBadRunId())
.superRefine(refuseBadLabel())
.superRefine(refusePhysicalWithImageFields())
.superRefine(refuseRequiresWithIdempotencyKey());

Expand Down
1 change: 1 addition & 0 deletions src/contract/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export {
LEASE_ID_PATTERN,
leaseIdSchema,
refuseModelWithClass,
refuseBadLabel,
refuseBadRunId,
RUN_ID_PATTERN,
leaseRequestFields,
Expand Down
2 changes: 1 addition & 1 deletion src/contract/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface ProtocolRange {
const protocolRangeSchema = z.object({ min: z.number().int(), max: z.number().int() });

/** Widen only once a second version is kept alive side by side with the first; a bump that leaves no shim behind moves both ends. */
export const PROTOCOL_VERSION_RANGE: ProtocolRange = { min: 100, max: 100 };
export const PROTOCOL_VERSION_RANGE: ProtocolRange = { min: 101, max: 101 };

const LEGACY_DAEMON_PROTOCOL_VERSION = 2;

Expand Down
2 changes: 2 additions & 0 deletions src/core/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ export interface LeaseRecord {
readonly idChosenByRequester: boolean;
// why: `| undefined` because a lease read from a worker (the contract's type) is projected as this type by a gateway.
readonly runId?: string | undefined;
readonly label?: string | undefined;
}

export interface LeaseTiming {
Expand Down Expand Up @@ -500,6 +501,7 @@ export interface LeaseRequestRecord<Grant = LeaseGrant> {
*/
readonly leaseId?: string;
readonly runId?: string;
readonly label?: string;
/**
* The gateway's request id (ADR 0021) when this request is a gateway dispatch, a probe. Kept so
* a probe settled at the next start still names it.
Expand Down
13 changes: 9 additions & 4 deletions src/core/lease-request-store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { IdGenerator } from "../ports/index.js";
import { isSettled, type LeaseRequestFailure, type LeaseRequestRecord } from "./domain.js";
import type { DeviceRequest } from "./driver.js";
import { presentFields } from "./present-fields.js";

/** `lease.requestRetentionMs` and `lease.maxRequestRecords`, as a store applies them. */
export interface LeaseRequestLimits {
Expand All @@ -21,6 +22,7 @@ export interface NewLeaseRequest {
readonly idempotencyKey?: string;
readonly leaseId?: string;
readonly runId?: string;
readonly label?: string;
readonly fleetRequestId?: string;
readonly request: DeviceRequest;
}
Expand Down Expand Up @@ -103,10 +105,13 @@ export function newLeaseRequestRecord<Grant>(
return {
createdAt: now,
id,
...(input.idempotencyKey === undefined ? {} : { idempotencyKey: input.idempotencyKey }),
...(input.leaseId === undefined ? {} : { leaseId: input.leaseId }),
...(input.runId === undefined ? {} : { runId: input.runId }),
...(input.fleetRequestId === undefined ? {} : { fleetRequestId: input.fleetRequestId }),
...presentFields({
idempotencyKey: input.idempotencyKey,
leaseId: input.leaseId,
runId: input.runId,
label: input.label,
fleetRequestId: input.fleetRequestId,
}),
ownerId: input.ownerId,
request: { ...input.request },
requesterId: input.requesterId,
Expand Down
8 changes: 8 additions & 0 deletions src/core/present-fields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// why: a field that is absent stays absent on a stored record (never `undefined`), as `exactOptionalPropertyTypes` needs.
export function presentFields<T extends object>(
fields: T,
): { [K in keyof T]?: Exclude<T[K], undefined> } {
return Object.fromEntries(Object.entries(fields).filter(([, value]) => value !== undefined)) as {
[K in keyof T]?: Exclude<T[K], undefined>;
};
}
8 changes: 8 additions & 0 deletions src/core/registry-rows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ const LEASE_COLUMNS = [
"last_renewed_at",
"id_chosen_by_requester",
"run_id",
"label",
] as const;

const REQUEST_COLUMNS = [
Expand All @@ -196,6 +197,7 @@ const REQUEST_COLUMNS = [
"lease_id",
"fleet_request_id",
"run_id",
"label",
"platform",
"model",
"os_version",
Expand Down Expand Up @@ -224,6 +226,7 @@ const GRANT_COLUMNS = [
"last_renewed_at",
"id_chosen_by_requester",
"run_id",
"label",
"estimated_provision_ms",
"estimated_boot_ms",
"estimated_reclaim_ms",
Expand Down Expand Up @@ -329,6 +332,7 @@ function leaseValues(lease: LeaseRecord): SqliteValue[] {
lease.lastRenewedAt,
flagValue(lease.idChosenByRequester),
lease.runId ?? null,
lease.label ?? null,
];
}

Expand Down Expand Up @@ -380,6 +384,7 @@ export function writeLeaseRequest(database: SqliteDatabase, record: LeaseRequest
record.leaseId ?? null,
record.fleetRequestId ?? null,
nullable(record.runId),
nullable(record.label),
request.platform,
request.model ?? null,
request.osVersion ?? null,
Expand Down Expand Up @@ -412,6 +417,7 @@ export function writeLeaseRequest(database: SqliteDatabase, record: LeaseRequest
lease.lastRenewedAt,
flagValue(lease.idChosenByRequester),
nullable(lease.runId),
nullable(lease.label),
grant.timing.estimatedProvisionMs,
grant.timing.estimatedBootMs,
grant.timing.estimatedReclaimMs,
Expand Down Expand Up @@ -609,6 +615,7 @@ function leaseFromRow(table: string, key: string, row: Row, idColumn: string): L
ownerId: reader.text("owner_id"),
requesterId: reader.text("requester_id"),
...present("runId", reader.optText("run_id")),
...present("label", reader.optText("label")),
ttlDeadline: reader.int("ttl_deadline"),
ttlMs: reader.int("ttl_ms"),
};
Expand Down Expand Up @@ -650,6 +657,7 @@ function loadLeaseRequests(
...present("leaseId", reader.optText("lease_id")),
...present("fleetRequestId", reader.optText("fleet_request_id")),
...present("runId", reader.optText("run_id")),
...present("label", reader.optText("label")),
ownerId: reader.text("owner_id"),
request: requestFromRow(reader),
requesterId: reader.text("requester_id"),
Expand Down
9 changes: 8 additions & 1 deletion src/core/registry-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ ALTER TABLE lease_requests ADD COLUMN run_id TEXT;
ALTER TABLE lease_grants ADD COLUMN run_id TEXT;
`;

const REGISTRY_V9 = `
ALTER TABLE leases ADD COLUMN label TEXT;
ALTER TABLE lease_requests ADD COLUMN label TEXT;
ALTER TABLE lease_grants ADD COLUMN label TEXT;
`;

export const registryOwner: SqliteSchemaOwner = {
migrations: [
REGISTRY_V1,
Expand All @@ -160,7 +166,8 @@ export const registryOwner: SqliteSchemaOwner = {
REGISTRY_V6,
REGISTRY_V7,
REGISTRY_V8,
REGISTRY_V9,
],
name: "registry",
version: 8,
version: 9,
};
Loading
Loading