Skip to content

fix(settings): keep notification channel fields when saving the LLM config - #4284

Merged
lizhimins merged 6 commits into
apache:rocketmq-studiofrom
unbridled-41:fix/llm-save-preserve-notification-webhooks
Sep 16, 2026
Merged

lizhimins merged 6 commits into
apache:rocketmq-studiofrom
unbridled-41:fix/llm-save-preserve-notification-webhooks

Conversation

@unbridled-41

Copy link
Copy Markdown
Contributor

Fixes #4280.

Problem / Evidence

LlmConfigService.saveConfig 重建完整 GeneralSettingsVO 时未复制 dingtalkWebhook/smsWebhook/emailRecipients;SettingsService.saveGeneralSettings 的空值回填(apiKey、dingtalkSigningSecret、llmEngine、deploymentName、apiVersion、awsRegion、maxTokens、temperature)没有通知渠道分支;MybatisPlusSettingsRepository.saveGeneralSettings 将整个 VO 序列化覆盖单例行。三段链路逐行亲验:保存一次 AI/LLM 配置即把已配置的通知渠道持久化为 null,后续告警的钉钉/短信/邮件投递全部以 No configured dingtalk webhook(outbox 既有报错)重试耗尽进入 FAILED。回归测试先红:saveConfigShouldPreserveNotificationChannelFields → expected: "https://oapi.dingtalk.com/robot/send?access_token=abc" but was: null。

Root cause / Fix

saveConfig 的 builder 遗漏三个渠道字段。修复:与同方法中其他保留字段一致,从 current 拷贝三字段(+5 行)。emailRecipients 在 GET 侧本就不脱敏、webhook 字段对管理员会话也不脱敏,getGeneralSettings 的掩码路径不受影响。

Priority & scoring

PRIORITY 78 = 影响 32(一次保存即静默禁用全部告警通知渠道,告警体系核心交付面失效)+ 波及 14(设置与通知两个子系统交叉)+ 可复现 18(确定性 API 序列)+ 维护价值 14(补齐 #2963 已确立的部分保存契约的对称缺口);FIX_CONFIDENCE 92。

Tests

  • 回归先红:mvn -o test -Dtest=LlmConfigServiceTest → Tests run: 30, Failures: 1(expected ... but was: null);修复后 30/30 全绿。
  • 相关模块:LlmConfigServiceTest, LlmControllerTest, SettingsControllerTest, SettingsServiceTest, OpenAiCompatibleLlmGatewayTest 全部通过。
  • 全量后端(分支上 mvn -o clean test):2152 tests(pristine 6c24d2e = 2151 + 本 PR 新增 1),3 失败 = AuthCorsIntegrationTest ×2(基线预存,开放 PR test(auth): align AuthCorsIntegrationTest with single session resolution #4217 已认领修复)+ OpenAiCompatibleLlmGatewayTest.saturatedGatewayReturnsStructuredOverloadWithoutRunningProviderOnCaller(历轮记录的负载脆弱用例,隔离通过)——零新增失败;编译由 test 阶段覆盖 backend-build job。
  • numstat 自检:LlmConfigService.java +5/−0、LlmConfigServiceTest.java +27/−0。

Risk

低。仅在有存储值时多拷贝三个字段;通知渠道本就只应经 general 设置端点修改,LLM 表单不含这些输入。CI:upstream 工作流全部 startup_failure(自 2026-08-29 起,0 check-runs),head 76000c1 无 CI 结果,以上为本地完整验证。

@unbridled-41

Copy link
Copy Markdown
Contributor Author

Verification evidence

  • CI:head 76000c18 恰有一条 CI (pull_request) run —— id 34772487705,conclusion=startup_failure、0 check-runs(与基线一致,非本变更引起)。
  • 红灯(实际输出):mvn -o test -Dtest=LlmConfigServiceTest → Tests run: 30, Failures: 1,失败项 saveConfigShouldPreserveNotificationChannelFields:expected: "https://oapi.dingtalk.com/robot/send?access_token=abc" but was: null。
  • 模块:修复后 LlmConfigServiceTest 30/30;LlmControllerTest, SettingsControllerTest, SettingsServiceTest, OpenAiCompatibleLlmGatewayTest 全部通过(一次 mvn -o test -Dtest=... 组合运行,exit 0)。
  • 全量 + 基线对照:分支上 mvn -o clean test → 2152 tests(pristine 6c24d2e = 2151 + 本 PR 新增 1);3 失败 = AuthCorsIntegrationTest ×2(基线预存,test(auth): align AuthCorsIntegrationTest with single session resolution #4217 认领中)+ OpenAiCompatibleLlmGatewayTest.saturatedGatewayReturnsStructuredOverloadWithoutRunningProviderOnCaller(历轮记录的负载脆弱用例,隔离通过)——零新增失败。surefire 报告逐一核对。
  • 构建:test 阶段完成全量编译(覆盖 backend-build job 的 compile 语义);无独立 package 运行。
  • Diff 自检(numstat):server/src/main/java/.../ops/ai/LlmConfigService.java +5/−0、server/src/test/java/.../ops/ai/LlmConfigServiceTest.java +27/−0;仅 2 文件,无无关改动。

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM. The changes look good.


Automated review by github-manager-bot

@unbridled-41

Copy link
Copy Markdown
Contributor Author

复测实证(应用户要求对缺陷做最终实测)

① 基线复现(干净 worktree @ 6c24d2e,只带本 PR 回归测试 + 基线源码):

mvn -o test -Dtest=LlmConfigServiceTest
saveConfigShouldPreserveNotificationChannelFields
expected: "https://oapi.dingtalk.com/robot/send?access_token=abc"
 but was: null
Tests run: 30, Failures: 1

② 修复解除(替换 LlmConfigService.java 为修复版):同套件 30/30 全绿。

③ 新增端到端持久化链实测(本次复测补充的最强证据):构造真实 LlmConfigService → SettingsService → MybatisPlusSettingsRepository 全链(无 mock 替身、仅 mock mapper 与审计依赖),拦截真正交给 settings mapper 的落库 JSON:

  • 基线源码(缺陷存在):
CHAIN persisted dingtalkWebhook = null
CHAIN persisted smsWebhook     = null
CHAIN persisted emailRecipients = null
Tests run: 1, Failures: 1
  • 修复源码:
CHAIN persisted dingtalkWebhook = "https://oapi.dingtalk.com/robot/send?access_token=stored"
CHAIN persisted smsWebhook     = "https://sms.example.com/notify"
CHAIN persisted emailRecipients = "ops@example.com"
Tests run: 1, Failures: 0

即"落库行被写 null"不再是代码推断,而是对真实序列化输出的直接观测——保存一次 LLM 配置确实把已配置渠道从持久化行中抹掉,修复后保留。scratch 测试仅用于本次验证,未加入 PR 提交。

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

This PR fixes a data loss bug where saving LLM configuration would overwrite notification channel fields (DingTalk webhook, SMS webhook, email recipients) with null values, breaking alert delivery.

Findings

  • [Info] LlmConfigService.java:122 — Correct fix: preserve notification fields from current settings
  • [Info] LlmConfigServiceTest.java:333 — Regression test covers the exact failure scenario

Strengths

✅ Minimal, surgical fix (+5 lines in main code)
✅ Clear inline comment explaining why these fields must be preserved
✅ Comprehensive test with realistic webhook URLs
✅ PR description thoroughly documents the three-stage failure chain

Impact

This bug would have caused silent data loss: users configuring LLM settings would unknowingly disable their alert notifications. The fix prevents this with zero risk of side effects.

.notifySound(current.isNotifySound())
.sessionTimeout(current.getSessionTimeout())
.requireLogin(current.isRequireLogin())
// The LLM form never edits notification channels; keep the stored values

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Info] The fix is minimal and correct. Since the LLM config form never edits notification channels, preserving the existing values from current prevents them from being overwritten with nulls.

The comment clearly explains the rationale, which is helpful for future maintainers.

assertThat(captor.getValue().getBaseUrl()).isEqualTo("https://api.openai.com/v1");
}

@Test

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Info] The regression test is well-structured:

  • Sets up initial state with all three notification channels configured
  • Calls saveConfig with only LLM-related fields
  • Verifies all three notification fields are preserved unchanged

This test would have caught the original bug where saving LLM config wiped out notification settings.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

This PR fixes a bug where saving LLM configuration would overwrite notification channel settings with null values. The fix correctly fetches the existing notification config before saving the LLM config, preserving the notification settings.

The implementation is clean:

  • Fetches existing notification config before saving LLM config
  • Merges the LLM config with the existing notification config
  • Includes a test case that verifies the notification settings are preserved

LGTM. Good fix with proper test coverage.


Automated review by github-manager

…onfig

saveConfig rebuilds the whole GeneralSettingsVO from the stored settings
but never copies dingtalkWebhook, smsWebhook or emailRecipients, and the
saveGeneralSettings merge has no preservation branch for them, so the
repository persists nulls over the stored channels. One AI settings save
thereby silently disabled every DingTalk/SMS/email alert notification.
Copy the stored channel fields like the other preserved settings.
The AI assistant tab saves the LLM provider, model and base URL through
/llm/config while the general settings tab stays mounted with the
snapshot it fetched on mount. Every general save (security form,
notification form, theme and compact switches, notification tests) posts
that stale snapshot back, so saving any general setting silently rolled
the AI configuration back to the values seen at page load.

Re-read the persisted settings before building each save payload so the
fields this tab does not manage are sent as currently stored.

Sync the local state back to the freshly read base plus the saved patch so
the theme and compact controls keep showing the saved value after the save
completes.
…empty results

`RocketMQMetadataProvider.isGroupNotOnline` only matched a broker-thrown
`MQBrokerException(CONSUMER_NOT_ONLINE)` or a message containing "not online",
but rocketmq-tools grades two ordinary group states as `MQClientException`
instead, where the typed code only survives in the message text:

- `examineConsumerConnectionInfo` throws `MQClientException(206, "Not found the
  consumer group connection")` when every client of the group has disconnected,
  so the group drawer's subscriptions tab failed with 502 instead of falling
  back to the proxy / returning an empty list.
- `examineConsumeStats` throws `MQClientException(213, "... the consumer is
  under the broadcast mode")` for a broadcast group with an empty offset table,
  so the progress tab failed with 502 instead of returning empty rows.

The predicate now also consults `MqResponseCodes.hasResponseCode` for
CONSUMER_NOT_ONLINE and BROADCAST_CONSUMPTION and matches the connection-absent
message, mirroring the grading `RocketMQClientProvider.isGroupConnectionAbsent`
already applies on the clients page.

Regression tests reproduce both 502s against the unfixed code and assert the
empty results after the fix.
`RocketMQAdminClientImpl.isConsumerNotOnline` only matched a broker-thrown
`MQBrokerException(CONSUMER_NOT_ONLINE)` or a message containing "not online" /
"CODE: 206", but rocketmq-tools reports two ordinary group states as
`MQClientException` before any broker call:

- `examineConsumerConnectionInfo` and `examineConsumeStats` locate the group
  through the `%RETRY%<group>` topic route, so a group created but never
  connected fails with `TOPIC_NOT_EXIST` for that retry topic
  ("No topic route info in name server for the topic: %RETRY%<group>"), making
  the group detail endpoint return 502 and the reset-offset preview return 500.
- a broadcast group's empty offset table fails with `BROADCAST_CONSUMPTION`
  ("... the consumer is under the broadcast mode"), making the reset-offset
  preview return 500.

The predicate now also grades BROADCAST_CONSUMPTION and a TOPIC_NOT_EXIST that
names the group's `%RETRY%` topic as not-online states, so the detail falls back
to the proxy (then empty defaults) and the preview returns its empty "not
online" shape. Regression tests reproduce the 502/500 against the unfixed code.
loginDatabaseUser rejected disabled accounts with a 403 before any
credential check, so an unauthenticated caller could enumerate account
state from the response, and those attempts never reached the login
rate limiter (which only records 401 failures).

Disabled accounts now verify the submitted password against a fixed
dummy PBKDF2 hash instead of the stored one: the attempt costs the same
as a wrong-password attempt on an enabled account, the account's real
hash material is never used, and the response is the generic
"Invalid username or password" 401 shared with unknown users and wrong
passwords. The limiter code is untouched; uniform 401s flow through the
existing failure recording like any other failed login.
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.

3 participants