feat(http): expose the control plane over HTTP - #68
Open
V3RON wants to merge 2 commits into
Open
Conversation
Network-facing HTTP API as a sibling frontend to the CLI and stdio MCP: detached-only leases, async lease-request resources with poll/long-poll/SSE, bearer-token auth with agent/operator roles (simlock token CLI), renew-time health notices, and a reserved dataPlane field for the agent-device integration (#66). Off by default behind config http.enabled; served only after startup convergence and closed first on daemon stop.
- tear the daemon down when the HTTP listener fails to bind, instead of leaving a zombie serving the unix socket after a reported startup failure - answer POST /v1/lease-requests immediately for allowDownload requests, so a multi-minute runtime download inside resolveSpec cannot hold the POST open - stop deriving lease ttlMs from ttlDeadline - grantedAt (wrong after any renewal); report the tracked value or the mode default, expiresAt stays authoritative - cap long-polls at 60s and finish them on client abort, releasing listeners and timers instead of pinning them for a caller-chosen duration - stop logging /v1/healthz (unauthenticated + synchronous log sink) - bound the idempotency map: 200-char key cap, 10k-entry FIFO eviction, and entry+timer cleanup when a submission is rejected before becoming visible - log a warning when a requested grant ttlMs cannot be applied
This was referenced Sep 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is this?
This PR gives simlock a network-facing HTTP API (closes #65). Until now the daemon was reachable only over its unix socket, so every agent had to live on the same machine as the simulators. With
http.enabledturned on, a remote agent can lease a device, watch the acquisition progress, renew, and release — over plain HTTP behind a tunnel — while the daemon keeps sole authority over queueing, provisioning, and cleanup.It ships off by default and changes nothing for existing CLI/MCP users: the gateway is a third sibling frontend over the same role interfaces, and the core is untouched except for one addition (per-request cancel).
How does it work?
Everything lives under
/v1, documented in the new docs/HTTP-API.md:GET /v1/healthz) requiresAuthorization: Bearer slk_…. Tokens are minted with the newsimlock token create --role agent|operatorcommand and stored as SHA-256 hashes intokens.json; the token is the requester identity, so one-lease-per-agent is enforced by credential rather than by an honor-system env var.POST /v1/lease-requestsreturns201immediately; the client then pollsGET /v1/lease-requests/{id}(with?wait=long-poll) or streams SSE from…/eventsthrough the samequeued → provisioning → booting → grantedstages the CLI prints today.DELETEcancels a still-queued request via a new corecancelPending, which reuses the queue timeout's safety envelope — a request with device work already in flight reports409 REQUEST_NOT_CANCELLABLEinstead.POST /v1/leases/{id}/renew— the held-mode "connection = lease" model deliberately doesn't cross the network. Renew responses carrynotices(device_unhealthy/device_recovered) drained since the last renew, andGET /v1/leases/{id}/eventsstreams the same facts live, ending withlease_lost.GET /v1/leases,/v1/devices,/v1/events(?since=|/stream)behind theoperatorrole.nukeis deliberately not exposed over HTTP.daemon stop, via a newstopAuxiliaryhook. Lease payloads carry a reserveddataPlane: nullfield for the agent-device integration (agent-device integration: bind the HTTP control plane into agent-device as a remote lease provider #66) so its arrival is additive.The app layer is a pure
Request → ResponseHono app — the only file touching a real listener is the@hono/node-serveradapter — so the entire route surface unit-tests throughapp.request()with fakes and a manually-advanced clock, in keeping with the repo's ports discipline. New e2e coverage drives the full loop (token → lease → renew → release, plus 401/403/409 paths) against the fake driver.Why is this useful?
timeoutMsmeans a vanished client cannot hold a queue slot, and a restarted client recovers its lease fromGET /v1/leases/{id}instead of leaking it.cancelPending) reuses existing rejection machinery and emits through the existinglease.rejectedevent family.