Skip to content

⚛️ refactor: Move Run Display, Live Attachment and PTC Trace Atoms to Jotai - #17138

Open
berry-13 wants to merge 2 commits into
refactor/chat-event-handlersfrom
refactor/chat-run-atoms
Open

berry-13 wants to merge 2 commits into
refactor/chat-event-handlersfrom
refactor/chat-run-atoms

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

Three pieces of chat run state were still Recoil atoms in the app store: activeRunFamily (the run a pane displays, which audio autoplay keys "already played" on), messageAttachmentsMap (attachments that arrive mid-stream, with its per-conversation selector) and ptcTraceByToolCallId (the live trace of a programmatic tool call's inner calls). The chat package is moving off Recoil one atom at a time, each with every reader and writer.

This converts all three to Jotai with all their consumers: the SSE and resumable bindings, the audio hooks and useClearStates, the attachment preview and message hooks, useChatHelpers, the parts host and useStepHandler. They now live with the stream code that owns them (hooks/SSE/atoms.ts, hooks/SSE/ptc.ts, and the sandbox-starting atom moved beside them to hooks/SSE/sandbox.ts) instead of ~/store, so useSSE, useStepHandler and useAttachmentHandler no longer import Recoil or ~/store at all. No behavior changes. Stacked on #17136.

Type of change

  • Refactor

Testing

Tested environments/configuration:

Not applicable: the atoms hold the same values with the same defaults; only the store changes.

Automated tests:

  • Specs that seeded or read these atoms through Recoil now do it through Jotai, each render on its own store so no state leaks between tests: the audio, attachment preview, attachments, attachment handler, step handler, step equivalence, ExecuteCode and PtcToolTrace specs, and the useResumableSSE.spec.ts setter mock.
  • In client: hooks/SSE, hooks/Chat, hooks/Files, hooks/Messages, hooks/Audio, hooks/Config, the audio input specs, components/Chat/Messages/Content, Providers and data-provider/SSE: 170 suites, 3,422 tests 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 for users. Logout clears activeRunFamily through the Jotai store as it clears the other run atoms.

Checklist

  • I reviewed my own changes
  • Relevant tests have been added or updated
  • 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:01.105924Z 921fbe9 New commits
🔒 Security Review ✅ Completed 2026-10-15T07:35:05.846682Z 73e4426 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 73e44265ba

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +205 to +207
ptcStore.set(ptcTraceByToolCallId(atomKey), EMPTY_PTC_TRACE);
}
knownPtcAtomKeys.current.clear();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Evict reset PTC family members

When a long-lived tab visits conversations containing many PTC invocations, this cleanup replaces each value but never removes the corresponding member from Jotai's atomFamily cache. Because atomFamily retains every parameter in an internal map, clearing knownPtcAtomKeys makes those message/tool keys permanently unreachable by later cleanup, so memory grows across conversation switches despite this boundary being intended to release the atoms. After publishing the empty value to any mounted subscriber, call ptcTraceByToolCallId.remove(atomKey), as the subagent cleanup already does for its dynamic families.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 5d8c3fc: resetPtcAtoms now calls ptcTraceByToolCallId.remove(atomKey) after publishing the empty trace; useStepHandler.spec asserts the eviction.

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