Repository navigation
🤖 feat: limit the CPU and memory that all local agent commands share - #6894
ibetitsmike wants to merge 3 commits into
Conversation
Settings > Agents > Resource limits sets one CPU limit (cores) and one memory limit (GiB) for all commands of local and worktree workspaces. Xum enforces them with a cgroup v2 child (xum-agents) of the cgroup it runs in, which must be delegated to the user that runs Xum. Each agent shell joins xum-agents before its command runs; a failed move prints one warning and the command runs without the limit. When the cgroup cannot be managed, Settings shows why and commands run unlimited.
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9acff811fc
ℹ️ 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".
- The service applies unchanged limits again while they are not applied, so Try again in another backend's Settings retries here too. The warning logs once per new reason. - A failure to remove the limits reports "Could not remove the limits from the agent cgroup" instead of "No limit is set". - Settings follows config changes made elsewhere and keeps a field that is being edited. agentResourceLimits.get waits for queued applies. - Settings disables its fields and Try again offline, refuses an offline save, and shows the saved limits after a reconnect. - xum run and xum workflow apply the saved limits and dispose the service on exit.
|
@codex review |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Settings > Agents > Resource limits now subscribes to config.onConfigChanged, so subscriptionInventory.test.ts needs a restart rule for its file. A new client re-runs its effect; the live client is now named api, which the effect-deps shape check looks for.
Summary
Agents that run in parallel on one machine can use all of its CPU and memory and slow down everything else. This PR adds Settings → Agents → Resource limits: one CPU limit (cores) and one memory limit (GiB) that all local agent commands share, enforced with a Linux cgroup v2.
How it works
xum-app, enables thecpuandmemorycontrollers, createsxum-agents, and writescpu.maxandmemory.max.LocalBaseRuntime.execand the workspace init hook start each command with one shell line that moves the shell intoxum-agents. If the move fails, the command still runs and prints one warning on stderr.xum-agentsbefore the status says Active. Otherwise Settings shows the reason with Try again, and commands run without a limit.agentResourceLimitsinconfig.json. The server applies it at startup, on every config change, and on save.xum runandxum workflowapply it too. Settings follows changes made in another window or backend.docs/config/agent-resource-limits.mdx.Testing
LocalBaseRuntime, config parsing, and the Settings UI with changes made elsewhere, offline, and reconnect.src/cli/agentResourceLimits.test.tsrunsxum runandxum workflowwith a saved limit.xum server): 8 busy loops used 2.51 cores under a 2.5 core limit, a Go 1.26 binary gotGOMAXPROCS=3, and under 1 GiB a 2 GiB allocation was OOM-killed while the server kept running. Changing and clearing limits, a restart fromxum-app, an init hook, and the "cannot manage" status behaved as documented.xum workflowin a new delegated cgroup createdxum-agentswith the saved 1.25 cores and 1.5 GiB.make static-check(hadolint is not installed locally),make lint-eslint, andmake crap-checkpass.Risks
xum-appafter the limits are cleared.Review record
agentResourceLimits.getwaits for queued applies, so the status matches the limits.xum runandxum workflowstart the limits service on the real config and dispose it on exit.subscriptionInventory.test.ts, because the newconfig.onConfigChangedsubscription had no restart rule. b6925ee adds it.Requiredpassed on this commit.