fix(cli): dedupe Bitwarden BWS_ACCESS_TOKEN warning across subprocesses - #34314
Closed
konsisumer wants to merge 1 commit into
Closed
fix(cli): dedupe Bitwarden BWS_ACCESS_TOKEN warning across subprocesses#34314konsisumer wants to merge 1 commit into
konsisumer wants to merge 1 commit into
Conversation
`hermes` startup spawns child Python processes (gateway, TUI server, ACP adapter) that each call `load_hermes_dotenv()` at import time. The in-process `_APPLIED_HOMES` guard short-circuits repeats within one process, but module state does not survive a subprocess boundary — so users with `secrets.bitwarden.enabled: true` but no `BWS_ACCESS_TOKEN` saw the same "BWS_ACCESS_TOKEN is not set" stderr line 2-3x per startup (NousResearch#32715). Gate the Bitwarden status prints on a new `_HERMES_BWS_STATUS_PRINTED` env var, set on first emit. Subprocesses inherit `os.environ` and skip the prints; sanitization + credential-origin tracking still run unchanged. `reset_secret_source_cache()` clears the marker so tests and long-running processes can force a re-emit. Fixes NousResearch#32715
19 tasks
Contributor
Author
|
Closing — superseded by the consolidated #46641, which folds this PR's change in alongside the related work on the same issue. Reopen if that's not right. |
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?
Dedupes the Bitwarden Secrets Manager status line across the child Python processes spawned during
hermesstartup, so a user withsecrets.bitwarden.enabled: truebut noBWS_ACCESS_TOKENno longer sees the same warning 2–3 times before the interactive session starts.The in-process
_APPLIED_HOMESguard (added in #32271 the day before this issue was filed) already collapses within-process repeats. That guard is module state, so it doesn't survive a subprocess boundary — and the spawned helpers (gateway, TUI server, ACP adapter, ...) each import their entrypoint module which callsload_hermes_dotenv()at import time, so each one re-emitted the warning. This PR adds a cross-process marker viaos.environso siblings inherit it and stay quiet.Functional behavior in each subprocess is unchanged: the config read, the (cached) fetch attempt, the credential injection into
os.environ, the ASCII sanitization pass, and the source-tracking dict update all still run. Only the duplicated stderr noise is suppressed.Related Issue
Fixes #32715
Type of Change
Changes Made
hermes_cli/env_loader.py: introduced_BWS_STATUS_PRINTED_ENV = "_HERMES_BWS_STATUS_PRINTED"; gated the threeprint(" Bitwarden Secrets Manager: ...")call sites on its absence; set it before printing (so a sibling race only lets the first one through); extendedreset_secret_source_cache()to pop the marker so tests and explicit refresh callers can re-emit.tests/test_env_loader_secret_sources.py: addedtest_apply_external_secret_sources_dedupes_across_subprocesses(pre-set marker +enabled: trueconfig → no stderr) andtest_apply_external_secret_sources_prints_warning_once_then_sets_marker(marker absent → warning printed and marker set to"1").How to Test
main: in a freshHERMES_HOME, write~/.hermes/config.yamlwithsecrets:\n bitwarden:\n enabled: true\n project_id: foo\n, ensureBWS_ACCESS_TOKENis unset, runhermes, and confirm thesecrets.bitwarden.enabled is true but BWS_ACCESS_TOKEN is not set...line appears 2–3 times on stderr before the prompt.$VIRTUAL_ENV/bin/pytest tests/test_env_loader_secret_sources.py tests/test_bitwarden_secrets.py tests/hermes_cli/test_env_loader.py -q --timeout=60. The new tests intest_env_loader_secret_sources.pydirectly exercise the cross-process and first-emit behaviors viamonkeypatch.setenv(env_loader._BWS_STATUS_PRINTED_ENV, "1").test_apply_external_secret_sources_records_bitwarden_origin(unchanged); it stubs a successful BSM fetch and assertsget_secret_source("ANTHROPIC_API_KEY") == "bitwarden"still holds, verifying that the gated print sites did not also gate the sanitization / source-tracking work.$VIRTUAL_ENV/bin/ruff check hermes_cli/env_loader.py tests/test_env_loader_secret_sources.pyandruff format --checkboth clean;scripts/check-windows-footguns.pyclean for the two files.What platforms tested on
os.environreads/writes with no platform-specific surface, so behavior is identical on Linux, macOS, native Windows, and WSL2; the inheritance semantics (os.environpropagates acrosssubprocess.Popenon every supported platform) are what the fix relies on.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests pass (ran the env-loader / bitwarden / secret-source slice — 57 passed, 2 skipped)Documentation & Housekeeping
docs/, docstrings) — or N/A (no user-visible config or behavior added; the marker env var is internal, leading underscore)cli-config.yaml.exampleif I added/changed config keys — N/A (no new config keys)CONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/Aos.environpropagation is the same on every supported platform;scripts/check-windows-footguns.pyclean