Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

xavierliang
Copy link

@xavierliang xavierliang commented Aug 17, 2025

Summary

This PR supersedes and replaces #159. It includes all improvements from #159 (stabilizing streaming message rendering and post-completion sync), and adds a robust Sidebar refresh mechanism for newly created sessions.

Brought over from #159

  • Streaming ownership guard: render incremental updates only for the active session using activeCursorStreamSessionIdRef and pendingCursorViewingSessionIdRef.
  • Auto-navigation stabilization: when session-created arrives, auto-navigate only from / and avoid double-handling by advancing the processed index before returning.
  • Post-completion authoritative sync (Cursor): after cursor-result, silently reload and replace history if the fetched log is richer or differs.
  • Prevent cross-session contamination and flicker during streaming; preserve current chat state when background updates arrive.

New in this PR

  • Sidebar refresh on session-created: schedule a single delayed refresh (same behavior as clicking the Sidebar refresh button), and cancel it if an incoming projects_updated already includes the new session.
  • Relax additive-update guard so Sidebar updates remain visible during active sessions (Cursor always treated as additive; Claude checks by id only).

Related issues

Test plan

  • Create new session → Sidebar shows the new session once; no infinite refresh.
  • Switch to another session while creating a new one → background refresh still occurs; no UI flicker; selected session unaffected.
  • Stream long outputs → increments only render for the correct session; no contamination across sessions.
  • After completion (Cursor), history silently reloaded and replaced only when richer/different.

- Live updates: incremental WS processing with immutable updates; dedupe final text; lock streaming ownership to the intended session; ignore increments when viewing another session; stable keys. (Claude unaffected)
- Post-completion sync: after cursor-result, silently reload authoritative session history and replace only if richer/different; guard by current viewed session and clear timers on session change.

File: src/components/ChatInterface.jsx
…n init

- Only navigate to /session/:id when current URL is '/'
- Avoid clearing selectedSession for Cursor when projects_updated lacks cursorSessions
- Sidebar refresh now also fetches cursorSessions to update sessions list properly

This addresses rapid page switches (flashing) and stale sidebar sessions.
- On receiving session-created with a sessionId, if current URL is '/',
  navigate to /session/:id and mark as system session change to preserve
  current chat content. This matches manual clicking behavior and stops
  the flicker loop.
- Navigate once to /session/:id when at '/' using a ref guard
- Avoid await/prefetch to prevent async issues and request bursts
- Remove automatic /api/cursor/config fetch from ChatInterface
- Mount only active tab (Files/Shell/Git not mounted on Chat)
- Avoid auto refreshProjects calls after cursor session completes
…n-update

- Trigger the exact same logic as clicking the Sidebar refresh button (`handleSidebarRefresh`) when a new real session id arrives via WebSocket.
- Schedule a single delayed refresh (800ms) to avoid racing backend persistence; cancel the pending refresh if a `projects_updated` containing the session arrives first.
- Loosen additive-update guard so Sidebar can update during active sessions (Cursor always additive; Claude checks existence by id only).
- Prevent WS message reprocessing loop in ChatInterface by advancing processed index before early return on auto navigation.
@xavierliang xavierliang changed the title fix(sidebar): refresh on session-created; stabilize streaming message render fix(sidebar): refresh on session-created; stabilize streaming and navigation (supersedes #159) Aug 17, 2025
@viper151
Copy link
Contributor

@xavierliang Can you check if the PR is still needed with the v1.8.1 changes in the sessions ?

@xavierliang
Copy link
Author

Yes, it's still needed

@viper151
Copy link
Contributor

@xavierliang thanks. are you able to resolve the conflicts and test it again?

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.

Bug: Incomplete message rendering during live stream (corrects on refresh)
2 participants