Repository navigation
docs(api): a client guide -- interfaces, the calls each mocactl sbx command makes, errors and retries - #925
Conversation
…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]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
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
/v1with{error, message}(errors.ts),SandboxExecinsandbox.v1behind the relay, and/v1/turn+ SSE on the harness.harnessUrlreally is onGET /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 fromPUT …/modeorPOST …/mode-token(sandbox-handlers.ts:3056,SANDBOX_MODE_TOKEN_TTL_S), and the one re-mint onPERMISSION_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(includingpolicy_changed409 aterrors.ts:138,mode_not_allowed403 at:141),@moca/server(turn_in_progresswithturnId,turnErrorCode's 410config_bundle_not_foundand 422config_bundle_unsupported,server.ts:345-356,:551-554), and the supervisor's 429overloadedwithRetry-After: 1(admission.ts:10-22). internal_errorreally carries no message (errors.ts:249-272);Retry-Afterreally is only on the control plane's two 409s (retryAfterShas 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.
| > 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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_changedandquota_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_mismatchwith the runningturnId(a cancel naming another turn).
- control plane:
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
left a comment
There was a problem hiding this comment.
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:
- The error table:
turn_not_foundis marked harness only, but the control plane also returns404 turn_not_foundfor async turns (packages/control-plane/src/errors.ts:181). Mark it both. - The
sbx rmrow:GET /v1/sandboxes/{id}runs for every sandbox (to read its mode); only a lease sandbox then gets a token mint andLeaseControl sandbox_deleted(packages/mocactl/src/sbx/commands.ts:684-703). Suggested: "GET /v1/sandboxes/{id}; for a lease sandbox, a token andLeaseControl sandbox_deleted, then …". - 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]>
|
@webchang Thanks. Fixed in 94280ba:
From a clean clone: 237 files, 0 broken links; site build, no broken links. |
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.yamlandsandbox.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":The three interfaces. Control-plane REST
/v1,SandboxExecgRPC 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.mocactl sbxcommand → the API calls it makes. Every row was checked in themocactlsource, with these corrections to the source:templates createreads no policy; only--dry-rundoes (templates.ts:487-492);429 buildsQueuedafterRetry-After, with a 30 s fallback (:546-554);sbx modereads first and resends without the idle timeout on400;sbx rm's lease step is best effort, capped at 15 s, after the unpulled-changes check;--seed,follow,activate --waitandupare included;sbx createwaits out409 template_not_activefor up to 10 min;set_modere-mints its token once onPERMISSION_DENIED.The top-level
mocactlrows stay in the generatedcli-mocactlreference.One error table across REST, SSE and gRPC, with a "what a client should do" column. It adds the codes the source missed:
410 config_bundle_not_found,digest_mismatch,endpoint_unresolved,unauthorized,credential_not_found,turn_not_found,destination_conflict;501 workload_runs_unavailable;429 overloaded.refresh_reuse_detectedis a server-side record; the client sees400 invalid_grant.Exit codes for
mocactlandmocactl sbx.Retry rules. When
Retry-Afteris 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.mdanddocs/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 linkopenapi.yaml.Left out because they couldn't be verified: a 900 s device-code lifetime (the server passes
expiresInthrough) 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; nosbx[0-9], cohort or w3id in the changed files.scripts/check-docs-site.sh: 62 pages, no broken links.Assisted-By: Claude Code