Skip to content

Conversation

@springtiming
Copy link
Contributor

@springtiming springtiming commented Dec 22, 2025

Fixes #659

Background

When running chatluna.room.clear in a private chat without specifying a room name, the command may incorrectly return “room not found” error

even though the user already has a resolved default room

Root Cause

The resolve_room middleware has already successfully resolved the default room and written it to:

context.options.room

However, in clear_room middleware, the following condition is used:

if (context.options.room_resolve != null) {
}

As long as room_resolve exists (even when name is undefined), the middleware always attempts a second room lookup.
This lookup fails and overwrites the already resolved targetRoom, resulting in a “room not found” error.

Fix

Update the condition in clear_room to only re-resolve the room when targetRoom is still null.

This avoids overriding the default room already resolved by resolve_room and aligns the behavior with delete_room middleware.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @springtiming, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the clear_room middleware that caused "room not found" errors in private chats when a room name was not explicitly provided. By refining the room resolution logic, the change ensures that an already established default room is respected and not inadvertently overwritten by subsequent lookups, thereby improving the reliability and consistency of room management commands.

Highlights

  • Bug Fix: Resolves an issue where the chatluna.room.clear command in private chats (DMs) without a specified room name would incorrectly return a "room not found" error, even when a default room was already resolved.
  • Root Cause Identified: The problem stemmed from the clear_room middleware performing an unnecessary second room lookup if context.options.room_resolve existed, even if its name was undefined. This lookup would overwrite an already resolved default room.
  • Refined Room Resolution Logic: The fix updates the condition in clear_room to only attempt to re-resolve the room if targetRoom is still null. This prevents overriding an already resolved default room and aligns the behavior with the delete_room middleware.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 22, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

概览

修改了 clear_room.ts 中的条件判断逻辑,使得房间解析仅在 targetRoom 为空时才进行。当已提供目标房间时,跳过解析块,保持其他流程不变。

变更内容

内容分类 / 文件 变更摘要
房间清除中间件修复
packages/core/src/middlewares/room/clear_room.ts
调整房间解析条件:将无条件解析改为仅在 targetRoomnull 时执行,避免重复解析已提供的目标房间,修复私聊状态下无法清除房间上下文的问题

估计代码审查工作量

🎯 2 (简单) | ⏱️ ~5-8 分钟

需关注的重点:

  • 验证条件判断逻辑是否完全涵盖所有路径分支
  • 确保空值检查在后续代码中仍然有效

可能相关的拉取请求

诗歌

🐰 一只兔子修复了房间的秘密,
条件判断勿重复,才能设置终极!
私聊清除不再难,targetRoom 为空才扫描,
代码简洁又高效,这次修复真漂亮~

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确总结了主要变化:改进clear_room中间件的房间解析逻辑。
Linked Issues check ✅ Passed 代码变更符合#659的目标:修复在私聊中不指定房间名称时clear命令的失败问题。
Out of Scope Changes check ✅ Passed 所有变更仅限于clear_room中间件的条件语句改进,完全在#659问题的范围内。
Description check ✅ Passed Pull request description clearly explains the issue, root cause, and fix with code context and comparison to delete_room middleware.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
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 addresses a bug in the clear_room middleware that caused it to incorrectly re-resolve a room, even when one was already available in the context. The fix, which prevents this re-resolution by checking if targetRoom is already set, is correct and effectively solves the issue. I've included one suggestion to further refine the logic for improved efficiency and clarity.

@springtiming
Copy link
Contributor Author

Note: This issue seems to be introduced in PR #656

@dingyi222666 dingyi222666 merged commit 7564c7b into ChatLunaLab:v1-dev Dec 23, 2025
5 checks passed
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] 私聊状态下无法清除房间上下文,显示未找到房间

2 participants