Skip to content

fix(tarko): prevent frequent api/v1/models calls by memoizing callbacks#1378

Merged
ulivz merged 3 commits intomainfrom
fix/models-api-frequent-calls
Sep 8, 2025
Merged

fix(tarko): prevent frequent api/v1/models calls by memoizing callbacks#1378
ulivz merged 3 commits intomainfrom
fix/models-api-frequent-calls

Conversation

@ulivz
Copy link
Member

@ulivz ulivz commented Sep 4, 2025

Summary

Fixed frequent API calls to api/v1/models during SSE responses by optimizing callback function memoization in NavbarModelSelector. The issue was caused by unstable function references triggering unnecessary re-renders and API calls.

image

Root cause: Arrow functions () => apiService.getAvailableModels() and (sessionId, provider, modelId) => apiService.updateSessionModel(sessionId, provider, modelId) were being created on every render, causing the useEffect dependency array to trigger repeatedly.

Solution:

  1. Moved API calls directly into the component with useCallback for stable function references
  2. Optimized handleModelChange dependencies to only include activeSessionId
  3. Removed unnecessary prop drilling of callback functions

Performance impact: Eliminates infinite API call loops while maintaining full functionality.

Checklist

  • Added or updated necessary tests (Optional).
  • Updated documentation to align with changes (Optional).
  • Verified no breaking changes, or prepared solutions for any occurring breaking changes (Optional).
  • My change does not involve the above items.

@netlify
Copy link

netlify bot commented Sep 4, 2025

Deploy Preview for agent-tars-docs ready!

Name Link
🔨 Latest commit b6a267f
🔍 Latest deploy log https://app.netlify.com/projects/agent-tars-docs/deploys/68be88a4d4a248000828da10
😎 Deploy Preview https://deploy-preview-1378--agent-tars-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@ulivz ulivz force-pushed the fix/models-api-frequent-calls branch from 459d695 to b6a267f Compare September 8, 2025 07:41
@ulivz ulivz changed the title fix(tarko): prevent frequent api/v1/models calls by memoizing callbacks fix(tarko): prevent frequent api/v1/models calls by memoizing callbacks Sep 8, 2025
@ulivz ulivz merged commit e07ec41 into main Sep 8, 2025
10 checks passed
@ulivz ulivz deleted the fix/models-api-frequent-calls branch September 8, 2025 07:55
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

Comments