fix: prevent context bleed in thread/topic sessions#53489
fix: prevent context bleed in thread/topic sessions#53489ttfnrob wants to merge 1 commit intoopenclaw:mainfrom
Conversation
Thread and topic sessions were inheriting the full parent group session context via createBranchedSession(). This caused new threads to see orphaned assistant messages and tool results from unrelated conversations in the same group — but NOT the user messages that triggered them. The resulting asymmetric context is confusing and breaks session isolation. The fix: write a clean session file for thread/topic forks instead of branching from the parent transcript. Thread sessions are already isolated by their session key (:topic:/:thread: suffix) and their own JSONL file. The parentSession header is preserved for audit/lineage purposes. Fixes openclaw#758 Reported also on Slack and Telegram forum topics. Co-authored-by: Protostar <protostar@openclaw>
Greptile SummaryThis PR fixes context bleed in thread/topic sessions (Slack threads, Telegram forum topics, Discord threads) by replacing
Confidence Score: 5/5
Reviews (1): Last reviewed commit: "fix: prevent context bleed in thread/top..." | Re-trigger Greptile |
|
Feishu topic mode (group chats with chat_mode=topic) has the same context bleed issue. When creating a new topic thread in a Feishu group, the thread session inherits parent group context via createBranchedSession(), causing orphaned assistant messages and tool results from unrelated conversations to appear in the thread. This breaks session isolation for Feishu topics, same as #758. Please add Feishu to the affected channels list. |
Problem
Thread and topic sessions (Telegram forum topics, Slack threads, Discord threads) were inheriting the full parent group session context via
createBranchedSession(). This caused new threads to see orphaned assistant messages and tool results from unrelated conversations in the same group — but NOT the user messages that triggered them.The resulting asymmetric context is confusing, breaks isolation, and makes it impossible to start clean conversations via threads.
Reproduction steps (as documented in #758):
Root Cause
forkSessionFromParentRuntime()insession-fork.runtime.tscallsmanager.createBranchedSession(leafId)which copies the parent transcript into the thread's JSONL file. The pi-mono branching logic carries assistant messages and tool results but not the user messages that triggered them — producing asymmetric, leaked context in every new thread.Fix
Write a clean session file for thread/topic forks instead of branching from the parent transcript. Thread sessions are already isolated by:
:topic:/:thread:suffix)<sessionId>-topic-<threadId>.jsonl)The
parentSessionheader is preserved in the new file for audit/lineage purposes. Each thread now starts with a clean slate — only workspace bootstrap files (SOUL.md,AGENTS.md, etc.) provide shared context, which is the correct behaviour.Testing
parentSessionfield in the JSONL header preserves the lineage linkRelated