Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ This file defines how coding agents should work in this repository.
prefer explicit `--gpu-ids 0` unless the text is intentionally demonstrating
the all-visible-GPUs default.
- Avoid placing new project-specific documentation in the root directory; keep only canonical top-level docs (for example, `AGENTS.md`, `README.md`) at root.
- Keep `docs/reference/cli.md` focused on command syntax, options, and CLI
result shapes. Put REST, JSON-RPC, MCP, dashboard, and endpoint contracts in
`docs/guides/mcp.md` and link there instead of duplicating endpoint tables in
the CLI reference.

### Quality Bar

Expand Down
17 changes: 16 additions & 1 deletion docs/guides/mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ is still in progress. That includes both `status(job_id)` and the all-session
Returned session `params` are snapshots; local embedding callers can inspect
or modify the returned object without mutating service state. Known fields in
`params` are always present and follow the same public session contract as
`start_keep`.
`start_keep`; omitted `gpu_ids` is represented as `null`, not by omitting the
key.
If an already-started worker later reports a terminal runtime or allocation
failure, the retained session is refreshed to `state="runtime_failed"` with
`last_error`. It remains visible and stoppable. This is distinct from normal
Expand Down Expand Up @@ -239,6 +240,20 @@ results in deterministic snapshot order using the same additive fields.

## REST quick examples

### REST endpoint index

| Endpoint | Method | Purpose |
| --- | --- | --- |
| `/health` | GET | Service liveness probe. |
| `/api/gpus` | GET | GPU telemetry with start-compatible visible ordinals. |
| `/api/sessions` | GET | All tracked keep sessions. |
| `/api/sessions/{job_id}` | GET | One tracked keep session. |
| `/api/sessions` | POST | Start a keep session from a JSON object body. |
| `/api/sessions` | DELETE | Stop all sessions. |
| `/api/sessions/{job_id}` | DELETE | Stop one session. |
| `/rpc` | POST | Exact JSON-RPC compatibility endpoint. |
| `/` | GET | Dashboard UI. |

```bash
curl http://127.0.0.1:8765/health
curl http://127.0.0.1:8765/api/gpus
Expand Down
52 changes: 5 additions & 47 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,53 +181,11 @@ ownership record.
| `--host`, `--port` | Service host/port. `--host` must be a DNS hostname or IPv4 address, and `--port` must be a plain ASCII decimal integer in `1..65535`. |
| `--force` | Skip session RPC checks and stop the daemon only if the auto-start ownership record verifies the process. |

## Service HTTP endpoints

Only omitted/`null` `job_id` values mean generated IDs or all-sessions, depending
on the method. Custom IDs must be non-empty strings containing only letters,
digits, `.`, `_`, `-`, or `~`, and may not be standalone `.` or `..`; invalid
REST path IDs return `400` before acting.
Supported REST route/method errors are JSON objects: validation errors return
`400`, unknown API routes return `404`, expected startup-unavailable session
creation returns `503`, and unexpected service/runtime failures return `500`
instead of dropping the connection. Encoded noncanonical spellings such as
`/api%2Fsessions`, `/api%252Fsessions`, `/api%3Bdebug`, or `/api%3Fsessions`
are treated as unknown API routes and return JSON `404` responses rather than
the dashboard HTML shell, including when the API-looking target is revealed only
after deeper repeated decoding. Raw leading-double-slash API aliases such as
`//api/sessions` are also unknown routes and do not start or stop sessions.
Exact API collection routes such as `/api/gpus` and `/api/sessions` do not
accept query strings or path parameters unless documented; query-shaped
collection URLs return JSON `404` responses.
The dashboard consumes those JSON objects and displays `error.message` when it is
present, falling back to the plain response body or HTTP status only when needed.
Direct JSON-RPC service calls report the same expected hardware/platform
startup-unavailable conditions, including failed CUDA/ROCm visible-device
enumeration and unavailable PyTorch MPS backends, with error code `-32000`;
arbitrary runtime failures remain `-32603 Internal error`. CLI service commands
send explicit JSON-RPC 2.0
request envelopes to `/rpc`; omitted-version direct calls are retained only for
legacy local scripts.
When `list_gpus()` returns validated visible records, explicit JSON-RPC
`start_keep` `gpu_ids` must match those listed IDs before controller startup.
Omitted direct-call `params` are treated as `{}` for compatibility, but explicit
`params: null` or any other non-object `params` value returns `-32602 Invalid
params` before method side effects.
Status records include a complete `params` snapshot with `gpu_ids`, `vram`,
`interval`, and `busy_threshold`; omitted `gpu_ids` is represented as `null`,
not by omitting the key.

| Endpoint | Method | Purpose |
| --- | --- | --- |
| `/health` | GET | Service liveness probe. |
| `/api/gpus` | GET | GPU telemetry (`id`/`visible_id` are start-compatible visible ordinals; optional `physical_id`/`uuid` are metadata; unselectable CUDA/ROCm records are omitted; unsupported fields are `null`; expected enumeration unavailability is a structured `503`; the dashboard treats unavailable utilization as `n/a`, not `0%`). |
| `/api/sessions` | GET | Tracked keep sessions, including `state="starting"` during startup, `state="runtime_failed"` plus `last_error` for retained worker failures, and `state`/`last_error` for in-progress or failed stops. |
| `/api/sessions/{job_id}` | GET | One session status, including `state` and `last_error` when active, starting, runtime-failed, or retained after stop problems. |
| `/api/sessions` | POST | Start session with a JSON object body (`gpu_ids`, `vram`, finite positive bounded `interval`, `busy_threshold`, `job_id`); `vram` accepts human sizes or bytes, rejects byte-equivalent values below 4 bytes or above 1 PiB, and rounds internal tensor element counts up, omitted `gpu_ids` means all GPUs visible to the service process, omitted `busy_threshold` uses `25`, and duplicate, out-of-range, or selections with more than 64 entries are invalid. Explicit `gpu_ids` are checked against a validated `list_gpus()` response; an explicit empty `gpu_ids` list is invalid, an empty validated GPU listing is `503`, and malformed listing payloads are structured `500` errors before any session starts. |
| `/api/sessions` | DELETE | Stop all sessions; returns `stopped`, `timed_out`, `failed`, and `errors`. |
| `/api/sessions/{job_id}` | DELETE | Stop one session; returns `stopped`, `timed_out`, `failed`, and `errors`. |
| `/rpc` | POST | Exact JSON-RPC compatibility endpoint; noncanonical `/rpc` URLs, including leading `//rpc` and encoded exact aliases such as `/%252Frpc` or deeper repeated encodings, return structured `404` errors. |
| `/` | GET | Dashboard UI. |
## Service API reference

This page focuses on CLI commands and options. For REST routes, JSON-RPC
methods, MCP tools, dashboard behavior, and service error envelopes, see the
[MCP and Service API guide](../guides/mcp.md).

## Environment variables

Expand Down
26 changes: 13 additions & 13 deletions tests/test_package_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,19 +261,19 @@ def test_bundled_operator_skill_keeps_platform_sanity_checks_in_sync():


def test_rest_session_docs_distinguish_empty_gpu_ids_from_empty_listing():
public_docs = {
"cli_reference": (PROJECT_ROOT / "docs/reference/cli.md").read_text(
encoding="utf-8"
),
"mcp_guide": (PROJECT_ROOT / "docs/guides/mcp.md").read_text(encoding="utf-8"),
}

for doc in public_docs.values():
normalized_doc = re.sub(r"\s+", " ", doc)
assert "an explicit empty `gpu_ids` list is invalid" in normalized_doc
assert "empty validated GPU listing is `503`" in normalized_doc
assert "a valid empty list is `503`" not in normalized_doc
assert "valid empty GPU list" not in normalized_doc
cli_reference = (PROJECT_ROOT / "docs/reference/cli.md").read_text(encoding="utf-8")
mcp_guide = (PROJECT_ROOT / "docs/guides/mcp.md").read_text(encoding="utf-8")
normalized_mcp_guide = re.sub(r"\s+", " ", mcp_guide)

assert "[MCP and Service API guide](../guides/mcp.md)" in cli_reference
assert "## Service HTTP endpoints" not in cli_reference
assert "an explicit empty `gpu_ids` list is invalid" not in cli_reference
assert "an explicit empty `gpu_ids` list is invalid" in normalized_mcp_guide
assert "empty validated GPU listing is `503`" in normalized_mcp_guide
assert "omitted `gpu_ids` is represented as `null`" in normalized_mcp_guide
assert "`/api/sessions/{job_id}` | GET" in mcp_guide
assert "a valid empty list is `503`" not in normalized_mcp_guide
assert "valid empty GPU list" not in normalized_mcp_guide


def test_sdist_manifest_does_not_package_test_suite():
Expand Down