Skip to content

fix(agent): merge config defaults via deepAssign on agentcli sync#868

Merged
dingyi222666 merged 1 commit into
ChatLunaLab:v1-devfrom
yabo083:fix/agentcli-sync-config-defaults
May 19, 2026
Merged

fix(agent): merge config defaults via deepAssign on agentcli sync#868
dingyi222666 merged 1 commit into
ChatLunaLab:v1-devfrom
yabo083:fix/agentcli-sync-config-defaults

Conversation

@yabo083
Copy link
Copy Markdown
Contributor

@yabo083 yabo083 commented May 18, 2026

Summary

  • syncAgentcliConfig now calls agent.reload() without arguments, so the partial config written to disk passes through readConfig and gets merged with defaults instead of being assigned raw
  • readConfig uses deepAssign (from koishi-plugin-chatluna/utils/object) to deep-merge trigger, computer, and subAgent against defaults, so partial saved sections (e.g. computer: {} or missing trigger) no longer wipe out nested defaults

Problem

When the agentcli sandbox writes a partial config.json (e.g. only mcp changes, with "computer": {} or missing trigger), and the user runs chatluna.agent sync:

  1. syncAgentcliConfig previously passed the raw JSON directly to agent.reload(next)
  2. reload skipped readConfig because cfg was already provided
  3. _setConfig assigned the incomplete config — this.trigger.config = cfg.trigger became undefined
  4. Every subsequent chat request crashed with TypeError: Cannot read properties of undefined (reading 'providers') in isProviderEnabled
  5. Similar crash for computer.local.enabled in buildStatus when computer: {}

The root cause is that the sync path bypassed readConfig entirely. Routing it back through readConfig (and making readConfig itself deep-merge defaults for computer/subAgent, not just trigger) fixes both the sync flow and any independent path that may have written a partial config to disk.

Test plan

  • Create a config.json with only { "mcp": { "mcpServers": {} } } (missing computer, trigger, subAgent details)
  • Run chatluna.agent sync — should load without errors
  • Verify trigger providers (cron, activity, keyword) are enabled by default
  • Verify computer backends have correct default structure
  • Verify builtin sub-agents (plan, general, explore) have descriptions populated
  • Send a chat message — should not crash with TypeError

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8c832f20-7f3f-41f8-bd96-59605a1eba71

📥 Commits

Reviewing files that changed from the base of the PR and between 0762863 and 87559b3.

📒 Files selected for processing (2)
  • packages/extension-agent/src/config/read.ts
  • packages/extension-agent/src/utils/agentcli_sync.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/extension-agent/src/utils/agentcli_sync.ts

走查总览

该 PR 调整代理配置的读取与同步流程:在 readConfig 中引入 deepAssign 统一配置合并策略,对 triggercomputersubAgent 进行显式深度合并,同时改变配置同步后重加载的参数传递方式。

变更内容

配置合并与重加载参数调整

层级 / 文件 说明
配置深度合并实现
packages/extension-agent/src/config/read.ts
导入 deepAssign 工具,将 triggercomputersubAgent 的配置合并改用 deepAssign 统一处理,替代原先的手动展开与分别处理逻辑。
配置重加载参数调整
packages/extension-agent/src/utils/agentcli_sync.ts
syncAgentcliConfigagent.reload() 调用改为无参,不再传入新配置对象 next

估算代码审查工作量

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

诗歌

🐰 深度合并来整顿,
触发器、计算机、代理齐声应,
重加载改参数,
配置流线更清晰,
逻辑顺畅胜从前。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确反映了 PR 的主要变化:通过 deepAssign 进行配置合并以修复 agentcli 同步问题。
Description check ✅ Passed 描述详细说明了问题所在、解决方案和测试计划,与代码更改内容完全相关。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
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 merging logic for computer and subAgent configurations and ensures a default trigger configuration is applied. It also refactors the agent reload call in the CLI sync utility. Feedback focuses on addressing a shallow merge issue in the subAgent.defaults configuration that could result in lost settings and suggests using Object.entries to simplify the builtin sub-agent merging logic.

Comment thread packages/extension-agent/src/config/read.ts Outdated
Comment thread packages/extension-agent/src/config/read.ts Outdated
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.

🧹 Nitpick comments (1)
packages/extension-agent/src/service/index.ts (1)

725-725: 💤 Low value

指出 triggercomputer/subAgent 在防御性赋值上的不一致。

createDefaultTriggerConfig() 的签名和返回类型验证无误。但存在一个值得关注的不一致之处:在 AgentConfig 接口中,triggercomputersubAgent 都是必需属性(非可选),然而在 _setConfig 方法中,只有 trigger 获得了后备逻辑(cfg.trigger ?? createDefaultTriggerConfig()),而 computersubAgent 则直接赋值(cfg.computercfg.subAgent)。

readConfig 的深度合并已确保 trigger 总是被定义,则这个后备逻辑可能多余;否则,为了保持一致性和防御性,应该对 computersubAgent 也应用相同的保护策略,或将这些属性标记为可选。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/extension-agent/src/service/index.ts` at line 725, The assignment in
_setConfig is inconsistent: this.trigger.config uses a fallback (cfg.trigger ??
createDefaultTriggerConfig()) while cfg.computer and cfg.subAgent are assigned
directly; update _setConfig to defendively apply the same fallback behavior for
computer and subAgent (e.g., use cfg.computer ?? createDefaultComputerConfig()
and cfg.subAgent ?? createDefaultSubAgentConfig() or equivalent defaults), or
alternatively update the AgentConfig interface to mark computer and subAgent as
optional; locate references to AgentConfig, _setConfig, this.trigger.config,
cfg.trigger, cfg.computer, and cfg.subAgent to implement the chosen fix so the
code is consistent and type-safe.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/extension-agent/src/service/index.ts`:
- Line 725: The assignment in _setConfig is inconsistent: this.trigger.config
uses a fallback (cfg.trigger ?? createDefaultTriggerConfig()) while cfg.computer
and cfg.subAgent are assigned directly; update _setConfig to defendively apply
the same fallback behavior for computer and subAgent (e.g., use cfg.computer ??
createDefaultComputerConfig() and cfg.subAgent ?? createDefaultSubAgentConfig()
or equivalent defaults), or alternatively update the AgentConfig interface to
mark computer and subAgent as optional; locate references to AgentConfig,
_setConfig, this.trigger.config, cfg.trigger, cfg.computer, and cfg.subAgent to
implement the chosen fix so the code is consistent and type-safe.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c9fc96b6-9df1-46fa-b2f4-f410e4089bc1

📥 Commits

Reviewing files that changed from the base of the PR and between 2806be6 and 0762863.

📒 Files selected for processing (3)
  • packages/extension-agent/src/config/read.ts
  • packages/extension-agent/src/service/index.ts
  • packages/extension-agent/src/utils/agentcli_sync.ts

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 enhances the configuration handling by explicitly merging computer and subAgent settings with their defaults in readConfig, and ensures a default trigger configuration is applied during service updates. Additionally, the agent reload logic in the CLI sync utility was simplified. Review feedback indicates that the mcp section and subAgent.defaults also need more robust merging strategies to prevent partial user configurations from accidentally overwriting nested default values, such as MCP tools or sub-agent permission rules.

Comment thread packages/extension-agent/src/config/read.ts Outdated
Comment thread packages/extension-agent/src/config/read.ts Outdated
Route syncAgentcliConfig through agent.reload() so the partial config
written from agentcli passes through readConfig and gets merged with
defaults. readConfig now uses deepAssign for trigger/computer/subAgent
so partial saved sections (e.g. `computer: {}` or missing trigger) no
longer override nested defaults and crash isProviderEnabled / buildStatus.
@dingyi222666 dingyi222666 force-pushed the fix/agentcli-sync-config-defaults branch from 0762863 to 87559b3 Compare May 19, 2026 06:04
@dingyi222666 dingyi222666 changed the title fix(agent): deep-merge defaults in readConfig to prevent TypeError on partial config fix(agent): merge config defaults via deepAssign on agentcli sync May 19, 2026
@dingyi222666 dingyi222666 merged commit 3b82556 into ChatLunaLab:v1-dev May 19, 2026
4 of 5 checks passed
@yabo083 yabo083 deleted the fix/agentcli-sync-config-defaults branch May 19, 2026 18:06
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