Skip to content

[Fix] Fix room resolution and proxy configuration issues#568

Merged
dingyi222666 merged 4 commits into
v1-devfrom
fix/room-resolve
Sep 30, 2025
Merged

[Fix] Fix room resolution and proxy configuration issues#568
dingyi222666 merged 4 commits into
v1-devfrom
fix/room-resolve

Conversation

@dingyi222666
Copy link
Copy Markdown
Member

This PR fixes critical issues with room resolution logic, middleware initialization, and proxy configuration validation.

Bug Fixes

  • Fix template clone room visibility check to properly filter non-direct sessions
  • Fix middleware initialization timing by moving setup to ready event
  • Fix message_delay middleware dependency chain (now runs after check_room)
  • Fix proxy configuration to validate empty addresses and prevent runtime errors
  • Fix model type checking to use ModelType.llm instead of ModelType.all
  • Auto-create rooms for direct messages regardless of autoCreateRoomFromUser setting

Other Changes

  • Add chatluna_docstore table cleanup in wipe middleware
  • Improve proxy error messages with helpful hints
  • Simplify proxy logging output
  • Fix config schema for blackList default value
  • Bump core version to 1.3.0-alpha.48 and update peer dependencies across all packages

- Fix template clone room visibility check to require non-direct sessions
- Move middleware setup to ready event to ensure proper initialization order
- Update message_delay middleware to run after check_room instead of resolve_room
- Fix room checking logic and improve comment clarity
- Auto-create rooms for direct messages regardless of autoCreateRoomFromUser setting
- Use ModelType.llm instead of ModelType.all when checking available models
- Add chatluna_docstore table cleanup in wipe middleware

These changes ensure proper room resolution for template clone rooms and fix
middleware initialization timing issues that could cause inconsistent behavior.
- Add validation to reject empty proxy addresses with warning message
- Fix config schema for blackList default value
- Simplify proxy logging to show configured address
- Improve proxy protocol error message with helpful hint
- Use logical OR operator for consistent null coalescing

These changes prevent runtime errors from invalid proxy configurations
and provide better feedback when proxy settings are misconfigured.
Update core package version and peer dependency references across all
adapter and service packages to maintain version consistency.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 30, 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.

Walkthrough

本次变更调整了房间可见性与自动创建逻辑(含直聊场景)、消息延迟中间件的执行时序与返回、启动流程中间件初始化时机、配置项默认值声明、代理地址校验与日志,以及系统清理流程中新增表清理。

Changes

Cohort / File(s) Summary
房间与可见性/创建逻辑
packages/core/src/chains/rooms.ts, packages/core/src/middlewares/room/resolve_room.ts, packages/core/src/middlewares/room/check_room.ts
反转了 template_clone 在直聊(session.isDirect)判定中的条件;resolve_room 改为查询 LLM 类型模型以判断可用性;扩展了在直聊或 autoCreateRoomFromUser 时自动创建私有/主房间并设置 roomMasterId、visibility、name;小幅注释文字调整,控制流大体保留。
消息延迟中间件时序与返回
packages/core/src/middlewares/chat/message_delay.ts
在无消息队列或存在命令时明确返回 CONTINUE(忽略延迟);将该中间件从 resolve_room 之后移动到 check_room 之后运行,其他链路顺序保持。
启动与代理设置
packages/core/src/index.ts, packages/core/src/utils/request.ts
将 setupMiddleware 调用移入应用 ready 回调;setupProxy 中代理地址选择由 ?? 改为 `
配置默认值声明
packages/core/src/config.ts
blackList schema 从 Schema.computed(Schema.boolean()).default(false) 改为 Schema.computed(Schema.boolean().default(false)).default(false)(内层 boolean 也有默认)。
系统清理流程
packages/core/src/middlewares/system/wipe.ts
在现有的 chathub_* 表清理后新增删除 chatluna_docstore 表的步骤,其他流程不变。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Gateway as 入口/事件
  participant Chain as 中间件链
  participant CheckRoom as check_room
  participant Delay as message_delay
  participant Cmd as lifecycle-handle_command

  User->>Gateway: 收到消息
  Gateway->>Chain: 触发处理
  Chain->>CheckRoom: 校验房间
  Note right of CheckRoom: 新群允许先执行命令的分支未变
  CheckRoom-->>Chain: 结果/继续
  Chain->>Delay: 延迟逻辑(新位置)
  alt 未启用队列 或 有命令
    Delay-->>Chain: CONTINUE(不延迟)
  else 需延迟
    Delay-->>Chain: 延时后继续
  end
  Chain->>Cmd: 命令处理
Loading
sequenceDiagram
  autonumber
  actor User
  participant Resolve as resolve_room
  participant Model as 模型查询(LLM)
  participant Store as 房间存储

  User->>Resolve: 进入/发送消息
  Resolve->>Model: 查询可用模型 (type=LLM)
  Model-->>Resolve: 可用/不可用
  alt 直聊 或 autoCreateRoomFromUser=true
    Resolve->>Store: 创建私有/主房间 (clone template)
    Note right of Resolve: 设置 roomMasterId、visibility、name 等
  else 已存在或无需创建
    Resolve-->>User: 使用既有房间
  end
  Resolve-->>User: 返回房间信息
Loading
sequenceDiagram
  autonumber
  participant App as 应用入口
  participant Ready as ready 回调
  participant MW as setupMiddleware
  participant Proxy as setupProxy / setGlobalProxyAddress

  App->>Ready: 启动完成
  Ready->>MW: 初始化中间件(新时机)
  Ready->>Proxy: 初始化代理
  Proxy-->>Ready: 日志输出/校验(空值早退/协议提示)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

我在字节田里跳三下,蹦两下,
直聊一唤,新房悄然长起。
延迟甩尾,命令先跑去,
代理风轻,日志轻声说话。
清表如扫叶——咔嚓、咔嚓。 🐇✨

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 (2 passed)
Check name Status Explanation
Title Check ✅ Passed PR 标题 “[Fix] Fix room resolution and proxy configuration issues” 涉及房间解析和代理配置的核心修复,与此次 PR 中的问题修复相符,但并未涵盖中间件初始化时机、消息延迟顺序、模型类型校验等其他重要修复,因此虽部分相关但未能全面总结改动的主要内容。
Description Check ✅ Passed PR 描述对房间解析逻辑、中间件初始化时机、消息延迟中间件顺序、代理配置校验、模型类型检查及其他变更等内容进行了清晰罗列,与实际更改保持一致,能够帮助审查者快速了解此次多项修复和改进,因此通过检查。
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/room-resolve

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0840804 and 340b90f.

📒 Files selected for processing (1)
  • packages/core/src/utils/request.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/utils/request.ts

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
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

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

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @dingyi222666, 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 delivers a series of critical bug fixes and minor enhancements aimed at improving the stability and functionality of the chatluna plugin ecosystem. The changes primarily focus on refining room management logic, ensuring correct middleware execution, and strengthening proxy configuration validation. These updates collectively contribute to a more robust and predictable user experience within the Koishi framework.

Highlights

  • Room Resolution & Visibility: Fixed issues with template clone room visibility to correctly filter non-direct sessions and ensured direct messages always auto-create rooms, regardless of the autoCreateRoomFromUser setting.
  • Middleware Timing & Dependencies: Corrected middleware initialization timing by moving the setup to occur after the ready event, and adjusted the message_delay middleware's dependency to run after check_room.
  • Proxy Configuration Robustness: Improved proxy configuration by adding validation for empty addresses, simplifying logging output, and enhancing error messages for unsupported proxy protocols.
  • Configuration & Model Type Checks: Fixed the blackList configuration schema to correctly apply its default value and updated model type checking to specifically use ModelType.llm instead of ModelType.all.
  • Database Cleanup: Included the chatluna_docstore table in the system wipe middleware for more comprehensive database cleanup operations.
  • Version & Dependency Updates: Bumped the core koishi-plugin-chatluna package version to 1.3.0-alpha.48 and updated its peer dependencies across all associated adapter and service packages.
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.

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 series of important bug fixes and improvements, particularly around room resolution, middleware initialization, and proxy configuration. The changes are well-targeted and address the described issues effectively. I have one suggestion in packages/core/src/utils/request.ts to make the proxy address validation logic more concise and robust. Overall, this is a solid set of fixes that enhances the stability and usability of the plugin.

Comment thread packages/core/src/utils/request.ts Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/core/src/config.ts (1)

100-102: 移除嵌套 default(false),仅保留外层 default(false)
在 packages/core/src/config.ts 第 100 行,将

blackList: Schema.computed(Schema.boolean().default(false)).default(false)

改为

blackList: Schema.computed(Schema.boolean()).default(false)

以保持与其他 Schema.computed 用法(一层 default)一致。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 44985ec and 0840804.

⛔ Files ignored due to path filters (26)
  • packages/azure-openai-adapter/package.json is excluded by !**/*.json
  • packages/claude-adapter/package.json is excluded by !**/*.json
  • packages/core/package.json is excluded by !**/*.json
  • packages/deepseek-adapter/package.json is excluded by !**/*.json
  • packages/dify-adapter/package.json is excluded by !**/*.json
  • packages/doubao-adapter/package.json is excluded by !**/*.json
  • packages/embeddings-service/package.json is excluded by !**/*.json
  • packages/gemini-adapter/package.json is excluded by !**/*.json
  • packages/hunyuan-adapter/package.json is excluded by !**/*.json
  • packages/image-renderer/package.json is excluded by !**/*.json
  • packages/image-service/package.json is excluded by !**/*.json
  • packages/long-memory/package.json is excluded by !**/*.json
  • packages/mcp-client/package.json is excluded by !**/*.json
  • packages/ollama-adapter/package.json is excluded by !**/*.json
  • packages/openai-adapter/package.json is excluded by !**/*.json
  • packages/openai-like-adapter/package.json is excluded by !**/*.json
  • packages/plugin-common/package.json is excluded by !**/*.json
  • packages/qwen-adapter/package.json is excluded by !**/*.json
  • packages/rwkv-adapter/package.json is excluded by !**/*.json
  • packages/search-service/package.json is excluded by !**/*.json
  • packages/shared/package.json is excluded by !**/*.json
  • packages/spark-adapter/package.json is excluded by !**/*.json
  • packages/variable-extension/package.json is excluded by !**/*.json
  • packages/vector-store-service/package.json is excluded by !**/*.json
  • packages/wenxin-adapter/package.json is excluded by !**/*.json
  • packages/zhipu-adapter/package.json is excluded by !**/*.json
📒 Files selected for processing (8)
  • packages/core/src/chains/rooms.ts (1 hunks)
  • packages/core/src/config.ts (1 hunks)
  • packages/core/src/index.ts (2 hunks)
  • packages/core/src/middlewares/chat/message_delay.ts (2 hunks)
  • packages/core/src/middlewares/room/check_room.ts (2 hunks)
  • packages/core/src/middlewares/room/resolve_room.ts (2 hunks)
  • packages/core/src/middlewares/system/wipe.ts (1 hunks)
  • packages/core/src/utils/request.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/core/src/utils/request.ts (2)
packages/core/src/index.ts (1)
  • logger (38-38)
packages/core/src/utils/error.ts (1)
  • ChatLunaError (13-41)
🔇 Additional comments (10)
packages/core/src/middlewares/system/wipe.ts (1)

46-46: 无需添加额外错误处理
chatluna_docstore 表已在 ChatLunaPluginctx.database.extend('chatluna_docstore', …) 中定义并注册,确保在清理中间件执行前必然存在,与其他表的处理方式一致。批准该更改。

packages/core/src/utils/request.ts (2)

80-83: 代理地址验证逻辑正确。

新增的空地址校验可以有效防止无效代理配置,并通过警告日志提示用户。早期返回避免了后续不必要的处理。


90-90: 错误提示信息改进得当。

添加了 "Try add http:// or socks" 的提示,能够更好地指导用户修正代理协议配置错误。

packages/core/src/middlewares/room/check_room.ts (1)

18-18: 注释优化,无功能性变更。

仅对中文注释进行了微调,逻辑保持不变。

Also applies to: 27-27

packages/core/src/middlewares/chat/message_delay.ts (2)

31-32: 显式返回 CONTINUE 提升了代码可读性。

明确返回状态并添加注释说明忽略命令执行或延时未开启的情况,使逻辑更清晰。


130-130: 确认 message_delaycheck_room 顺序兼容
message_delay 仅依赖 context.commandconfig.messageQueue,不使用 context.options.room 且无其他中间件依赖该锚点,顺序调整后功能保持一致。

packages/core/src/index.ts (2)

79-79: 中间件初始化时机调整合理。

setupMiddleware 移至 ready 事件处理函数内执行,确保中间件在所有组件初始化完成后再设置,修复了时序问题。这与 PR 目标中提到的"将中间件初始化移至 ready 事件"一致。


146-148: 请确认 setGlobalProxyAddress 的空字符串处理
config.proxyAddress 在 schema 中默认值为 '',而 || 会把所有假值(包括空字符串)回退到 ctx.http.config.proxyAgent。请检查 packages/core/src/index.tssetGlobalProxyAddress(约第80–83行)在接收到空字符串时是否已做早期返回,避免行为差异。

packages/core/src/middlewares/room/resolve_room.ts (2)

150-151: 正确的模型类型检查

将模型可用性检查从 ModelType.all 改为 ModelType.llm 是正确的。聊天功能只需要 LLM 模型,使用 ModelType.all 会包含嵌入模型等不相关类型,可能导致误判。


170-225: 确认直聊场景始终创建私有房间并移除冗余判断

  • config.autoCreateRoomFromUser || session.isDirect 逻辑确保直聊场景(session.isDirect = true)无论配置如何均走私有房间分支,else 分支仅用于群聊模板克隆。
  • else 分支内对 session.isDirect 的嵌套三元判断在此条件下恒为 false,可删除以简化逻辑。
  • 请确认预期行为:直聊会话仅创建 visibility = 'private',群聊才创建 visibility = 'template_clone'

Comment thread packages/core/src/chains/rooms.ts
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.

1 participant