Repository navigation
fix(sbx): Redis memory limit and image pin, relay rolls, worker units - #758
Conversation
Seven faults in deploy/sbx, found operating SBX0 namespaces and their KVM hosts. setup.sh: - Redis had no maxmemory, so one that outgrew its 256 MiB container was OOM-killed with every session and sandbox record. redis.conf now sets `maxmemory 200mb` and `maxmemory-policy noeviction`: a full Redis refuses writes (503 redis_unavailable) and evicts nothing. The Secret does not restart redis-0; the RUNBOOK gives the CONFIG SET for a running namespace. - SBX_REDIS_IMAGE (pinned by digest, refused otherwise) renames the base's Valkey image in the generated overlay. Valkey 9 (rossoctl#670) cannot read RDB format 12, which Redis 7.4 writes, so a namespace with such data crash-loops redis-0 after an upgrade; this keeps it on Redis 7 until it is migrated. - One settings hash, over every setting, was stamped on both the control plane and the relay, so a template, subject or quota change rolled the relay and ended every running Exec. The relay now gets its own hash, over only what it reads at boot (the token issuer, the in-flight cap, the public keyset, the attach and exec certificates); the control plane's is unchanged. Worker tokens need no roll (the relay reads them at each attach). The first run after this change rolls the relay once. install-host.sh and [email protected]: - The last worker's uninstall removed sbx.slice's file without stopping it, so systemd kept it loaded until a reboot. It is stopped first. - The shared unit had Wants=/After=moca-egress.service, so a --no-egress worker started whatever egress proxy the host had. The dependency is now a per-worker drop-in (sbx-worker@<id>.service.d/egress.conf), written only with egress and removed by a --no-egress reinstall and by --uninstall; --egress no longer warns about CA trust for --no-egress workers. - The unit ran /usr/local/bin/microvm-worker, the path deploy/microvm's P4 worker runs from, so on a host with both one build replaced the other. SBX_WORKER_BIN (absolute; default /usr/local/libexec/sbx/microvm-worker) is written into ExecStart, and a missing binary is refused before systemd is touched. - The unit fixed SH_GUEST_RAM_MB=256, so a worker on a 4096 MiB snapshot was admitted and cgroup-sized for 256 MiB guests. The worker's env file now carries the snapshot manifest's guest_ram_mb; a snapshot without it is refused, and so is a --budget-mb that cannot hold one session ((guest RAM + 32) x 3 + the 1024 MiB reserve). Tests: setup.test.sh (the rendered redis.conf, the image rename and its refusal, which pod each change rolls) and install-host.test.sh (the slice stop, the drop-in, the warning, SBX_WORKER_BIN, the guest RAM and budget checks). README and RUNBOOK document SBX_REDIS_IMAGE, SBX_WORKER_BIN, the Redis limit, which change rolls which pod, and a worker's minimum budget. SBX_WORKER_BIN must be an absolute path of plain characters (letters, digits, . _ - /), since ExecStart is rewritten with sed; a test pins the budget check's standby depth and reserve to the unit's values so they cannot drift. Refs rossoctl#734 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
One conflict, the egress paragraph of install-host.sh's header: main's new default allowlist source (deploy/sbx/egress-allow.env, rossoctl#719) kept, with this PR's per-worker egress drop-in lines. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
clawgenti
left a comment
There was a problem hiding this comment.
Clawgenti Code Review
Summary
Careful deploy fixes:
maxmemory 200mb+noevictionsits under the 256Mi container limit, andnoevictionmaps to the documented503 redis_unavailable.RELAY_HASHcovers exactly what the relay pod reads (issuer,SH_SANDBOX_MAX_INFLIGHT, keyset, and the attach/exec certs the ghostunnel sidecars mount).- The budget check's (guest + 32) × 3 + 1024 matches
vmpool's overhead, standby depth and reserve. - The digest regex refuses unpinned
SBX_REDIS_IMAGEvalues.
No must-fix issues. There is one suggestion inline, about upgrading a host that already runs several egress workers.
Author: webchang (MEMBER — maintainer)
Areas reviewed: Shell (setup.sh, install-host.sh), systemd unit, Kustomize/Redis config, Docs (README, RUNBOOK), tests
Agent/IDE config (.claude/.vscode): none
Commits: 2 commits, all signed-off: yes
CI status: passing
All checks pass. Ready for human review.
Verified by:
install-host.test.sh: 43 ok.setup.test.sh: 42 ok.- shellcheck
-S warning: no new findings on the changed lines. bash -non everydeploy/sbxscript: clean.systemd-analyze verifyon[email protected]: only the expected placeholder-binary note.- A throwaway upgrade probe (base
install-host.sh, then head, against a mocked systemctl). I deleted it afterwards.
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
| # The worker's dependency on moca-egress, only with egress: Wants= + After=, not Requires=, so a | ||
| # moca-egress restart does not stop the worker (why: deploy/microvm/moca-egress.service). A | ||
| # re-install with --no-egress removes it. | ||
| local dropin_dir="$SBX_UNIT_DIR/sbx-worker@$id.service.d" |
There was a problem hiding this comment.
suggestion: Installing or reinstalling any one worker with this version rewrites the shared [email protected]. That drops Wants=/After=moca-egress.service and changes ExecStart to SBX_WORKER_BIN, but only the worker being installed gets this egress.conf drop-in. Any other egress worker on the same host that an older install-host.sh installed keeps MOCA_EGRESS_CONTROL_SOCK in its env and has no drop-in. On its next restart it is no longer ordered after moca-egress.
Probe:
- Base
install-host.shinstalls worker A with egress. - Head
install-host.shinstalls worker B.
Result: the template now has only After=network-online.target, and only sbx-worker@sbx_b.service.d/ exists, even though A's env still has the socket. (I deleted the probe.) The impact is limited, because the control client dials lazily and heals. But early Execs after a reboot can race moca-egress, and RUNBOOK §2 "Upgrading" does not say that every worker must be reinstalled.
Suggested fix: in install_units, write or refresh egress.conf for every $SBX_ENV_DIR/workers/*.env that carries MOCA_EGRESS_CONTROL_SOCK (the same selection warn_untrusting_workers uses). Alternatively, add a RUNBOOK §2 note that this upgrade means re-running install-host.sh for each worker.
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
All of the fixes verified. The redis:7-alpine@sha256:858f009f… pin exists on Docker Hub (7.4.11), and it's the one #670 removed. The digest regex is correct and the overlay renders newName+digest. noeviction is the right policy, since OOM writes surface as 503 redis_unavailable. RELAY_HASH's inputs currently match exactly what patch-relay.yaml reads. The drop-in syntax and VM_OVERHEAD_MB=32 (= vmpool.DefaultVMOverheadBytes) check out, and no bash-4-only constructs were added. CI is 17/17 green (including deploy-scripts-bash32), DCO is OK, and it merges cleanly with main.
Heads-up: this conflicts with #757 in deploy/sbx/install-host.sh, as the PR body notes. Nit on the body: it says "one signed-off commit", but the head also has a (signed-off) merge from main.
| # The worker's dependency on moca-egress, only with egress: Wants= + After=, not Requires=, so a | ||
| # moca-egress restart does not stop the worker (why: deploy/microvm/moca-egress.service). A | ||
| # re-install with --no-egress removes it. | ||
| local dropin_dir="$SBX_UNIT_DIR/sbx-worker@$id.service.d" |
There was a problem hiding this comment.
suggestion: upgrade path for workers already on a host. install_units rewrites the shared [email protected] on every worker install, which drops Wants=/After=moca-egress.service and switches ExecStart to SBX_WORKER_BIN. Only the worker being installed gets the egress.conf drop-in and SH_GUEST_RAM_MB. Other egress workers on the same host pick up the new template at their next restart, and then they have no ordering after moca-egress, keep the unit's 256 MiB guest RAM, and never get the budget check. It isn't fatal: moca-egress is WantedBy=multi-user.target and the control client dials lazily. Please add an explicit step to RUNBOOK §2 ("after upgrading, re-run install-host.sh for every worker on each host"), or have install_units warn about installed workers that have MOCA_EGRESS_CONTROL_SOCK but no drop-in.
| printf '[Unit]\nAfter=moca-egress.service\nWants=moca-egress.service\n' >"$dropin_dir/egress.conf" | ||
| chmod 0644 "$dropin_dir/egress.conf" | ||
| fi | ||
| record "worker sbx-worker@$id $SBX_ENV_DIR/workers/$id.env $SBX_UNIT_DIR/sbx-$id.slice" |
There was a problem hiding this comment.
suggestion: the header (L40-42) promises that every file this script writes is listed in the manifest, but the new sbx-worker@$id.service.d/egress.conf drop-in isn't recorded here. --uninstall removes it by a hardcoded path (L730), so nothing leaks today. Consider adding it to this record "worker …" line when egress is on, or narrowing the header's claim.
| } | openssl dgst -sha256 -hex | awk '{print substr($NF, 1, 16)}')" | ||
| [[ "$SETTINGS_HASH" =~ ^[0-9a-f]{16}$ ]] || die 'could not hash the settings (openssl dgst)' | ||
| # The relay's env from sbx-settings, by key, as patch-relay.yaml names them. | ||
| relay=('SH_SANDBOX_TOKEN_ISSUER=sbx-control-plane' "SH_SANDBOX_MAX_INFLIGHT=$SBX_MAX_INFLIGHT") |
There was a problem hiding this comment.
nit: the relay hash inputs are listed by hand, and SH_SANDBOX_TOKEN_ISSUER=sbx-control-plane duplicates the sbx array's value. If a new configMapKeyRef is added to ocp-sbx/patch-relay.yaml, the relay will silently stop rolling on it. Consider a shared variable for the issuer, plus a test that every configMapKeyRef key in patch-relay.yaml is among RELAY_HASH's inputs (like the STANDBY_DEPTH drift test).
| ( | ||
| export S_0="$pw" S_1="redis://:$pw@redis.$NS.svc:6379" | ||
| S_2="$(printf 'requirepass %s\nappendonly yes\ndir /data\n' "$pw")" | ||
| S_2="$(printf 'requirepass %s\nappendonly yes\ndir /data\nmaxmemory 200mb\nmaxmemory-policy noeviction\n' "$pw")" |
There was a problem hiding this comment.
nit (unmeasured): maxmemory 200mb leaves about 56 MiB under base redis.yaml's 256Mi limit. That headroom has to absorb the AOF-rewrite/BGSAVE fork's copy-on-write and allocator fragmentation, neither of which maxmemory counts. Near the cap under write load, that could still OOM-kill the pod. Consider about 150-170mb or a larger limit, and a comment here noting that the two values must move together.
Conflicts and resolutions: - deploy/sbx/install-host.sh, validate_worker: kept both checks, check_snapshot_ram (this branch) then check_jail_path (main). - deploy/sbx/install-host.sh, install_worker's worker env: kept this branch's SH_GUEST_RAM_MB line and main's digest-keyed jail, SH_CHROOT_BASE=$(jail_dir "$id"). - deploy/sbx/setup.sh, the settings header: kept both entries, SBX_REDIS_IMAGE then SBX_TEMPLATE_STORE. - deploy/sbx/tests/setup.test.sh: kept both blocks; main's template store block stays 15 and this branch's SBX_REDIS_IMAGE block is now 16. Follow-up in the merge (no conflict marker): main's too-long SBX_SRV case in deploy/sbx/tests/install-host.test.sh made a snapshot directory without a manifest, so this branch's check_snapshot_ram refused it before check_jail_path ran; the case now copies the default snapshot's manifest. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
|
Merged main (d4babb8). Tests ran locally on the existing node_modules, since a fresh install is held by the new hono pin's release-age window; CI is the full check. Assisted-By: Claude Code |
Upstream main (634781a) carries rossoctl#758's deploy fixes, which touch the same lines as the read-ahead change. No API version change: this branch claims none. Conflicted: - deploy/sbx/README.md: both paragraphs kept, the read-ahead one after the uninstall paragraph, then main's template-onboarding one. - deploy/sbx/install-host.sh: main's SBX_WORKER_BIN default and its validate_worker comment kept; the SBX_READ_AHEAD_KB default and the read-ahead functions added beside them (this branch's older copy of the comment dropped). - deploy/sbx/[email protected]: main's unit, with no moca-egress dependency (the egress drop-in carries it), kept; only sbx-read-ahead.service is added to After=, with its comment. - deploy/sbx/tests/install-host.test.sh: main's snap() fixture and its guest-RAM and SBX_WORKER_BIN blocks kept; the findmnt mock, the SBX_SYSFS export and the read-ahead block added, the read-ahead block after main's. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Closes #734.
Deploy fixes for the sandbox service (
deploy/sbx): a Redis memory limit and a pinned Redis image, the relay rolling when its own settings change, and the worker units. One signed-off commit.Notes for review:
setup.shrun after this change rolls the relay once, which ends running Execs, because the relay gains its own settings hash. After that, a template, subject or quota change rolls only the control plane.install-host.sh, so whichever merges second needs a rebase.Tests on the tip:
deploy/sbx/tests/setup.test.shpasses (0not ok);install-host.test.sh: 41 ok on bash 5 and on bash 3.2. On bash 3.2, the existing janitor case fails ondeclare -A;janitor.shis untouched here;7 files, +325 / -68.
Assisted-By: Claude Code