Repository navigation
feat(k8s): SH_WORKSPACE_IDLE for the container worker, default 8h (#338) - #882
Conversation
The container worker reads SH_WORKSPACE_IDLE, but nothing in deploy/k8s set it, so its 30-minute default applied: a HITL session that waited longer for a person resumed in an empty workspace. deploy/microvm writes 8h. setup.sh takes it as a sticky input, like SH_TRUSTED_PROXY_HOPS (rossoctl#874): validated in parse_args and in write_settings for a stored value, stored in moca-settings, empty meaning 8h. The check mirrors the worker's time.ParseDuration and > 0 rule, and is stricter (whole h/m/s in order), so `30`, `-1m` and `0h` are refused before any apply. The sandboxes run in moca-sandbox and a configMapKeyRef reads only its own namespace, so setup.sh mirrors the value to ConfigMap moca-sandbox-settings there. base/sandbox.yaml and the workload PodTemplate read it with an optional ref (no ConfigMap: the worker's 30m). write_overlay stamps the value on the sandbox pod template, and the key is left out of the settings hash, so a change rolls only the sandboxes. 8h, not less: /workspace is the pod's writable layer (an emptyDir with no sizeLimit on ocp-single), with no ephemeral-storage limit or quota, so the idle sweep is the only bound. The README, configuration reference and upgrade note say so; the reset is still silent and there is no release. Part of rossoctl#338 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
pdettori
left a comment
There was a problem hiding this comment.
Clean, configuration-only change: a sticky, validated SH_WORKSPACE_IDLE in setup.sh (default 8h), mirrored to a sandbox-namespace ConfigMap, read by the sandboxes through an optional configMapKeyRef, and stamped on the sandbox pod template so a change rolls only the sandboxes.
Verified against the PR head:
- Settings hash really is unchanged:
afteris built withjq -ncS, sojq -cS 'del(.SH_WORKSPACE_IDLE)'reproduces the pre-change string byte for byte, and the control plane and supervisor don't roll on upgrade. - Fresh install:
ensure_namespacesruns beforewrite_settings, so themoca-sandbox-settingsapply never races the namespace. - Workload sandboxes: they run in
moca-sandbox, and themoca-provisioneradmission policy restricts onlysecretKeyRef/secretRef, so theconfigMapKeyRefis admitted. - No crashloop from a short value: with
SH_WORKSPACE_EMPTY_IDLEunset, the runner caps its 15m default at Idle, so e.g.10mboots. - Validation is stricter than
time.ParseDuration, and the 6-digits-per-unit bound stays far under Go's limit. No other patch adds sandbox pod-template annotations, so the singleaddis safe on ocp, kind and ocp-single.DefaultWorkspaceIdleis30m, matching the reference doc.
Author: webchang (MEMBER, maintainer)
Areas reviewed: Shell (setup.sh, tests, fixture), K8s manifests, TS tests, Docs
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing (17/17)
One nit inline.
| empty `SH_WORKSPACE_EMPTY_IDLE` (15 minutes by default) after its last command is removed sooner | ||
| `SH_WORKSPACE_IDLE` (30 minutes by default; the microVM installer and `deploy/k8s/setup.sh` set 8 | ||
| hours), and the next turn is **not told** that it happened (#338). On a container worker, a per-session | ||
| directory that is still empty `SH_WORKSPACE_EMPTY_IDLE` (15 minutes by default) after its last command is removed sooner |
There was a problem hiding this comment.
nit: the rewrap left this line at 120 characters, against ~103 for the rest of the paragraph. Moving "after its last command is removed sooner" to the next line would keep it even.
There was a problem hiding this comment.
Rewrapped in 64bed40; the words are unchanged.
Review nit: the rewrap left one line at 120 characters; the paragraph now keeps the file's width. Part of rossoctl#338 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
Brings rossoctl#878 (the sync /runs disconnect contract), rossoctl#880 (the RUNBOOK's reproduction recipe) and rossoctl#882 (deploy/k8s SH_WORKSPACE_IDLE for the container worker, default 8h). No conflicts. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Part of #338: deploy/k8s sets the container sandboxes' SH_WORKSPACE_IDLE (default 8h)
What changed and why
The container worker (
remote-worker/cmd/worker) already readsSH_WORKSPACE_IDLE, but nothing underdeploy/k8sset it, so the code default of 30 minutes applied: a human-in-the-loop session on a
deploy/k8sstack that waitedlonger than that for a person resumed in an empty
/workspace.deploy/microvmwrites8hfor the same reason.This is option 4 from the issue thread: configuration only.
deploy/k8s/setup.sh:SH_WORKSPACE_IDLEis a new sticky input, handled the way fix(oidc): bound outstanding login starts per client address, not just in total #874 addedSH_TRUSTED_PROXY_HOPS: checked inparse_args, resolved inwrite_settings(unset keeps the stored value; setbut empty returns to the default), written to
moca-settings, and a bad stored value is refused with the messagesaying how to clear it. Empty means
8h, and the resolved value is what gets stored.workspaceRunnerincmd/worker/main.gorefuses to boot onanything
time.ParseDurationrejects or reads as<= 0.setup.shaccepts whole hours, minutes and seconds,each at most once and in that order (
8h,90m,1h30m), and refuses30,-1m,0hand1d. It isstricter than Go (no sign, fraction or sub-second unit), so a value it accepts never crashloops the worker.
configMapKeyRefreads only its pod's namespace. Thesandboxes run in
moca-sandbox, andmoca-settingsis inmoca. Sosetup.shalso writes the value to a newConfigMap,
moca-sandbox-settings, in the sandbox namespace. It has its own name because onocp-singlebothnamespaces are the same one.
base/sandbox.yamland the workloadPodTemplateread it with anoptional
configMapKeyRef: a manifest applied withoutsetup.shstill boots, on the worker's 30-minutedefault.
write_overlaystamps the value on the sandbox pod template(
moca.dev/workspace-idle), and the key is left out of the settings-hash input. The control plane and thesupervisor don't read it, so they don't roll for it. Their hash is the same as before this change, so the upgrade
doesn't roll them. A workload's sandboxes take a new value when their pods next start (the template is read at
create).
A sandbox pod's
/workspaceis its container's writable layer, or anemptyDirwith nosizeLimitonocp-single. The manifests set noephemeral-storagerequest or limit, and no quota or LimitRange covers it. Theonly bound is the idle sweep, which runs every
min(idle/4, 1m). So8hmatchesdeploy/microvm. The READMEand the reference doc state the trade-off: disk is not admission-controlled, a longer idle holds more idle
sessions' files at once, and under node disk pressure the kubelet evicts a sandbox pod with all its workspaces.
deploy/k8s/README.md§2 settings list, the container-worker row and the Kubernetes installerinputs in
docs/reference/configuration.md, an upgrade note indocs/operations/upgrades.md, and the default indocs/concepts/brain-and-hands.md. The upgrade note says the firstsetup.shrun after the upgrade rolls everymoca-sandboxpod once, which silently resets container sessions' workspaces. It also says how to keep the oldbehavior (
SH_WORKSPACE_IDLE=30m).Tests
deploy/k8s/tests/setup.test.sh:moca-settingsnow holds exactly twenty keys, on the main path and onocp-singlewith Routes.SH_WORKSPACE_IDLE:8hinmoca-settings, inmoca-sandbox-settings(which holds only that key) and in thesandbox annotation.
1h30mlands in both ConfigMaps, changes the sandbox annotation and leaves the settings hashunchanged.
8h.30,-1m,0h,0m0s,1d,8H,1.5h,+8h,30m1h,1h_,8h(trailing space) and1234567his refused, and nothing is written.30) is refused, namingmoca-settings, and set but empty clears it.ocp-single,moca-sandbox-settingslands in the one namespace besidemoca-settings.packages/supervisor/test/k8s(rendered throughkubectl kustomize):base-sandbox.test.ts: the sandbox readsSH_WORKSPACE_IDLEfrommoca-sandbox-settings, optionally, andnothing in
moca-sandboxreferencesmoca-settings.base-provisioner.test.ts: the workloadPodTemplatereads it the same way as the shared pool.generated-overlay.test.ts(write_overlay's real output): the annotation on the sandbox pod template forocp, for kind next to the image ID, and for an
ocp-singlecustom namespace next to its emptyDir patch.packages/provisioner: the fakePodTemplatecarries theconfigMapKeyRef, andprovisioner.test.tschecksthat it reaches the workload's container unchanged. 114 tests pass.
setup.shand manifest changes stashed, the newbase-sandboxandgenerated-overlaytests fail (noSH_WORKSPACE_IDLEenv, no annotation), andsetup.test.shfails on thekey count.
shellcheck -S warningonsetup.sh,setup.test.shand the overlay fixture: clean. Prettier is clean, andscripts/check-doc-links.pyreports 0 broken links.Out of scope
The rest of #338 stays open, as agreed in the thread:
with
/workspace/<sessionId>/directories accumulate on sandbox pods for workload runs #551).This PR changes only when the reset happens on
deploy/k8s.Every commit is signed off (DCO).
Assisted-By: Claude Code