Skip to content

feat(health): Add configurable upstream error rules - #830

Merged
tbphp merged 9 commits into
mainfrom
tbphp/custom-error-rules
Oct 10, 2026
Merged

tbphp merged 9 commits into
mainfrom
tbphp/custom-error-rules

Conversation

@tbphp

@tbphp tbphp commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

关联 Issue / Related Issue

Refs #753

变更内容 / Change Content

  • Bug fix
  • New feature
  • Other changes

Allow operators to customize existing upstream error handling without changing the decision or execution architecture. Rules match HTTP status codes and case-insensitive keywords in error codes, types, or messages, then choose whether to retry and one state action: keep state, cool down a model or credential, count a failure toward blacklisting, or skip the group for the current request.

  • Support global defaults and complete group overrides. Missing group configuration inherits global rules; an explicit empty list suppresses them. The first matching rule applies.
  • Preserve existing replay safety, client-error and authentication boundaries, committed-response constraints, blacklist thresholds, and configuration snapshots.
  • Provide compact, collapsible rule editors in both frontends. Status codes and keywords are entered as removable tags; retry uses a switch, and cooldown inputs appear alongside the selected action. Error handling is placed at the end of routing settings.
  • Modern group settings show the editor only in override mode and start new overrides with an empty list. Switching modes retains the group's configured rule draft.
  • Modern global and group saves collect pending inputs, trim whitespace, and deduplicate values before validating and saving. Keywords are deduplicated case-insensitively. Pending inputs count as unsaved changes; invalid status codes block saving and receive an inline error.
  • Reuse the modern public tag component for error rules, filter summaries, multi-select values, parameter summaries, and model/group labels. A parameter controls the remove icon, while linked group labels retain navigation.
  • Limit rule lists to 100 entries and 65,535 encoded bytes, matching existing settings storage across supported database drivers. Include Chinese, English, and Japanese translations and readable matched-rule log labels.

Rules use existing error evidence, including errors already recognized under HTTP 200. New 2xx error detection and scanning normal answer text remain outside this change. Credential probes and recovery behavior are unchanged. No database schema migration or new dependency is required.

Validation: make check passed after integrating origin/main at 3745fbab, covering Go module checks and vet, frontend lint/style/format checks, TypeScript checks, frontend and Go builds, and go test -count=1 . ./internal/.... Earlier custom error-rule storage contracts passed on SQLite, real MySQL 8.4, and real PostgreSQL 18, covering persistence, inheritance, group overrides, empty overrides, escaped Unicode keywords, and storage-size boundaries. Those external-database runs were not repeated for this frontend-only revision. No automated browser or E2E tests were run.

自查清单 / Checklist

  • I ran make check, or documented why it could not run and what remains unverified.
  • This PR is focused and contains no unrelated changes.
  • I updated any required public documentation or release notes.
  • I confirmed that commits, logs, and fixtures contain no sensitive data.
  • Where applicable, I documented compatibility or data-migration impact.

Public documentation and release notes are unchanged; no documentation update is included in this PR.

Copilot AI balanced review requested due to automatic review settings October 6, 2026 13:24

Copilot 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

📝 Walkthrough

Walkthrough

新增全局和分组自定义错误规则。后端负责校验、继承和应用规则,并将分组规则传入网关健康决策。经典版和现代版前端新增规则配置、编辑、验证及日志标识展示。


Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to bcdf6

Entering a cooldown in the modern rule editor can prevent the rule from updating. Fix that editing path before merging.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 2.13% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 47 functions across 35 files. (9 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check Passed 标题准确概括了本次新增的可配置上游错误规则功能,内容明确且与变更范围一致。
Description check Passed 描述完整说明了功能范围、继承与覆盖行为、兼容性边界、验证结果和未执行的测试。变更内容与自查清单基本符合模板要求。

Full details: Docstring Coverage

Explanation

Docstring coverage is 2.13% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 47 functions across 35 files. (9 skipped: 9 unsupported.)


  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@coderabbitai coderabbitai Bot 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.

Note

Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.

🟡 Other comments (1)
web/src/frontends/modern/features/config/ErrorRulesEditor.vue-142-190 (1)

142-190: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

将现代编辑器的 cooldown 更新值转换为字符串。

现代 AppTextField 的 number 输入会将可解析值写为数字。随后 errorRuleValue 对 row.cooldown 调用 trim(),会抛出类型错误并阻断现代编辑器更新规则。经典编辑器发送字符串,不受此问题影响。

建议修复
-          v-model="row.cooldown"
+          :model-value="row.cooldown"
+          @update:model-value="row.cooldown = String($event)"

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: QUIET
  • Plan: Advanced
  • Run ID: 47480bf5-4dd9-46ad-a09f-0b9f3ec5e50c
📥 Commits

Reviewing files that changed from the base of the PR and between a5c691b and bcdf661.

📒 Files selected for processing (44)
  • internal/control/error_rules_test.go
  • internal/control/group_detail.go
  • internal/control/group_settings.go
  • internal/control/settings.go
  • internal/gateway/custom_error_rules_test.go
  • internal/gateway/handler.go
  • internal/gateway/jev_decision.go
  • internal/gateway/live.go
  • internal/gateway/mistral_realtime.go
  • internal/gateway/websocket_turn.go
  • internal/health/decision.go
  • internal/health/error_rules.go
  • internal/health/error_rules_test.go
  • internal/health/execution_judge.go
  • internal/state/error_rules_test.go
  • internal/state/runtime_settings.go
  • internal/state/snapshot.go
  • web/src/frontends/classic/api/control/types.ts
  • web/src/frontends/classic/app/resources/groups.ts
  • web/src/frontends/classic/app/resources/settings.ts
  • web/src/frontends/classic/components/config/ErrorRulesEditor.vue
  • web/src/frontends/classic/features/groups/group-route.ts
  • web/src/frontends/classic/features/groups/settings/GroupSettingsTab.vue
  • web/src/frontends/classic/features/groups/settings/group-settings-patch.ts
  • web/src/frontends/classic/features/monitor/LogDetailDrawer.vue
  • web/src/frontends/classic/features/settings/ReliabilitySettingsSection.vue
  • web/src/frontends/classic/features/settings/SettingsView.vue
  • web/src/frontends/classic/features/settings/settings-patch.ts
  • web/src/frontends/classic/i18n/locales/en-US/core.ts
  • web/src/frontends/classic/i18n/locales/ja-JP/core.ts
  • web/src/frontends/classic/i18n/locales/zh-CN/core.ts
  • web/src/frontends/modern/api/group-detail.ts
  • web/src/frontends/modern/api/settings.ts
  • web/src/frontends/modern/features/config/ErrorRulesEditor.vue
  • web/src/frontends/modern/features/groups/GroupAdvancedPanel.vue
  • web/src/frontends/modern/features/logs/LogDetailPanel.vue
  • web/src/frontends/modern/features/settings/SettingsView.vue
  • web/src/frontends/modern/features/settings/settings-draft.ts
  • web/src/frontends/modern/features/settings/use-settings-editor.ts
  • web/src/frontends/modern/i18n/locales/en-US.ts
  • web/src/frontends/modern/i18n/locales/ja-JP.ts
  • web/src/frontends/modern/i18n/locales/zh-CN.ts
  • web/src/shared/error-rule-messages.ts
  • web/src/shared/error-rules.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@tbphp

tbphp commented Oct 6, 2026

Copy link
Copy Markdown
Owner Author

Addressed the cooldown input issue in ef85c66: the modern rule editor converts numeric input updates to strings before parsing. The same commit omits empty optional condition arrays when reading rules, so editing and then restoring a rule no longer leaves settings marked as changed. make check passed.

The docstring coverage warning in the review summary is not a quality gate defined by this repository, so no bulk docstring changes are included.

@tbphp tbphp self-assigned this Oct 7, 2026
@tbphp tbphp added the enhancement New feature or request label Oct 7, 2026
@tbphp tbphp added this to the v2.0.0 milestone Oct 7, 2026
@tbphp
tbphp merged commit 7888400 into main Oct 10, 2026
12 checks passed
@tbphp
tbphp deleted the tbphp/custom-error-rules branch October 10, 2026 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants