Skip to content

Commit 60196d2

Browse files
authored
(Hotfix): Github token fails to refresh on cloud openhands (#7532)
1 parent b9af018 commit 60196d2

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

openhands/integrations/provider.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
)
1515
from pydantic.json import pydantic_encoder
1616

17+
from openhands.core.logger import openhands_logger as logger
1718
from openhands.events.action.action import Action
1819
from openhands.events.action.commands import CmdRunAction
1920
from openhands.events.stream import EventStream
@@ -268,7 +269,9 @@ async def get_env_vars(
268269
get_latest: Get the latest working token for the providers if True, otherwise get the existing ones
269270
"""
270271

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:
272275
return {}
273276

274277
env_vars: dict[ProviderType, SecretStr] = {}
@@ -289,6 +292,20 @@ async def get_env_vars(
289292
if token:
290293
env_vars[provider] = token
291294

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+
292309
if not expose_secrets:
293310
return env_vars
294311

0 commit comments

Comments
 (0)