Skip to content

feat(control-plane): mint and refresh a turn's two grants (#388) - #807

Merged
cwiklik merged 3 commits into
rossoctl:mainfrom
cwiklik:feat/388-s2-grants-core
Nov 13, 2026
Merged

cwiklik merged 3 commits into
rossoctl:mainfrom
cwiklik:feat/388-s2-grants-core

Conversation

@cwiklik

@cwiklik cwiklik commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

What this does

MI1 §6.1–§6.2's grants core: a separate Ed25519 key ring, the typ: moca-grant+jwt token
format, turn_exp, and the two lifecycle endpoints. Discharges
#388 items 1–2 and the turn_exp half of
#387's M2.

A worker presents the session token it was handed with the turn to POST /internal/turn-grants
and gets two grants: the inference half names the session's credential, the sandbox half names its
sandbox-egress credentials — by NAME, never by value (§7.2). A grant is a capability spent at
an enforcement point, not a secret, so nothing here decrypts anything and no secret reaches a
response, an audit entry or a log line. One test serialises the whole response plus the audit entry
and asserts the stored secret value appears in neither.

POST /internal/grants/refresh takes either half mid-turn and re-mints both. turn_exp is an
absolute cap carried forward unchanged, so no number of refreshes extends a turn, and a refresh past
it is refused rather than clamped. The session record is re-read rather than echoed, which is what
lets a credential changed mid-turn take effect and a tombstoned session stop refreshing.

Why a separate key ring

The grant ring is a different key from the session signer, so a session token can never pass as a
grant even where an aud check is forgotten. Note for anyone writing an out-of-tree verifier:
aud: moca-sandbox now names two different tokens — this grant and SBX0's sandbox access token —
and only typ separates them. Both verifiers pin their own.

packages/control-plane/test/fixtures/grant-vectors.json is §12.2's cross-language contract for the
future Go verifier: 17 vectors, public key only, verifier-side only. Each vector carries segments
rather than a whole compact JWS — a committed JWS is a finding for every secret scanner that walks
this repo, and these are public by construction, so joining three strings with a dot is the reader's
job (one line here, one line in Go).

Interim, and named as such

Nothing redeems a grant yet. Both routes are unmounted unless MOCA_GRANT_SIGNING_KEY is set and
404 before the body is read (ADR-0045's shape), so a deployment that has not generated the ring
behaves exactly as before — which is the correct setting today. /internal/credentials and
/internal/turn-credentials both stay (§6.2's "replaces /internal/credentials" lands with the
redeemer), and MOCA_TENANCY=multi still refuses async turns. There is no revocation list by design:
MOCA_GRANT_TTL_S is the revocation latency.

Out of scope here: /internal/token, the moca-egress inference listener, all Go code including the
Go verifier, applyModelGateway's grant mode, §6.6's first-subject pin, lifting the tenancy gate,
and deployment wiring — the routes are gated off, so nothing needs the key until a redeemer exists.

New configuration

MOCA_GRANT_SIGNING_KEY, MOCA_GRANT_PUBLIC_KEYS, MOCA_GRANT_TTL_S (300), MOCA_TURN_MAX_S
(1800) — all documented in docs/reference/configuration.md, all optional, none consumed by any
redeemer yet. OpenAPI goes to 1.7.0 (openapi.yaml, docs/api/CHANGELOG.md,
docs/reference/change-policy.md).

Verification

  • make fmt → clean, no files changed
  • make typecheck → 0
  • SKIP=hadolint-docker make lint → 0
  • control-plane suite → 1456 passed, 3 skipped, 0 failed (66 files)

One pre-existing flake seen twice during this work, in test/two-subject.test.ts — a race in that
file's own HTTP/Redis setup, once as ECONNRESET and once as a 404 on session create. The file
passes alone (10/10) and the suite passes on re-run. It is in code this PR does not touch; worth its
own issue.

Assisted-By: Claude Code

MI1 §6.1-§6.2's grants core: a separate Ed25519 key ring, the
`typ: moca-grant+jwt` token format, `turn_exp`, and the two lifecycle
endpoints. Discharges rossoctl#388 items 1-2 and the `turn_exp` half of rossoctl#387's M2.

A worker presents the session token it was handed with the turn to
POST /internal/turn-grants and gets two grants: the inference half names the
session's credential and the sandbox half names its `sandbox-egress`
credentials -- by NAME, never by value (§7.2). A grant is a capability spent
at an enforcement point, not a secret, so nothing here decrypts anything and
no secret reaches a response, an audit entry or a log line.

POST /internal/grants/refresh takes either half mid-turn and re-mints both.
`turn_exp` is an absolute cap carried forward unchanged, so no number of
refreshes extends a turn and a refresh past it is refused rather than clamped.
The session record is re-read rather than echoed, which is what lets a
credential changed mid-turn take effect and a tombstoned session stop
refreshing.

The ring is a separate key from the session signer so a session token can
never pass as a grant even where an `aud` check is forgotten. Note that
`aud: moca-sandbox` now names two different tokens -- this grant and SBX0's
sandbox access token -- and only `typ` separates them; both verifiers pin
their own. `test/fixtures/grant-vectors.json` is §12.2's cross-language
contract for the future Go verifier, carrying the public key only.

Interim, and named as such: nothing redeems a grant yet. Both routes are
unmounted unless MOCA_GRANT_SIGNING_KEY is set and 404 before the body is
read, so a deployment that has not generated the ring behaves exactly as
before -- which is the correct setting today. /internal/credentials and
/internal/turn-credentials both stay, and MOCA_TENANCY=multi still refuses
async turns. There is no revocation list by design: MOCA_GRANT_TTL_S is the
revocation latency.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
@cwiklik
cwiklik requested a review from pdettori as a code owner November 13, 2026 14:06
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 13, 2026

@clawgenti clawgenti 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 of the S2 grants-core slice (MI1 §6.1–§6.2). No must-fix findings.

Author: cwiklik (CONTRIBUTOR — returning external, elevated scrutiny; every changed file read in full)
Areas reviewed: TypeScript control-plane code, routes/server wiring, OpenAPI + docs, tests, security (§3.5), agent/IDE config
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, signed-off (DCO pass)
CI status: all checks passing

Verified empirically on head dc0cbb3: the three new test files (58 tests) and the five touched existing files (105 tests) all pass under vitest on a clean checkout of the PR branch. The vectors fixture's public-only key + segments-not-token design was spot-checked against grant-vectors.test.ts (accept/reject matrix including alg: none, HS256, unknown kid, tampered payload, past-turn_exp, both wrong-typ cases). The separate-ring property (typ pinned both directions, session token rejected as grant and grant rejected as session token) is covered in grant.test.ts and passes.

The two comments below are a suggestion and a nit; nothing here blocks merge.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

// Descriptors only -- `list` is the route that must enumerate without decrypting. A session may
// hold several egress credentials (one per destination), so this is a list and not a choice.
const descriptors = await deps.credentials.list(rec.owner);
const egress = descriptors.filter((d) => d.consumer === 'sandbox-egress').map((d) => d.name);

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 — the sandbox grant's egress enumerates every sandbox-egress credential the owner holds at mint time (and again at each refresh), while MI1 §6.1 words the claim as "the list of sandbox-egress credential names the session may use". Since the session record binds only the inference credential, there is no per-session narrowing available today, so this is presumably intended — but a turn's sandbox grant widens to the owner's full egress set, and a credential added mid-turn enters the grant at the next refresh. Impact is bounded because §6.3 step 3 re-filters by destination.hosts at redemption, but it would be worth one sentence in the TurnGrants schema (or the CHANGELOG) stating that egress is owner-scoped, not session-scoped, so the future Go verifier and out-of-tree readers don't assume session scoping the record can't express.

Suggested fix: a doc line in docs/api/openapi.yaml's TurnGrants.sandboxGrant description (and/or the sandbox-grant claims comment in grant.ts) saying the list is the owner's sandbox-egress set at mint/refresh time, narrowed per destination at the token endpoint.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct, and the comment on that claim was the wrong one — it said "the sandbox-egress credentials the session may use" while the code lists the owner's whole set. Documented in 34d549e in both places you named: the SandboxGrantClaims.egress doc comment in grant.ts and the TurnGrants.sandboxGrant description in openapi.yaml. Both now say it is the owner's set as of the mint, that one added mid-turn appears at the next refresh, and that §6.3 step 3's destination.hosts re-filter makes the claim an upper bound rather than an entitlement.

No behaviour change: nothing on the session record narrows the set, so there is nothing to narrow against until a redeemer exists.

One thing the same line deserved: credentials.list is uncached, and on the Kubernetes store it costs a kubectl get secret subprocess (k8s-secret-store.ts:201 → :129). That is one per issue and one per refresh, so an 1800 s turn refreshing at half-life would spawn ~13 where the existing exchange spawns 1 (exchange.ts:188 calls credentials.get once). Zero load today because nothing refreshes, so it now carries a shortcut: comment naming the limit and when to upgrade rather than a cache nothing needs yet.

if (!rec || rec.owner !== claims.sub || rec.tombstone) {
throw new CpError('session_not_found', undefined, claims.sid);
}
return mintFor(rec, claims.tenant, claims.turn_exp, 'grants_refreshed', deps);

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 — in refreshTurnGrants every claim is re-derived from the session record (decision D4) except tenant, which is echoed from the presented grant. The grant is signed by our own ring so this isn't a forgery vector, and sessions presumably never change tenant, but it's the one claim that deviates from the re-read rationale documented two lines above ("reconstructs BOTH halves from the session"). If SessionRecord carries tenant, passing rec.tenant here would make the re-read story uniform and cost nothing.

Suggested fix: mintFor(rec, rec.tenant ?? claims.tenant, claims.turn_exp, 'grants_refreshed', deps) — or a comment noting tenant is immutable on a session so the echo is deliberate.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 34d549e, with one adjustment to the suggested line.

SessionRecord.tenant is a non-optional string (ownership.ts:73), so rec.tenant ?? claims.tenant has a dead half — rec.tenant alone is correct.

The same echo was on the issue path too: sessionFromToken returned { rec, tenant: claims.tenant } and issueTurnGrants passed that through, so fixing only refresh would have left the asymmetry half-closed. Both paths now read the record, which made mintFor's tenant parameter dead (it was rec.tenant from both callers) and let sessionFromToken go back to returning just the SessionRecord. Net deletion.

turn_exp stays the one value a refresh carries forward, and the comment now says why: it is an absolute cap, so carrying it is what stops a refresh extending the turn. Everything else is re-read. Pinned by a new test asserting a tenant changed mid-turn shows up in the refreshed grant.

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

Correction to the review above: its body was submitted without the tracking marker the automation state machine reads, so this follow-up carries it. No new findings — the review at #pullrequestreview-5892556613 stands as written (2 comments: 1 suggestion on egress owner-scoping, 1 nit on tenant echo in refresh; nothing blocking).

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

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

Reviewed the grants core: grant.ts mint/verify, grant-exchange.ts issue/refresh, the sessionFromToken split, the route gate, the keyset/signer label refactor, and the openapi/CHANGELOG/configuration docs, against MI1 §6.1–§6.2.

The core looks right. The JWS is verified (alg/typ/kid/signature) before any claim is trusted. The aud and iss are pinned, with no leeway. exp = min(now+ttl, turn_exp), with a refusal rather than an exp<=iat grant. turn_exp is carried forward from the verified claims on refresh. The session is re-read on refresh, with owner/tombstone giving the same 404 shape as issue. Names only, no secret reaches the response or audit. The fail-closed audit write is correct. The feature gate is applied at matchRoute, so 404 comes before the body is read, as in ADR-0045. MOCA_GRANT_SIGNING_KEY is in CONTROL_PLANE_SECRETS.

Three suggestions inline, none blocking:

  1. The "one code so a caller can't tell which check failed" rationale is contradicted by the message that writeError returns.
  2. No boot check that the grant ring is actually separate from the session ring.
  3. turn_exp is re-anchored on each /internal/turn-grants, so re-issue (not refresh) extends a turn. Worth binding to the turn before the redeemer lands.

CI: green except deploy-scripts-bash32 and k8s-kind-e2e, which were still pending at review time.

Assisted-By: Claude Code

Comment thread packages/control-plane/src/errors.ts Outdated
// unknown kid, past `exp`, past `turn_exp` (MI1 §6.3's checklist item 1). Deliberately not split
// the way the session token's token_invalid/token_expired are: a grant is presented by the data
// plane, whose only move on any of them is to re-exchange, and a code naming WHICH check failed
// tells a holder of a tampered grant how close it got. Distinct from `invalid_grant` below, which

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 — The single-code rationale ("a code naming WHICH check failed tells a holder of a tampered grant how close it got") doesn't hold on the wire: verifyGrant raises bad(err.message) / bad('wrong grant audience') / bad('grant expired') / bad('this turn has reached turn_exp'), and writeError (errors.ts:219) sends message whenever it differs from the code. So the 401 body says exactly which check failed, and grant-exchange.test.ts:306 asserts that the message names typ. Either keep the messages (they're useful to a worker, and the caller already holds SH_EXCHANGE_TOKEN) and reword this comment plus the matching claims in CHANGELOG 1.7.0 ("so a caller cannot tell which") and the openapi /internal/grants/refresh 401 description, or strip message for grant_invalid in writeError and log it server-side instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, and you reviewed dc0cbb3 — 34d549e had already taken the first of your two options for this comment's own line and the /internal/grants/refresh 401, for the reason you give: the messages are useful, the caller already holds SH_EXCHANGE_TOKEN, and grant-exchange.test.ts:306 pins that one names typ. Stripping message would have meant deleting that assertion to protect a property the route's auth already provides.

You did catch one I missed: CHANGELOG 1.7.0 still said "so a caller cannot tell which". Fixed in b2db565 — it now says the one code exists because the caller's only move on any failure is to get a new grant, and that message does name the failed check.

That is all three places you listed; /internal/turn-grants's own 401 never made the claim, since the token it refuses is a session token rather than a grant.

| undefined {
const raw = env.MOCA_GRANT_SIGNING_KEY;
if (!raw) return undefined;
const grantSigner = makeSigner(raw, 'MOCA_GRANT_SIGNING_KEY');

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 stops an operator from setting MOCA_GRANT_SIGNING_KEY to the same key as SH_SESSION_TOKEN_PRIVATE_KEY, or from listing a session-ring key in MOCA_GRANT_PUBLIC_KEYS. Either one silently removes the §6.1 "separate key ring" property this PR leans on (leaving only typ between the two tokens). A boot check is one line here: refuse when grantSigner.kid equals the session signer.kid, or when any grantVerifyKeys kid is in verifyKeys. That makes the property part of the code rather than operator discipline, the same way makeSigner refuses a public key. It would need depsFromEnv to pass the session kid in, or the check could go there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in b2db565 — this was a real hole, and the right place for it is a boot error for exactly the reason you give: nothing detects it at runtime, because every token still verifies.

grantRingFromEnv now takes the session verify keys and refuses on a shared kid. One check covers both shapes you named, because verifyKeysFromEnv already puts the session signer's own key in that map: reusing SH_SESSION_TOKEN_PRIVATE_KEY as the grant key lands the same kid, and a session key listed in MOCA_GRANT_PUBLIC_KEYS lands in the grant map. And since a kid is a sha256 of the SPKI DER (token.ts:98), equal kid is equal key — no false positive is possible, so the check needs no escape hatch.

I passed the session ring in rather than putting the check in depsFromEnv, so it is tested where the ring is built; verifyKeys is now a named local there instead of inline. Four tests: undefined with no key, a disjoint ring verifies its own key, and each of the two shared-key shapes refuses to boot.

Worth flagging for whoever deploys this: it is a new way for startup to fail. Safe today only because nothing sets MOCA_GRANT_SIGNING_KEY yet and the routes are gated off — a deployment that had already set it to the session key would stop booting rather than warn. That is the trade I would take for a property that is otherwise invisible, but it is a trade.

return mintFor(
rec,
tenant,
turnExp(nowS, undefined, deps.config.turnMaxS),

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 — turn_exp is anchored to "now" on every call to /internal/turn-grants, and nothing ties an issue to a turn (no turnId, no record). So a holder of SH_EXCHANGE_TOKEN and a still-valid session token can re-issue to get a fresh now + MOCA_TURN_MAX_S. Refresh can't extend a turn, but re-issue can. The upper bound is then the session token's own lifetime and renewal, not MOCA_TURN_MAX_S. That's fine while nothing redeems a grant. Before the redeemer lands, consider binding issuance to the turn (e.g. the turn record's start time / dequeue time, which §5.4's caps-aware form already needs), or at least note the limitation next to the CHANGELOG's "no number of refreshes extends a turn".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct, and it means MOCA_TURN_MAX_S caps a turn's refresh chain rather than a session — the docs implied more than that.

I took the second option, not the binding, deliberately. The anchor you point at is the turn record's start/dequeue time, and the interactive path that reaches /internal/turn-grants today has no turn record at all; inventing a turn identity here would duplicate what the dequeue path's grants need for §5.4's caps-aware form, which is the slice D5 scoped this to. Doing it now means building that concept twice and throwing one away.

So in b2db565 the limit is named rather than papered over: a shortcut: comment on issueTurnGrants stating that re-issue starts a fresh window, that the real bound is the session token's lifetime, and that the fix is to anchor to the turn record when the redeemer makes turn_exp enforce anything. The CHANGELOG's "no number of refreshes extends a turn" now says a fresh issue does start a new window, and the same correction went into the openapi turnExp description and the MOCA_TURN_MAX_S row in configuration.md.

If you would rather the binding land in this PR than in the redeemer's, say so and I will take it — it is a scope call, not a disagreement.

…paths

PR rossoctl#807 review. Two findings, plus two the same pass turned up in my own
files.

`refreshTurnGrants` echoed the presented grant's `tenant` claim while
re-reading every other field from the session record. `SessionRecord.tenant`
is a non-optional string, so the reviewer's suggested `rec.tenant ??
claims.tenant` has a dead half: `rec.tenant` alone is the fix. The same echo
existed on the issue path through `sessionFromToken`'s returned tenant, so
both now read the record and `mintFor` loses the parameter -- it was
`rec.tenant` from both callers. `sessionFromToken` goes back to returning the
record, which is what it returned before this slice widened it.

`turn_exp` stays the one value a refresh carries forward, because it is an
absolute cap.

The `egress` claim is the session OWNER's `sandbox-egress` set, not a
per-session subset -- nothing on the record narrows it -- and my own doc
comment said "the session may use", asserting a scoping the code does not
do. Documented as an upper bound re-filtered by `destination.hosts` at
redemption (§6.3 step 3), in both `grant.ts` and the OpenAPI schema. The
`list` call behind it is also one uncached `kubectl get secret` per issue AND
per refresh, now carrying a `shortcut:` comment naming that limit.

`errors.ts` and the 401 description both claimed the single `grant_invalid`
code withholds which check failed. It does not: `writeError` sends
`err.message` and `verifyGrant`'s messages name the exact check. The one code
is still right -- the caller's only move is to re-exchange -- so the wrong
justification is replaced rather than the behaviour.

Tests: a failed audit write must refuse the grant and log nothing (the
refusal branch had no test, matching `turn-exchange.test.ts:328`), and the
refreshed `tenant` follows the record. Control-plane suite 1458 passed, 3
skipped, 0 failed.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
…ssion ring

PR rossoctl#807 review, three suggestions from @ingpaolodettori-dev.

Nothing stopped an operator pointing MOCA_GRANT_SIGNING_KEY at
SH_SESSION_TOKEN_PRIVATE_KEY, or listing a session public key in
MOCA_GRANT_PUBLIC_KEYS. Either one collapses §6.1's separate-ring property
that this whole slice leans on, leaving `typ` as the only thing between a
session token and a grant -- and nothing detects it at runtime, because every
token still verifies. `grantRingFromEnv` now takes the session verify keys
and refuses to boot on a shared kid. A kid is a sha256 of the SPKI, so equal
kid is equal key and no false positive is possible; the session map already
holds the signer's own key, so one check covers both ways in.

`turn_exp` is anchored to now on every issue and nothing identifies a turn to
anchor to, so a re-issue starts a fresh window even though a refresh cannot.
Binding issuance to a turn record needs the dequeue path's record (§5.4's
caps-aware form already needs it), which is the redeemer's slice, so the
limit gets a `shortcut:` comment naming it and when to upgrade, and the
CHANGELOG, the openapi `turnExp` description and MOCA_TURN_MAX_S stop
claiming it caps more than one turn's refresh chain.

The single-code rationale was corrected in 34d549e for errors.ts and the
refresh 401, but the CHANGELOG still said "so a caller cannot tell which".
It can: writeError sends `message`. Reworded there too -- the messages stay,
since the route is behind the shared bearer and grant-exchange.test.ts:306
pins that one names `typ`.

Tests: four on grantRingFromEnv -- undefined without a key, a disjoint ring
verifies its own, and the two shared-key shapes each refuse to boot.
Control-plane suite 1462 passed, 3 skipped, 0 failed.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
@cwiklik
cwiklik merged commit f60db30 into rossoctl:main Nov 13, 2026
17 checks passed
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
Upstream main (f60db30) adds session grants (rossoctl#807) as API 1.7.0, so
this branch's section moves to 1.8.0.

Conflicted:
- docs/api/CHANGELOG.md: main's 1.7.0 (grants) and 1.6.0 kept as main
  has them; this branch's session-templates section is now 1.8.0,
  above them.
- docs/reference/configuration.md: main's control-plane table (with
  the grant variables) kept; this branch's SH_SANDBOX_TEMPLATES row
  (the seed and the harness profile) put back into it.

Also changed in the merge:
- docs/api/openapi.yaml: info.version 1.8.0.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
Upstream main (f60db30) adds session grants (rossoctl#807) as API 1.7.0, so
this branch's section moves to 1.8.0.

Conflicted:
- docs/api/CHANGELOG.md: main's 1.7.0 (grants) and 1.6.0 kept as main
  has them; this branch's enrollment section is now 1.8.0, above them.
- docs/reference/configuration.md: main's control-plane table (with
  the grant variables) kept; this branch's SH_PROVENANCE_DIR row (the
  members store) put back into it.

Also changed in the merge:
- docs/api/openapi.yaml: info.version 1.8.0.
- docs/reference/http-api.md: the subjects routes say API 1.8.0.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
Upstream main (f60db30) adds session grants (rossoctl#807) as API 1.7.0, so
this branch's section moves to 1.8.0.

Conflicted:
- docs/api/CHANGELOG.md: main's 1.7.0 (grants) and 1.6.0 kept as main
  has them; this branch's section is now 1.8.0, above them.
- docs/reference/configuration.md: main's control-plane table (with
  the grant variables) kept; this branch's SH_GATE_RECORD_SCHEMA row
  added back into it.

Also changed in the merge:
- docs/api/openapi.yaml: info.version 1.8.0.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
Upstream main (f60db30) adds the sandbox lease wire (rossoctl#802) as API
1.6.0, which this branch also claimed, and session grants (rossoctl#807) as
API 1.7.0; this branch's section moves to 1.8.0.

Conflicted:
- docs/api/CHANGELOG.md: main's 1.7.0 (grants) and 1.6.0 (sandbox
  modes) kept as main has them; this branch's template-admin section
  is now 1.8.0, above them.
- docs/api/openapi.yaml: info.version 1.8.0 (this branch said 1.6.0,
  main 1.7.0).
- packages/control-plane/src/sandbox-handlers.ts: the imports are the
  union (this branch's provenance, identity and isEnrolled imports,
  and main's MIN_IDLE_TIMEOUT_S).
- packages/control-plane/test/openapi-contract.test.ts: the enrollable
  route count is 24: the base's 18, this branch's four template admin
  routes and main's two sandbox mode routes.

Also changed in the merge:
- docs/reference/http-api.md: the template admin routes say API 1.8.0.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
Upstream main (f60db30) adds session grants (rossoctl#807) in the control
plane and its docs. No file conflicted, and no file this branch
changes is touched; no API version change.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 16, 2026
…te lifecycle stack

Upstream main 0dc3d01 (API 1.21.0) carries the reviewed, final form of
the features this branch held in early, integrated versions, through the
PRs filed from this fork (rossoctl#755-rossoctl#776, rossoctl#781, rossoctl#782, rossoctl#784-rossoctl#786, rossoctl#789-rossoctl#794,
rossoctl#798-rossoctl#800) and the maintainer's lease mode, grants and lease clients
(rossoctl#763, rossoctl#802, rossoctl#807, rossoctl#808, rossoctl#810, rossoctl#812, rossoctl#814). Where upstream has a feature,
upstream's version wins: its code, tests, openapi, CHANGELOG (byte
identical), docs and specs.

The fork was 736 commits behind and 390 ahead (merge base dd0ce71).

Conflict resolution (148 files, 82 both-modified, 66 both-added): every
conflicted file is upstream's side as is (byte identical to 0dc3d01).
No conflicted file differs from 0dc3d01 in this commit.

One file merged without a conflict and was set back to upstream's:
- packages/mocactl/src/sbx/push.ts: the auto-merge added the fork's
  baselineAtHead a second time beside upstream's own (fb28e06's
  function, already upstream); upstream's file as is.

With that, this commit's tree is 0dc3d01's plus the 18 files only the
fork has (below). Every other file the fork changed is upstream's.

Conflicted files, all resolved to upstream's side (0dc3d01):
- deploy/k8s/overlays/ocp-combined/kustomization.yaml (AA)
- deploy/k8s/overlays/ocp-combined/patch-addressing.yaml (AA)
- deploy/k8s/overlays/ocp-combined/patch-relay.yaml (AA)
- deploy/microvm/P4-ON-P6.md (UU)
- deploy/microvm/build-rootfs.sh (UU)
- deploy/microvm/build-snapshot.sh (UU)
- deploy/microvm/setup-microvm.sh (UU)
- deploy/microvm/tests/build-rootfs.test.sh (UU)
- deploy/microvm/tests/build-snapshot.test.sh (UU)
- deploy/microvm/tests/setup-microvm.test.sh (UU)
- deploy/sbx/README.md (UU)
- deploy/sbx/RUNBOOK.md (UU)
- deploy/sbx/host-agent.sh (AA)
- deploy/sbx/install-host.sh (UU)
- deploy/sbx/sbx-host-agent-wanted.service (AA)
- deploy/sbx/sbx-host-agent-wanted.timer (AA)
- deploy/sbx/sbx-host-agent.service (AA)
- deploy/sbx/[email protected] (UU)
- deploy/sbx/setup.sh (UU)
- deploy/sbx/template-onboarding/GUIDE.md (AA)
- deploy/sbx/template-onboarding/ONBOARDING.md (AA)
- deploy/sbx/template-onboarding/README.md (AA)
- deploy/sbx/template-onboarding/examples/django__django-11133.gate-record.json (AA)
- deploy/sbx/template-onboarding/examples/django__django-11133.json (AA)
- deploy/sbx/template-onboarding/governance/GATING-RULES.md (AA)
- deploy/sbx/template-onboarding/governance/PROCESS.md (AA)
- deploy/sbx/template-onboarding/governance/README.md (AA)
- deploy/sbx/template-onboarding/template-build.sh (AA)
- deploy/sbx/template-onboarding/template-register.sh (AA)
- deploy/sbx/template-onboarding/tests/examples.test.sh (AA)
- deploy/sbx/template-onboarding/tests/template-build.test.sh (AA)
- deploy/sbx/template-onboarding/tests/template-register.test.sh (AA)
- deploy/sbx/template-onboarding/verify-provenance.py (AA)
- deploy/sbx/templates-check.sh (AA)
- deploy/sbx/tests/host-agent.test.sh (AA)
- deploy/sbx/tests/install-host.test.sh (UU)
- deploy/sbx/tests/overlay-combined.test.sh (AA)
- deploy/sbx/tests/setup.test.sh (UU)
- deploy/sbx/tests/templates-check.test.sh (AA)
- deploy/vm/tests/setup-vm.test.sh (UU)
- docs/api/CHANGELOG.md (UU)
- docs/api/harness-openapi.yaml (UU)
- docs/api/openapi.yaml (UU)
- docs/concepts/sandboxes-and-tiers.md (UU)
- docs/reference/change-policy.md (UU)
- docs/reference/cli-mocactl.md (UU)
- docs/reference/configuration.md (UU)
- docs/reference/http-api.md (UU)
- docs/sbx/user-guide.md (UU)
- docs/specs/2026-10-15-sbx0-internal-sandbox-service-design.md (UU)
- docs/specs/2026-10-30-session-sandbox-templates-design.md (AA)
- docs/specs/2026-11-03-template-lifecycle-and-provenance-design.md (AA)
- docs/specs/2026-11-05-combined-control-plane-design.md (AA)
- docs/specs/2026-11-08-enrollment-and-roles-api-design.md (AA)
- docs/specs/2026-11-08-sandbox-egress-records-design.md (AA)
- docs/specs/2026-11-08-subject-trust-gate-records-design.md (AA)
- docs/specs/README.md (UU)
- harness/src/run-turn.ts (UU)
- harness/src/sandbox-affinity.ts (UU)
- harness/src/select-sandbox.ts (UU)
- harness/test/select-sandbox-templates.test.ts (AA)
- harness/test/turn-seed.test.ts (AA)
- harness/test/turn-stream.test.ts (UU)
- packages/control-plane/src/activation-lock.ts (AA)
- packages/control-plane/src/activation.ts (AA)
- packages/control-plane/src/egress-handlers.ts (UU)
- packages/control-plane/src/egress-log.ts (AA)
- packages/control-plane/src/errors.ts (UU)
- packages/control-plane/src/exchange.ts (UU)
- packages/control-plane/src/handler-util.ts (UU)
- packages/control-plane/src/handlers.ts (UU)
- packages/control-plane/src/host-handlers.ts (AA)
- packages/control-plane/src/identity.ts (UU)
- packages/control-plane/src/index.ts (UU)
- packages/control-plane/src/main.ts (UU)
- packages/control-plane/src/member-handlers.ts (AA)
- packages/control-plane/src/members.ts (AA)
- packages/control-plane/src/ownership.ts (UU)
- packages/control-plane/src/provenance.ts (AA)
- packages/control-plane/src/routes.ts (UU)
- packages/control-plane/src/sandbox-config.ts (UU)
- packages/control-plane/src/sandbox-handlers.ts (UU)
- packages/control-plane/src/server.ts (UU)
- packages/control-plane/src/template-catalog.ts (AA)
- packages/control-plane/src/template-policy.ts (AA)
- packages/control-plane/src/token.ts (UU)
- packages/control-plane/test/activation.test.ts (AA)
- packages/control-plane/test/egress-redis.test.ts (AA)
- packages/control-plane/test/errors.test.ts (UU)
- packages/control-plane/test/host-flow.test.ts (AA)
- packages/control-plane/test/members.test.ts (AA)
- packages/control-plane/test/openapi-contract.test.ts (UU)
- packages/control-plane/test/provenance.test.ts (AA)
- packages/control-plane/test/repository-allowlist.test.ts (AA)
- packages/control-plane/test/route-authz-enumeration.test.ts (UU)
- packages/control-plane/test/route-profile.test.ts (UU)
- packages/control-plane/test/routes.test.ts (UU)
- packages/control-plane/test/sandbox-egress.test.ts (AA)
- packages/control-plane/test/sandbox-handlers.test.ts (UU)
- packages/control-plane/test/session-templates.test.ts (AA)
- packages/control-plane/test/subject-trust.test.ts (AA)
- packages/control-plane/test/template-admin.test.ts (AA)
- packages/control-plane/test/template-catalog.test.ts (AA)
- packages/control-plane/test/template-create.test.ts (AA)
- packages/knative-server/src/server.ts (UU)
- packages/knative-server/src/turn-auth.ts (UU)
- packages/knative-server/test/turn-auth.test.ts (UU)
- packages/mocactl/src/api/errors.ts (UU)
- packages/mocactl/src/api/frames.ts (UU)
- packages/mocactl/src/cli.ts (UU)
- packages/mocactl/src/core/session-manager.ts (UU)
- packages/mocactl/src/core/session-options.ts (UU)
- packages/mocactl/src/headless.ts (UU)
- packages/mocactl/src/sbx/api.ts (UU)
- packages/mocactl/src/sbx/call-record.ts (AA)
- packages/mocactl/src/sbx/cli.ts (UU)
- packages/mocactl/src/sbx/commands.ts (UU)
- packages/mocactl/src/sbx/dry-run.ts (AA)
- packages/mocactl/src/sbx/exec.ts (UU)
- packages/mocactl/src/sbx/run.ts (UU)
- packages/mocactl/src/sbx/templates.ts (AA)
- packages/mocactl/test/contract.test.ts (UU)
- packages/mocactl/test/harness.test.ts (UU)
- packages/mocactl/test/headless.test.ts (UU)
- packages/mocactl/test/helpers/sbx.ts (UU)
- packages/mocactl/test/run-record.test.ts (AA)
- packages/mocactl/test/sbx-admin-subjects.test.ts (AA)
- packages/mocactl/test/sbx-cli.test.ts (UU)
- packages/mocactl/test/sbx-egress.test.ts (AA)
- packages/mocactl/test/sbx-exec.test.ts (UU)
- packages/mocactl/test/sbx-templates.test.ts (AA)
- packages/mocactl/test/session-manager.test.ts (UU)
- packages/mocactl/test/session-options.test.ts (UU)
- remote-worker/cmd/microvm-worker/main.go (UU)
- remote-worker/cmd/microvm-worker/template_record.go (AA)
- remote-worker/cmd/microvm-worker/template_record_test.go (AA)
- remote-worker/cmd/microvm-worker/verify_cache.go (AA)
- remote-worker/cmd/microvm-worker/verify_cache_test.go (AA)
- remote-worker/internal/egress/audit_test.go (UU)
- remote-worker/internal/session/labels.go (UU)
- remote-worker/internal/vmpool/errors.go (UU)
- remote-worker/internal/vmpool/guestconn.go (UU)
- remote-worker/internal/vmpool/guestconn_test.go (UU)
- remote-worker/internal/vmpool/launcher_firecracker.go (UU)
- remote-worker/internal/vmpool/launcher_firecracker_egress_unix_test.go (UU)
- remote-worker/internal/vmpool/snapshot.go (UU)
- remote-worker/internal/vmpool/snapshot_test.go (UU)
- remote-worker/internal/vmpool/verifycache.go (AA)

Fork-only files, kept as they are (upstream has no such file):
- deploy/sbx/mint-login.sh, deploy/sbx/tests/mint-login.test.sh: a test
  login minted with the deployment's signing key. Checked against
  upstream: makeSigner/mint, SANDBOX_API_ISSUER, the moca-mu1 Secret and
  its label, the env keys it reads and mocactl's sbx-auth.json shape are
  all still upstream's.
- deploy/sbx/template-onboarding/deck/ (README, requirements, the two
  generators, deck_kit.py, the two PDFs, .gitignore): the fork's decks.
- deploy/sbx/template-onboarding/GUIDE.pdf: regenerated from upstream's
  GUIDE.md in a later commit.
- deploy/sbx/template-onboarding/governance/GAPS-AND-ASSUMPTIONS.md and
  INVENTORY-2026-11-02.md: the fork's register and inventory.
- docs/specs/2026-11-09-cold-start-pacing-design.md,
  2026-11-09-memory-aware-placement-design.md and
  2026-11-10-mocactl-template-commands-design.md: the fork's design
  notes; upstream folded their content into its lifecycle spec
  (§6.4 memory, §6.5 pacing) and the user guide (mocactl).
- docs/tools/gen_pdf.py, docs/tools/gen_toc.py: the PDF and TOC tools.

Fork-only behaviour, decided one by one (from git log 0dc3d01..f125c02
--no-merges, checked against 0dc3d01):

Ported onto upstream's code, each in its own commit after this one:
- The pinned-session retire guard (c571226): a retire is refused
  (409 build_in_use) while an active Moca Pi session is pinned to the
  build. Upstream's buildsInUse checks live sandboxes only and its
  comment says pinned sessions are still to be checked.
- Reuse only while a host holds the snapshot (G29, 521efe5): upstream
  reuses any registered build with the same inputs; its own lifecycle
  spec (§4, Reuse) says a registered build is reused only while a host
  reports holding its snapshot.
- install-host.sh --uninstall-shared and the mounted legacy jail guard
  (5e66397): upstream has neither.
- GUIDE §4b.4's base example without skip_git_identity_check
  (f125c02): upstream applies X12 under every profile, so its example
  create would be refused.
- Links from upstream's READMEs to the fork-only files above.

Dropped, because upstream's design replaces them on purpose:
- Removal of admin-rejected builds: upstream stops them and never
  removes them (the user's decision in rossoctl#786).
- The harness-profile catalog's fallback to SH_SESSION_TEMPLATES
  (902255b): upstream serves the harness profile the store's templates
  only (its test was renamed so); a combined plane is unaffected.
- The fork's register ids (G-numbers), window dates and results
  pointers inside the documents upstream now has (RUNBOOK, README,
  GUIDE, ONBOARDING, PROCESS, GATING-RULES, P4-ON-P6, the specs):
  upstream's text wins; the fork's own documents above keep them.
- The fork's image-builder-specific wording in GATING-RULES.md:
  upstream's generic wording (the image builder) is taken as is.

Dropped, could be re-proposed (no upstream equivalent, but the port is
an API change or its intent upstream is unclear):
- TurnPlacement.template, a turn result naming the session's sandbox
  template (9d6004d): a harness API field; upstream's CHANGELOG is kept
  byte identical.
- An imported build's catalog entry and create record carrying the
  declared seed (20d0995): sessions are seeded the same (upstream falls
  back to the declared seed); only the field in the catalog API goes.
- mocactl: sbx create --seed checking the seeded HEAD against the spec's
  baseline_commit; activate --wait stopping at once on not_held or
  memfile_mismatch; ApiError's readiness, readinessReason and
  queuePosition in refusals; an admin write refused when the control
  plane URL came only from the login; the admin-write issuer check for
  the combined profile; the dry run's X1.offline check and its guest_mb
  and git-less advice; the quota, policy and build lines' extra fields
  (quotaSource, selfAttest, allowedRepositories, heldBy, attestation).
  Upstream's reviewed client (rossoctl#767, rossoctl#768) left them out; the server
  still enforces every rule.

Already upstream (not lost): build reuse (G21), the verify cache, the
host agent's --keep-shared removals, read-ahead, the hash_version 2
check in the microVM worker, M7, G39, G42, G43, G48, G49, G50, mocactl
--record, --version, the minted login's own control plane, activate
--wait sizing, and every other fork feature listed in the task.

The relay's per-client tokens: not on this branch (the fork's
sandbox-relay main.ts is older upstream code), so nothing to resolve.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
@pdettori pdettori added this to the v0.11.0 milestone Nov 17, 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.

4 participants