Skip to content

#3120: 0.2.0 AD6: agent-safe process environment on Linux hosts (OOM order, CPU quota) - #3221

Open
jparker2006 wants to merge 5 commits into
mainfrom
ticket/3120-agent-safe-env
Open

jparker2006 wants to merge 5 commits into
mainfrom
ticket/3120-agent-safe-env

Conversation

@jparker2006

Copy link
Copy Markdown
Member

Closes #3120
Part of #3120

Source and credit: idea only (no upstream code was read or ported).

Summary

On Linux, each local-driver turn now runs with an owner-only shell helper (BASH_ENV, plus CLAUDE_ENV_FILE for claude, sourcing any existing file) that raises starting shells' /proc/self/oom_score_adj to 500 while the harness process keeps its default. When the driver's cgroup sets a CPU quota (cpu.max on v2 or cpu.cfs_quota_us/cpu.cfs_period_us on v1), the turn also receives OMP_NUM_THREADS, PYTHON_CPU_COUNT and CARGO_BUILD_JOBS set to ceil(quota / period) unless already set. Nothing changes on macOS or when no quota is set.

Evidence

  • Before: docs/evidence/3120/red.md — running the new adapters/local/test_driver.py cases against the base adapters/local/driver failed all 4 CPU-quota assertions (returning None instead of '2'), with the OOM test skipped because the local sandbox starts processes at oom_score_adj 500 (runs under CI).
  • After: python3 -I adapters/local/test_driver.py -v passed 26 tests with 1 skipped (OOM test skipped on local host with default oom_score_adj 500; runs under CI).

Self-check

  • Undo-change proof: git worktree add --detach /tmp/build/probe-undo HEAD && git -C /tmp/build/probe-undo checkout origin/main -- adapters/local/driver && python3 -I adapters/local/test_driver.py Local.test_a_cpu_quota_sizes_the_turns_workers_and_an_owner_set_value_wins printed FAILED (failures=4) at its own assertions (None != '2').
  • Error paths: python3 -I -c "...d.cpu_quota() / d.agent_environment(...)..." printed error-paths: ok (unwritable OSError=Permission denied, cpu_quota=None, non-linux={}) (unwritable state dir raises OSError caught as Refused in launch, missing/zero cgroup returns None, non-Linux returns {}).
  • Guards fail closed: python3 -I adapters/local/test_driver.py -v Local.test_with_no_cpu_quota_or_without_proc_as_on_macos_the_turn_environment_is_unchanged printed OK (unlimited/missing cgroup and macOS/no-proc leave env unchanged; helper is created mode 0o600 atomically and never lowers a higher oom_score_adj).
  • Privacy: python3 -I tools/privacy-check/hook.py --url https://github.com/openwizdev/OpenWiz --repo /tmp/build/OpenWiz --head HEAD --base origin/main printed literals: not used and exited 0.
  • User data: git diff origin/main...HEAD -- adapters/local/driver printed helper paths written only under STATE (<run>.bash-env, <run>.claude-env), sourcing any existing BASH_ENV/CLAUDE_ENV_FILE without modifying or deleting user files.
  • Unchanged consumers: python3 -I adapters/local/test_driver.py -v printed Ran 27 tests ... OK (skipped=1); launch() is only called internally by start and wake in adapters/local/driver.
  • Comments: python3 -I .wizskills/skills/review-ticket/scripts/comments.py --base origin/main --head HEAD printed nothing and exited 0.

Merge danger

Door: two-way. Blast radius: local

Rulings

none

Facts

  • Branch: ticket/3120-agent-safe-env
  • Head: 93aadfd1228fdd923019fd08006fd430b0c58d23
  • Tree: 061a96b49161347d3f54148b5d2b07233791fef0
  • Size: changed: 145 lines in 4 files; tests apart: 105 lines in 2 files (plan: S: about 200 lines and 10 files; size: ok)
  • Changed paths: adapters/local/driver, adapters/local/fixtures/fake-harness, adapters/local/test_driver.py, adapters/local/README.md (shared: one bullet), changes/3120.md; supporting edit: docs/evidence/3120/red.md (kind: own evidence folder; supports all acceptance criteria and adapters/local/test_driver.py)
  • Tests:
    • test_on_linux_a_turns_shells_go_first_under_memory_pressure_and_the_harness_keeps_its_default — catches: Linux turns leaving shell oom_score_adj equal to the harness default, losing an owner-set BASH_ENV, omitting CLAUDE_ENV_FILE for claude, or creating world-readable helper files.
    • test_a_cpu_quota_sizes_the_turns_workers_and_an_owner_set_value_wins — catches: missing or miscalculated cgroup v2/v1 CPU quota worker limits (OMP_NUM_THREADS, PYTHON_CPU_COUNT, CARGO_BUILD_JOBS), ignoring tighter parent cgroup quotas, or overriding owner-set values.
    • test_with_no_cpu_quota_or_without_proc_as_on_macos_the_turn_environment_is_unchanged — catches: injecting CPU variables when no quota is set (max, missing, -1) or altering the turn environment on macOS / non-Linux hosts.
  • Red run: docs/evidence/3120/red.md (FAILED (failures=4, skipped=1) on base driver)
  • Claims: Linux turns raise shell oom_score_adj to 500 while harness keeps default; cgroup v2/v1 CPU quotas set OMP_NUM_THREADS, PYTHON_CPU_COUNT, CARGO_BUILD_JOBS to ceil(quota/period) unless owner-set; macOS and no-quota paths are unchanged.
  • Seams: cpu_quota(), shells_go_first(), and agent_environment() are isolated functions in adapters/local/driver so AD2 merges cleanly alongside AD6.
  • CI at this head: pending at PR creation; waiting for green CI.
  • Gaps: local sandbox starts processes at oom_score_adj 500 so the OOM test skips locally and is exercised by Linux CI.

… checks the turn

GitHub's runner starts each step at oom_score_adj 500, so the test could not
tell the turn's shells from the harness and failed under CI. The test now
lowers its own value to 0 for its length when the host allows it, and puts it
back afterwards.

Co-Authored-By: Claude Opus 5.5
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.

0.2.0 AD6: agent-safe process environment on Linux hosts (OOM order, CPU quota)

1 participant