@@ -146,18 +146,21 @@ const exitedAgent = (
146146 units : Map < string , FakeUnit > ,
147147 cgroupRoot : string ,
148148 unit : string ,
149- { populated, oomKills } : { readonly populated : boolean ; readonly oomKills : number } ,
149+ { populated, oomKills } : { readonly populated : boolean ; readonly oomKills : number | undefined } ,
150150) => {
151151 const controlGroup = `/${ unit } ` ;
152152 NodeFS . mkdirSync ( NodePath . join ( cgroupRoot , controlGroup ) , { recursive : true } ) ;
153153 NodeFS . writeFileSync (
154154 NodePath . join ( cgroupRoot , controlGroup , "cgroup.events" ) ,
155155 `populated ${ populated ? 1 : 0 } \nfrozen 0\n` ,
156156 ) ;
157- NodeFS . writeFileSync (
158- NodePath . join ( cgroupRoot , controlGroup , "memory.events" ) ,
159- `low 0\nhigh 0\nmax 0\noom ${ oomKills } \noom_kill ${ oomKills } \noom_group_kill 0\n` ,
160- ) ;
157+ // An undefined count leaves memory.events unreadable.
158+ if ( oomKills !== undefined ) {
159+ NodeFS . writeFileSync (
160+ NodePath . join ( cgroupRoot , controlGroup , "memory.events" ) ,
161+ `low 0\nhigh 0\nmax 0\noom ${ oomKills } \noom_kill ${ oomKills } \noom_group_kill 0\n` ,
162+ ) ;
163+ }
161164 units . set ( unit , { activeState : "active" , result : "success" , controlGroup } ) ;
162165} ;
163166
@@ -247,6 +250,17 @@ describe("AgentScope service", () => {
247250 ) ,
248251 ) ;
249252
253+ it . effect ( "leaves a scope alone while its OOM count can't be read" , ( ) =>
254+ withFakeSystemd ( ( { scope, units, calls, cgroupRoot } ) =>
255+ Effect . gen ( function * ( ) {
256+ const agent = yield * scope . wrap ( { command : "agent" , args : [ ] , name : "t" , threadId : "a" } ) ;
257+ exitedAgent ( units , cgroupRoot , unitOf ( agent ) , { populated : true , oomKills : undefined } ) ;
258+ yield * scope . stop ( unitOf ( agent ) ) ;
259+ expect ( stopsOf ( calls ) ) . toEqual ( [ ] ) ;
260+ } ) ,
261+ ) ,
262+ ) ;
263+
250264 it . effect ( "stops an OOM-killed scope itself when systemd has no OOMPolicy for scopes" , ( ) =>
251265 withFakeSystemd (
252266 ( { scope, units, calls, cgroupRoot } ) =>
0 commit comments