@@ -187,30 +187,50 @@ describe("AgentScope service", () => {
187187 ) ,
188188 ) ;
189189
190- it . effect (
191- "keeps shared Codex scopes running without attributing their OOM to the launch thread" ,
192- ( ) =>
193- withFakeSystemd ( ( { scope, units, calls } ) =>
194- Effect . gen ( function * ( ) {
195- const agent = yield * scope . wrap ( { command : "agent" , args : [ ] , name : "t" , threadId : "a" } ) ;
196- expect ( agent . args ) . toContain ( "--property=OOMPolicy=stop" ) ;
197- units . set ( unitOf ( agent ) , { activeState : "failed" , result : "oom-kill" } ) ;
198- expect ( yield * scope . oomKilled ( "a" ) ) . toBe ( true ) ;
190+ it . effect ( "keeps shared scopes running without attributing their OOM to the launch thread" , ( ) =>
191+ withFakeSystemd ( ( { scope, units, calls } ) =>
192+ Effect . gen ( function * ( ) {
193+ const agent = yield * scope . wrap ( { command : "agent" , args : [ ] , name : "t" , threadId : "a" } ) ;
194+ expect ( agent . args ) . toContain ( "--property=OOMPolicy=stop" ) ;
195+ units . set ( unitOf ( agent ) , { activeState : "failed" , result : "oom-kill" } ) ;
196+ expect ( yield * scope . oomKilled ( "a" ) ) . toBe ( true ) ;
199197
200- const codex = yield * launchCodex ( scope , "a" ) ;
201- expect ( codex . args ) . toContain ( "--property=OOMPolicy=continue" ) ;
202- expect ( codex . args ) . not . toContain ( "--property=OOMPolicy=stop" ) ;
203- expect ( codex . args ) . toContain ( "--property=TimeoutStopSec=10s" ) ;
204- expect ( codex . args ) . toContain ( "--collect" ) ;
205- units . set ( unitOf ( codex ) , { activeState : "active" , result : "success" } ) ;
206- expect ( yield * scope . oomKilled ( "a" ) ) . toBe ( false ) ;
207- units . set ( unitOf ( codex ) , { activeState : "failed" , result : "oom-kill" } ) ;
208- expect ( yield * scope . oomKilled ( "a" ) ) . toBe ( false ) ;
209- expect (
210- calls . filter ( ( [ , verb , unit ] ) => verb === "show" && unit === unitOf ( codex ) ) ,
211- ) . toEqual ( [ ] ) ;
212- } ) ,
213- ) ,
198+ const shared = yield * scope . wrap ( {
199+ command : "agent" ,
200+ args : [ ] ,
201+ name : "opencode" ,
202+ threadId : "a" ,
203+ shared : true ,
204+ } ) ;
205+ expect ( shared . args ) . toContain ( "--property=OOMPolicy=continue" ) ;
206+ expect ( shared . args ) . not . toContain ( "--property=OOMPolicy=stop" ) ;
207+ expect ( shared . args ) . toContain ( "--property=TimeoutStopSec=10s" ) ;
208+ expect ( shared . args ) . toContain ( "--collect" ) ;
209+ units . set ( unitOf ( shared ) , { activeState : "active" , result : "success" } ) ;
210+ expect ( yield * scope . oomKilled ( "a" ) ) . toBe ( false ) ;
211+ units . set ( unitOf ( shared ) , { activeState : "failed" , result : "oom-kill" } ) ;
212+ expect ( yield * scope . oomKilled ( "a" ) ) . toBe ( false ) ;
213+ expect (
214+ calls . filter ( ( [ , verb , unit ] ) => verb === "show" && unit === unitOf ( shared ) ) ,
215+ ) . toEqual ( [ ] ) ;
216+ } ) ,
217+ ) ,
218+ ) ;
219+
220+ it . effect ( "gives each Codex thread a scope that reports its own OOM kill" , ( ) =>
221+ withFakeSystemd ( ( { scope, units } ) =>
222+ Effect . gen ( function * ( ) {
223+ const first = yield * launchCodex ( scope , "a" ) ;
224+ const second = yield * launchCodex ( scope , "b" ) ;
225+ expect ( unitOf ( first ) ) . not . toBe ( unitOf ( second ) ) ;
226+ expect ( first . args ) . toContain ( "--property=OOMPolicy=stop" ) ;
227+ expect ( first . args ) . not . toContain ( "--collect" ) ;
228+ units . set ( unitOf ( first ) , { activeState : "failed" , result : "oom-kill" } ) ;
229+ units . set ( unitOf ( second ) , { activeState : "active" , result : "success" } ) ;
230+ expect ( yield * scope . oomKilled ( "a" ) ) . toBe ( true ) ;
231+ expect ( yield * scope . oomKilled ( "b" ) ) . toBe ( false ) ;
232+ } ) ,
233+ ) ,
214234 ) ;
215235
216236 it . effect ( "keeps a running scope while hundreds of other threads launch" , ( ) =>
0 commit comments