Reduce OOM-kill risk for oz agent process in direct backend (REMOTE-2166)#108
Draft
seemeroland wants to merge 1 commit into
Draft
Reduce OOM-kill risk for oz agent process in direct backend (REMOTE-2166)#108seemeroland wants to merge 1 commit into
seemeroland wants to merge 1 commit into
Conversation
The hypothesis from REMOTE-2166: the oz agent process (oz CLI) is being OOM-killed by the kernel instead of the memory-hungry child processes it spawns (e.g. `cargo build`), causing cloud agent runs to go silent. Changes: - direct backend: after spawning the oz agent process, write a protective OOM score adjustment (-300) to /proc/<pid>/oom_score_adj so the kernel prefers killing heavy child processes over the agent coordinator. Requires CAP_SYS_RESOURCE for negative values; the operation is best-effort and execution continues with a warning if the capability is unavailable. - main.go: protect the long-lived worker process itself at startup with oom_score_adj=-500; losing the worker disrupts all active tasks and server reconnects. - Detect SIGKILL exits on the oz agent process, log a prominent error with a dmesg hint, and emit a new `agent.sigkill_detected` trace event for observability. - Add new `agent_oom` task failure reason to metrics and a clear user-facing message guiding operators to check VM memory and reduce build parallelism (e.g. CARGO_BUILD_JOBS=1). Co-Authored-By: Oz <oz-agent@warp.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Cloud agent runs were going silent for ~1 hour. The hypothesis (REMOTE-2166): the Linux OOM killer was targeting the
oz agentprocess (the coordinator) instead of its memory-hungry child processes (e.g.cargo buildwithCARGO_BUILD_JOBS=1still consuming significant memory). Once the agent process was killed, the run went dark until the VM was re-spun and a follow-up message resumed it.Changes
internal/worker/direct.gocmd.Run()tocmd.Start()+ OOM protection +cmd.Wait().oom_score_adj = -300to/proc/<pid>/oom_score_adj. This tells the Linux OOM killer to prefer killing the agent's children (the heavy compilers/tools) over the agent coordinator itself. RequiresCAP_SYS_RESOURCEfor negative values; the call is best-effort — a warning is logged if the capability is unavailable and execution continues normally.classifyAgentExitError: detects SIGKILL exits on the oz agent process, logs a prominent error with admesginvestigation hint, and emits anagent.sigkill_detectedspan event with apossible_oom_killhint for tracing.main.gooom_score_adj = -500. The worker manages task lifecycle and server reconnects; losing it is more disruptive than losing a single oz agent run.CAP_SYS_RESOURCEis missing.internal/metrics/metrics.goTaskFailureReasonAgentOOM = "agent_oom"to the bounded failure reason constants andtaskFailureReasonsslice, so SIGKILL exits surface in theoz_worker_task_failures_totalmetric with a distinctreasonlabel.internal/worker/errors.goagent_oomfailures guiding operators to check VM memory (dmesg) and reduce build parallelism (CARGO_BUILD_JOBS=1).Notes
oom_score_adjvalues requireCAP_SYS_RESOURCE. Warp's own factory VMs should have this; self-hosted workers running as non-root without the capability will see a warning log but are otherwise unaffected.OOMKilledvia the container state; Kubernetes handles OOM at the cgroup/pod level).cargo build) — that would give even stronger protection, but requires changes to the oz CLI binary rather than this repo.Conversation: https://staging.warp.dev/conversation/f2fe5d7a-21e4-425b-a07d-e6476974386b
Run: https://oz.staging.warp.dev/runs/019f6729-eba5-70ff-908a-7e9a34214faa
This PR was generated with Oz.