openclaw - ✅(Solved) Fix exec tool can launch known-heavy upstream validation commands inside live Gateway resource domain [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#77121Fetched 2026-05-05 05:51:54
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
2
Author
Timeline (top)
commented ×1cross-referenced ×1

The exec tool allows agents to run arbitrary shell commands in the live Gateway execution context. When an agent launches heavy OpenClaw upstream validation commands — such as pnpm install, pnpm lint:core, tsgo / tsgolint, or broad vitest runs — those commands share the same systemd user cgroup as openclaw-gateway.service. Under memory pressure, this can:

  1. kill transient heavy child processes and still mark the whole gateway unit as oom-kill, causing an automatic service restart,
  2. or, without swap, hard-hang the host requiring manual reboot.

This was observed in production across two incidents where agent sessions independently launched corepack pnpm install && corepack pnpm exec vitest run ... && corepack pnpm lint:core on an upstream checkout within the workspace.

Root Cause

  • Agents can and do generate heavy validation commands autonomously during PR follow-up, issue investigation, and upstream debugging.
  • Manual wrapper discipline is not scalable: sessions started before the wrapper was created continue to run commands bare.
  • Without swap and without cgroup isolation, a single heavy exec can destabilize or restart the entire Gateway service.
  • This is not an edge case: two incidents in ~17 hours from the same thread.

Fix Action

Fix / Workaround

Workaround (operator-side)

These are effective mitigations but rely on manual discipline and do not prevent new sessions from bypassing the wrapper.

A prepare-only source patch has been developed in a disposable upstream checkout:

PR fix notes

PR #77140: fix(exec): block unisolated heavy validation commands

Description (problem / solution / changelog)

Summary

  • add an exec-tool preflight guard for known-heavy validation commands before local Gateway execution
  • fail closed for unisolated package-manager install/lint/build/typecheck/test commands and direct tsgo / tsgolint / oxlint / broad test runners
  • classify broader diagnostics such as rg -S, recursive grep, and git diff --stat as maybe-heavy without fail-closing them yet
  • allow commands already isolated via openclaw-heavy-run or an explicit resource-limited systemd-run --user --scope -p MemoryMax=...
  • expose analyzeHeavyExecCommand in __testing and cover direct, chained, shell-wrapped, maybe-heavy, light, isolated, and execute-path blocking cases

Closes #77121.

Why

Agents can autonomously generate heavyweight upstream validation commands during issue/PR follow-up. When those commands run through local Gateway exec, they share the live Gateway service resource domain. Existing mitigations help adjacent surfaces, but do not prevent arbitrary agent-generated heavy validation from starting unisolated:

  • #70419 improves Linux OOM victim selection for child processes, but it does not prevent heavy commands from entering the Gateway unit cgroup.
  • #71652 guards local tsgo scripts under pressure, but does not cover arbitrary agent exec commands such as pnpm install or pnpm lint:core.
  • #43176 caps broad find scans, which is complementary but covers a different command class.

This PR adds a narrower fail-closed guard at the exec entry point.

Behavior

Blocked unless isolated:

  • pnpm / npm / yarn / bun / corepack install, update, lint, build, typecheck, or test scripts
  • direct tsgo, tsgolint, oxlint, vitest, jest, mocha
  • shell-wrapped/chained variants, for example bash -lc 'cd repo && corepack pnpm lint:core'

Detected but not blocked yet:

  • maybe-heavy broad diagnostics such as rg -S, recursive grep, and git diff --stat

Allowed:

  • light commands such as git status --short
  • commands wrapped by openclaw-heavy-run -- <command>
  • explicit resource-scoped commands such as systemd-run --user --scope -p MemoryMax=... -- <command>

Emergency bypass:

  • OPENCLAW_EXEC_HEAVY_ENFORCEMENT=off

Test plan

Run through a resource-isolated wrapper locally:

[workspace]/.github/scripts/openclaw-heavy-run --   corepack pnpm exec vitest run src/agents/bash-tools.exec.script-preflight.test.ts

Result:

2 files passed
126 tests passed
8 skipped

Also passed:

git diff --check

Notes / scope boundaries

  • This PR intentionally does not introduce a new built-in process supervisor or cgroup manager.
  • This PR intentionally does not replace #70419, #71652, #75820, or #43176; it complements them at the agent exec entry point.
  • The command-class heuristic is conservative for known-heavy validation commands. Maybe-heavy diagnostics are classified for observability/tests but are not fail-closed yet to avoid excessive operator friction.
  • The refusal message intentionally names a generic configured resource-isolation wrapper rather than a local filesystem path.

Files changed

d56991f8 fix(exec): block unisolated heavy validation commands
 .../bash-tools.exec.script-preflight.test.ts       |  88 ++++++++
 src/agents/bash-tools.exec.ts                      | 235 +++++++++++++++++++++
 2 files changed, 323 insertions(+)

Local diff summary

.../bash-tools.exec.script-preflight.test.ts       |  88 ++++++++
 src/agents/bash-tools.exec.ts                      | 235 +++++++++++++++++++++
 2 files changed, 323 insertions(+)

Changed files

  • src/agents/bash-tools.exec.script-preflight.test.ts (modified, +102/-0)
  • src/agents/bash-tools.exec.ts (modified, +273/-0)
RAW_BUFFERClick to expand / collapse

exec tool can launch known-heavy upstream validation commands inside live Gateway resource domain

Summary

The exec tool allows agents to run arbitrary shell commands in the live Gateway execution context. When an agent launches heavy OpenClaw upstream validation commands — such as pnpm install, pnpm lint:core, tsgo / tsgolint, or broad vitest runs — those commands share the same systemd user cgroup as openclaw-gateway.service. Under memory pressure, this can:

  1. kill transient heavy child processes and still mark the whole gateway unit as oom-kill, causing an automatic service restart,
  2. or, without swap, hard-hang the host requiring manual reboot.

This was observed in production across two incidents where agent sessions independently launched corepack pnpm install && corepack pnpm exec vitest run ... && corepack pnpm lint:core on an upstream checkout within the workspace.

Relation to existing work

This issue is complementary to several existing PRs/issues:

  • #70419 (merged) raises child oom_score_adj to make children more likely to be killed than the gateway. This helps kill selection but does not prevent unisolated heavy commands from starting, and systemd can still restart the gateway unit when any child inside its cgroup is killed.
  • #71652 refuses local tsgo under host pressure in scripts. This is scoped to the tsgo script path, not arbitrary agent-generated exec commands.
  • #75820 addresses worktree heavy-check locks. Complementary ergonomics, not exec-tool enforcement.
  • #43176 caps broad find exec scans. Complementary timeout guard for a different command class.

None of these prevent arbitrary heavy validation through the exec tool itself.

Environment

  • OpenClaw: 2026.4.24 (observed); latest at time of report: 2026.5.2
  • OS: Ubuntu 24.04 LTS (arm64)
  • Runtime: Gateway systemd user service
  • Host: VPS instance

Observed behavior

Incident 1

  • Agent session launched cd /tmp/openclaw-upstream-append-write-20260503 && git diff --check && corepack pnpm lint:core inside the live Gateway exec context.
  • Gateway RSS was already elevated from accumulated sessions/subagents.
  • Kernel OOM killed tsgolint (~3.7 GiB anon RSS) inside the openclaw-gateway.service cgroup.
  • systemd marked openclaw-gateway.service as Failed with result 'oom-kill' and restarted it automatically.
  • Gateway peak for the unit: ~11.0 GiB.

Incident 2

  • Same thread/agent re-launched the same validation pattern (corepack pnpm install --frozen-lockfile && corepack pnpm exec vitest run ... && corepack pnpm lint:core).
  • Host became unresponsive under memory pressure and required manual force reboot.
  • No kernel OOM table persisted in journal (hard reboot before log flush).

In both cases, the agent was performing legitimate upstream PR follow-up validation, but the execution path placed multi-GB build/lint processes inside the same systemd cgroup as the live Gateway.

Proposed behavior

Before local host=gateway (non-sandbox, non-node) exec runs, detect whether the command matches known-heavy validation patterns:

Always-heavy:

  • package-manager: pnpm/npm/yarn/bun/corepack + install, update, lint*, build*, typecheck*, test*
  • direct executables: tsgo, tsgolint, oxlint, vitest, jest, mocha

Maybe-heavy:

  • rg -S / rg --no-ignore / recursive grep
  • git diff --stat

Allowed without guard:

  • light commands (git status, targeted file reads, narrow grep)
  • commands already wrapped by an isolation helper (e.g., openclaw-heavy-run -- <command>)
  • commands already in an explicit resource-limited scope (e.g., systemd-run --user --scope -p MemoryMax=...)

On detection: fail closed with a clear instruction to use an isolation wrapper. Provide an environment-variable escape hatch (OPENCLAW_EXEC_HEAVY_ENFORCEMENT=off) only for explicitly approved emergency bypass.

Why this matters

  • Agents can and do generate heavy validation commands autonomously during PR follow-up, issue investigation, and upstream debugging.
  • Manual wrapper discipline is not scalable: sessions started before the wrapper was created continue to run commands bare.
  • Without swap and without cgroup isolation, a single heavy exec can destabilize or restart the entire Gateway service.
  • This is not an edge case: two incidents in ~17 hours from the same thread.

Workaround (operator-side)

Until a built-in guard exists, operators can:

  1. Use a wrapper script (e.g., openclaw-heavy-run) that embeds a memory/RSS/session preflight and runs the command inside systemd-run --user --scope with MemoryMax.
  2. Add zram/swap as a host-level safety buffer.
  3. Instruct agents via session/system-prompt guidance to use the wrapper for heavy commands.

These are effective mitigations but rely on manual discipline and do not prevent new sessions from bypassing the wrapper.

Validation

A prepare-only source patch has been developed in a disposable upstream checkout:

  • Modified src/agents/bash-tools.exec.ts to add analyzeHeavyExecCommand / rejectUnisolatedHeavyExecCommand before local gateway exec.
  • Added tests to src/agents/bash-tools.exec.script-preflight.test.ts covering direct, chained, shell-wrapped, maybe-heavy, light, isolated, and execution-path blocking cases.
  • pnpm exec vitest run src/agents/bash-tools.exec.script-preflight.test.ts: 2 files passed, 124 tests passed.
  • git diff --check: clean.

The patch is available if maintainers want to review it.

Open questions

  • Should this be an exec-tool-level guard, or a broader session-level resource policy (e.g., per-session MemoryMax via systemd-run --user --scope for all heavy exec)?
  • Should the wrapper name/path be configurable via tools.exec.heavyCommandWrapper?
  • Is OPENCLAW_EXEC_HEAVY_ENFORCEMENT=off the right escape-hatch name, or should it integrate with existing tools.exec.security / tools.exec.ask?

extent analysis

TL;DR

Implement a guard in the exec tool to detect and prevent heavy validation commands from running inside the live Gateway execution context without proper isolation.

Guidance

  • Identify known-heavy validation patterns, such as package managers (pnpm, npm, yarn, etc.) and direct executables (tsgo, tsgolint, vitest, etc.), and detect them before running the command.
  • Fail closed with a clear instruction to use an isolation wrapper if a heavy command is detected, and provide an environment-variable escape hatch (OPENCLAW_EXEC_HEAVY_ENFORCEMENT=off) for explicitly approved emergency bypass.
  • Consider implementing a session-level resource policy, such as per-session MemoryMax via systemd-run --user --scope, for all heavy exec.
  • Use a wrapper script (e.g., openclaw-heavy-run) that embeds a memory/RSS/session preflight and runs the command inside systemd-run --user --scope with MemoryMax as a temporary mitigation.

Example

// src/agents/bash-tools.exec.ts
function analyzeHeavyExecCommand(command: string): boolean {
  const heavyPatterns = [
    /pnpm\s+(install|update|lint|build|typecheck|test)/,
    /tsgo|tsgolint|vitest|jest|mocha/,
  ];
  return heavyPatterns.some((pattern) => pattern.test(command));
}

function rejectUnisolatedHeavyExecCommand(command: string): void {
  if (analyzeHeavyExecCommand(command)) {
    throw new Error(`Heavy command detected: ${command}. Please use an isolation wrapper.`);
  }
}

Notes

The proposed solution focuses on detecting and preventing heavy validation commands from running inside the live Gateway execution context. However, the optimal approach may depend on the specific requirements and constraints of the system. Further discussion and testing may be necessary to determine the

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix exec tool can launch known-heavy upstream validation commands inside live Gateway resource domain [1 pull requests, 1 comments, 2 participants]