Repository navigation
Description
Part of #1635.
Scope
A held remote simlock lease and simlock mcp ride out a network drop. Before the grant they re-attach to the same request by its idempotency key (and ask again once after a worker restart); after it they reconnect and renew until the lease's deadline, with a notice line at the drop and at the return. A silent connection counts as a drop after 45 s. A refused reconnect, a lost lease or a passed deadline ends them with today's codes, and 5 minutes out of reach while waiting fails with REMOTE_UNREACHABLE. simlock mcp with --url/SIMLOCK_URL and a token serves its tools from the farm and launches nothing. On the daemon's own machine both behave as today.
A user would notice: a CI step that fails on a short Wi-Fi drop, two requests on the farm after a re-attach, a held command that never ends when the farm is gone, or a local held lease that starts reconnecting.
Technical spec
Commit 1cd9315.
Rows
Behaviours: B10, B11
Interfaces: I10
Existing code: X16, X17, X26 (the mcp half), X28, X31, X19 (reference/cli.mdx lease section, getting-started/connect-your-agent.mdx, reference/errors.mdx DAEMON_CONNECTION_LOST row)
Facts
| # | Fact | Source |
|---|---|---|
| F1 | A held lease renews through the lease-policy timer and races the hold; on a lost connection it prints the "still yours" line and ends | src/cli/commands/lease.ts:148-165, :247-273 |
| F2 | Lease policy stops on UNKNOWN_LEASE, FORBIDDEN or a passed deadline and retries any other failure |
src/lease-policy/index.ts:184-186, src/lease-policy/AGENTS.md |
| F3 | A release on the way out waits at most 5 s | src/lease-policy/index.ts:62 |
| F4 | simlock lease sends timeoutMs only with --timeout |
src/cli/commands/lease.ts:103, :225 |
| F5 | MCP builds a new client on each reconnect and never repairs a dead one; tool calls may launch a daemon, renewals never do | src/mcp/session.ts:49-51, src/mcp/main.ts:202, :221 |
| F6 | requires and idempotencyKey together are refused, and neither simlock lease nor lease_simulator can send requires, so a key always goes |
src/contract/operations-lease-request.ts:146-160, src/mcp/contracts.ts:50 |
| F7 | simlock mcp hands the MCP server only the daemon flag today |
src/cli/commands/mcp.ts:23 |
Modules touched
src/cli/commands/lease.ts, src/cli/commands/mcp.ts and src/cli/types.ts (McpStdioLauncher takes the URL and token), src/mcp/ (main.ts, session.ts, connect.ts, AGENTS.md), src/lease-policy/ (a reconnect schedule beside the renew timer, AGENTS.md), src/cli/AGENTS.md (Holding a lease), and the website pages reference/cli.mdx, getting-started/connect-your-agent.mdx, reference/errors.mdx. Searches: onConnectionLost, startLeaseRenewal, connectForRenew, connectToRunningDaemon, connectWithAutoLaunch, idempotencyKey in src/cli and src/mcp, RELEASE_TIMEOUT_MS.
Rules in play
- ADR 0081 §4 and ADR 0004: a connection never kept a lease; reconnecting only renews or re-attaches.
- ADR 0003 §10: the typed client does not reconnect; the CLI and MCP do, outside it.
src/cli/AGENTS.mdHolding a lease: "Renewal stops before the release; no timer outlives a command" holds for the reconnect timer too.src/mcp/AGENTS.md: the renew path never launches; no reconnect after a refused handshake or a version mismatch.src/lease-policy/AGENTS.md:stop()before releasing.- Documentation rule 9: the three website pages.
Tests
Seam: simlock lease (held and --detach) and simlock mcp over stdio with a fake session that drops or goes silent, and the fake clock (models: src/cli/index-admin-holder-renew.test.ts, src/cli/lease-connect-signal.test.ts, src/mcp/session-reconnect.test.ts, src/mcp/session-renewal.test.ts).
- B10: a held remote lease across a drop: back before the deadline; 45 s silent; back with
UNKNOWN_LEASE;WORKER_UNREACHABLEfor 50 s then renewed; never back; reconnect 401; reconnectPROTOCOL_VERSION_UNSUPPORTED; the try schedule; drop while queued and back; a worker restart while queued; a second restart; past--timeout; 5 minutes unreachable with no--timeout; Ctrl-C while disconnected; close 4003; a local held lease (no reconnect) - B11: remote
simlock mcp:lease_simulatorwithrequesterIdand an idempotency key;run_on_device;lease_status; a renew after a drop; 45 s silent; a drop past the deadline; a refused reconnect; stdin EOF releases;--urlwith no token
Done when
pnpm test:changedpasses, with every Tests line above as a test, and the existing held-lease and MCP tests pass unchanged.pnpm checkpasses.- The website build passes:
pnpm --dir website install && pnpm --dir website build && node website/scripts/check-openapi.mjs.
Out of scope
simlock files(simlock files moves files to and from a remote lease's folder #1643).
Depends on
Written by an agent.
Activity