Skip to content

🗂️ refactor: Split useEventHandlers by Responsibility - #17136

Open
berry-13 wants to merge 1 commit into
refactor/chat-resume-on-loadfrom
refactor/chat-event-handlers
Open

berry-13 wants to merge 1 commit into
refactor/chat-resume-on-loadfrom
refactor/chat-event-handlers

Conversation

@berry-13

Copy link
Copy Markdown
Collaborator

Pull Request

Before submitting, please review the Contributing Guide.

Documentation changes belong in the LibreChat documentation repository.

Summary

useEventHandlers.ts (1,352 lines) held every handler the chat stream renders through: the turn-opening ones (legacy text, sync, created, title), the final handler, the error, cancel and abort paths, the pure error-turn builders, and the setup that wires the step, content and attachment handlers. One file for all of it made each handler hard to review and kept the file far over the chat package's size budget.

This splits it by responsibility in client/src/hooks/SSE/: turns.ts (the error-turn builders and the conversation title rule), useTurnHandlers (text, sync, created, title), useFinalHandler (the final handler and the early-abort restore), and useAbortHandlers (error, cancel and abort). They share one EventHandlerContext (handlers.ts) that useEventHandlers builds from the values it already read; useEventHandlers.ts keeps that setup and is now 277 lines, every new file under 400. No behavior changes. Stacked on #17134.

Open PRs #17020 and #16451 touch finalHandler and the subagent reset in this file; their changes apply unchanged to the moved code in useFinalHandler.ts and useEventHandlers.ts.

Type of change

  • Refactor

Testing

Tested environments/configuration:

Not applicable: the handlers are moved, not changed.

Automated tests:

  • useEventHandlers.spec.ts imports resolveErrorTurn from turns.ts; nothing else in the specs changed.
  • In client, the hooks/SSE specs (useEventHandlers, its cancel spec, titles, workspace, useResumableSSE, transport) plus hooks/Chat and data-provider/SSE: 1148 pass.
  • npx tsc --noEmit in client, eslint, prettier and sort-imports on the changed files: clean.

Screenshots / recordings

No user-facing change.

Risk / compatibility

None.

Checklist

  • I reviewed my own changes
  • Existing relevant tests pass
  • The change does not introduce new warnings or errors

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T19:41:54.019570Z 8f31f21 New commits
🔒 Security Review ✅ Completed 2026-10-15T07:24:05.083857Z c1024f9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codegraph-librechat codegraph-librechat Bot added the 🗺️ Chat State codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) label Oct 15, 2026
@berry-13
berry-13 force-pushed the refactor/chat-event-handlers branch from c1024f9 to 2900a42 Compare October 15, 2026 15:53
@berry-13
berry-13 added this pull request to stack #17153 October 15, 2026 16:13
@berry-13
berry-13 force-pushed the refactor/chat-event-handlers branch from 2900a42 to 8f31f21 Compare October 16, 2026 19:38
Copilot AI balanced review requested due to automatic review settings October 16, 2026 19:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

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

Labels

🗺️ Chat State codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants