Skip to content

feat(k8s): SH_WORKSPACE_IDLE for the container worker, default 8h (#338) - #882

Merged
webchang merged 2 commits into
rossoctl:mainfrom
webchang:pr/i338-k8s-workspace-idle
Nov 18, 2026
Merged

webchang merged 2 commits into
rossoctl:mainfrom
webchang:pr/i338-k8s-workspace-idle

Conversation

@webchang

Copy link
Copy Markdown
Member

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 reads SH_WORKSPACE_IDLE, but nothing under deploy/k8s
set it, so the code default of 30 minutes applied: a human-in-the-loop session on a deploy/k8s stack that waited
longer than that for a person resumed in an empty /workspace. deploy/microvm writes 8h for the same reason.
This is option 4 from the issue thread: configuration only.

  • deploy/k8s/setup.sh: SH_WORKSPACE_IDLE is a new sticky input, handled the way fix(oidc): bound outstanding login starts per client address, not just in total #874 added
    SH_TRUSTED_PROXY_HOPS: checked in parse_args, resolved in write_settings (unset keeps the stored value; set
    but empty returns to the default), written to moca-settings, and a bad stored value is refused with the message
    saying how to clear it. Empty means 8h, and the resolved value is what gets stored.
  • Validation follows the worker's own parsing. workspaceRunner in cmd/worker/main.go refuses to boot on
    anything time.ParseDuration rejects or reads as <= 0. setup.sh accepts whole hours, minutes and seconds,
    each at most once and in that order (8h, 90m, 1h30m), and refuses 30, -1m, 0h and 1d. It is
    stricter than Go (no sign, fraction or sub-second unit), so a value it accepts never crashloops the worker.
  • The sandboxes read it from their own namespace. A configMapKeyRef reads only its pod's namespace. The
    sandboxes run in moca-sandbox, and moca-settings is in moca. So setup.sh also writes the value to a new
    ConfigMap, moca-sandbox-settings, in the sandbox namespace. It has its own name because on ocp-single both
    namespaces are the same one. base/sandbox.yaml and the workload PodTemplate read it with an
    optional configMapKeyRef: a manifest applied without setup.sh still boots, on the worker's 30-minute
    default.
  • A change rolls only the sandboxes. write_overlay stamps 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 the
    supervisor 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).
  • Why 8h and not something smaller. I looked for a disk bound that would call for a lower value and found none.
    A sandbox pod's /workspace is its container's writable layer, or an emptyDir with no sizeLimit on
    ocp-single. The manifests set no ephemeral-storage request or limit, and no quota or LimitRange covers it. The
    only bound is the idle sweep, which runs every min(idle/4, 1m). So 8h matches deploy/microvm. The README
    and 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.
  • Docs: the deploy/k8s/README.md §2 settings list, the container-worker row and the Kubernetes installer
    inputs in docs/reference/configuration.md, an upgrade note in docs/operations/upgrades.md, and the default in
    docs/concepts/brain-and-hands.md. The upgrade note says the first setup.sh run after the upgrade rolls every
    moca-sandbox pod once, which silently resets container sessions' workspaces. It also says how to keep the old
    behavior (SH_WORKSPACE_IDLE=30m).

Tests

  • deploy/k8s/tests/setup.test.sh:
    • moca-settings now holds exactly twenty keys, on the main path and on ocp-single with Routes.
    • A new block covers SH_WORKSPACE_IDLE:
      • The default is 8h in moca-settings, in moca-sandbox-settings (which holds only that key) and in the
        sandbox annotation.
      • On kind, the annotation shares the one annotations add with the sandbox image ID.
      • A given 1h30m lands in both ConfigMaps, changes the sandbox annotation and leaves the settings hash
        unchanged.
      • A re-run keeps the value; set but empty returns it to 8h.
      • Each of 30, -1m, 0h, 0m0s, 1d, 8H, 1.5h, +8h, 30m1h, 1h_, 8h (trailing space) and
        1234567h is refused, and nothing is written.
      • A bad stored value (30) is refused, naming moca-settings, and set but empty clears it.
    • On ocp-single, moca-sandbox-settings lands in the one namespace beside moca-settings.
    • The whole suite passes.
  • packages/supervisor/test/k8s (rendered through kubectl kustomize):
    • base-sandbox.test.ts: the sandbox reads SH_WORKSPACE_IDLE from moca-sandbox-settings, optionally, and
      nothing in moca-sandbox references moca-settings.
    • base-provisioner.test.ts: the workload PodTemplate reads it the same way as the shared pool.
    • generated-overlay.test.ts (write_overlay's real output): the annotation on the sandbox pod template for
      ocp, for kind next to the image ID, and for an ocp-single custom namespace next to its emptyDir patch.
    • All 14 files and 114 tests pass.
  • packages/provisioner: the fake PodTemplate carries the configMapKeyRef, and provisioner.test.ts checks
    that it reaches the workload's container unchanged. 114 tests pass.
  • Before the fix: with the setup.sh and manifest changes stashed, the new base-sandbox and
    generated-overlay tests fail (no SH_WORKSPACE_IDLE env, no annotation), and setup.test.sh fails on the
    key count.
  • shellcheck -S warning on setup.sh, setup.test.sh and the overlay fixture: clean. Prettier is clean, and
    scripts/check-doc-links.py reports 0 broken links.

Out of scope

The rest of #338 stays open, as agreed in the thread:

This PR changes only when the reset happens on deploy/k8s.

Every commit is signed off (DCO).

Assisted-By: Claude Code

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 pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 18, 2026

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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: after is built with jq -ncS, so jq -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_namespaces runs before write_settings, so the moca-sandbox-settings apply never races the namespace.
  • Workload sandboxes: they run in moca-sandbox, and the moca-provisioner admission policy restricts only secretKeyRef/secretRef, so the configMapKeyRef is admitted.
  • No crashloop from a short value: with SH_WORKSPACE_EMPTY_IDLE unset, the runner caps its 15m default at Idle, so e.g. 10m boots.
  • 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 single add is safe on ocp, kind and ocp-single. DefaultWorkspaceIdle is 30m, 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.

Comment thread docs/concepts/brain-and-hands.md Outdated
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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]>
@webchang
webchang merged commit 2eb0219 into rossoctl:main Nov 18, 2026
17 checks passed
webchang added a commit to webchang/moca that referenced this pull request Nov 18, 2026
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]>
@pdettori pdettori added this to the v0.11.0 milestone Nov 19, 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.

2 participants