Skip to content

docs(api): a client guide -- interfaces, the calls each mocactl sbx command makes, errors and retries - #925

Merged
pdettori merged 3 commits into
rossoctl:mainfrom
pdettori:docs/client-guide
Nov 19, 2026
Merged

pdettori merged 3 commits into
rossoctl:mainfrom
pdettori:docs/client-guide

Conversation

@pdettori

Copy link
Copy Markdown
Member

Summary

This is a page for client developers, people writing a script, SDK, tool or agent integration against moca. The audience had no home: the contracts are in openapi.yaml, harness-openapi.yaml and sandbox.proto, and the error and exit codes were spread over several references. The page draws on the genuinely new parts of the client developer guide; about 75% of that guide repeats published pages and is linked instead. Everything is corrected against the code.

New docs/api/client-guide.md, "Build a client: interfaces, calls, errors and retries":

  1. The three interfaces. Control-plane REST /v1, SandboxExec gRPC through the relay, and the harness's turns over REST/SSE, with the credential each one takes. Lifetimes link to the security model and the direct-API page rather than being restated.

  2. mocactl sbx command → the API calls it makes. Every row was checked in the mocactl source, with these corrections to the source:

    • a real templates create reads no policy; only --dry-run does (templates.ts:487-492);
    • it re-posts on 429 buildsQueued after Retry-After, with a 30 s fallback (:546-554);
    • sbx mode reads first and resends without the idle timeout on 400;
    • sbx rm's lease step is best effort, capped at 15 s, after the unpulled-changes check;
    • the reads done by --seed, follow, activate --wait and up are included;
    • sbx create waits out 409 template_not_active for up to 10 min;
    • set_mode re-mints its token once on PERMISSION_DENIED.

    The top-level mocactl rows stay in the generated cli-mocactl reference.

  3. One error table across REST, SSE and gRPC, with a "what a client should do" column. It adds the codes the source missed:

    • harness 410 config_bundle_not_found, digest_mismatch, endpoint_unresolved, unauthorized, credential_not_found, turn_not_found, destination_conflict;
    • 501 workload_runs_unavailable;
    • the supervisor's 429 overloaded.

    refresh_reuse_detected is a server-side record; the client sees 400 invalid_grant.

  4. Exit codes for mocactl and mocactl sbx.

  5. Retry rules. When Retry-After is sent, and the busy backoff of 1/2/4/8 s with jitter (default 4 retries, capped at 20, MOCACTL_SBX_BUSY_RETRIES).

There is one pointer each from docs/sandbox/how-to/direct-api.md and docs/harness/reference/http-api.md. No other page changes, so this PR doesn't conflict with #924 (templates) or the users-and-roles PR. Once #924 merges, the template routes can link its Template API page; for now they link openapi.yaml.

Left out because they couldn't be verified: a 900 s device-code lifetime (the server passes expiresIn through) and the Go/Python example clients' exit codes (linked instead). There are no internal names, no spec or ADR links, and none of the source repo's citations.

Testing (from a clean clone of the branch)

  • make check-links: 237 files, 0 broken links.
  • scripts/check-docs-publish.sh: 84 files, no matches; no sbx[0-9], cohort or w3id in the changed files.
  • scripts/check-docs-site.sh: 62 pages, no broken links.
  • Prettier 3.10.1 is clean.

Assisted-By: Claude Code

…ommand makes, errors and retries

A client developer had no page of their own: the contracts are in
openapi.yaml, harness-openapi.yaml and sandbox.proto, and the error and
exit codes were spread over several references. From the client
developer guide's genuinely new parts, corrected against the code:

- docs/api/client-guide.md (new): the three interfaces (control-plane
  REST, SandboxExec gRPC through the relay, the harness's turns over
  REST/SSE) and the credential each takes; the mocactl sbx command ->
  API calls table (a real `templates create` reads no policy -- only
  --dry-run does -- and re-posts on 429 buildsQueued; `sbx mode` reads
  first and retries without the idle timeout; `sbx rm`'s best-effort
  lease step; `sbx create` waits out 409 template_not_active); one error
  table across REST, SSE and gRPC with what a client should do, adding
  the codes the source missed (harness 410 config_bundle_not_found,
  digest_mismatch, endpoint_unresolved, unauthorized,
  credential_not_found, turn_not_found, destination_conflict, 501
  workload_runs_unavailable, the supervisor's 429 overloaded); the exit
  codes; and the retry rules (Retry-After, busy backoff 1/2/4/8 s).
- One pointer each from the sandbox direct-API page and the harness HTTP
  API page.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori
pdettori marked this pull request as ready for review November 19, 2026 18:36
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 19, 2026

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review — docs(api): a client guide — interfaces, calls, errors and retries

A useful page in the right place, and the bridge table is the part that did not exist anywhere. I checked the rows against packages/mocactl/src/sbx/*.ts and the error table against the control plane, @moca/server and the supervisor; nothing blocking, one suggestion inline about the "every error code" claim the cross-reference makes.

Interfaces and credentials

  • The three interfaces match the code: control plane REST under /v1 with {error, message} (errors.ts), SandboxExec in sandbox.v1 behind the relay, and /v1/turn + SSE on the harness. harnessUrl really is on GET /v1/discovery (handlers.ts:840).
  • The credential table is right, including {"activity": false} on a no-command mint (sandbox-handlers.ts:3019, sbx/api.ts:518-525), the set-mode token from PUT …/mode or POST …/mode-token (sandbox-handlers.ts:3056, SANDBOX_MODE_TOKEN_TTL_S), and the one re-mint on PERMISSION_DENIED (mode.ts:52-62).

The bridge table

Spot-checked every row I could not confirm from memory: login (discovery gate then deviceLogin's new code on expiry, auth.ts:41-47), follow/activate --wait/retire --wait (5 s polls, start line via listHosts, 30 s fallback, templates.ts:32-38, :620-760), create (10-minute template_not_active wait, commands.ts:391-418), get (status + epoch-known re-send, lease-commands.ts:219-275), mode (idle-timeout carry and the 400 retry, lease-commands.ts:71-102), rm (best-effort sandbox_deleted, 15 s cap, commands.ts:671-703), create --seed (seedSandbox), up (bound, then labelled lookup, then create, sync.ts:273-306), doctor, egress, credentials, mcp (30 s keepalive). The 401-refresh-once rule is control-plane.ts:83-95; the busy retry is run.ts:63-74 (4 by default, 20 max, 1/2/4/8 s with jitter, exit 75).

Errors and exits

  • Codes and statuses match CP_ERROR_CODES/STATUS (including policy_changed 409 at errors.ts:138, mode_not_allowed 403 at :141), @moca/server (turn_in_progress with turnId, turnErrorCode's 410 config_bundle_not_found and 422 config_bundle_unsupported, server.ts:345-356, :551-554), and the supervisor's 429 overloaded with Retry-After: 1 (admission.ts:10-22).
  • internal_error really carries no message (errors.ts:249-272); Retry-After really is only on the control plane's two 409s (retryAfterS has two producers) and on every harness 503/429 (retryHeaders), never on a control-plane 503.
  • The gRPC table matches docs/sandbox/how-to/direct-api.md (Outcomes versus failures), and the exit-code table matches both generated references.

Checks — check-links 237 files/0 broken, publish hygiene 84 files clean, CI 18/18 (docs job and site build included). Draft PR; the review is against fae161d7.

One suggestion inline on the error-code coverage claim.

Comment thread docs/harness/reference/http-api.md Outdated
> they fit together and records behaviour the specs do not. Workload routes are covered in
> [`docs/harness/how-to/workloads.md`](../how-to/workloads.md).

For every error code with what a client should do about it, and the retry rules, see

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: "For every error code" overstates what the table holds. Eleven of the control plane's 59 codes are absent (grant_invalid, turn_not_claimable, credential_unsafe, destination_ambiguous, no_credential, envelope_invalid, and — the ones a client can actually act on — policy_changed, quota_changed, bootstrap_subject, self_revoke, admin_granted), and so are several harness turn codes a direct client meets: prompt_required, sessionId_required, turn_mismatch, tenant_not_allowed, read_error. Either soften the sentence ("the error codes a client meets, and the retry rules" — which is what the page's own intro says), or add the client-facing few above. policy_changed/quota_changed in particular matter to anyone driving the admin routes the page already names.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 35e3584, both ways.

  • The sentence now reads "For the error codes a client meets, with what to do about each, and the retry rules".
  • The table gains the client-facing codes you listed, each checked in the code:
    • control plane: 409 policy_changed and quota_changed (a ?expect= write after the stored policy or quota changed, nothing written: read again and re-apply), 409 bootstrap_subject (change it in the settings), 409 admin_granted (revoke the role first), 409 self_revoke (another admin must);
    • harness: 400 prompt_required / sessionId_required, 400 tenant_not_allowed (drop the tenant parameter), 409 turn_mismatch with the running turnId (a cancel naming another turn).

I left out the internal or non-client codes (grant_invalid, turn_not_claimable, credential_unsafe, destination_ambiguous, no_credential, envelope_invalid, read_error). The softened sentence now matches that scope.

…client-facing codes added)

The HTTP API page's pointer said the client guide lists "every error
code"; it lists the ones a client meets. The sentence now says so, and
the table gains the client-facing codes it lacked, each from the code:

- control plane: 409 policy_changed and quota_changed (a ?expect=
  write after the stored policy or quota changed; nothing written),
  409 bootstrap_subject (a subject the settings enroll), 409
  admin_granted (unenrolling an admin: revoke the role first), 409
  self_revoke (an admin revoking its own role) -- errors.ts,
  member-handlers.ts, sandbox-handlers.ts:2791;
- harness: 400 prompt_required and sessionId_required, 400
  tenant_not_allowed (an authenticated read naming a tenant), 409
  turn_mismatch with the running turnId (a cancel naming another turn)
  -- server.ts, turn-registry.ts.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>

@webchang webchang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this carries the bridge, error, exit-code and retry tables well, and adds codes our guide lacked. I checked the error statuses, the Retry-After rule and mocactl's waits, polls and retries against the code; they match. Two one-line fixes and a question:

  1. The error table: turn_not_found is marked harness only, but the control plane also returns 404 turn_not_found for async turns (packages/control-plane/src/errors.ts:181). Mark it both.
  2. The sbx rm row: GET /v1/sandboxes/{id} runs for every sandbox (to read its mode); only a lease sandbox then gets a token mint and LeaseControl sandbox_deleted (packages/mocactl/src/sbx/commands.ts:684-703). Suggested: "GET /v1/sandboxes/{id}; for a lease sandbox, a token and LeaseControl sandbox_deleted, then …".
  3. A question: where should a client find the default limits? #924 carries the template quotas (100 / 10 / 8 / 200) and the 3 live sandboxes per subject, but not the per-sandbox ones a client hits: 2 Execs in flight per sandbox, the longest command, and the 16 MiB / 8 MiB message sizes. A short "Quotas and limits" section here, or in docs/sandbox/concepts/limits.md, would cover it.

…x rm's reads, limits)

- Error table, turn_not_found: the control plane's own 404
  turn_not_found is the worker exchange route's (turn-exchange.ts:85),
  which a client never calls; a client reading an unknown async turn
  (GET /v1/sessions/{id}/turns/{turnId}) gets 404 not_found
  (turn-handlers.ts:55). The row stays harness and says so.
- Bridge table, sbx rm: GET /v1/sandboxes/{id} runs for every sandbox
  (to read its mode); only a lease sandbox then gets a token and
  LeaseControl sandbox_deleted (commands.ts:684-703).
- New "Quotas and limits": where each default a client hits lives --
  per sandbox (2 Execs in flight, 16 MiB per message, 8 MiB of stdout,
  a longest command of one token lifetime minus 60 s), per user (3 live
  sandboxes, 7-day idle lifetime) and template quotas (GET /v1/quota).
- concepts/limits.md: the longest command is one token lifetime minus
  60 s (14 minutes by default), not 15 minutes -- the timeout is capped
  there for every Exec (exec-conn.ts:361, run.ts:141), matching the
  direct-API page.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori

Copy link
Copy Markdown
Member Author

@webchang Thanks. Fixed in 94280ba:

  1. turn_not_found. I checked this before marking it "both". The control plane's own 404 turn_not_found comes from the worker exchange route (turn-exchange.ts:85, the POST …/turns/exchange path the drain calls), which a client never calls. A client reading an unknown async turn (GET /v1/sessions/{id}/turns/{turnId}) gets 404 not_found (turn-handlers.ts:55, "no such turn on this session"). So the row stays harness and now says that a client gets not_found from the control plane. Marking it "both" would have sent a client looking for a code it never receives.

  2. The sbx rm row now reads: "GET /v1/sandboxes/{id} (to read its mode); for a lease sandbox, a sandbox token and LeaseControl sandbox_deleted, …" (commands.ts:684-703).

  3. Limits. There's a new "Quotas and limits" section. It points to where each default lives rather than restating them:

    • per sandbox: 2 Execs in flight, 16 MiB per message, 8 MiB of stdout, longest command = token lifetime − 60 s; on the direct-API page's Limits;
    • per user: 3 live sandboxes and the 7-day idle lifetime; on the Limits concept page;
    • template quotas: via GET /v1/quota / mocactl sbx quota.

    While checking these I found that concepts/limits.md said the longest command is "one token lifetime (15 minutes)". The code caps every Exec at the lifetime minus 60 s (exec-conn.ts:361, run.ts:141), so it's now 14 minutes, matching the direct-API page.

From a clean clone: 237 files, 0 broken links; site build, no broken links.

@pdettori
pdettori merged commit 7781cdb into rossoctl:main Nov 19, 2026
17 checks passed
@pdettori pdettori added this to the v0.11.0 milestone Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants