Skip to content

Conversation

@Artuomka
Copy link
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings January 12, 2026 10:12
@Artuomka Artuomka enabled auto-merge January 12, 2026 10:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the TimeoutInterceptor to support different timeout values for AI endpoints versus standard endpoints. AI endpoints require significantly longer timeouts (5-10 minutes) to accommodate longer processing times, while other endpoints maintain the existing 15-second timeout in production.

Changes:

  • Added logic to detect AI endpoints by checking if the request URL includes '/ai/v2/request/'
  • Configured AI endpoints with 300-second (5-minute) timeout in production and 600-second (10-minute) timeout in test environments
  • Maintained existing 15-second and 200-second timeouts for non-AI endpoints in production and test environments respectively

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const timeoutMs = process.env.NODE_ENV !== 'test' ? 15000 : 200000;
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
const request = context.switchToHttp().getRequest();
const isAIEndpoint = request.url.includes('/ai/v2/request/');
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using string matching with includes() for route detection is fragile and may match unintended URLs. Consider using a more robust approach like checking the route path from the controller metadata or using a regular expression with word boundaries to ensure exact path matching.

Suggested change
const isAIEndpoint = request.url.includes('/ai/v2/request/');
const isAIEndpoint = /^\/ai\/v2\/request(\/|$)/.test(request.url);

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +17
const timeoutMs = isAIEndpoint
? process.env.NODE_ENV !== 'test'
? 300000
: 600000
: process.env.NODE_ENV !== 'test'
? 15000
: 200000;
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nested ternary operators make this logic difficult to read and maintain. Consider extracting timeout values into named constants (e.g., AI_TIMEOUT_PROD, AI_TIMEOUT_TEST) and using a more straightforward if-else structure or a lookup object.

Copilot uses AI. Check for mistakes.
@Artuomka Artuomka merged commit 1e610d4 into main Jan 12, 2026
25 checks passed
@Artuomka Artuomka deleted the backend_ai_logs branch January 12, 2026 10:20
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.

2 participants