Skip to content

fix(sbx): Redis memory limit and image pin, relay rolls, worker units - #758

Merged
pdettori merged 3 commits into
rossoctl:mainfrom
webchang:pr/i11-sbx-deploy-fixes
Nov 13, 2026
Merged

pdettori merged 3 commits into
rossoctl:mainfrom
webchang:pr/i11-sbx-deploy-fixes

Conversation

@webchang

Copy link
Copy Markdown
Member

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:

  • The first setup.sh run 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.
  • A worker's budget must hold one session of its snapshot's guest: (guest RAM + 32) × 3 + 1024 MiB. That's 13,408 MiB for a 4,096 MiB guest.
  • A rebase between this and fix(microvm,knative-server): microVM worker and snapshot-build fixes #757. Both edit install-host.sh, so whichever merges second needs a rebase.

Tests on the tip:

  • deploy/sbx/tests/setup.test.sh passes (0 not ok);
  • install-host.test.sh: 41 ok on bash 5 and on bash 3.2. On bash 3.2, the existing janitor case fails on declare -A; janitor.sh is untouched here;
  • shellcheck is clean.

7 files, +325 / -68.

Assisted-By: Claude Code

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

Clawgenti Code Review

Summary

Careful deploy fixes:

  • maxmemory 200mb + noeviction sits under the 256Mi container limit, and noeviction maps to the documented 503 redis_unavailable.
  • RELAY_HASH covers 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_IMAGE values.

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 -n on every deploy/sbx script: clean.
  • systemd-analyze verify on [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"

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: 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:

  1. Base install-host.sh installs worker A with egress.
  2. Head install-host.sh installs 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 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.

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"

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: 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"

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

Comment thread deploy/sbx/setup.sh
} | 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")

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

Comment thread deploy/sbx/setup.sh
(
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")"

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 (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]>
@webchang

Copy link
Copy Markdown
Member Author

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

@pdettori
pdettori merged commit 7a5b5d9 into rossoctl:main Nov 13, 2026
16 checks passed
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
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]>
@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.

SBX0 deploy fixes: Redis memory limit and image pin, relay rolls, worker units

4 participants