@@ -23,7 +23,11 @@ describe("sessions_yield tool", () => {
2323
2424 it ( "invokes onYield callback with default message" , async ( ) => {
2525 const onYield = vi . fn ( ) ;
26- const tool = createSessionsYieldTool ( { sessionId : "test-session" , onYield } ) ;
26+ const tool = createSessionsYieldTool ( {
27+ sessionId : "test-session" ,
28+ claimYield : ( ) => true ,
29+ onYield,
30+ } ) ;
2731 const result = await tool . execute ( "call-1" , { } ) ;
2832 const details = result . details as SessionsYieldDetails ;
2933 expect ( details . status ) . toBe ( "yielded" ) ;
@@ -36,7 +40,11 @@ describe("sessions_yield tool", () => {
3640 // The callback message becomes operator-visible scheduler context, so the
3741 // tool must not replace a supplied reason with the default text.
3842 const onYield = vi . fn ( ) ;
39- const tool = createSessionsYieldTool ( { sessionId : "test-session" , onYield } ) ;
43+ const tool = createSessionsYieldTool ( {
44+ sessionId : "test-session" ,
45+ claimYield : ( ) => true ,
46+ onYield,
47+ } ) ;
4048 const result = await tool . execute ( "call-1" , { message : "Waiting for fact-checker" } ) ;
4149 const details = result . details as SessionsYieldDetails ;
4250 expect ( details . status ) . toBe ( "yielded" ) ;
@@ -47,7 +55,11 @@ describe("sessions_yield tool", () => {
4755
4856 it ( "keeps private context separate from the user-facing acknowledgment" , async ( ) => {
4957 const onYield = vi . fn ( ) ;
50- const tool = createSessionsYieldTool ( { sessionId : "test-session" , onYield } ) ;
58+ const tool = createSessionsYieldTool ( {
59+ sessionId : "test-session" ,
60+ claimYield : ( ) => true ,
61+ onYield,
62+ } ) ;
5163 const result = await tool . execute ( "call-1" , {
5264 message : "Resume after the fact-checker replies" ,
5365 acknowledgment : "Research started; results will follow." ,
@@ -65,12 +77,13 @@ describe("sessions_yield tool", () => {
6577 ) ;
6678 } ) ;
6779
68- it ( "persists yield intent before aborting the requester run" , async ( ) => {
80+ it ( "claims completion ownership before aborting the requester run" , async ( ) => {
6981 const order : string [ ] = [ ] ;
7082 const tool = createSessionsYieldTool ( {
7183 sessionId : "test-session" ,
72- onBeforeYield : ( ) => {
73- order . push ( "persist" ) ;
84+ claimYield : ( ) => {
85+ order . push ( "claim" ) ;
86+ return true ;
7487 } ,
7588 onYield : ( ) => {
7689 order . push ( "abort" ) ;
@@ -79,15 +92,15 @@ describe("sessions_yield tool", () => {
7992
8093 await tool . execute ( "call-1" , { } ) ;
8194
82- expect ( order ) . toEqual ( [ "persist " , "abort" ] ) ;
95+ expect ( order ) . toEqual ( [ "claim " , "abort" ] ) ;
8396 } ) ;
8497
8598 it ( "does not abort the requester when yield intent cannot persist" , async ( ) => {
8699 const failure = new Error ( "sqlite unavailable" ) ;
87100 const onYield = vi . fn ( ) ;
88101 const tool = createSessionsYieldTool ( {
89102 sessionId : "test-session" ,
90- onBeforeYield : ( ) => {
103+ claimYield : ( ) => {
91104 throw failure ;
92105 } ,
93106 onYield,
@@ -97,6 +110,27 @@ describe("sessions_yield tool", () => {
97110 expect ( onYield ) . not . toHaveBeenCalled ( ) ;
98111 } ) ;
99112
113+ it . each ( [
114+ { name : "the claim callback is unavailable" } ,
115+ { name : "the turn owns no pending child completion" , claimYield : ( ) => false } ,
116+ ] ) ( "keeps the turn active when $name" , async ( { claimYield } ) => {
117+ const onYield = vi . fn ( ) ;
118+ const tool = createSessionsYieldTool ( {
119+ sessionId : "test-session" ,
120+ ...( claimYield ? { claimYield } : { } ) ,
121+ onYield,
122+ } ) ;
123+
124+ const result = await tool . execute ( "call-1" , { } ) ;
125+
126+ expect ( result . details ) . toMatchObject ( {
127+ status : "error" ,
128+ error :
129+ "No pending child completion is owned by this turn. Continue working because independent background operations complete separately." ,
130+ } ) ;
131+ expect ( onYield ) . not . toHaveBeenCalled ( ) ;
132+ } ) ;
133+
100134 it ( "returns error without onYield callback" , async ( ) => {
101135 const tool = createSessionsYieldTool ( { sessionId : "test-session" } ) ;
102136 const result = await tool . execute ( "call-1" , { } ) ;
0 commit comments