Skip to content

fix(sandbox): bump config hash when buildSandboxCreateArgs flags change - #76590

Closed
aaajiao wants to merge 2 commits into
openclaw:mainfrom
aaajiao:fix/sandbox-init-config-hash
Closed

aaajiao wants to merge 2 commits into
openclaw:mainfrom
aaajiao:fix/sandbox-init-config-hash

Conversation

@aaajiao

@aaajiao aaajiao commented May 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a SANDBOX_DOCKER_CREATE_ARGS_EPOCH constant and a createArgsEpoch field to both SandboxHashInput and SandboxBrowserHashInput, so the existing config-hash recreate path also fires when buildSandboxCreateArgs adds, removes, or changes container creation flags.

This PR adds the mechanism only. It does not ship any flag change itself. Whichever PR adds the first real flag change (for example #74083 adding --init) bumps the epoch from the bootstrap value in the same release as the flag.

Why

buildSandboxCreateArgs already drives container recreation via the labelled openclaw.configHash, but the hash inputs only capture mount layout (mountFormatVersion) and browser security flags (securityEpoch). Other docker create flags are invisible to the hash. So adding any new flag in a future PR (--init, cgroup limits, sysctls, capabilities, namespace flags, etc.) does NOT invalidate the hash, and existing containers keep running with their old flags forever.

The most-affected pattern is exactly the one #68691 reports: long-running sandbox containers (scope: "agent" + prune.maxAgeDays: 0) stay alive for weeks and never recreate naturally. Without an epoch in the hash, they never pick up new flags.

What this PR adds

  1. SANDBOX_DOCKER_CREATE_ARGS_EPOCH in src/agents/sandbox/constants.ts, set to a neutral bootstrap value ("2026-05-bootstrap") and date-tagged so reviewers can tell at a glance which release introduced the bump.
  2. Header comment on the constant explicitly telling future contributors to bump the epoch in the same PR (or a follow-up PR) as the actual flag change, never speculatively. Pre-bumping under a name like "init-tini" would let containers be recreated with a hash claiming the new behaviour while the actual create args still lack it.
  3. createArgsEpoch: string in both SandboxHashInput and SandboxBrowserHashInput. Mirrors the existing securityEpoch / mountFormatVersion pattern.
  4. Both call sites updated (docker.ts:ensureSandboxContainer, browser.ts:ensureSandboxBrowser) to pass the new constant.
  5. openclaw.createArgsEpoch=... container label stamped at create time, alongside the existing openclaw.mountFormatVersion label, for diagnostics.
  6. Tests (config-hash.test.ts, docker.config-hash-recreate.test.ts) updated; new test "changes when docker create args epoch changes" mirrors the existing security-epoch test using neutral "epoch-v1"/"epoch-v2" sentinels.
  7. CHANGELOG entry under ## Unreleased > ### Fixes describing the mechanism, with Thanks @aaajiao. per repo convention.

Reusability

When future PRs add or change container flags, the contributor only needs to bump the SANDBOX_DOCKER_CREATE_ARGS_EPOCH string in the same change and add a one-line history entry to the comment. No new types, no new test scaffolding, no risk of forgetting to invalidate the hash.

Relationship to #74083 (and #68691)

Originally I had named this epoch after the --init rollout. Per clawsweeper P1 review, that was wrong — it would let this PR claim a feature ship that lives in a separate PR. The current value is neutral; the --init rollout in #74083 is responsible for bumping the epoch when it lands. With both merged in the same release, the long-running-container pattern reported in #68691 is fully addressed.

Test plan

  • pnpm test src/agents/sandbox/config-hash.test.ts — existing + new tests pass locally
  • pnpm test src/agents/sandbox/docker.config-hash-recreate.test.ts — recreate path still asserts hash mismatch triggers docker rm -f
  • Maintainer-side: full CI pass (note: the unrelated checks-node-agentic-cli failures in plugins-location-bridges.test.ts reproduce on upstream/main — see commit 5ecd01ff9 — and have no overlap with sandbox)
  • Live verification: a future flag change (such as fix(sandbox): pass --init so tini reaps zombie processes #74083) bumps the epoch and a long-running scope: "agent" sandbox is recreated on next agent run

🤖 Generated with Claude Code

@aaajiao
aaajiao requested a review from a team as a code owner May 3, 2026 09:16
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels May 3, 2026
@clawsweeper

clawsweeper Bot commented May 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 1, 2026, 7:31 PM ET / 23:31 UTC.

Summary
The branch adds a sandbox Docker create-args epoch to sandbox/browser config hashes and container labels, updates hash tests, and adds a changelog entry.

PR surface: Source +22, Tests +40, Docs +1. Total +63 across 7 files.

Reproducibility: yes. source-level: current main lacks a general create-args epoch in the sandbox hash while sandbox reuse depends on openclaw.configHash. I did not run a live Docker workload in this read-only review.

Review metrics: 1 noteworthy metric.

  • Sandbox hash identity surface: 1 hash input added to 2 hash shapes; 1 Docker label added. Hash identity controls whether existing sandbox and browser containers are reused, removed, or left stale during upgrades.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🧂 unranked krab
Result: blocked until real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Add redacted real Docker output, logs, or a recording showing an existing stale-hash container taking the intended recreate path.
  • Refresh against current main while preserving dockerEnvPolicyEpoch, readOnlyWorkspaceSkillMounts, and current sandbox tests.
  • Coordinate the epoch bump with the real Docker create-args change or get explicit maintainer acceptance of mechanism-only invalidation.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Only local Vitest/CI evidence is present; the contributor needs redacted real Docker terminal output, logs, a recording, or linked artifact, then should update the PR body for a fresh review.

Risk before merge

  • [P1] The neutral bootstrap epoch changes sandbox and browser hash identity before any Docker create-args flag changes, so cold containers can be removed and recently used running containers can remain stale with only a manual recreate hint.
  • [P1] The branch is conflicting against current main; any refresh must preserve newer hash inputs such as dockerEnvPolicyEpoch and read-only skill mounts plus current sandbox tests.
  • [P1] The external PR only reports local Vitest/CI evidence, not redacted real Docker terminal output, logs, a recording, or a linked artifact showing the stale-hash recreate path after the change.

Maintainer options:

  1. Combine the epoch with the real flag rollout (recommended)
    Refresh or replace the split branches so the Docker create-args flag, epoch bump, tests, and redacted recreate proof land as one reviewed rollout.
  2. Accept mechanism-only invalidation
    Maintainers may intentionally accept the one-time hash identity change before a flag lands, but should explicitly own the upgrade behavior and release-note context.
  3. Pause or replace the branch
    If the branch remains conflicting or proofless, pause it and open one narrow replacement PR for the complete sandbox init rollout.

Next step before merge

  • [P1] Human handling is needed because the remaining blockers are upgrade/rollout coordination, a conflicting branch, and contributor real-Docker proof rather than a narrow repair ClawSweeper can safely make.

Security
Cleared: No concrete security or supply-chain concern found; the diff changes sandbox hash metadata, Docker labels, tests, and changelog text without dependency, workflow, secret, or package-resolution changes.

Review findings

  • [P1] Tie the epoch to the real create-args change — src/agents/sandbox/docker.ts:567
  • [P3] Drop the release-owned changelog entry — CHANGELOG.md:196
Review details

Best possible solution:

Land or replace this as one coordinated sandbox rollout that couples the real Docker create-args change with the epoch bump, removes the normal-PR changelog edit, preserves current hash inputs/tests, and proves fresh plus upgrade Docker behavior.

Do we have a high-confidence way to reproduce the issue?

Yes, source-level: current main lacks a general create-args epoch in the sandbox hash while sandbox reuse depends on openclaw.configHash. I did not run a live Docker workload in this read-only review.

Is this the best way to solve the issue?

No, not as a split mechanism-only PR. The epoch pattern is useful, but the safer fix is to bump it with the real create-args change and prove the existing-container rollout.

Full review comments:

  • [P1] Tie the epoch to the real create-args change — src/agents/sandbox/docker.ts:567
    This passes a neutral createArgsEpoch into the expected sandbox hash even though the PR intentionally ships no Docker create-args change. Current main removes cold containers on hash mismatch and leaves recently used running containers on the old hash with only a manual recreate hint, so land this with the actual flag change or explicit maintainer acceptance of mechanism-only invalidation.
    Confidence: 0.9
  • [P3] Drop the release-owned changelog entry — CHANGELOG.md:196
    Root AGENTS.md marks CHANGELOG.md as release-owned for normal PRs, and the PR body already carries release-note context. Remove this changelog edit and leave release generation to the release process.
    Confidence: 0.92

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 03d23c56d14d.

Label changes

Label justifications:

  • P1: This PR is part of the fix path for sandbox PID-1 zombie accumulation that can exhaust process slots in long-running agent containers.
  • merge-risk: 🚨 compatibility: The diff changes the hash identity used to decide whether existing sandbox and browser containers are reused or recreated during upgrade.
  • merge-risk: 🚨 availability: The hash mismatch path can remove cold containers or leave recently used running containers stale with only a manual recreate hint.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Only local Vitest/CI evidence is present; the contributor needs redacted real Docker terminal output, logs, a recording, or linked artifact, then should update the PR body for a fresh review.
Evidence reviewed

PR surface:

Source +22, Tests +40, Docs +1. Total +63 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 4 24 2 +22
Tests 2 40 0 +40
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 65 2 +63

What I checked:

  • Repository policy read: Root AGENTS.md and scoped src/agents/AGENTS.md were read; the review applied the compatibility-sensitive sandbox lifecycle guidance and release-owned changelog policy. (AGENTS.md:1, 03d23c56d14d)
  • Current main hash inputs: Current main hashes Docker config, optional Docker env policy epoch, workspace identity, mount format, and read-only skill mounts, but has no general buildSandboxCreateArgs epoch. (src/agents/sandbox/config-hash.ts:17, 03d23c56d14d)
  • Current main recreate path: Current main removes cold containers on hash mismatch, but recently used running containers keep the old hash and only log a manual recreate hint. (src/agents/sandbox/docker.ts:640, 03d23c56d14d)
  • PR head final diff: The PR adds SANDBOX_DOCKER_CREATE_ARGS_EPOCH as a neutral bootstrap value, passes it into both hash shapes, stamps openclaw.createArgsEpoch, and edits CHANGELOG.md. (src/agents/sandbox/docker.ts:567, 220b8f543ec7)
  • Live PR state: GitHub reports the head as CONFLICTING/DIRTY against main; the cross-repository branch is maintainer-editable but needs refresh before normal merge review. (220b8f543ec7)
  • Real behavior proof gap: The PR body lists only local Vitest commands and leaves live verification unchecked; no comments add redacted Docker output, logs, recording, or artifact for the recreate path. (220b8f543ec7)

Likely related people:

  • steipete: Authored the original sandbox container config-hash auto-recreate path and later browser hash migration work around this lifecycle boundary. (role: feature history owner; confidence: high; commits: 79d8267413cc, 1835dec2004f, 1f1fc095a0ab; files: src/agents/sandbox/docker.ts, src/agents/sandbox/config-hash.ts, src/agents/sandbox/browser.ts)
  • joshavant: Recently added explicit Docker env-policy hashing on the same sandbox create and reuse path that any refresh must preserve. (role: recent area contributor; confidence: medium; commits: 045a581069dc; files: src/agents/sandbox/config-hash.ts, src/agents/sandbox/docker.ts, src/agents/sandbox/browser.ts)
  • dims: Added the sandbox browser security hash epoch pattern, the closest merged analogue for this proposed create-args epoch. (role: adjacent owner; confidence: medium; commits: fbf11ebdb711; files: src/agents/sandbox/constants.ts, src/agents/sandbox/browser.ts, src/agents/sandbox/config-hash.ts)
  • hobo-l-20230331: Worked on sandbox registry lookup and reuse paths that determine how hash mismatches affect existing containers. (role: adjacent owner; confidence: medium; commits: 975891153f98; files: src/agents/sandbox/docker.ts, src/agents/sandbox/registry.ts, src/agents/sandbox/docker.config-hash-recreate.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@aaajiao

aaajiao commented May 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Both findings addressed in 8202308d4:

[P1] Renamed SANDBOX_DOCKER_CREATE_ARGS_EPOCH from "2026-05-init-tini" to a neutral "2026-05-bootstrap" value, and added a header comment explicitly warning future contributors not to pre-bump speculatively. PR description updated to reframe this as mechanism-only — --init lands separately in #74083, which is now responsible for the epoch bump in the same release as the flag.

[P3] Added Thanks @aaajiao. to the Unreleased CHANGELOG entry.

Re-ran the affected tests; the config-hash.test.ts new case now uses neutral "epoch-v1"/"epoch-v2" sentinels.

Note on CI: the checks-node-agentic-cli failures (plugins-location-bridges.test.ts > listPersistedBundledPluginLocationBridges > keeps persisted bundled relocations npm-first for launch + the catalog-metadata sibling) reproduce on upstream/main and predate this branch — they look related to commit 5ecd01ff9 (fix(plugins): trust managed npm peer links). No overlap with src/agents/sandbox/*. checks-node-core is the aggregator that fails because of those.

@aaajiao

aaajiao commented May 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper

aaajiao added 2 commits May 3, 2026 18:10
buildSandboxCreateArgs already drives container recreation via the
labelled configHash, but the hash inputs only capture mount layout and
browser security flags. Adding or changing other docker create flags
(such as --init in #74083) does not invalidate the hash, so existing
containers keep their previous flags forever.

Long-running deployments — for example scope: "agent" with
prune.maxAgeDays: 0 — never recreate naturally and never pick up a new
flag. The most-affected pattern is exactly the one #68691 reports for
the missing --init: a multi-week sandbox accumulating <defunct> children
under PID 1 because tini was not enabled at create time.

Add a SANDBOX_DOCKER_CREATE_ARGS_EPOCH constant and a createArgsEpoch
field to both SandboxHashInput and SandboxBrowserHashInput. Bump the
date-tagged epoch whenever buildSandboxCreateArgs gains, drops, or
changes container creation flags. Mirrors the existing
SANDBOX_BROWSER_SECURITY_HASH_EPOCH / mountFormatVersion pattern, and
also stamps the epoch as an openclaw.createArgsEpoch container label
for diagnostics, alongside the existing mountFormatVersion label.

Pairs with #74083: that PR adds --init; this commit makes the rollout
actually reach existing containers. Refs #68691, #74083.
Address clawsweeper review on PR #76590:

- [P1] Rename SANDBOX_DOCKER_CREATE_ARGS_EPOCH from "2026-05-init-tini"
  to a neutral "2026-05-bootstrap" value. The previous string implied
  --init was already part of this PR; in fact --init lands separately
  in #74083. Pre-bumping under that string would let containers be
  recreated with an "init-tini" hash while the actual create args
  still lack --init, and a later same-string bump in #74083 would no
  longer force a recreate.

  Add a header comment that explicitly tells future contributors to
  bump the epoch in the same PR (or a follow-up PR) as the actual
  flag change, never speculatively.

  Test using "2026-05-init-tini"/"2026-04-pre-init" sentinels updated
  to neutral "epoch-v1"/"epoch-v2" so the test asserts the mechanism
  without claiming any specific feature lineage.

- [P3] Add "Thanks @aaajiao." attribution to the Unreleased changelog
  entry per repo convention.

This PR now adds the mechanism only. Whichever PR ships the first
real buildSandboxCreateArgs flag change (e.g. the --init rollout in
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added stale Marked as stale due to inactivity triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 31, 2026
@clawsweeper clawsweeper Bot added the rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. label May 31, 2026
@barnacle-openclaw barnacle-openclaw Bot removed the stale Marked as stale due to inactivity label May 31, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels Jun 14, 2026
@steipete

steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution. I’m closing this stale PR because the latest review rated the current branch F: it still lacks the requested real-behavior proof or merge-ready branch shape, and there has been no human follow-up after the review. A fresh, focused PR against current main with the requested proof is welcome.

@steipete

Copy link
Copy Markdown
Contributor

Thank you @aaajiao — the rollout invariant from this PR has landed on main through #103441 as f698703934f, with your contribution preserved through a co-author trailer.

The landed fix uses one shared create-arguments epoch in both ordinary and browser sandbox hashes. Idle old-hash containers recreate automatically; recently active containers are preserved and receive the existing explicit recreate hint. Focused tests, real Docker lifecycle proof, and exact-head CI run 29072559013 all passed. Recording the canonical landed proof here; this PR was already closed.

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

Labels

agents Agent runtime and tooling merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants