feat(agent): clear missing-package error, opt-in strict, on_error hook (O1/O2)#92
Merged
Conversation
Agent-init failures now degrade gracefully with an actionable message. When guard-agent is absent, to_agent_config raises AgentPackageNotInstalledError (guard-core 3.2.0) and the middleware surfaces "pip install fastapi-guard[agent]" instead of the misleading "check agent_api_key" path. Failures fire the on_error(stage="agent_init") hook and set agent_degraded, exposed via agent_stats; agent_strict=True re-raises for fail-fast deployments. Adds the [agent] optional-dependency extra. Updates IPv6/IPv4 whitelist-vs-blacklist assertions for guard-core 3.2.0 explicit-whitelist-overrides-blacklist precedence (O5).
1de0c8b to
2d40b1a
Compare
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.
Summary
Design-partner feedback O1/O2 (agent-error clarity), fastapi-guard adapter half. Mirrors the guard-core 3.2.0 engine change (#25) and guard-agent transport hook (#20).
When
enable_agent=Truebut theguard-agentpackage is missing,to_agent_config()now raisesAgentPackageNotInstalledError(guard-core 3.2.0). The middleware catches it and surfaces an actionable message —pip install fastapi-guard[agent]— instead of the old misleading "checkagent_api_key" path.Behavior
agent_degraded, and fireon_error(stage="agent_init", exc, {}).agent_strict=Truere-raises, for deployments where the agent is mandatory.agent_stats({"enabled": ..., "degraded": ...}).[agent]optional-dependency extra.Tests
tests/test_middleware/test_agent_init_clarity.py— missing-package fail-soft message,agent_strictraises,on_errorfires withstage="agent_init",agent_statsdegraded, generic-failure fail-soft.Note
Depends on the
AgentPackageNotInstalledErrorsymbol introduced in guard-core 3.2.0. Merge/release alongside the coordinated guard-core 3.2.0 publish.