Skip to content

feat(agent): clear missing-package error, opt-in strict, on_error hook (O1/O2)#92

Merged
rennf93 merged 1 commit into
masterfrom
feat/agent-init-clarity
Jun 23, 2026
Merged

feat(agent): clear missing-package error, opt-in strict, on_error hook (O1/O2)#92
rennf93 merged 1 commit into
masterfrom
feat/agent-init-clarity

Conversation

@rennf93

@rennf93 rennf93 commented Jun 23, 2026

Copy link
Copy Markdown
Owner

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=True but the guard-agent package is missing, to_agent_config() now raises AgentPackageNotInstalledError (guard-core 3.2.0). The middleware catches it and surfaces an actionable message — pip install fastapi-guard[agent] — instead of the old misleading "check agent_api_key" path.

Behavior

  • Fail-soft by default: agent-init failures log + continue, set agent_degraded, and fire on_error(stage="agent_init", exc, {}).
  • Opt-in fail-fast: agent_strict=True re-raises, for deployments where the agent is mandatory.
  • Observable: degraded state is exposed via agent_stats ({"enabled": ..., "degraded": ...}).
  • New [agent] optional-dependency extra.

Tests

  • New tests/test_middleware/test_agent_init_clarity.py — missing-package fail-soft message, agent_strict raises, on_error fires with stage="agent_init", agent_stats degraded, generic-failure fail-soft.
  • Updated IPv6/IPv4 whitelist-vs-blacklist assertions for guard-core 3.2.0 explicit-whitelist-overrides-blacklist precedence (O5).
  • Full suite: 242 passed, 100% line + branch coverage, zero warnings.

Note

Depends on the AgentPackageNotInstalledError symbol introduced in guard-core 3.2.0. Merge/release alongside the coordinated guard-core 3.2.0 publish.

@github-actions github-actions Bot added dependencies pyproject.toml or uv.lock area: middleware Touches guard/middleware.py (ASGI middleware adapter) tests Test suite changes labels Jun 23, 2026
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).
@rennf93 rennf93 force-pushed the feat/agent-init-clarity branch from 1de0c8b to 2d40b1a Compare June 23, 2026 07:11
@rennf93 rennf93 merged commit ec57236 into master Jun 23, 2026
11 checks passed
@rennf93 rennf93 deleted the feat/agent-init-clarity branch June 23, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: middleware Touches guard/middleware.py (ASGI middleware adapter) dependencies pyproject.toml or uv.lock tests Test suite changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant