Skip to content

Conversation

@ulivz
Copy link
Member

@ulivz ulivz commented Sep 8, 2025

Summary

Complete rewrite of session status management - eliminated all manual session status API calls and rely entirely on real-time socket events.

Root Cause

Multiple redundant session status checking mechanisms caused ~318 frequent API calls:

  1. Manual status check in setActiveSessionAction
  2. Periodic status check in useSession hook
  3. Socket request-status emission on joinSession
  4. Unnecessary connectionStatusAtom updates triggering re-renders

Solution

Simplified to socket-only status management:

  • ❌ Removed checkSessionStatusAction entirely
  • ❌ Removed manual status check when switching sessions
  • ❌ Removed periodic status polling in useSession
  • ❌ Removed socket request-status emission
  • ✅ Session status now managed purely through real-time socket events
  • ✅ Prevented unnecessary connection status atom updates
  • ✅ Fixed multiple connection monitoring timers

Result: Session status API calls reduced from ~318 to zero manual calls - status updates only via socket events as intended.

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 8, 2025

Deploy Preview for agent-tars-docs ready!

Name Link
🔨 Latest commit dc20023
🔍 Latest deploy log https://app.netlify.com/projects/agent-tars-docs/deploys/68bed4405971d80008e375bf
😎 Deploy Preview https://deploy-preview-1433--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.

Remove function dependencies from useEffect arrays that were causing
infinite re-renders when creating/switching sessions:
- Remove checkSessionStatus from useSession hook dependencies
- Remove setActiveSession from SessionRouter dependencies
- Fix memoization in useSession to prevent unnecessary re-renders
@ulivz ulivz force-pushed the fix/session-status-frequent-calls branch from 748f56a to d75b74b Compare September 8, 2025 11:48
Previous commit incorrectly removed checkSessionStatus from the
returned object, which would break API consumers. This commit
restores it while keeping the dependency array fix.
Fixed frequent session status API calls by preventing multiple
connection monitoring timers from being started. Used useRef to
ensure initConnectionMonitoring is only called once, and separated
session loading logic into its own effect.
…gistration

Moved handleSessionStatusUpdate logic into useEffect to prevent
frequent socket re-registration. The callback was recreated on every
activeSessionId change, causing joinSession to be called repeatedly
and triggering excessive session status API calls.
Only update connectionStatusAtom when connection status actually
changes. The 30-second health check was updating the atom every
time, causing all dependent useEffects to re-run and trigger
frequent session status API calls.
Removed all manual session status API calls and rely entirely on
socket events for status updates. This eliminates the root cause
of frequent status API calls:

- Removed checkSessionStatusAction
- Removed manual status check in setActiveSessionAction
- Removed periodic status check in useSession
- Removed socket request-status emission

Session status is now managed purely through real-time socket events.
Enhanced error handling when server goes down:
- Added error state display in ChatInput with dismiss button
- Improved session status error handling with connection updates
- Restore user input on network errors for better UX
- Clear error messages when user types or reconnects

Now when server crashes during message sending:
1. User sees clear error message
2. Input content is restored automatically
3. Connection status updates appropriately
4. User can dismiss error and retry
Fixed critical bug where aborted sessions would show as processing
after page refresh:

- Restored checkSessionStatusAction for manual status checking
- Added real status check in setActiveSessionAction on session switch
- Removed forced isProcessing: false that overwrote real status
- Keep socket events as primary status updates, manual check as fallback

Now page refresh correctly shows real session status instead of
wrong cached state.
Fixed critical issues in session status management:

1. Type Safety:
   - Fixed API response type mismatch in checkSessionStatusAction
   - Only use fields that API actually returns (isProcessing, state)
   - Preserve existing status fields when updating from API

2. Duplicate Event Handling:
   - Removed redundant global agent-status listener in useSession
   - Fixed socket listener cleanup in joinSession method
   - Added proper handler reference tracking for cleanup

These fixes prevent runtime errors and ensure status updates
are processed exactly once without conflicts.
@ulivz ulivz changed the title fix(tarko): prevent frequent session status API calls WIP: fix(tarko): prevent frequent session status API calls Sep 8, 2025
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