14
14
)
15
15
from pydantic .json import pydantic_encoder
16
16
17
+ from openhands .core .logger import openhands_logger as logger
17
18
from openhands .events .action .action import Action
18
19
from openhands .events .action .commands import CmdRunAction
19
20
from openhands .events .stream import EventStream
@@ -268,7 +269,9 @@ async def get_env_vars(
268
269
get_latest: Get the latest working token for the providers if True, otherwise get the existing ones
269
270
"""
270
271
271
- if not self .provider_tokens :
272
+ # TODO: We should remove `not get_latest` in the future. More
273
+ # details about the error this fixes is in the next comment below
274
+ if not self .provider_tokens and not get_latest :
272
275
return {}
273
276
274
277
env_vars : dict [ProviderType , SecretStr ] = {}
@@ -289,6 +292,20 @@ async def get_env_vars(
289
292
if token :
290
293
env_vars [provider ] = token
291
294
295
+ # TODO: we have an error where reinitializing the runtime doesn't happen with
296
+ # the provider tokens; thus the code above believes that github isn't a provider
297
+ # when it really is. We need to share information about current providers set
298
+ # for the user when the socket event for connect is sent
299
+ if ProviderType .GITHUB not in env_vars and get_latest :
300
+ logger .info (
301
+ f'Force refresh runtime token for user: { self .external_auth_id } '
302
+ )
303
+ service = GithubServiceImpl (
304
+ external_auth_id = self .external_auth_id ,
305
+ external_token_manager = self .external_token_manager ,
306
+ )
307
+ env_vars [ProviderType .GITHUB ] = await service .get_latest_token ()
308
+
292
309
if not expose_secrets :
293
310
return env_vars
294
311
0 commit comments