Skip to content

fix: summarize a chat with its own memory prompt, not the open chat's - #6936

Open
Karanvir1729 wants to merge 1 commit into
ChatGPTNextWeb:mainfrom
Karanvir1729:fix/summarize-target-session-memory
Open

Karanvir1729 wants to merge 1 commit into
ChatGPTNextWeb:mainfrom
Karanvir1729:fix/summarize-target-session-memory

Conversation

@Karanvir1729

Copy link
Copy Markdown

💻 变更类型 | Change Type

  • feat
  • fix
  • refactor
  • perf
  • style
  • test
  • docs
  • ci
  • chore
  • build

🔀 变更说明 | Description of Change

Fixes #6935

summarizeSession(refreshTitle, targetSession) summarizes targetSession, but it took the memory prompt from getMemoryPrompt(), which reads the chat on screen (currentSession()). It runs when a reply finishes, so if the user has opened another chat by then, the finished chat's new summary is built from the other chat's memory, and its own earlier summary is lost.

  • getMemoryPrompt takes an optional session. With no argument it still reads the current chat.
  • summarizeSession passes the chat it summarizes.
  • getMessagesWithMemory passes the chat it read the messages from. It calls getMemoryPrompt after await isMcpEnabled(), so it had the same problem if the chat changed during that await. That path was not reproduced.
  • test/summarize-session-memory.test.ts: two chats with different memory prompts, chat B open, summarizeSession(false, chatA). The summary request must carry chat A's memory and not chat B's.

📝 补充信息 | Additional Information

Checks run locally (Node 22):

  • The new test fails on main in 3 of 3 runs (the summary request carries chat B's memory) and passes with this change in 3 of 3. It is synchronous, with no timers, so it does not depend on machine speed.
  • jest --ci (the test:ci script): 37 suites, 175 tests pass.
  • eslint and prettier --check on the two changed files: clean.
  • Other paths, from reading the code (not tested): if the summary request fails, nothing changes compared with before. If chat A is deleted while its reply streams, summarizeSession reads the captured session object and updateTargetSession drops the result, as before. With no argument, getMemoryPrompt() behaves as before.

Reproduction and measurements are in the issue: with the steps there, chat A's summary request carried chat B's memory in 10 of 10 runs, against 0 of 10 when chat B was opened only after the summary was done. With this change applied to the same local setup, the same steps gave 0 of 10.

AI assistance: Claude (Claude Code) investigated this, reproduced it with the measurements above, wrote the fix and the test, ran the checks above, and drafted this description. I have not reproduced it by hand, run the tests or reviewed the fix myself yet.

summarizeSession(refreshTitle, targetSession) took the memory prompt from
getMemoryPrompt(), which reads the chat on screen. When a reply finished
after the user had opened another chat, the finished chat's new summary
was built from the other chat's memory and its own earlier summary was
dropped.

getMemoryPrompt now takes an optional session; summarizeSession passes
the chat it summarizes and getMessagesWithMemory the chat it read the
messages from.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Opening another chat while a reply streams builds this chat's memory prompt from the other chat's memory

1 participant