refactor: unify request errors + add audit log middleware#328
Merged
Destynova2 merged 1 commit intoApr 28, 2026
Merged
Conversation
Replaces the `AppError` + `ProviderError` split with a single `RequestError` enum that carries the upstream HTTP status verbatim (502/503/504) instead of flattening every provider failure to a generic 502 body. Introduces the canonical `RequestError::is_retryable` classifier as the single source of truth for retry/backoff decisions and removes three duplicate 429 detectors from `dispatch/retry.rs`. Also adds an Axum audit-log middleware (`audit_log_layer`) that emits an `AuditEvent::RequestProcessed` entry for every request lifecycle — including OAuth, config, and error paths that previously bypassed audit entirely. Uses an `AuditedAlready` response-extension marker so the dispatch path (which writes a richer DLP/risk/token-aware entry) is not double-logged. Closes the audit gap that allowed silent model enumeration via DLP probes (EU AI Act Article 6 / PCI DSS 3.4). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
AppError+ProviderErrorsplit with a singleRequestErrorenum that carries the upstream HTTP status verbatim (502/503/504) instead of flattening every provider failure to a generic 502 body. New variants:BadRequest,Unauthorized,Forbidden,NotFound,ParseError,RoutingError,RateLimited{provider, retry_after_ms},ProviderUpstream{provider, status, body},BudgetExceeded{limit_usd, actual_usd},DlpBlocked,AuthRevoked,Internal(anyhow::Error).RequestError::is_retryable()is the canonical retry classifier — removes three duplicate 429 detectors fromdispatch/retry.rsand centralises the matcher.audit_log_layer) that emitsAuditEvent::RequestProcessedfor every request — including OAuth, config, and error paths that previously bypassed audit entirely. De-dupes via theAuditedAlreadyresponse-extension marker so the dispatch pipeline (which writes a richer DLP/risk/token-aware entry) is the single source of truth on the hot path. Closes the audit gap that allowed silent model enumeration via DLP probes (EU AI Act Article 6 / PCI DSS 3.4).Test plan
cargo check(default features, all features, no-default-features)cargo clippy --tests --all-targets -- -D warningscargo fmt --checkcargo nextest run— 1357/1357 tests pass on rebased branchRequestError::IntoResponseandis_retryable()covering every variant🤖 Generated with Claude Code