fix(cron): use load_hermes_dotenv so BSM secrets resolve for cron jobs#34041
Open
liuhao1024 wants to merge 1 commit into
Open
fix(cron): use load_hermes_dotenv so BSM secrets resolve for cron jobs#34041liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
cron/scheduler.pyuses baredotenv.load_dotenv()to reload.envbefore each cron job. This skips the BSM (Bitwarden Secrets Manager) resolution thathermes_cli.env_loader.load_hermes_dotenv()provides, so any cron job that needs a BSM-managed credential (Discord token, provider key, etc.) sees the.envplaceholder instead of the real value → HTTP 401.Fix: Replace
from dotenv import load_dotenv; load_dotenv(...)withfrom hermes_cli.env_loader import load_hermes_dotenv; load_hermes_dotenv(hermes_home=_get_hermes_home()). This matches the gateway's own.envloading behavior and activates BSM resolution for cron jobs.Related Issue
Fixes #33465
Type of Change
Changes Made
cron/scheduler.py— Replace bareload_dotenv()withload_hermes_dotenv()in_run_job_impl()(~line 1470)tests/cron/test_scheduler.py— Update 16 mock patches from"dotenv.load_dotenv"to"hermes_cli.env_loader.load_hermes_dotenv"tests/cron/test_cron_profile.py— Update 2monkeypatch.setattrcalls and assertions for new function signature (hermes_home=keyword arg)tests/cron/test_cron_workdir.py— Update 1monkeypatch.setattrcallHow to Test
pytest tests/ -q— all tests should passChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture and workflows — or N/ACode Intelligence
cron/scheduler.py:_run_job_impl(called per cron job, .env reload at ~line 1470)hermes_cli.env_loader.load_hermes_dotenvused in gateway startup (cli.py,gateway/run.py)load_hermes_dotenvinternally handles encoding fallback (_load_dotenv_with_fallback) and env file sanitization, so the explicit try/except UnicodeDecodeError is no longer neededChecklist