Skip to content

fix: stop recursive Git shims from exhausting agent sandboxes - #202815

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-agent-git-wrapper-recursion-20260919
Nov 21, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-agent-git-wrapper-recursion-20260919

Conversation

@steipete

@steipete steipete commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The agent Git wrapper removes only its own directory from PATH before rediscovering git. A user forwarding shim can restore that directory and repeatedly re-enter the wrapper, exhausting a sandbox's process and memory limits. #202798 fixed recursive test fixtures; the product owner still needed repair.

User Impact

Host, Docker, Podman, and private persistent Docker launchers now bake in a validated stable absolute native Git path during preparation. Realpath validates candidates; script shims and their symlink aliases are skipped without execution. Calls use the prepared path. Package-manager symlink upgrades keep working, and a missing path triggers one safe resolution attempt before an actionable error.

Normal nested Git calls keep working. Credentials, egress, identity, history/projection policy, and maintenance flags stay unchanged. No new environment variables, configuration, cache, or schema; the environment-name budget remains 462. The canonical-path binding and nesting sentinel from the first revision have been removed.

Why This Change Was Made

One installer owns host and container launcher generation. It lives in a small sibling module to keep the runtime script within the existing source-size cap; the extracted command and launcher bytes are identical. Containers prepare from the read-only mounted source; private children install after configured setup. The executable PATH launcher stays on that resource mount and sources its prepared script from /tmp in the same shell, preserving default noexec mounts and read-only workspaces. Preparation utilities use command -p, so a restricted workload PATH cannot hide mkdir or mktemp. Installation preserves the existing 0755 directory mode. The fetch-failure regression now fails native Git's upload-pack transport rather than replacing Git through PATH.

Production grows by 76 lines for preparation, missing-target recovery, and container startup integration; the per-call PATH loop and environment handoffs are removed. The separate history-lock work in #199982 is untouched.

Evidence

The current bounded regression fails on exact unchanged parent f247afced37d159af27f7f019b950b6c696c125d because the forwarding shim is executed. It passes with this repair. Unbounded-cycle reproduction ran only under hard caps (macOS RLIMIT_NPROC and Linux pids.max=64): base exhausts the cap; the repaired forwarding chain completes. Recovery skips a wrapper alias and returns 127 when no native Git exists. The upgrade regression replaces the native target and then removes the prepared path; both cases work without re-preparation, including shell-special characters in the path.

Actual Docker backend proof covers ordinary and private persistent execution with workspaceAccess="ro", a read-only root, default noexec /tmp, and configured setup that exits 0. The native-Git control attempts transport for a missing-object probe; the mounted wrapper stays offline and creates no packs. The prior revision reproduces exit 126 on direct execution from noexec storage. A private absolute command with a restricted PATH reproduced exit 127 before the utility-path repair and now exits 0. Task containers were removed. Final five-file focused tests pass: 85 on Node, 83 on Bun, with two existing broker skips covered by Node. Full-diff Codex autoreview after the renderer extraction is scoped-clean at P0–P2. pnpm check:changed is green on the final source, including unchanged environment budget 462/462 and the source-size gate. Exact-head CI and ClawSweeper zero-item review remain required.

Host generated-launcher measurements use a synthetic btrfs repository with 62,000 files / 1.116 GB, native Git 2.39.5, five alternating A/B pairs of 1,000 calls and five A/A pairs. No production data. Allocation runs use separate five-pair 100-call batches; instrumented timings are discarded.

Command Wall median before → after CPU median before → after Allocation requests before → after
git --version 0.79819 → 0.73092 ms 0.78911 → 0.73057 ms 323,454 → 296,850 B
git rev-parse --verify HEAD 1.07701 → 1.05357 ms 1.08125 → 1.05870 ms 343,727 → 321,704 B

Allocation calls fall 488.29→431.29 and 647.29→598.29, with exact A/A matches. Counts cover malloc/calloc/realloc requests and amortized batch-shell overhead, excluding mmap/live RSS; the allocation-only interposer substitutes fork for vfork to isolate counters.

A/A wall medians: version 0.80959/0.83234 ms; probe 0.98134/1.03084 ms. CPU controls: 0.81020/0.83330 and 0.98481/1.03589 ms. The small probe gain is within A/A variation; this establishes no added median overhead, not a production speedup claim. This owner never reads session or agent databases. Reproduction scripts are in scripts/perf/agent-git-wrapper*.

The host launcher is byte-identical after the container delivery repair. A separate final-container run uses the same btrfs fixture and paired method. Paired median wall/CPU deltas are −0.00484/−0.00083 ms for version calls and −0.19845/−0.19190 ms for revision probes. Separate version medians are 0.89468→0.90874 ms wall and 0.89723→0.91167 ms CPU; that positive difference is smaller than the A/A variation (wall 0.95091/0.87510 ms). Both summaries are reported: the noisy version sample supports no demonstrated regression, not a precise speedup. Probe medians are 1.38057→1.18212 ms wall and 1.38454→1.19263 ms CPU. Container allocation requests fall 323,454→306,740 B and 343,727→316,746 B; calls fall 488.29→437.29 and 647.29→575.29, with exact A/A allocation matches.

ClawSweeper correctly found the noexec delivery regression, and Codex found preparation utilities depending on the workload PATH; both are repaired with actual Docker proof. The earlier budget-growth failure is eliminated. No inherited-failure exception is requested.

@clawsweeper

clawsweeper Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts docker Docker and sandbox tooling agents Agent runtime and tooling size: M labels Nov 21, 2026
@steipete
steipete marked this pull request as ready for review November 21, 2026 01:00
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T02:41:58.719690Z fcb23b3 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: fcb23b369aff7dd4042873acda2edae543b54dc7
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/sandbox/docker-backend.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.

Carefully review these changes before merging.

@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: d1d6ad27ad

ℹ️ 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".

Comment thread src/infra/agent-git-shim.ts Resolved
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 21, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 21, 2026
@clawsweeper

clawsweeper Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Prepare stable native Git bindings for host and container launchers so forwarding scripts cannot recursively re-enter the agent Git wrapper.

Example: A forwarding Git script restores PATH=/state/tmp/agent-git:/home/agent/bin:/usr/bin:/bin before invoking git.

  • Before: The agent wrapper rediscovered the forwarding script and could exhaust the sandbox process limit.
  • After: The prepared wrapper invokes /usr/bin/git directly while preserving its offline-probe and history policies.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, useful repair with production-path evidence and both earlier blockers resolved; exact-head CI remains pending.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Supplied host-launcher and actual Docker-backend results exercise capped recursion, stable-target replacement, missing-path recovery, ordinary and private execution with read-only workspace/root and noexec /tmp, offline missing-object probes, and a restricted-PATH workload that now exits 0.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Agent Git commands can repeatedly launch forwarding scripts until their sandbox runs out of processes or memory.
Reason: A demonstrated resource-exhaustion path is repaired at its existing owner, with maintainer-approved native selection and no new user settings.

Merge readiness

✅ Ready for maintainer review

This PR fixes a concrete runtime recursion path that remains on main; both prior findings are resolved, and no new actionable defect was found.

Priority: P2
Reviewed head: fcb23b369aff7dd4042873acda2edae543b54dc7

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway startup prepares the host Git launcher; Docker and Podman preparation bind container-native Git, and agent commands pass through the wrapper to native Git.

flowchart TD
  A[Gateway startup] --> B[Shared launcher installer]
  B --> C[Host Git launcher]
  B --> D[Read-only container launcher]
  E[Container preparation] --> F[Prepared temporary script]
  D --> F
  C --> G[Native Git]
  F --> G
Loading

Technical review

Best possible solution:

Retain the shared installer and stable native binding, including safe missing-target recovery and executable container delivery that sources noexec storage.

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

Current-main lookup permits a forwarding script to restore the wrapper directory and re-enter it; supplied capped reproductions establish process exhaustion, while this read-only review independently verified the source path.

Is this the best way to solve the issue?

The change fixes executable selection at preparation, shares generation across host and container callers, and preserves upgrade-stable symlinks without adding a nesting sentinel or configuration.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against c30d95148e24.

Provenance checked

  • Git executable selection changes intended behavior with a stated reason (b6d8eb2: Keep agent existence and ancestry probes offline through a managed PATH wrapper while retaining ordinary content reads.)
  • History preparation and transport-failure coverage keeps the original intent (ff0a22c: Bound shared partial-clone content hydration and prevent failed preparation from falling through to unrestricted lazy fetching.)
  • Launcher upgrade lifecycle keeps the original intent (fdc15a4: Keep generated launchers working when package-manager upgrades remove version-specific executable targets.)
  • Container preparation and private execution keeps the original intent (f7ef9b3: Complete backend preparation inside the existing allocation cleanup boundary while preserving reused containers.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • weiqinl: Raw commit fdc15a4 adds src/infra/openclaw-cli-shim.ts:34 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: fdc15a4a1df2; files: src/infra/openclaw-cli-shim.ts)

PR surface

Source +76, Tests +140, Docs +13, Other +145. Total +374 across 13 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 119 43 +76
Tests 4 172 32 +140
Docs 1 13 0 +13
Config 0 0 0 0
Generated 0 0 0 0
Other 4 149 4 +145
Total 13 453 79 +374

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Forwarding Git scripts can exhaust an affected sandbox, but the trigger is limited to that executable-lookup configuration.
  • merge-risk: 🚨 compatibility: Script-based Git backends are intentionally bypassed in favor of native Git; the maintainer-authored body explicitly accepts and documents this behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-21T01:30:12.843Z sha d1d6ad2 :: blocked before merge. :: [P1] Preserve a working Git binding when the installed version is replaced
  • reviewed 2026-11-21T02:06:26.303Z sha 389eb84 :: needs changes before merge. :: [P1] Keep the Docker Git launcher off noexec temporary storage

Reviewed November 20, 2026, 9:47 PM ET / November 21, 2026, 02:47 UTC (Revision 3).

@steipete

Copy link
Copy Markdown
Contributor Author

Addressed the one open item in the latest review on head 389eb84a597a6fdb6f65c2d2fd5cd157d61135de:

  1. Preserve a working Git binding when the installed version is replaced. The resolver now uses realpath only for validation and records the stable absolute candidate path. Missing-target recovery repeats the same safe selection once. The regression retargets the stable symlink, deletes the old native executable, then removes the prepared path entirely and recovers past a script fixture. All calls succeed without preparation or Gateway restart. Explicit Node and Bun runs pass.

The environment-budget decision is eliminated: both proposed environment names and the sentinel were removed. The installer writes the binding directly into each host/container launcher; the budget stays at the unchanged base value 462. Native Git remains the target through normal calls. Under a verified 64-process cgroup, the base forwarding chain exhausts the cap; the new forwarding chain succeeds, safe missing-path recovery skips the wrapper alias, and missing native Git exits 127 with an actionable error. The PR body contains the refreshed behavior and btrfs timing/CPU/allocation evidence.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete

Copy link
Copy Markdown
Contributor Author

Addressed the one open item from revision 2 on final head fcb23b369aff7dd4042873acda2edae543b54dc7:

  1. Keep the Docker Git launcher off noexec temporary storage. Confirmed on 389eb84a597a6: actual Docker with workspaceAccess="ro" and the default /tmp mount reports rw,nosuid,nodev,noexec; direct execution of the prepared script returns 126. The installer now creates an executable launcher on the existing read-only resource mount. That shell sources the prepared script rather than executing it from /tmp. Parent preparation and PATH selection and private-child startup both use this delivery path. No mount flags are changed and no extra process is added.

Actual backend proof now passes for ordinary and private execution with a read-only workspace/root, default noexec /tmp, pids=64, network disabled, and configured setup that exits 0. A native-Git control attempts transport for a missing object; the mounted wrapper stays offline and adds no packs. The existing backend regression now covers rw/ro workspaces and a readable but nonexecutable prepared script.

Codex also caught private preparation utilities depending on the workload PATH. All installer utilities now use command -p; the real restricted-PATH private-command reproduction changes from exit 127 at mkdir to successful workload exit 0. Stable target replacement/recovery remains covered, both proposed environment names remain removed, and the budget is unchanged at 462. Full-diff Codex autoreview is scoped-clean. The PR body includes refreshed behavior, proof, and host/container btrfs wall/CPU/allocation results, including A/A variation and the positive difference between separate version-call medians.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 21, 2026
@steipete
steipete merged commit b8de11e into main Nov 21, 2026
171 of 172 checks passed
@steipete
steipete deleted the steipete/perf-micro-agent-git-wrapper-recursion-20260919 branch November 21, 2026 03:11
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 21, 2026
…aw#202815)

* fix: stop recursive Git shims from exhausting agent sandboxes

* fix: bind agent Git launchers to stable native paths

* fix: keep prepared sandbox Git executable on noexec mounts
tideclaw-bot pushed a commit that referenced this pull request Nov 23, 2026
* fix: stop recursive Git shims from exhausting agent sandboxes

* fix: bind agent Git launchers to stable native paths

* fix: keep prepared sandbox Git executable on noexec mounts

(cherry picked from commit b8de11e)
Release adaptation: Resolve sandbox import context and retain the baseline PATH-oriented transport fixture. Test native Git binding and non-executable prepared scripts without importing the separate read-only-workspace temporary-directory policy.:
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 99549941ae356962358c61d7c88c6a40f73a8041)
(cherry picked from commit 13911bfc241d8d30c25bf1ed1e9e36160cc68b22)
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
* fix: keep agent temporary files in owned scratch

* fix: preserve sandbox temp access and queued isolation custody

(cherry picked from commit f91bc99)

Release adaptation: keep the staged #202815 Git shim implementation and independently assert both Git shim execution and writable owned temp in its merged Docker/Podman fixture. Use the beta.3 isolated custody configuration (896f33d52174), not ambient sandbox inventory.

Companions: #193677 scratch expiry owner is present (99ba844); #202815 is present-equivalent (7d33d1a). #202122 is independent Git/scratch clone reclamation, #202428 is CLI history ownership, #202644 is host file-write authority, and #202874 is workspace cleanup scheduling; none prerequisite. Other later same-path commits concern separate template, sandbox, prompt, sharing, or run-lifecycle policy; see the lane companion audit.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit a4070bc5b669308210b62a0b80b92c16af768b34)
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 docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts security-sensitive-changed size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant