Repository navigation
docs: operations pages for P6 on Kubernetes (PR 7b of REORG-PLAN) - #501
Conversation
Upgrades, Redis backup and recovery, observability, sizing and scaling, and troubleshooting, taken from deploy/k8s, setup.sh and the code. Each page states what is not documented or measured instead of guessing: single points of failure, no tested backup or rollback, no session TTL, JSON-only metrics and no published capacity numbers. Linked from the docs index and the README; REORG-PLAN records PR 7b. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
The repository documents no backup procedure and none has been tested, so the Redis page now recommends no method. Retention guidance stays. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Document pausing the control plane's rollout while the supervisor rolls, and the checks to run afterwards because setup.sh is expected to stop at its control-plane wait. Marked unverified: plain kubectl, not run against deploy/k8s. 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.
Thanks, this is a useful page set. I checked it against main 08eb2a9; most of the ~200 checkable claims hold up with file:line evidence (resource numbers, probe settings, /metrics fields, every log string, the audit decision list, error codes, key names and TTLs, setup.sh wait order, the redis-cli invocations relying on REDISCLI_AUTH). I reviewed all three commits, including ad57be4 (harness-first procedure).
Requesting changes for two upgrade-page inaccuracies an operator would act on (inline): on base/OCP a plain setup.sh re-run with the default :latest does not upgrade anything, and the relay runs the harness image with Recreate, so every --image bump drops every attached sandbox (the page ties that to tiers instead). The rest are suggestions and nits.
On the "Please check" items
/readyzafter drain: not quite.drainAll()setsdrainedbut does not clearhealthy(supervisor/src/pool.ts:306-320; it only stops a latereadyfrom re-marking a drained worker,:369-376), so/readyzstays 200 until workers actually exit or report unhealthy. That claim isn't in these pages as far as I can see, so nothing to change unless it's added.- Sandbox
phase: unknown: consistent with the code. The control plane's only RBAC is a Role onsecretsinmoca-credentials(control-plane.yaml:10-27), andresolveSandboxmaps any kubectl failure, RBAC denial included, tounknown(resources.ts:44-47). The "inferred" label is right. - Per-pod admission / one pod 429 while another has room: consistent. Admission is per supervisor process (
admission.ts) and the Service balances connections, not load. - Harness-before-control-plane: the ordering requirement is documented in ADR-0038 (
docs/adrs/0038-mocactl-config-bundle-promotion.md:86-87) and the promote guide (docs/guides/promote-claude-workflow.md:20-21), so the page could cite them. Not splitting the image and usingrollout pauseinstead seems right to me.setup.shapplies with plainkubectl apply -kand the manifest doesn't setspec.paused, so the pause should survive the apply. See the inline nit on how the paused wait ends. - KEK rotation: ring semantics confirmed (
envelope.ts:41-63,72-76,111-132: newest seals, all tried on open); the warning about deletingmoca-mu1is accurate (setup.sh:606-617). See the inline note on the base64 encoding. - Backup: fine to recommend nothing. For the Compose/VM sentence (redis page line 21): no named Redis volume is confirmed (
deploy/compose/docker-compose.yml:18-25,deploy/vm/setup-vm.sh:227-235), but whether theredisimage's anonymous/datavolume survives a Compose recreate orpodman run --replaceisn't settled by the repo.
Not checked: nothing was deployed; the procedure in ad57be4 and the inferred rows remain unrun. CI: all 14 checks green at ad57be4; all 3 commits are DCO signed off.
| > **Preview.** For P6 on Kubernetes ([`deploy/k8s`](../../deploy/k8s/README.md)). The repository documents no | ||
| > rollback procedure; what is below is what the scripts and manifests do. | ||
|
|
||
| ## Re-running `setup.sh` is the upgrade |
There was a problem hiding this comment.
must-fix: On base/OCP with the default image, re-running setup.sh does not upgrade anything. The pod template renders image: ghcr.io/rossoctl/moca:latest (deploy/k8s/base/kustomization.yaml:14-20), and off Kind there is no image-id annotation (setup.sh:989-995). An unchanged re-run therefore produces an identical template, nothing rolls (the deploy README says this too), and no newer latest is pulled. A new image only arrives when the image ref changes (--image, ideally a digest), or by chance when a pod restarts and re-pulls :latest. Please say that an upgrade on base/OCP means passing a new --image (a tag or @sha256 digest). Re-running with the same inputs only reconciles. Line 28's "pin it for repeatable upgrades" should then read as the required step, not an optional one.
| | Component | Strategy | What you will see | | ||
| | ------------- | ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- | | ||
| | Supervisor | Rolling, `maxUnavailable: 0`, `maxSurge: 1` | A new pod must become Ready first; in-flight turns on the old pod get the drain below | | ||
| | Relay | `Recreate`, one replica | A short window with no relay: sandboxes detach, in-flight turns fail and are retried | |
There was a problem hiding this comment.
must-fix: The relay runs the harness image too (deploy/k8s/base/relay.yaml:30, image: moca-harness) and uses strategy: Recreate (relay.yaml:15). So every harness --image bump recreates the relay. That detaches every sandbox and P4 host, and in-flight turns fail. The page doesn't say this anywhere:
- Line 41-42 ties the relay recreate and the sandbox roll to "the first apply that introduces sandbox tiers". The deploy README (
deploy/k8s/README.md:131-140, and the root README around line 805) ties it to the first apply of a P6.3 release, on every stack, tiered or not. The cause is the new env vars (SH_SANDBOX_AFFINITY_TTL_SECONDSin relay.yaml,SANDBOX_TIERin sandbox.yaml). As written, an untiered operator will think they're unaffected. - Lines 61-62 say one
--imagebump moves the supervisor and control plane together. It moves the relay as well.
Please add to the Relay row that any harness image change recreates it, and fix the tier sentence.
| | ------------- | ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- | | ||
| | Supervisor | Rolling, `maxUnavailable: 0`, `maxSurge: 1` | A new pod must become Ready first; in-flight turns on the old pod get the drain below | | ||
| | Relay | `Recreate`, one replica | A short window with no relay: sandboxes detach, in-flight turns fail and are retried | | ||
| | Control plane | One replica, default strategy | Brief unavailability of login and credential exchange | |
There was a problem hiding this comment.
suggestion: control-plane.yaml sets no strategy, so the Deployment default applies: RollingUpdate with 25%/25%. With one replica that rounds to maxSurge 1 and maxUnavailable 0, so the new pod has to pass /readyz before the old one goes. A rollout has no planned gap in login or exchange. The only exception is the no-client-id case, which runs 0 replicas. The control plane also sets no terminationGracePeriodSeconds, so it gets the default 30 s.
| | Relay | `Recreate`, one replica | A short window with no relay: sandboxes detach, in-flight turns fail and are retried | | ||
| | Control plane | One replica, default strategy | Brief unavailability of login and credential exchange | | ||
| | Redis | StatefulSet, one replica | See [Redis backup and recovery](redis-backup-recovery.md) | | ||
| | Sandboxes | StatefulSet, parallel | Pod-local workspaces are lost: a rolled or restarted sandbox resets every container session's workspace **silently** | |
There was a problem hiding this comment.
suggestion: podManagementPolicy: Parallel (base/sandbox.yaml:24) only affects pod creation and scaling. No updateStrategy is set, so updates use the StatefulSet default: RollingUpdate, one pod at a time, highest ordinal first, each pod waiting for Ready. A sandbox roll is therefore sequential, and with many sandboxes it takes a while. Something like "StatefulSet, rolling one pod at a time" would be accurate.
| in order: Redis, relay, supervisor, control plane (only if a GitHub client id is set), sandboxes. There is no | ||
| per-component ordering inside the apply itself. | ||
|
|
||
| Inputs are **sticky**: a variable you leave unset keeps its stored value, and one set to the empty string clears |
There was a problem hiding this comment.
nit: "Set to the empty string clears it" has exceptions:
- An empty
SH_SANDBOX_COUNTcounts as unset and keeps the stored count (setup.sh:166,:397). --image/--sandbox-imagecan't be empty (need_value,setup.sh:80,86-87). The README's way to reset them is to pass the default explicitly or delete the key.SH_WAIT_SECONDSisn't sticky at all (setup.sh:174).
| | `401 token_invalid` / `token_expired` / `token_required` | Expired token, or the signing key changed after `moca-mu1` was replaced | `mocactl login`; compare `SH_SESSION_TOKEN_PUBLIC_KEYS` with the control plane's key (same `moca-mu1`) | Log in again; after rotating `moca-mu1` restart the control plane and supervisor | | ||
| | `400 invalid_grant` on refresh | Refresh token unknown, revoked, expired, or reused outside the 30 s grace | Audit decisions `refresh_refused`, `refresh_reuse_detected` | Log in again | | ||
| | `404 session_not_found` | Someone else's session (the control plane answers 404, never 403), a deleted one, or Redis was lost | `redis-cli EXISTS session:<sid>`; `HGETALL sh:cp:session:<sid>` | Create a new session | | ||
| | `410 config_bundle_not_found` | The session's bundle expired (30 days), was deleted, or Redis was wiped | n/a | Re-promote with `mocactl promote DIR` | |
There was a problem hiding this comment.
nit: 410 is what a turn gets (knative-server/src/server.ts:376). The control plane uses the same code with 404 (control-plane/src/errors.ts:67-68), e.g. when a session is created with an unknown or expired digest. Worth listing both statuses.
| | `410 config_bundle_not_found` | The session's bundle expired (30 days), was deleted, or Redis was wiped | n/a | Re-promote with `mocactl promote DIR` | | ||
| | `429 bundle_quota_exceeded` | The bundle byte budget is full | n/a | `mocactl bundles delete DIGEST` (an admin can delete anyone's) | | ||
| | Supervisor never becomes Ready | The published `latest` image predates `/readyz`; startup compile exceeds 30 x 5 s; probes filtered | `kubectl describe pod`; `curl :8081/readyz` | Kind: rebuild with `--build`. OpenShift: use `--image` with a current image. For filtered probes see the README | | ||
| | Control plane stuck at 0/1 | Redis not up yet, or no GitHub client id was given (replicas are 0 then) | `kubectl -n moca get deployment moca-control-plane`; log line `redis client error` | Wait for Redis, or `SH_GITHUB_CLIENT_ID=<id> deploy/k8s/setup.sh --target kind --skip-build` | |
There was a problem hiding this comment.
nit: With no GitHub client id, setup.sh renders replicas: 0 (:982-985, :1009), so kubectl get deployment shows 0/0, not "stuck at 0/1". 0/1 is the Redis-not-up case only.
|
|
||
| ## When none of this helps | ||
|
|
||
| Run `mocactl doctor`; it checks the control plane, login, credentials and harness reachability in order, and stops |
There was a problem hiding this comment.
nit: mocactl doctor runs 7 ordered checks (cli-mocactl.md#doctor), and the last one isn't read-only: it creates and then deletes a scratch session. Since this is the operator's fallback step, it's worth saying.
|
|
||
| ## The audit stream | ||
|
|
||
| The control plane appends to the Redis stream `sh:cp:audit` (trimmed to about 1,000,000 entries) with fields `ts`, |
There was a problem hiding this comment.
nit: The optional fields leave out family. Every refresh-token decision writes it (control-plane/src/refresh-redis.ts:60-61,75-78,128-129,204-206; refresh-store.ts:110-118), and the anon entry writes family: '-'. Everything else in the list matches the code. The 16 decision names are exactly the set the control plane writes.
| ## Per-session placement | ||
|
|
||
| Workers report, best effort, where each session ran. `GET /v1/sessions/{id}/resources` returns the session, harness, | ||
| sandbox, lease and placement (sandbox id, tier, last `workspace_reset`). The data is self-reported by the harness |
There was a problem hiding this comment.
nit: The placement field is workspaceReset, shaped {at, from} or null (control-plane/src/resources.ts:58-64,98-104). The wire event is called workspace_reset, so the current wording mixes the two up. The response also carries a top-level queue that is always null (resources.ts:114).
- Upgrades: on base/OCP an upgrade needs a new --image (re-running with :latest changes nothing); the relay runs the harness image and is recreated on every image change; sticky-input exceptions; control plane and sandbox rollout strategies; the harness-first procedure resumes the control plane from a second terminal. - Redis: refresh-token and signing-key effects, KEK entry format, which secrets exist and who creates them, Redis password handling, retry behaviour. - Sizing: saturation 429s every connection, what the manifest test enforces, the 400 for an oversized bundle. - Troubleshooting: 404 vs 410 for a missing bundle, 0/0 vs 0/1, what the last doctor check does. - Observability: the family audit field and the workspaceReset shape. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
|
Addressed in f6e2092. Must-fix: on base/OCP an upgrade now means passing a new |
The repository does not establish whether the redis image's anonymous /data volume survives a recreate, so say to assume it does not. 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.
Thanks for the quick turnaround. I re-reviewed ad57be4..7190a28 (f6e2092, 7190a28) against main 08eb2a9. All 19 items from the previous review are addressed, including both must-fixes: upgrading now means passing a new --image, and the relay row says every harness image change recreates it, with the P6.3 note now applying to every stack. I checked the new wording against the code: the control-plane default strategy and 30 s grace, the sandbox StatefulSet default update order, the sticky-input exceptions, refresh-token recovery, the KEK base64 format, the moca-redis keys, the per-connection 429, the 400 for an oversized bundle, 404 vs 410, 0/0 vs 0/1, family, and workspaceReset. It all holds.
Approving. The inline comments are a suggestion and nits. One of them is a race in the new two-terminal procedure. The others are a few items that weren't raised last round.
Not checked: nothing was deployed, so the harness-first procedure is still unrun. CI: all 14 checks are green at 7190a28, and all 5 commits are DCO signed off.
| kubectl -n moca rollout pause deployment/moca-control-plane | ||
| deploy/k8s/setup.sh --target kind --skip-build # your usual flags, including --image | ||
|
|
||
| # terminal 2, in parallel |
There was a problem hiding this comment.
suggestion: Terminal 2 has a race. If it starts before setup.sh has applied the new template, kubectl rollout status deployment/moca-supervisor sees the old, finished rollout and returns at once. The resume then fires right away, and the control plane rolls in parallel with the supervisor. That silently defeats the harness-first ordering this procedure is for. setup.sh does several things before its single kubectl apply -k (secrets, overlay, image build/load on Kind), so this window isn't small.
A suggested fix is to start terminal 2 only after setup.sh prints Waiting for deployment "moca-supervisor" rollout to finish (the apply has happened by then). Another option is to have terminal 2 first wait until the supervisor template carries the new image, then run rollout status. Either way, say "start this after …" rather than "in parallel".
| No ordering is required. The control plane and supervisor reconnect to Redis on their own without a restart (the | ||
| control plane retries forever with the delay capped at 2 seconds; the session clients retry a bounded number of | ||
| times and reconnect on their next call), and the control plane's `/readyz` reports 503 while Redis is down and recovers by itself. With Redis down, session | ||
| routes return 503 `redis_unavailable` while credential routes keep working. |
There was a problem hiding this comment.
suggestion: "credential routes keep working" holds at the handler level (auditBestEffort, handlers.ts:213-235), but not on k8s. The control plane's readinessProbe is /readyz (base/control-plane.yaml:96-99, period 5 s, default failureThreshold 3), and as the previous sentence says, /readyz returns 503 while Redis is down. So within about 15 s the only replica leaves the Service endpoints. The supervisor reaches the control plane through that Service (SH_CONTROL_PLANE_URL=http://moca-control-plane.moca.svc:8080, base/supervisor.yaml:84), and so do login and exchange. In practice they become unreachable too, and turns needing a credential get 503 credential_unavailable. Either say so here and in the troubleshooting redis_unavailable row, or decouple readiness from Redis (a separate change).
|
|
||
| ## Secrets to back up separately | ||
|
|
||
| `setup.sh` creates the first four rows once and never rotates them; the per-user Secrets in `moca-credentials` are |
There was a problem hiding this comment.
nit: "the first four rows" includes the moca-credentials row, which the same sentence then says the control plane creates. Maybe "setup.sh creates moca-mu1, moca-redis and the relay Secrets once…". Also, the conditions differ slightly. moca-relay-sandbox-tokens is created on every OpenShift run, even with no P4 IDs, when it stays empty (ensure_p4_tokens, setup.sh:509-510). moca-relay-tls needs OpenShift and P4 IDs (setup.sh:811-812).
| | Secret | Contents | If lost | | ||
| | ------------------------------------ | --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ||
| | `moca-mu1` | `SH_SESSION_TOKEN_PRIVATE_KEY`, `SH_SESSION_TOKEN_PUBLIC_KEYS`, `SH_CREDENTIAL_KEK`, `SH_EXCHANGE_TOKEN` | **Losing the KEK makes every stored credential unreadable**, with no way back without the old key. Losing the signing key invalidates every outstanding access and session token; clients that refresh should recover (not verified) | | ||
| | `moca-credentials` namespace Secrets | One encrypted Secret per user | Users must re-add their credentials | |
There was a problem hiding this comment.
nit: On ocp-single there is no moca-credentials namespace. Credentials live in SH_SINGLE_NAMESPACE (overlays/ocp-single/patch-addressing.yaml:29, delete-ns-credentials.yaml). The same applies at line 39.
|
|
||
| ## What lives in Redis | ||
|
|
||
| | Data | Expires | If Redis is lost | |
There was a problem hiding this comment.
nit: This table leaves out a few things:
- Workload records
sh:wl:<owner>:<name>andsh:wl-quota:<owner>. They exist only whenMOCA_CONTEXT_WORKLOADS_ENABLED=1, and losing them orphans Context Service resources. - The
leaf-queuestream. - The bundle keys
config:bundle:<digest>. The "Config bundles" row could name its key.
| - A turn longer than about 15 to 20 seconds does not survive a rollout. The committed session does; the work in | ||
| that turn is lost. | ||
| - Attach streams on a draining worker end without a terminal frame; a client re-attaches to another worker. | ||
| I did not verify that `mocactl` does this automatically. |
There was a problem hiding this comment.
nit: This caveat can go. mocactl re-attaches automatically: session-manager.ts:28-29,519 retries up to REATTACH_TRIES=5 times with exponential backoff from REATTACH_BASE_MS=500. Also, "I did not verify" is the only first-person sentence in these pages.
| Workers report, best effort, where each session ran. `GET /v1/sessions/{id}/resources` returns the session, harness, | ||
| sandbox, lease and placement (sandbox id, tier, and `workspaceReset`, either `{at, from}` or null; the stream event | ||
| is called `workspace_reset`). A top-level `queue` is always null. The data is self-reported by the harness | ||
| and display-only. Some fields still carry Knative-era values (`mode` is `leaf-job` or `knative`), and the sandbox |
There was a problem hiding this comment.
nit (pre-existing manifest bug, FYI): Missing RBAC isn't the only reason phase would read unknown. The supervisor sets KAGENTI_SANDBOX_POOL_SELECTOR=app=sandbox (base/supervisor.yaml:78), but the sandbox pods are labelled app: moca-sandbox (base/sandbox.yaml:25-27). As far as I can see the selector is only read for this display path (control-plane/src/resources.ts:31), so nothing else breaks. It's worth a separate issue rather than a change here.
Summary
PR 7b of
docs/REORG-PLAN.md: operations documentation for P6 on Kubernetes (deploy/k8s), the first path planned for Stable. Two of the Stable criteria (upgrade and recovery docs) depend on it. Docs only. Based onmainafter #499.docs/operations/index.mdplus five pages: upgrades, Redis backup and recovery, observability, sizing and scaling, troubleshooting.docs/index.mdand the README; the plan file records 7b.Everything comes from the manifests,
setup.shand the code. Where the repository documents nothing, the page says so, and the index lists the gaps up front:save/appendfsync/maxmemorysettings;/metricsis JSON, not Prometheus, and the relay and sandboxes have no health endpoints;Please check
/readyzgoing 503 once all workers drain, the sandboxphasereadingunknown(the control plane has no pod permissions), per-pod admission letting one pod 429 while another has room, and a node-drain gap. They are marked.setup.sh(one image serves both). The upgrades page says so; is splitting them intended?envelope.ts(ring, newest first).setup.shcannot perform it, and deletingmoca-mu1destroys every stored credential; the page warns about this.Verification
scripts/check-doc-links.pyreports 0 broken links over 181 files; Prettier run on changed files. No deployment was run.make lintnot run locally; CI will.Assisted-By: Claude (Anthropic AI) [email protected]