File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed
packages/runner/src/builtins Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -358,6 +358,8 @@ async function invokeToolCall(
358358 await ensureSourceCharmRunning ( runtime , charmMeta ) ;
359359 }
360360
361+ const { resolve, promise } = Promise . withResolvers < any > ( ) ;
362+
361363 // runSynced charm
362364 runtime . editWithRetry ( ( tx ) => {
363365 if ( pattern ) {
@@ -372,12 +374,22 @@ async function invokeToolCall(
372374 }
373375 } ) ;
374376
375- await runtime . idle ( ) ;
376-
377- // If this was a pattern, stop it now that we have the result
378- if ( pattern ) runtime . runner . stop ( result ) ;
377+ if ( pattern ) {
378+ // wait until we know we have the result of the tool call
379+ // not just that the transaction has been comitted
380+ const cancel = result . sink ( ( r ) => {
381+ r !== undefined && resolve ( r ) ;
382+ } ) ;
383+ const resultValue = await promise ;
384+ cancel ( ) ;
379385
380- return { type : "json" , value : result . get ( ) } ;
386+ // stop it now that we have the result
387+ runtime . runner . stop ( result ) ;
388+ return { type : "json" , value : resultValue } ;
389+ } else {
390+ await runtime . idle ( ) ;
391+ return { type : "json" , value : result . get ( ) } ;
392+ }
381393}
382394
383395/**
You can’t perform that action at this time.
0 commit comments