@@ -88,17 +88,9 @@ const STOP_TIMEOUT_OPTION = "--property=TimeoutStopSec=10s";
8888// Nested agent scopes inherit only the controllers enabled on their parent
8989// slices. Without Delegate, rootless containers (kind + Podman, Docker rootless)
9090// fail cgroup setup when tools like make deploy run inside an agent session.
91- const DELEGATE_OPTIONS = [
92- "--property=Delegate=yes" ,
93- "--property=DelegateControllers=cpu cpuset io memory pids" ,
94- ] as const ;
95- const DELEGATE_PROPERTIES = [
96- "Delegate=yes" ,
97- "DelegateControllers=cpu cpuset io memory pids" ,
98- ] as const ;
99- // systemd derives parent slice names from the leaf name, so
100- // app-t3code-agents.slice always lives under app-t3code.slice.
101- const PARENT_SLICE = "app-t3code.slice" ;
91+ // Pass controllers via Delegate= (systemd-run rejects DelegateControllers=).
92+ // Systemd enables those controllers on ancestor slices when the scope starts.
93+ const DELEGATE_OPTION = "--property=Delegate=cpu cpuset io memory pids" ;
10294const STOPPING_POLL_INTERVAL = "100 millis" ;
10395const STOPPING_POLL_ATTEMPTS = 20 ;
10496const CLEAR_FAILED_INTERVAL = "1 second" ;
@@ -187,9 +179,9 @@ export const make = Effect.gen(function* () {
187179 // Prefer Delegate-enabled options so nested cgroups can enable cpu/cpuset/io.
188180 // Fall back when the local systemd rejects those properties.
189181 const stopOptions = [ STOP_TIMEOUT_OPTION ] ;
190- const stopWithDelegate = [ ...stopOptions , ... DELEGATE_OPTIONS ] ;
182+ const stopWithDelegate = [ ...stopOptions , DELEGATE_OPTION ] ;
191183 const oomOptions = [ ...stopOptions , "--property=OOMPolicy=stop" ] ;
192- const oomWithDelegate = [ ...oomOptions , ... DELEGATE_OPTIONS ] ;
184+ const oomWithDelegate = [ ...oomOptions , DELEGATE_OPTION ] ;
193185 const scopeOptions = ( yield * probe ( oomWithDelegate ) )
194186 ? oomWithDelegate
195187 : ( yield * probe ( oomOptions ) )
@@ -217,33 +209,18 @@ export const make = Effect.gen(function* () {
217209 stderr : limited . _tag === "Some" ? limited . value . stderr . trim ( ) : undefined ,
218210 } ) ;
219211 }
220- // Delegate on parent and agent slices so controllers reach nested scopes.
221- for ( const slice of [ PARENT_SLICE , AGENT_SLICE , ownedSlice ] ) {
222- const delegated = yield * run ( systemctl , [
223- "--user" ,
224- "set-property" ,
225- "--runtime" ,
226- slice ,
227- ...DELEGATE_PROPERTIES ,
228- ] ) ;
229- if ( delegated . _tag === "None" || delegated . value . code !== 0 ) {
230- yield * Effect . logWarning ( "Could not enable cgroup Delegate on agents slice" , {
231- slice,
232- stderr : delegated . _tag === "Some" ? delegated . value . stderr . trim ( ) : undefined ,
233- } ) ;
234- }
235- }
236212 yield * Effect . logInfo ( "Agent scopes are on" , {
237213 slice : AGENT_SLICE ,
238214 ...limits ,
239215 oomPolicy : scopeOptions . includes ( "--property=OOMPolicy=stop" ) ,
240- delegate : scopeOptions . includes ( "--property=Delegate=yes" ) ,
216+ delegate : scopeOptions . includes ( DELEGATE_OPTION ) ,
241217 } ) ;
242218 return {
243219 systemdRun,
244220 systemctl,
245221 runtimeDir,
246- supportsOomPolicy,
222+ supportsOomPolicy : scopeOptions . includes ( "--property=OOMPolicy=stop" ) ,
223+ supportsDelegate : scopeOptions . includes ( DELEGATE_OPTION ) ,
247224 } ;
248225 } ) ,
249226 ) ;
@@ -382,6 +359,7 @@ export const make = Effect.gen(function* () {
382359 // unload the unit even when it fails.
383360 options : [
384361 STOP_TIMEOUT_OPTION ,
362+ ...( scope . supportsDelegate ? [ DELEGATE_OPTION ] : [ ] ) ,
385363 ...( scope . supportsOomPolicy
386364 ? [ `--property=OOMPolicy=${ continuing ? "continue" : "stop" } ` ]
387365 : [ ] ) ,
0 commit comments