Skip to content

Latest commit

 

History

History
220 lines (166 loc) · 9.08 KB

executors.md

File metadata and controls

220 lines (166 loc) · 9.08 KB

Allocators and executors

UAT can keep the model loop and sessions in the control plane while running workspace tools on another machine. An allocator manages machine lifecycle through an external script. An executor connects directly to the control plane over WSS and runs workspace tools.

The first version is single-user and uses the existing SQLite database. One executor serves one session at a time, and one session has at most one executor. UAT does not replace a live executor.

Components

Component Responsibility
Control plane Model credentials, model loop, sessions, notes, queues, SQLite, tool routing
Allocator Registers machines and handles ensure, sleep, stop, and destroy commands
Stdio adapter External script that translates allocator commands into a machine provider API
Executor Runs read, write, edit, bash, grep, semantic_search, and apply_patch
Workspace Logical project identity and the files stored on a machine or local disk

Allocator and executor processes initiate their own WSS connections. The control plane never opens an inbound connection to them. The allocator is not in the tool-call path. uat serve speaks HTTP/WebSocket on its listener; a TLS terminator provides public WSS, and clients convert an https:// control URL to wss:// automatically.

Model Provider keys stay in the control plane. Executors receive tool calls only; they do not receive system prompts, notes, conversation history, or model credentials.

Direct executor

A direct executor is a local process that bypasses the allocator. It is marked allocation_mode=direct and sandboxed=false.

Start a control plane:

UAT_HTTP_TOKEN=change-me uat serve --listen 127.0.0.1:8737

Create a workspace and enroll an executor:

export UAT_CONTROL_URL=http://127.0.0.1:8737
export UAT_CONTROL_TOKEN=change-me

uat workspace create --spec '{"source":"local"}'
uat executor enroll --workspace <workspace-id>

The enroll response contains the executor ID and a token. Bind it to a session, then run it:

uat executor bind \
  --executor <executor-id> \
  --session <session-id> \
  --workspace <workspace-id>

uat executor run \
  --token <executor-token> \
  --workspace <workspace-id> \
  --workspace-root /path/to/project

When the session has a binding, workspace tools go to that executor. When the binding is removed, the same session uses local tools again. A bound session whose executor is offline fails the tool call; it never falls back to the control plane's filesystem.

Allocated executor

An allocated executor is started by an allocator and marked allocation_mode=allocated and sandboxed=true. UAT does not implement the sandbox. The allocator or an external wrapper chooses the machine, filesystem, network, and process restrictions.

Register an allocator:

uat allocator register --name my-machines

The response contains the allocator ID and token. Connect it to an external adapter:

uat allocator connect \
  --allocator-token <allocator-token> \
  --adapter ./my-machine-adapter.py

Create a workspace and ensure its machine and executor:

uat workspace create --machine <machine-id> --spec '{"size":"20GB"}'

uat allocator ensure \
  --allocator <allocator-id> \
  --machine <machine-id> \
  --workspace <workspace-id> \
  --session <session-id> \
  --idempotency-key ensure-<session-id>

ensure registers an executor, binds it to the session, and delivers a one-time executor token to the adapter over the live WSS command. The token is not written to SQLite or returned by the commands API. The adapter starts the machine and executor. The executor then connects directly to the control plane.

Lifecycle commands

Command Machine and executor Workspace
ensure Create or start the machine and executor Create or attach
sleep Suspend the machine, preserving state when supported Preserve
stop Stop the machine and executor Preserve disk
destroy Delete the machine Deleted only when delete_workspace=true

An adapter that cannot sleep returns ok=false with an explicit unsupported error. UAT does not silently turn sleep into stop.

Commands are persisted in SQLite before delivery. Each command has a command_id and idempotency_key; reconnects resend unacknowledged commands. Adapters should treat the idempotency key as the stable identity of the operation.

uat allocator sleep --allocator <allocator-id> --machine <machine-id> --idempotency-key sleep-1
uat allocator stop --allocator <allocator-id> --machine <machine-id> --idempotency-key stop-1
uat allocator destroy --allocator <allocator-id> --machine <machine-id> --delete-workspace --idempotency-key destroy-1
uat allocator commands --allocator <allocator-id>

Stdio adapter protocol

The adapter is a long-running process. UAT writes one JSON object per line to stdin and reads one JSON object per line from stdout. Diagnostics belong on stderr.

On startup, UAT sends describe:

{
  "command_id": "describe",
  "idempotency_key": "describe",
  "op": "describe",
  "options": {}
}

The adapter returns its machines:

{
  "command_id": "describe",
  "ok": true,
  "state": "running",
  "result": {
    "machines": [
      {
        "id": "machine-1",
        "external_id": "vm-123",
        "state": "running",
        "spec": {"provider": "example"},
        "labels": {"region": "local"}
      }
    ]
  }
}

Lifecycle commands use the same envelope:

{
  "command_id": "019...",
  "idempotency_key": "ensure-session-1",
  "op": "ensure",
  "machine": {"id": "machine-1", "spec": {"provider": "example"}},
  "workspace": {"id": "workspace-1", "spec": {"size": "20GB"}},
  "executor": {
    "id": "executor-1",
    "token": "one-time-token",
    "control_url": "https://control.example",
    "session_id": "session-1",
    "workspace_id": "workspace-1"
  },
  "options": {}
}

The adapter responds with:

{
  "command_id": "019...",
  "ok": true,
  "state": "running",
  "result": {"machine": "machine-1"}
}

machine.spec and workspace.spec are opaque to UAT. The adapter owns their interpretation.

HTTP API

All routes require UAT_HTTP_TOKEN when it is configured.

Method and path Purpose
POST /v1/allocators Register an allocator and return its token once
GET /v1/allocators List allocators
GET /v1/machines?allocator=<id> List machines
POST /v1/workspaces Create a logical workspace
GET /v1/workspaces/{id} Read a workspace
POST /v1/executors Enroll an executor and return its token once
GET /v1/executors List executors
POST /v1/allocators/{id}/commands Persist a lifecycle command
GET /v1/allocators/{id}/commands List lifecycle commands
GET /v1/sessions/{id}/executor Read the session binding
PUT /v1/sessions/{id}/executor Bind an offline executor to an idle session
DELETE /v1/sessions/{id}/executor Remove the binding while the executor is offline
GET /v1/allocator/ws Allocator WSS endpoint
GET /v1/executor/ws Executor WSS endpoint

The CLI is a thin wrapper over these routes and prints JSON. Scripts may use either surface.

Storage and recovery

The existing SQLite database stores allocators, machines, workspaces, executors, session bindings, binding generations, and allocator commands. Token hashes are stored. Registration endpoints return a plaintext token once; ensure delivers its executor token only over the live adapter command and never persists it. The server key used to derive stable ensure tokens lives in a separate owner-only .key file next to the database and must be backed up separately. SQLite stores only a non-secret key fingerprint; startup fails if the key file is missing or does not match the database.

A disconnected executor becomes offline. Reconnecting the same executor restores its binding. Binding changes are rejected while the executor is online. Rebinding after an explicit offline unbind increments the session's binding generation, so late results from the previous binding are rejected.

Adapter processes and executor bash subprocesses receive a sanitized environment. Control-plane tokens, Provider keys, and other process credentials are not inherited. Adapters should read machine-provider credentials from their own configuration or secret files. Use UAT_ALLOCATOR_TOKEN and UAT_EXECUTOR_TOKEN instead of long-lived token flags when scripting.

If an allocated machine is destroyed, its session keeps its context and notes in SQLite but has no usable workspace files. UAT does not create a replacement workspace automatically.

Limits

  • No multi-user or owner isolation.
  • No Postgres or multi-instance control plane.
  • No hot-swap or forced replacement of a running executor.
  • No built-in Docker, cloud VM, or Proxmox adapter.
  • No sandbox implementation.
  • No automatic workspace migration or exactly-once tool execution.
  • Project instructions for remote workspaces are not yet uploaded as a frozen manifest; remote sessions currently use the control plane's startup context.