Skip to content

fix(ltm): Retain per-user contexts when enabling dialogue isolation#7179

Closed
Reisenbug wants to merge 2 commits intoAstrBotDevs:masterfrom
Reisenbug:fix/ltm-preserve-contexts-on-unique-session-2
Closed

fix(ltm): Retain per-user contexts when enabling dialogue isolation#7179
Reisenbug wants to merge 2 commits intoAstrBotDevs:masterfrom
Reisenbug:fix/ltm-preserve-contexts-on-unique-session-2

Conversation

@Reisenbug
Copy link
Copy Markdown
Contributor

@Reisenbug Reisenbug commented Mar 30, 2026

开启群聊上下文感知的主动回复时,on_req_llm 会无条件执行 req.contexts = [], 导致对话隔离(unique_session)维护的 per-user 对话历史被清空,对话隔离无效

Modifications / 改动点

astrbot/builtin_stars/astrbot/long_term_memory.py: 仅在 unique_session 未开启时清空 req.contexts。开启时保留 per-user contexts,使其与群聊上下文背景并存。

  • This is NOT a breaking change. / 这不是一个破坏性变更。

逻辑错误,无报错日志。可通过在 on_req_llm 执行前后打印 req.contexts 验证:unique_session 开启时执行后 contexts 不再被清空

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Bug Fixes:

  • Ensure unique_session conversation contexts are not cleared when active reply is enabled, so per-user dialog isolation remains effective.

@auto-assign auto-assign bot requested review from Fridemn and Raven95676 March 30, 2026 07:38
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Mar 30, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot bot added the area:core The bug / feature is about astrbot's core, backend label Mar 30, 2026
@Reisenbug Reisenbug changed the title fix(ltm): preserve contexts when unique_session is enabled fix(ltm): Retain per-user contexts when enabling dialogue isolation Mar 30, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a unique_session configuration to conditionally prevent clearing request contexts when active reply is enabled. However, the current implementation incorrectly attempts to retrieve this setting from a processed configuration object that lacks the required key, making the feature non-functional. A suggestion was provided to correctly access the configuration via the context.

@Reisenbug Reisenbug closed this Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant