The best way to control Claude Code, Codex and more from any computer or phone
fix(server): delegate cgroups to agent scopes (#23913)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 27, 2026 at 19:16 UTC
4b00290ef05ddb445a465e62cf03fe13ccbd0998
2 files changed
+23
-4
apps/server/src/process/agentScope.test.ts
+18
@@ -227,6 +227,24 @@ describe("AgentScope service", () => {
227
),
228
);
229
230
+ it.effect("delegates every agent scope so rootless containers can manage their cgroups", () =>
231
+ withFakeSystemd(({ scope }) =>
232
+ Effect.gen(function* () {
233
+ const agent = yield* scope.wrap({ command: "agent", args: [], name: "t", threadId: "a" });
234
+ const codex = yield* launchCodex(scope, "a");
235
+ const terminal = yield* scope.wrap({
236
+ command: "agent",
237
+ args: [],
238
+ name: "terminal",
239
+ survivesRestart: true,
240
+ });
241
+ for (const launch of [agent, codex, terminal]) {
242
+ expect(launch.args).toContain("--property=Delegate=yes");
243
+ }
244
+ }),
245
+ ),
246
+ );
247
+
248
it.effect("stops agents a killed server left before the first launch", () =>
249
withFakeSystemd(({ scope, units, calls, stateDir }) =>
250
Effect.gen(function* () {
apps/server/src/process/agentScope.ts
+5
-4
@@ -83,7 +83,8 @@ function parseCgroupCounter(text: string, key: string): number | undefined {
83
}
84
85
// systemd's default 90 s stop timeout would outlast our leftover-agent wait.
86
-const STOP_TIMEOUT_OPTION = "--property=TimeoutStopSec=10s";
86
+// Delegation lets rootless containers (Podman, kind) manage their own cgroups.
87
+const SCOPE_OPTIONS = ["--property=TimeoutStopSec=10s", "--property=Delegate=yes"];
88
const STOPPING_POLL_INTERVAL = "100 millis";
89
const STOPPING_POLL_ATTEMPTS = 20;
90
const CLEAR_FAILED_INTERVAL = "1 second";
@@ -167,8 +168,8 @@ export const make = Effect.gen(function* () {
168
"true",
169
]).pipe(Effect.map((result) => result._tag === "Some" && result.value.code === 0));
170
// Scopes take OOMPolicy from systemd 253; older managers still get scopes.
170
- const supportsOomPolicy = yield* probe([STOP_TIMEOUT_OPTION, "--property=OOMPolicy=stop"]);
171
- if (!supportsOomPolicy && !(yield* probe([STOP_TIMEOUT_OPTION]))) {
171
+ const supportsOomPolicy = yield* probe([...SCOPE_OPTIONS, "--property=OOMPolicy=stop"]);
172
+ if (!supportsOomPolicy && !(yield* probe(SCOPE_OPTIONS))) {
173
yield* Effect.logInfo("Agent scopes are off: no systemd user manager");
174
return undefined;
175
}
@@ -359,7 +360,7 @@ export const make = Effect.gen(function* () {
360
// Without an owning thread nothing reads the result, so let systemd
361
// unload the unit even when it fails.
362
options: [
362
- STOP_TIMEOUT_OPTION,
363
+ ...SCOPE_OPTIONS,
364
...(scope.supportsOomPolicy
365
? [`--property=OOMPolicy=${continuing ? "continue" : "stop"}`]
366
: []),