feat: safe Anthropic disablement via ANTHROPIC_DISABLED flag#4216
feat: safe Anthropic disablement via ANTHROPIC_DISABLED flag#4216
Conversation
Add ANTHROPIC_DISABLED=true guard checks across all Anthropic-dependent components so they fail gracefully with clear error messages rather than silently or with obscure SDK errors. Changes: - fleet/_backends.py: AnthropicBackend raises ConfigurationError when ANTHROPIC_DISABLED=true; auto_detect_backend skips Anthropic and falls back to CopilotBackend; exports ConfigurationError in __all__ - eval/gherkin_agent_evaluator.py: _has_anthropic_api_key() returns False and logs warning when ANTHROPIC_DISABLED=true - agents/goal_seeking/hive_mind/query_expansion.py: replace bare print() with logger.warning(); honour ANTHROPIC_DISABLED flag to force local synonym fallback even when SDK is installed - vendor/blarify/agents/llm_provider.py: guard langchain-anthropic import and RotatingKeyChatAnthropic behind try/except so missing package emits warning rather than crashing at import time - vendor/blarify/agents/rotating_provider/rotating_anthropic.py: guard anthropic import with try/except + warning New tests: - tests/test_gherkin_evaluator_guard.py: covers ANTHROPIC_DISABLED guard in gherkin evaluator - tests/hive_mind/test_query_expansion.py: covers disabled flag and graceful fallback in query_expansion - src/amplihack/fleet/tests/test_backends.py: adds ConfigurationError and auto_detect fallback tests (40 total, all pass) All 40 tests pass. Every disabled path logs at minimum logger.warning with the controlling flag name before failing or falling back. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Wrap self.api_key in a _SecretValue sentinel so the key never appears in repr(), str(), or tracebacks. Use get_secret_value() only at the SDK call site. Also adds test_api_key_masked_in_repr to cover this contract. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ingKeyChatAnthropic - Add ANTHROPIC_DISABLED=true guard to RotatingKeyChatAnthropic.__init__ - Add comprehensive docs/ANTHROPIC_DISABLEMENT.md documentation - Register doc in mkdocs.yml Reference section Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Repo Guardian - Action RequiredTwo files in this PR appear to be ephemeral workstream artifacts that were accidentally committed and do not belong in the repository.
|
| File | Verdict |
|---|---|
docs/ANTHROPIC_DISABLEMENT.md |
✅ Durable reference documentation |
mkdocs.yml |
✅ Config update |
src/amplihack/**/*.py |
✅ Permanent code changes |
tests/**/*.py |
✅ Durable test infrastructure |
To override, add a PR comment containing repo-guardian:override (reason) where (reason) is a required non-empty justification for allowing run.sh and launcher.py in the repository.
Generated by Repo Guardian for issue #4216 · ◷
PR Triage — CI Failure DetectedAtlas PR Impact Check is failing on this PR. This check asserts that atlas layer metadata is kept current when source files change. Affected check: This PR modifies Recommended fix: Run All other checks pass (Validate Code, GitGuardian, docs checks, bot detection). Triage summary:
|
Pre-Merge Cleanup RequiredThe PR contains ~30 Before merge:
The 9 substantive changes (docs/ANTHROPIC_DISABLEMENT.md, run.sh, query_expansion.py, gherkin_agent_evaluator.py, _backends.py, llm_provider.py, rotating_anthropic.py, conftest.py, test_query_expansion.py, test_gherkin_evaluator_guard.py, launcher.py) and PROJECT.md/mkdocs.yml updates look reasonable for the ANTHROPIC_DISABLED flag feature, but the pycache files block clean merge-ready review. Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com |
Review summaryVerdict: Functional assessment ✅All four ANTHROPIC_DISABLED guard sites work correctly:
Test coverage is adequate. Documentation ( Blocking issues 🛑
Plus
Cross-ecosystemNot directly applicable to amplihack-rs (no Anthropic Python SDK dependency). However, the pattern (explicit disablement flag → early ConfigurationError → fallback to Copilot) is worth porting to any Rust LLM-backend selection if/when added; Recommended pathclean .pyc + drop ws-4215 cruft → revert PROJECT.md → rebase → merge. Core change is good; just hygiene. |
Closes #4215
Summary
Implements a safe disablement strategy for all Anthropic-dependent components via
ANTHROPIC_DISABLED=trueenvironment variable.Changes
fleet/_backends.py:AnthropicBackendraisesConfigurationErrorwhen disabled;auto_detect_backend()falls back toCopilotBackend;_SecretValuewrapper prevents API key leakage in repr/tracebackseval/gherkin_agent_evaluator.py:_has_anthropic_api_key()returnsFalseand logs warning when disabledagents/goal_seeking/hive_mind/query_expansion.py: honours flag; uses local synonym fallback when disabledvendor/blarify/agents/llm_provider.py: guarded langchain-anthropic import with try/exceptvendor/blarify/agents/rotating_provider/rotating_anthropic.py: guarded anthropic import with try/except + warningTests
41 tests pass (new tests in
tests/test_gherkin_evaluator_guard.py,tests/hive_mind/test_query_expansion.py,src/amplihack/fleet/tests/test_backends.py)Docs
docs/ANTHROPIC_DISABLEMENT.md— full operator guideCo-authored-by: Copilot 223556219+Copilot@users.noreply.github.com