Skip to content

fix(frontend): reconnect useMultiSSE when session id changes#7257

Open
wilmerdooley wants to merge 1 commit into
aden-hive:mainfrom
wilmerdooley:oss/issue-6391
Open

fix(frontend): reconnect useMultiSSE when session id changes#7257
wilmerdooley wants to merge 1 commit into
aden-hive:mainfrom
wilmerdooley:oss/issue-6391

Conversation

@wilmerdooley

@wilmerdooley wilmerdooley commented Jun 12, 2026

Copy link
Copy Markdown

Description

The useMultiSSE hook in core/frontend/src/hooks/use-sse.ts only checked whether an agentType key already existed in its connection map, so a session restart that reused the same agent type left the old EventSource connected and never opened one for the new session. This diff tracks the session id alongside each EventSource and reopens the connection when the session id changes (or the agent is removed).

Resolves #6391

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Related Issues

Resolves #6391

Changes Made

  • Store both the EventSource and its sessionId per agent type in the hook's internal map.
  • On each sessions update, close the existing connection when the agentType is removed or its sessionId differs from the desired one.
  • Open a new EventSource for any agent whose session is new or whose sessionId changed, filtering out entries with an empty sessionId.
  • Update the JSDoc on useMultiSSE to reflect the diff-and-reconnect behavior.

Testing

Describe the tests you ran to verify your changes:

  • Manual testing performed

Manually verified by starting a conversation, restarting the agent session, and confirming the frontend closes the old EventSource (logged via the existing [SSE] closing debug line) and opens a new one for the new sessionId, after which streaming responses, typing indicators, and tool call updates resume without a page refresh.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of multi-session connection handling and session lifecycle management.
    • Fixed issues with connection state management when sessions change or are removed.

Signed-off-by: wilmerdooley <wilmerdooley1@gmail.com>
@github-actions

Copy link
Copy Markdown

PR Requirements Warning

This PR does not meet the contribution requirements.
If the issue is not fixed within ~24 hours, it may be automatically closed.

PR Author: @wilmerdooley
Found issues: #6391 (assignees: none)
Problem: The PR author must be assigned to the linked issue.

To fix:

  1. Assign yourself (@wilmerdooley) to one of the linked issues
  2. Re-open this PR

Exception: To bypass this requirement, you can:

  • Add the micro-fix label or include micro-fix in your PR title for trivial fixes
  • Add the documentation label or include doc/docs in your PR title for documentation changes

Micro-fix requirements (must meet ALL):

Qualifies Disqualifies
< 20 lines changed Any functional bug fix
Typos & Documentation & Linting Refactoring for "clean code"
No logic/API/DB changes New features (even tiny ones)

Why is this required? See #472 for details.

@github-actions github-actions Bot added the pr-requirements-warning PR doesn't follow contribution guidelines. Please fix or it will be auto-closed. label Jun 12, 2026
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2e305dac-f5ff-4e68-9687-27b7a2dfcecf

📥 Commits

Reviewing files that changed from the base of the PR and between 3c390c9 and 6549d67.

📒 Files selected for processing (1)
  • core/frontend/src/hooks/use-sse.ts

📝 Walkthrough

Walkthrough

The useMultiSSE hook now properly reconnects when session IDs change for existing agent types. The diffing logic replaces a Set-based check with a Map filtered by non-empty session IDs, detects session changes via direct lookup, and closes or opens EventSources accordingly instead of only checking if an agent type key exists.

Changes

Session ID change detection in SSE reconnection

Layer / File(s) Summary
Session ID change detection and connection lifecycle
core/frontend/src/hooks/use-sse.ts
Updated module documentation and refactored diffing to use a Map keyed by agentType with non-empty sessionIds. The close-loop now detects both removed agents and session ID changes via desired.get(agentType), and the open-loop only creates EventSources for agents in the desired map. Logging is adjusted to report "session changed" vs "removed" based on lookup results.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A session changed, the old one fades,
Map keys whisper where connections trade,
Close the stale, let new ones flow,
Reconnection blooms—now users know! 🌱

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: fixing the useMultiSSE hook to reconnect when the session ID changes, which is the core objective of the pull request.
Linked Issues check ✅ Passed The pull request directly addresses all coding requirements from issue #6391: tracking session IDs alongside EventSource instances and reconnecting when session IDs change.
Out of Scope Changes check ✅ Passed All changes in the pull request are directly related to the stated objectives of issue #6391; no out-of-scope modifications were introduced.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-requirements-warning PR doesn't follow contribution guidelines. Please fix or it will be auto-closed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: useMultiSSE does not reconnect when session ID changes

1 participant