Skip to content

fix: sandbox containers exhaust process limits after long runs - #103441

Merged
steipete merged 1 commit into
mainfrom
codex/fix-sandbox-docker-init
Jul 10, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/fix-sandbox-docker-init

Conversation

@steipete

@steipete steipete commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Closes #68691

Supersedes #74083 and incorporates the rollout design from #76590.

What Problem This Solves

Fixes an issue where long-running sandbox containers could accumulate orphaned zombie processes until their process limit was exhausted, causing otherwise valid commands to fail.

Why This Change Was Made

Docker now starts every ordinary and browser sandbox with its built-in init process. One shared create-arguments epoch participates in both sandbox configuration hashes, so an idle container created under the old arguments is recreated automatically while a recently active container remains running and receives the existing explicit recreate hint. Existing environment, mount, network, capability, and security-policy inputs are unchanged.

Thanks @luckylhb90 for the original fix and @aaajiao for identifying the rollout requirement.

User Impact

New or safely recreated sandbox containers reap orphaned descendants and no longer leak zombie processes toward the configured PID limit. Active containers are not interrupted automatically.

Evidence

  • Real Docker 29.4 negative control without init: one PID-1 zombie after an orphaned grandchild exited.
  • Real Docker 29.4 with this branch: HostConfig.Init=true, PID 1 was docker-init, and the same orphaned-grandchild scenario left zero zombies.
  • Real OpenClaw sandbox flow: an idle old-hash container was recreated; a recently active old-hash container was preserved and emitted the exact openclaw sandbox recreate --all hint.
  • Focused Vitest proof: 63/63 tests passed across sandbox create arguments, ordinary/browser hashes, recreation, and hot-container deferral.
  • Targeted oxfmt and git diff --check passed.
  • Fresh configured Codex autoreview completed with no findings (0.91 confidence).
  • Exact-head hosted CI passed on 0aacb507926e4416dc0c4d5337668de265b15bdb: run 29072559013.

@steipete
steipete requested a review from a team as a code owner July 10, 2026 05:47
@openclaw-barnacle openclaw-barnacle Bot added docker Docker and sandbox tooling agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Jul 10, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aa7f49378b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@@ -47,6 +47,10 @@ export const DEFAULT_SANDBOX_COMMON_IMAGE = "openclaw-sandbox-common:bookworm-sl
export const SANDBOX_BROWSER_SECURITY_HASH_EPOCH = "2026-05-12-cdp-relay-auth";
export const SANDBOX_BROWSER_IMAGE_CONTRACT_EPOCH = "2026-05-12-cdp-relay-auth";

// Bump with shared Docker create-flag changes so existing ordinary and browser
// sandboxes roll through the hash/recreate path instead of keeping stale flags.
export const SANDBOX_DOCKER_CREATE_ARGS_EPOCH = "2026-07-10-init";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Avoid killing running sandboxes during init rollout

When upgrading with an existing pre-init Docker sandbox whose registry lastUsedAtMs is more than 5 minutes old but which still has an active docker exec or browser workload, this epoch makes it hash-mismatched and the existing ensureSandboxContainer/ensureSandboxBrowser cold branch removes it even though running is true. Long-running commands commonly exceed that window without refreshing the registry timestamp, so the next sandbox ensure can kill valid in-flight work during rollout; defer all running old-epoch containers or check for active work before removing them.

Useful? React with 👍 / 👎.

@steipete
steipete force-pushed the codex/fix-sandbox-docker-init branch from 93f6549 to 0aacb50 Compare July 10, 2026 05:56
@openclaw-barnacle openclaw-barnacle Bot removed docs Improvements or additions to documentation app: macos App: macos gateway Gateway runtime cli CLI command changes security Security documentation extensions: phone-control extensions: codex plugin: file-transfer labels Jul 10, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready verification for exact head 0aacb507926e4416dc0c4d5337668de265b15bdb:

  • OPENCLAW_TESTBOX=1 scripts/pr prepare-run 103441 accepted the exact-head hosted gates. CI run 29072559013 completed successfully, including build artifacts, lint, production/test types, contract checks, and the selected compact test shards.
  • node scripts/run-vitest.mjs src/agents/sandbox-create-args.test.ts src/agents/sandbox/config-hash.test.ts src/agents/sandbox/docker.config-hash-recreate.test.ts src/agents/sandbox/browser.create.test.ts passed 63/63 focused tests.
  • node .local/pr-74083-live.mjs exercised real Docker 29.4. Negative control without init retained one zombie. The fixed container reported HostConfig.Init=true, PID 1 docker-init, and zero zombies after the same orphan-grandchild scenario.
  • The same live script proved an idle old-hash OpenClaw container was recreated, while a recently active old-hash container was preserved and emitted the exact openclaw sandbox recreate --all hint.
  • Targeted oxfmt, git diff --check, and fresh configured Codex autoreview passed; autoreview reported no findings at 0.91 confidence.

Review artifacts are validated with recommendation READY FOR /prepare-pr, zero findings, and explicit ordinary/browser cold/hot branch coverage. No known proof gap remains for the touched surface.

@steipete
steipete merged commit f698703 into main Jul 10, 2026
118 of 122 checks passed
@steipete
steipete deleted the codex/fix-sandbox-docker-init branch July 10, 2026 06:10
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docker Docker and sandbox tooling maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sandbox zombie processes remain under PID 1 and accumulate until pids.max risk

1 participant