Refactor backend inference and messages into focused services#11
Merged
Conversation
…to focused services Refactored backend chat/query internals to reduce coupling and isolate responsibilities.\n\nWhat was done:\n- extracted message request helpers, validation, lock/idempotency, and replay utilities\n- moved core /messages orchestration into a dedicated module with a thin router facade\n- split inference logic into technical mode, streaming flow, and message-construction modules\n- separated model routing and quality-escalation paths for clearer control flow\n- preserved compatibility exports used by existing call sites and tests\n- added and wired supporting backend modules for context/stream/quota hardening completed in this sequence
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
sanjeevafk
added a commit
that referenced
this pull request
May 24, 2026
Refactor backend inference and messages into focused services
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.
This pull request introduces several improvements and refactorings to the codebase, focusing on technical debt cleanup, improved error logging, and the introduction of new utility modules. The key changes include the addition of a circuit breaker utility, centralization of constants, improved error handling with structured logging, and the extraction of helper modules and adapter patterns to support ongoing refactoring efforts.
New utility modules and technical debt cleanup:
CircuitBreakerutility inapi/services/circuit_breaker.pyfor rate limiting and protective throttling, encapsulating Redis-backed circuit breaker logic.api/constants.pyto simplify technical debt cleanup and standardize timeouts and TTLs across the codebase.Improved error handling and logging:
api/auth.py,api/routers/payments.py, andapi/services/cache.py, ensuring that failures in cache operations, Supabase lookups, and Redis interactions are logged for observability and debugging. [1] [2] [3] [4] [5] [6] [7] [8]Refactoring and helper extraction:
api/routers/messages_helpers.py, including deduplication, idempotency, lock management, and request validation utilities to improve code organization and maintainability.api/adapters/with a documented strangler pattern and adeprecated_in_favor_ofdecorator to facilitate gradual migration away from legacy modules. [1] [2]Minor improvements and cleanup:
api/services/cache.pyto use the new centralized constants for timeouts and improved naming consistency (safe_json_parseinstead ofsafeJsonParse). [1] [2]api/requirements.txtas part of the technical debt cleanup.These changes collectively improve code quality, observability, and pave the way for further modularization and refactoring.