Skip to content

Refactor backend inference and messages into focused services#11

Merged
sanjeevafk merged 2 commits into
mainfrom
dev
Apr 22, 2026
Merged

Refactor backend inference and messages into focused services#11
sanjeevafk merged 2 commits into
mainfrom
dev

Conversation

@sanjeevafk

@sanjeevafk sanjeevafk commented Apr 22, 2026

Copy link
Copy Markdown
Owner

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:

  • Added a new CircuitBreaker utility in api/services/circuit_breaker.py for rate limiting and protective throttling, encapsulating Redis-backed circuit breaker logic.
  • Centralized commonly used configuration values in api/constants.py to simplify technical debt cleanup and standardize timeouts and TTLs across the codebase.

Improved error handling and logging:

  • Replaced silent exception handling with structured logging in api/auth.py, api/routers/payments.py, and api/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:

  • Extracted message router helper logic into api/routers/messages_helpers.py, including deduplication, idempotency, lock management, and request validation utilities to improve code organization and maintainability.
  • Introduced an adapter layer in api/adapters/ with a documented strangler pattern and a deprecated_in_favor_of decorator to facilitate gradual migration away from legacy modules. [1] [2]

Minor improvements and cleanup:

  • Updated api/services/cache.py to use the new centralized constants for timeouts and improved naming consistency (safe_json_parse instead of safeJsonParse). [1] [2]
  • Removed unused or redundant dependencies from api/requirements.txt as part of the technical debt cleanup.

These changes collectively improve code quality, observability, and pave the way for further modularization and refactoring.

…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
@vercel

vercel Bot commented Apr 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
knowbear Ready Ready Preview, Comment Apr 22, 2026 4:08pm

@sanjeevafk sanjeevafk merged commit a6ac090 into main Apr 22, 2026
6 checks passed
sanjeevafk added a commit that referenced this pull request May 24, 2026
Refactor backend inference and messages into focused services
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant