Runtime API

Machine health, task takeover, Engines, credentials, role tags, installation scripts, and cloud sandboxes.

Runtime is the management plane for Workers and Engines. Most endpoints are user_only; the onboarding guide engine-onboarding is dual.

Endpoints

Machine health and event bus

Method Path Purpose
GET /api/runtime/admin/machine-health Machine health overview
GET /api/runtime/admin/machine-health/{runtime_id} Health details for a single engine
GET /api/runtime/admin/event-bus Event bus debugging
POST /api/runtime/admin/batch-recover Batch-recover stale tasks

Tasks and takeover

Method Path Purpose
GET /api/runtime/tasks/{task_id}/status Task status
POST /api/runtime/tasks/{task_id}/cancel Cancel a task
GET /api/runtime/issues/takeover-context Get takeover context by Issue
POST /api/takeover/sessions Start a takeover (atomic hand-off of a running task)
GET /api/takeover/sessions List takeover sessions (active by default)
GET /api/takeover/sessions/{session_id} Takeover session details (optionally renew token)
POST /api/takeover/sessions/{session_id}/progress Report local progress (written to task messages)
POST /api/takeover/sessions/{session_id}/attach Attach the local session id (so the panel can jump back)
POST /api/takeover/sessions/{session_id}/request-finish Local agent reports completion (user still confirms)
POST /api/takeover/sessions/{session_id}/finish Finish the takeover (finalize event + advance stage + optional handoff)
POST /api/takeover/sessions/{session_id}/abort Abort the takeover (stop only; never re-dispatch)
GET /api/runtime/tasks/{task_id}/detail Task details
POST /api/runtime/tasks/{task_id}/converge-event Terminal-state convergence compensation
POST /api/issues/{issue_id}/workspace/reset Reset an Issue workspace (idempotent; archives unpushed commits first)
GET /api/tasks/preflight Preflight the Git credential before starting a task
POST /api/tasks/complete Self-report task completion (structured fields in the Tasks API)
GET /api/runs/{run_id} Look up run status by run_id (read-only)

Engines and sessions

Method Path Purpose
GET /api/runtime/runtimes/{runtime_id}/tasks Engine tasks
GET /api/runtime/runtimes/{runtime_id}/sessions Engine sessions
GET /api/runtime/credentials/{cid}/tasks Tasks aggregated by credential
POST /api/runtime/runtimes/{runtime_id}/refresh-skills Rescan Skills
PUT /api/runtime/runtimes/{runtime_id}/alias Set an alias
PUT /api/runtime/runtimes/{runtime_id}/max-concurrent Set maximum concurrency
GET /api/runtime/runtimes/{runtime_id}/role-tags Role tags
PUT /api/runtime/runtimes/{runtime_id}/tags Set role tags
GET/PUT /api/runtime/runtimes/{runtime_id}/scene-tags Scene tags
GET /api/runtime/scene-tags Scenes and role tags

Onboarding and sandboxes

Method Path Purpose
GET /api/runtime/engine-onboarding One-click onboarding guide
GET /api/runtime/install Linux installation script
GET /api/runtime/install.ps1 Windows installation script
GET /api/runtime/start-worker.ps1 Windows start script
GET /api/runtime/grape-worker.tar.gz Worker package
GET /api/runtime/cloud-sandboxes Cloud sandbox list
DELETE /api/runtime/cloud-sandboxes/{sandbox_id} Destroy a cloud sandbox
GET /api/runtime/admin/sandbox/engines Sandbox switch per engine

Environment variables

The execution side (Worker / runtime / cloud sandboxes) reads the following variables. All have defaults unless noted, so they are optional.

Variable Default Effect
RUNTIME_TASK_TIMEOUT 3600 Task timeout (seconds); takes precedence over the same key in meta and runtime-config.json
AGENT_SILENT_WINDOW Derived from the timeout tier, capped at 600 Agent silence window (seconds); exceeding it marks the task as hung
RUNTIME_HEARTBEAT_INTERVAL 15 Heartbeat interval during a task (seconds), compressed with the silence window
CLOUD_WORKER_SANDBOX_MAX_LIFETIME 14400 Maximum lifetime of one cloud sandbox (seconds)
CUBESANDBOX_LIST_TIMEOUT_S 20 Timeout for listing cloud sandboxes (seconds)
CLOUD_SANDBOX_ACTIVE_WINDOW_S 1800 Window for "active sandbox" statistics (seconds)
CLOUD_WORKER_LLM_CRED_RETRIES 2 Retries for LLM credential errors; 0 disables retries
CLOUD_WORKER_RECONCILE_MAX_METADATA 200 Metadata entries carried per reconcile round
CLOUD_WORKER_SWEEP_INTERVAL 60 Cloud sandbox sweep interval (seconds, minimum 10)
CLOUD_WORKER_SWEEP_BACKOFF_STEP_S 60 Sweep retry backoff step (seconds)
CLOUD_WORKER_SWEEP_BACKOFF_CAP_S 300 Sweep retry backoff cap (seconds)
CLOUD_WORKER_SWEEP_BACKOFF_MAX_ENTRIES 1000 Maximum entries in the backoff table
PROBE_CACHE_TTL 86400 Cache lifetime for engine probe results (seconds)
PROBE_RETRY_BASE_BACKOFF_S 120 Base backoff for probe retries (seconds)
HWCLOUD_OUTPUT_TAIL_LINES 20 Tail lines echoed for AI Shell sessions
HWCLOUD_SESSION_NO_WRAP off Set to 1 to skip tail echoing and pass output through unchanged
RUNTIME_INSTALL_DIR Directory holding the runtime package Install directory, used to locate runtime.env and bundled scripts
GRAPE_MODEL_GATE_STATE_FILE State file under the runtime directory Path of the model gate state file
GRAPE_PROCESS_ROLE runtime Process role (mgmt / event / worker / insight / runtime)
GRAPE_ENV_ASSEMBLY_RETRY_BACKOFF_SECONDS 1.5 Retry backoff when task environment assembly fails (seconds)
GRAPE_STASH_ISOLATION 1 Workspace stash isolation; set 0 to disable
GRAPE_GIT_CLONE_WATCHDOG_MARGIN 30 Extra margin for the clone watchdog (seconds)
GRAPE_WORKSPACE_LEASE_HOURS 24 Workspace lease duration (hours)
GRAPE_WORKSPACE_LEASE_HEARTBEAT_SECONDS One third of the lease, minimum 30 Workspace lease heartbeat interval (seconds)
GRAPE_CLAIM_SCAN_PAGE 200 Claim candidate scan page size
GRAPE_CLAIM_SCAN_PAGES 5 Number of claim candidate scan pages
GRAPE_FORCE_REQUEUE_GUARD_S 60 Guard window for forced requeue (seconds)
HEALTH_STALE_QUEUED_HARD_THRESHOLD 900 Hard threshold for tasks queued too long (seconds); beyond it the task fails
GRAPE_TAKEOVER_FINISH_WAIT 1800 Maximum wait for a takeover session to finish (seconds)
GRAPE_FAILED_RECONCILE_GRACE_SECONDS 600 Grace period when reconciling failed tasks (seconds)
GRAPE_TASK_PREFLIGHT_REQUIRED 0 Set to 1 to require a passed preflight before a task starts
GRAPE_GIT_PROXY_BASE empty Base URL of the Git proxy; takeover tko_ tokens only work through it

Machine health

curl -fsS -H @~/.grape.auth \
  "$GRAPE_BASE_URL/api/runtime/admin/machine-health"

Check three things:

  1. Whether the Worker is online
  2. Whether the engine health check passes
  3. Whether tasks are piling up or are stale

Use machine-health/{runtime_id} for single-engine details.

Task takeover

  • takeover-context: look up the context required for takeover by Issue
  • tasks/{task_id}/detail: view task details
  • tasks/{task_id}/cancel: cancel a task
  • converge-event: compensate the terminal state; do not call it manually in the normal flow

Engine management

GET/PUT /api/runtime/runtimes/{runtime_id}/tags
GET/PUT /api/runtime/runtimes/{runtime_id}/scene-tags
PUT     /api/runtime/runtimes/{runtime_id}/alias
PUT     /api/runtime/runtimes/{runtime_id}/max-concurrent
POST    /api/runtime/runtimes/{runtime_id}/refresh-skills

Tags constrain dispatch. After changing tags, rebind or re-apply the scene node; otherwise tasks are still dispatched under the old rules.

Connect a Worker

engine-onboarding returns the onboarding guide; the installation scripts and Worker package are public download URLs. For the actual onboarding steps, see Runtime and Worker.

Common errors

Status Cause
400 Missing parameters or an invalid runtime_id
401 Unauthenticated
403 A tk_ token calling a user-level endpoint
404 Worker, Engine, or task not found
409 Task status conflict

Runtime and Worker | Engine overview | Authentication and credentials