Skip to content

fix: keep chat history scoped to each request - #625

Merged
sng-asyncfunc merged 1 commit into
AsyncFuncAI:mainfrom
YoungjaeDev:fix/chat-history-per-request
Nov 7, 2026
Merged

sng-asyncfunc merged 1 commit into
AsyncFuncAI:mainfrom
YoungjaeDev:fix/chat-history-per-request

Conversation

@YoungjaeDev

Copy link
Copy Markdown
Contributor

Summary

Since #619 reuses the RAG object across requests, rag.memory carries chat turns from one request into the next.

 research_chat(request)
   rag = prepare_repo_index(request)   # cached and shared per repo/token/provider/model/filters
-  rag.memory.add_dialog_turn(...)     # accumulates on the shared object
-  history = format(rag.memory())      # includes other requests' turns, and repeats
+  history = format(request.messages)  # this request's turns only
   prompt = prompt_builder(history, context, query)

Memory and CustomConversation had no other users, so they are removed. The <turn> format and the user/assistant pairing rule are unchanged.

Evidence

tests/backend/services/test_research_chat.py runs the real RAG class and stubs only the embedder, retriever, token count, model config, and streamer.

send(question A, answer A, follow-up A)
send(question B)           -> prompt has no turns from A
send(same conversation)x2  -> each turn appears once
send(Q1, A1, Q2, A2, Q3)   -> Q1 and Q2 in order, Q3 only in <query>
  • Before:

    FAILED test_request_without_history_ignores_earlier_request
    FAILED test_resending_a_conversation_does_not_duplicate_turns
    2 failed, 1 passed
    

    The third test guards turn order, so it passes both before and after.

    After:

    3 passed
    python -m pytest tests/backend tests/test_config.py tests/test_extract_repo_name.py -> 72 passed
    

The model calls are stubbed. This shows what goes into the prompt, not whether a model would have repeated a leaked conversation in its answer.

Merge Danger

Door: two-way

Blast Radius: chat

Wiki generation also calls research_chat, but it sends a single message, so its history is empty. No change to _RAG_CACHE or the Deep Research flow.

research_chat stored each request's prior turns in rag.memory. Since AsyncFuncAI#619 the
RAG object is cached and shared, so turns leaked into other requests and
repeated on resend. Build the history from request.messages and remove the
now-unused Memory class.
@sng-asyncfunc
sng-asyncfunc merged commit 279b383 into AsyncFuncAI:main Nov 7, 2026
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.

2 participants