Skip to content

A held remote simlock lease and simlock mcp reconnect and keep their lease through a network drop #1642

Closed

Description

@V3RON

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.md Holding 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_UNREACHABLE for 50 s then renewed; never back; reconnect 401; reconnect PROTOCOL_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_simulator with requesterId and 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; --url with no token

Done when

  • pnpm test:changed passes, with every Tests line above as a test, and the existing held-lease and MCP tests pass unchanged.
  • pnpm check passes.
  • 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 17, 2026
  4. 3 remaining items

  5. V3RON commented on Nov 17, 2026

    @V3RON
    ContributorAuthor

    Handoff

    Done: PR #1685 (stack #1680, on #1683), draft. B10 and B11 built; round 1, round 2 and the final fix-check ran. Fixed: MCP re-attaches a queued request, reconnect sockets closed, Ctrl-C cancels a queued request while reconnecting, four test gaps, three manual lines.

    Not done: R10 is open. src/cli/index-remote-mcp.test.ts:217 and :227-228, and src/cli/index-remote-reconnect.test.ts:142-143 check "no further attempts" right after a clock advance with no await settle(). Removing stop(); at src/lease-policy/index.ts:429 leaves the MCP file green.

    Findings: R10 [testing 10], test-only, the fix is await settle() before the three checks.

    Blocked on: the round cap is used up. The maintainer allows one more fix run and review check, then re-runs deliver 1635.

    Written by an agent.

  6. added
    task:blocked
    and removed
    task:ready
    on Nov 17, 2026
  7. removed their assignment
    on Nov 17, 2026
  8. added a commit that references this issue on Nov 18, 2026
    b90f158
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    task:blocked

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions