Skip to content

feat: shareProcessNamespace (default true) to reap zombies - #485

Merged
stubbi merged 1 commit into
mainfrom
feat/share-process-namespace
May 12, 2026
Merged

stubbi merged 1 commit into
mainfrom
feat/share-process-namespace

Conversation

@stubbi

@stubbi stubbi commented May 12, 2026

Copy link
Copy Markdown
Owner

Summary

Adds spec.shareProcessNamespace (default true) to OpenClawInstance. When enabled, all containers in the pod share a PID namespace and the Kubernetes pause container becomes PID 1, automatically reaping zombie processes that accumulate under the Node.js gateway (which does not call waitpid() on orphaned children).

Closes #471.
Supersedes #476 — incorporates @alexander-morris's production-validated approach with the docs, unit tests, e2e tests, and field placement requested in the review on #476.

Background

#471 reported 28 defunct processes accumulating under PID 1 on a production OpenClaw pod (QMD, git, shells, plugin helpers). Image-level fixes (tini in the entrypoint) are the most durable long-term solution and are tracked upstream at openclaw/openclaw#74083, but operator users have no clean way to wrap the entrypoint today. PID-namespace sharing is the standard Kubernetes-native answer and stacks harmlessly with a future upstream init process.

@alexander-morris validated the approach in production (28 agents, 7+ hours, zero zombie accumulation, zero unrelated restarts on 24/28 pods).

Changes

Core:

  • api/v1alpha1/openclawinstance_types.go — ShareProcessNamespace *bool with +kubebuilder:default=true, placed next to Security (pod-level runtime/security cluster) per review feedback on feat: add shareProcessNamespace to pod spec (defaults to true) #476.
  • internal/resources/statefulset.go — shareProcessNamespace() helper; treats nil as true so instances stored before the field existed still get the fix on next reconcile.

Generated (do not hand-edit):

  • api/v1alpha1/zz_generated.deepcopy.go
  • config/crd/bases/openclaw.rocks_openclawinstances.yaml
  • charts/openclaw-operator/templates/crds/openclaw.rocks_openclawinstances.yaml

Tests:

  • internal/resources/resources_test.go — three new builder cases: default-true (field unset), explicit-true, explicit-false. Pattern matches the existing AutomountServiceAccountToken tests.
  • test/e2e/e2e_suite_test.go — two new specs in the controller suite: default-true and explicit-false override. Pattern matches the adjacent runtimeClassName spec.

Docs:

  • README.md — new feature-table row and a "Shared Process Namespace" subsection with opt-out snippet and security trade-off.
  • docs/api-reference.md — spec.shareProcessNamespace field reference with type/default/behavior, security implication, and upgrade note about pod-template rollout for existing instances.

Security trade-off (called out in docs)

With sharing enabled, every container in the pod can see and signal every other container's processes. A compromised sidecar (Tailscale, Ollama, browser, custom) could send signals to the gateway and vice versa. For most deployments the zombie-reaping benefit clearly outweighs this; users with mutually-distrusting sidecars can opt out per instance and reap inside their image (tini/dumb-init).

Upgrade impact

Flipping the default to true means every existing OpenClawInstance will get a one-time pod-template change on next reconcile, rolling pods. Operators running large fleets should plan a maintenance window. Called out in the api-reference upgrade note.

Test plan

  • go test ./internal/resources/ passes (3 new tests covering default/true/false)
  • make lint passes (golangci-lint v1.64.5)
  • go vet ./... clean
  • make generate manifests sync-chart-crds regenerates cleanly (no manual edits to generated files)
  • E2E suite passes in CI on a real kind cluster (new specs follow the existing runtimeClassName pattern)

Credit

Production validation and original PR by @alexander-morris in #476.

🤖 Generated with Claude Code

Long-running gateway pods accumulate zombie processes from QMD memory,
git, plugins, and shells because the Node.js gateway runs as PID 1 and
does not call waitpid() on orphaned children. With shareProcessNamespace
enabled, the Kubernetes pause container becomes PID 1 and reaps zombies
automatically, no custom init/reaper image required.

Defaults to true so existing instances get the fix on next reconcile.
Users that need per-container PID isolation can opt out per instance.

Co-Authored-By: alexander-morris <[email protected]>
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 55.55556% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
api/v1alpha1/zz_generated.deepcopy.go 0.00% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@stubbi
stubbi merged commit 4cbfd4d into main May 12, 2026
8 checks passed
@stubbi
stubbi deleted the feat/share-process-namespace branch May 12, 2026 09:42
stubbi added a commit that referenced this pull request May 12, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.33.0](v0.32.1...v0.33.0)
(2026-05-12)


### Features

* shareProcessNamespace (default true) to reap zombies
([#485](#485))
([4cbfd4d](4cbfd4d))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: operator-managed gateway pods can accumulate zombie helper processes

2 participants