Skip to content

docs: mocactl, HTTP API and leaf references, first-run guide (PR 5b of REORG-PLAN) - #497

Merged
pdettori merged 2 commits into
rossoctl:mainfrom
pdettori:docs/reference-pr5b
Oct 12, 2026
Merged

pdettori merged 2 commits into
rossoctl:mainfrom
pdettori:docs/reference-pr5b

Conversation

@pdettori

@pdettori pdettori commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Summary

PR 5b of docs/REORG-PLAN.md: the reference pages for the CLI, the HTTP API and the leaf contract, plus a first-run guide. Docs only. Based on main after #493.

  • docs/reference/cli-mocactl.md: every command with flags, exit codes, endpoints, config.json keys and key bindings, from packages/mocactl and the built binary's --help.
  • docs/reference/http-api.md: how the control plane and data plane fit together, data-plane auth, /v1/turn (sync, SSE frames, detach/attach, cancel), /v1/runs, the error mapping, and the supervisor's 429 overload answer.
  • docs/reference/leaf-and-envelope.md: the inline leaf envelope and result that replaced the volume envelope, idempotency by sessionId, and the human-gate flow (re-POST with an inline decision).
  • docs/get-started/first-run.md: send a turn, resume by sessionId, stream, tear down, on the Compose trial path.
  • Fixes the human-gate wording: the code returns status paused; awaiting_approval appears only in the older file-based design. Glossary and README corrected.
  • Linked from docs/index.md, the get-started page and the README; the plan file records 5b.

Not done

The plan also listed install-cli and backend-* entry pages. I dropped them: docs/get-started/index.md already covers the CLI install and the backend choice, and per-path pages would duplicate the deploy READMEs. Concepts (5c) and operations pages are still to come.

Please check

  • First run is untested. I assembled the commands from the Compose README and the API behaviour and did not run them. The page says so; please run them or tell me which step fails.
  • Prompt-leaf session id: the turn uses the raw sessionId; the lease, promoted config and result record use the sanitized one. Documented as is (review confirmed); a code fix would be a follow-up.
  • Spec drift: docs/specs/2026-06-28-human-gate-design.md still describes the file-based gate with no superseded banner. The reference follows the code.
  • mocactl README vs code: exit codes 3 and 4 (and promote's exit 1 for a missing .claude tree) are not in the README; the reference lists them. The overlay keys (Sessions, Credentials, Palette) are not covered.

Verification

scripts/check-doc-links.py reports 0 broken links over 165 files; Prettier run on changed files; the key error codes were spot-checked against the source. make lint not run locally; CI will.

Assisted-By: Claude (Anthropic AI) [email protected]

- reference/cli-mocactl.md: commands, flags, exit codes, endpoints, config
  and key bindings, from packages/mocactl and its --help output.
- reference/http-api.md: how the control plane and data plane fit together,
  data-plane auth, /v1/turn (sync, SSE, attach, cancel), /v1/runs and the
  error mapping.
- reference/leaf-and-envelope.md: the inline leaf envelope and result that
  replaced the volume envelope, idempotency and the human-gate flow.
- get-started/first-run.md: send a turn, resume by sessionId and stream
  on the Compose trial path.
- Fix the human-gate wording (status is 'paused'; no awaiting_approval
  status in the code) in the glossary and README.
- Link the pages from docs/index.md, get-started and the README; update
  REORG-PLAN (PR 5b).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Oct 12, 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.

Summary

I checked the new reference pages against the code on main (5f1fec8; the PR adds only docs on top of it). Most of the page content holds: routes, auth codes, SSE frames, detach/attach, the LeafResult union, the gate flow, mocactl's flags, exit codes, doctor checks, keybindings and paths. One thing needs to change before merge. configRef on /v1/runs is described as if it behaved like /turn, but /runs ignores the session's bound bundle and the verdict leaf ignores configRef entirely. An integrator following the page would run leaves without their skills, and nothing would tell them. Everything else is suggestions and nits.

The prompt-leaf session-id question from the PR body has an answer: the turn gets the raw env.sessionId, and the lease, promoted config and result record get the sanitized one (inline comment).

Author: pdettori (MEMBER — maintainer)
Areas reviewed: Docs (reference pages, first-run guide, index/README/glossary link and wording changes)
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing (all 14 checks, incl. docs and lint)

Not covered: the first-run commands weren't executed. As the page says, they're untested.


`item` is `{item_id: string, file: string, pattern: string, require_approval?: boolean}`.

Optional fields on any envelope: `decision`, `model`, `provider`, `workspaceRef`, `repoUrl`, `ref`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix: configRef is not honoured on "any envelope", and /runs never inherits the session's bound bundle.

  • runLeaf reads env.configRef only for prompt (harness/src/run-leaf.ts:442) and solve (run-leaf.ts:565) leaves. The verdict leaf never reads it, so a verdict envelope with configRef silently runs without the bundle's skills.
  • handleRunLeafParsed calls runLeaf(body, buildConfig(auth)), and buildConfig (packages/knative-server/src/server.ts:81-103) drops auth.configRef. Only the /turn paths pass configRef: auth.configRef (server.ts:293,475,600). So an authenticated /runs gets a bundle only if the envelope names one.

Please say: configRef applies to prompt and solve leaves only, it must be in the envelope, and the session's bound bundle is not used on /runs.

- A token for one session cannot drive another: a `sessionId` in the body that differs from the
token's session gives 400 `session_mismatch`; an `X-SH-Subject` that differs from the token's
subject gives 400 `subject_conflict`.
- For authenticated turns the harness exchanges the token with the control plane for the user's

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix (same root cause as the leaf-envelope comment): "These always come from the control plane, never from the request" holds for /turn only. On /v1/runs, buildConfig(auth) (packages/knative-server/src/server.ts:81-103) drops auth.configRef, and the leaf takes its bundle from the envelope's configRef (harness/src/run-leaf.ts:442,565). Please scope this sentence to turns and point /runs readers to the leaf page.

Comment thread docs/reference/leaf-and-envelope.md Outdated
- The [human-gate design](../specs/2026-06-28-human-gate-design.md) still describes the file-based
design (`decisionRef`, `gateRef`, an `awaiting_approval` marker). This page follows the code.
- The P1 spec lists failure reasons without `saturated`, and statuses without `solved` and `responded`.
- Which session id a prompt leaf passes to its turn (the raw or the sanitized one) should be checked

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: this open question can be answered, so the reference doesn't need to send readers to the source. In a prompt leaf, the turn gets the raw env.sessionId (harness/src/run-leaf.ts:459-461, which opens or creates the Pi session under that id with no tenant prefix and no sanitising). The sandbox lease (run-leaf.ts:389), attachPromotedConfig (:446) and the result record (server.ts:894) all use the sanitized leafSessionId. Verdict and solve leaves use the sanitized id throughout. Either document this as is, or fix the code in a follow-up and link the issue.

Comment thread docs/reference/leaf-and-envelope.md Outdated

A `failed` result is returned as HTTP 200 on the sync path, not as a 4xx or 5xx, except `saturated`,
which becomes 503 with `Retry-After`. Every non-saturated outcome is stored at `leaf:result:<id>` with
a TTL of `LEAF_RESULT_TTL_SECONDS` (default 86400) and is readable with `GET /runs/status?sessionId=`;

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: GET /runs/status returns a reduced view, not the stored result (handleLeafStatus, packages/knative-server/src/server.ts:902-940):

  • failed has no message. The sync write also stores none: toResultRecord keeps no message (harness/src/leaf-result-store.ts:62).
  • solved and responded drop usage.
  • paused returns gateId both at top level and inside gate.
  • A missing record is 200 {status:"queued"}.
  • The lookup takes tenant as a query parameter (server.ts:908).

The same applies to line 73's "readable from /runs/status".

Comment thread docs/reference/leaf-and-envelope.md Outdated
gate decision are **inline** in the request, the result is the **response body**, and a copy is stored
in Redis for polling. The harness does no filesystem I/O of its own.

An envelope with the old fields is rejected with 400 `envelope_invalid`. Some scripts under

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: nothing checks for the old fields by name. isRunEnvelope (packages/knative-server/src/server.ts:777-799) only checks for a valid inline shape. A file-ref envelope gets 400 envelope_invalid because it has no item, problemStatement or prompt. An envelope with the old fields plus a valid item is accepted, and the old fields are ignored. Suggested wording: "an envelope without the inline fields (the old file-ref shape) is rejected…"

Comment thread docs/reference/cli-mocactl.md Outdated
| `4` | `auth token`: the control plane is unreachable |

Output convention: stdout carries only the result, and all messages go to stderr. Times in tables are
UTC. Not logged in prints `not logged in — run mocactl login first` and exits 2.

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: this message is not uniform:

  • The text has backticks: not logged in — run `mocactl login` first (headless.ts:164).
  • A failed refresh prints a different message instead ("the login could not be refreshed — is the control plane reachable?…", headless.ts:162-163).
  • auth token prints …run `mocactl login` and exits 3 (headless.ts:85-86).
  • logout while not logged in exits 0 (headless.ts:104-106).
  • promote --dry-run skips the check.

Consider "most commands" plus these exceptions.

Comment thread docs/reference/cli-mocactl.md Outdated
same global usage. `mocactl --version` prints a release tag, `edge-<sha>` or `dev`.

All flags are accepted by one parser. An unknown flag, or a missing flag value, prints the usage and
exits 2. A flag a command does not use is not always rejected; it may be ignored.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: some flags are always rejected outside their command, with exit 2 (packages/mocactl/src/cli.ts:129-143): --kind/--consumer/--host/--endpoint outside credentials add, --config outside run, and --all outside logout.

Comment thread docs/reference/cli-mocactl.md Outdated
- The prompt is the positionals joined with spaces. Exit 2 for an empty prompt, `--new` with
`--session`, `--config` with `--session` (a session's bundle is fixed at creation), a blank
`--config`, or an `--option` without `=`.
- `--option` keys: `inferenceCredential=NAME` and `sandboxTier=NAME`. A choice that is ambiguous or

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit:

  • With several sandboxTier choices and none given, run leaves it unset for the server default rather than exiting (core/session-options.ts:138).
  • A field with no choices but a given value exits 2 with the empty-hint text (:129-131).
  • Unknown --option keys are silently ignored, and =x (no key) exits 2 (:188).

Comment thread docs/reference/cli-mocactl.md Outdated
| `basic` | `username=…` and `password=…`, one per line |

Consumers are `inference`, `sandbox-egress` and `control-plane`. `basic` is not for inference; use it
with `--consumer sandbox-egress`. Anthropic `sk-ant-oat…` OAuth tokens are rejected, as is an

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit:

  • The sk-ant-oat… and sk-ant-api…-under-bearer rejections apply only to --consumer inference (core/credential-checks.ts:121).
  • "Bearer kind" means bearer or oauth2-token (:22).
  • There's also a pre-stdin rejection of an api.anthropic.com endpoint with a bearer kind (:41-42).

Comment thread docs/reference/cli-mocactl.md Outdated
| `2` | Wrong argument count; not logged in (not checked with `--dry-run`); preflight errors |
| `3` | A structural credential match; nothing was uploaded |

`--json` prints the whole result: `{digest, configRoot, skills, dropped, prompts, report, warnings, uploaded}`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: a dry run's --json also includes dryRun: true (core/promote.ts:168,238).

- configRef on /v1/runs: prompt and solve leaves only, from the envelope;
  the session's bound bundle is not used; scope the 'always from the
  control plane' sentence to /turn.
- Prompt-leaf session ids are inconsistent (raw for the turn, sanitized
  elsewhere): document it.
- /runs/status returns a reduced view; old-field handling, configRef
  format checks, tenant_not_allowed and workloadId ordering clarified.
- HTTP API: token TTL defaults and /workloads API tokens, URL matching,
  error body extras and passthrough codes, ended-turn attach semantics,
  extra control-plane codes, narrowed known gap.
- mocactl: always-rejected flags, login message variants, --option edge
  cases, credential-check scope, dry-run JSON, exit 3/4 wording.
- First run: the control-plane profile does not close anonymous /turn.

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

Copy link
Copy Markdown
Member Author

Addressed in 834fa2b: configRef on /v1/runs (prompt and solve leaves only, from the envelope; the session's bound bundle is not used) and the matching scoping of the 'always from the control plane' sentence; the prompt-leaf session-id inconsistency documented; the reduced /runs/status view; old-field handling, configRef format, tenant_not_allowed and workloadId ordering; the HTTP API suggestions and nits (token TTL defaults, /workloads API tokens, URL matching, error body extras, passthrough codes, attach semantics on a running turn, extra control-plane codes, narrowed known gap); the mocactl suggestions and nits; and first-run no longer claims the control-plane profile closes anonymous /turn.

@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.

Thanks. I re-checked 834fa2b against main (5f1fec8). All 20 items from the 19f457f review are addressed and the new wording matches the code: configRef is scoped to prompt/solve leaves and read from the envelope, the /runs/status reduced view, tenant_not_allowed on both /runs and /runs/status, the passthrough codes, token TTL defaults, attach-at-tail on a running turn, the mocactl flag, login and exit-code exceptions, and the first-run note on SH_REQUIRE_AUTH. One nit, inline.

Author: pdettori (MEMBER — maintainer)
Areas reviewed: Docs (incremental 19f457f..834fa2b: http-api, leaf-and-envelope, cli-mocactl, first-run)
Agent/IDE config (.claude/.vscode): none
Commits: 2, all signed-off: yes
CI status: passing (all 14 checks)

FYI: #496 makes --config valid on mocactl spawn and adds spawn/subagents/get. Whichever PR lands second should update cli-mocactl.md ("--config outside run") to match.

| `POST /run-leaf`, `GET /run-leaf/status` | session token | **Deprecated** aliases of `/runs` and `/runs/status`; log a warning once per process |

Matching is by URL and not uniform. `/health`, `/turn`, `/v1/turn` (POST), `/v1/turn/cancel`, `/runs`,
`/v1/runs` and `/run-leaf` match the exact URL, so a query string defeats them. `GET /v1/turn` requires

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: "GET /v1/turn requires and accepts a query string": a bare GET /v1/turn also routes (server.ts:1079-1080, url === '/v1/turn' || url.startsWith('/v1/turn?')) and answers 400 sessionId_required, not the empty 404. Maybe: "GET /v1/turn matches with or without a query string (a missing sessionId is 400)". Separately, this paragraph's line 59 is much longer than the surrounding wrap width.

@pdettori
pdettori merged commit 69a866a into rossoctl:main Oct 12, 2026
14 checks passed
@pdettori
pdettori deleted the docs/reference-pr5b branch October 12, 2026 21:10
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.

2 participants