Skip to content

fix: surface group pricing errors and reject nil options (#8034) - #8076

Draft
seefs001 wants to merge 1 commit into
QuantumNous:mainfrom
seefs001:fix/group-pricing-autogroups-nil-8034
Draft

seefs001 wants to merge 1 commit into
QuantumNous:mainfrom
seefs001:fix/group-pricing-autogroups-nil-8034

Conversation

@seefs001

@seefs001 seefs001 commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Agent

  • Tool / version: Pi 1.4.0;AI-assisted
  • Model (full id): gpt-6-astra(provider: responses)
  • Host: CLI
  • Date (UTC): 2026-10-28

Links

Closes #8034

User request

User authorized: open a Draft PR for the existing local fix. Do NOT rework the code.

No code changes, no new commits unless the branch is missing and must be recovered
Must stay draft (not ready for review)

Out of scope — refuse

  • Matched: no。修复仓库内分组设置的校验与持久化,不涉及上游转发或第三方服务。

Open gate — do not open unless all are satisfied

  • Out of scope: no
  • Usage / configuration / integration: no
  • Required issue facts present without invention: yes
  • Verification includes actual commands and observed results: yes
  • Body is factual and limited to the change: yes
  • Open: yes,保持 Draft

Kind

  • Bug fix

Issue facts

  • Actual behavior / impact: 分组定价页保存无反馈、没有 PUT /api/option/ 请求,离开页面后修改丢失。
  • Frequency: 已存储的 AutoGroups 为字面量 <nil> 时必现。
  • Evidence: 浏览器无请求,直接调用 PUT 可以保存;表单校验失败后只处理数字限制字段。
  • Environment: 官方 Windows 二进制,v1.0.0-rc.25;Edge 142.0.x,默认主题;/system-settings/billing/group-pricing。不涉及 relay。

Change

  • 前端为全部无效字段提供可见反馈。JSON 校验失败时打开现有 JSON 编辑器、展示错误并聚焦首个错误字段;保留单独数字限制错误的分区定位,补齐开关错误。保存按钮和表单提交共用处理逻辑。
  • 后端拒绝缺失或 nil Value,不再把它格式化为 <nil>;拒绝非法 AutoGroups,包括字面量 <nil>。单项、批量更新均先校验再写数据库;写入失败回滚,不发布新的 OptionMap 值。解析失败保留运行时分组。
  • 历史 <nil> 不会自动迁移为 [],保留原文供用户明确修正。

Research

Duplicate / prior art

  • 搜索:8034、AutoGroups in:title、group pricing in:title,并检查同名源分支。
  • 已有关闭且未合并的前端方案;本分支针对当前主线实现,并补充后端写入校验。未发现同名分支的现存 PR。

Docs and code

  • 官方系统设置文档:分组倍率由设置页编辑并保存,未将 <nil> 定义为合法配置。
  • DeepWiki:搜索摘要说明分组倍率与计费的关系;全文读取返回 HTTP 429,未据此推断实现。
  • README.md 的 Capabilities / Quick start:分组及定价属于管理配置。
  • 表单的 handleSubmit 错误分支和后端 option 更新路径证明这是校验缺陷,不是配置使用问题。

Alternatives considered

  • 自动替换历史值为 [] 会隐式修改路由配置,未采用。
  • 采用显式字段错误和写入前校验,不新增替代编辑器。

Files

Path Why
web/src/features/system-settings/models/group-ratio-form.tsx 展示并聚焦所有字段的校验错误
web/src/features/system-settings/models/ratio-settings-card.tsx, ratio-settings-schema.ts 提取现有规则供页面和测试共用,不改变校验语义
web/src/features/system-settings/models/__tests__/group-settings.test.tsx 覆盖错误展示、焦点、修正后保存、组合错误及原生提交
controller/option.go, model/option.go, setting/auto_group.go 拒绝 nil、写入前校验、失败不污染配置
controller/option_auto_group_test.go 三数据库持久化及失败回滚回归

Behavior

  • Before: <nil> 阻止提交却无可见反馈;无效值可能在返回错误前进入存储或内存。
  • After: 显示错误并允许明确修正;非法 AutoGroups 在写库前被拒绝。
  • Non-goals: 不迁移历史数据,不修改计费公式,不扩展修复历史 AutoGroups = {} 导致的可视化渲染错误。

Verification

以下为本提交完成时实际执行并观察的结果;发布草稿前核对了日志,未改代码或重跑无关测试。

  • cwd web/:bun run test src/features/system-settings/models/__tests__ src/components/json-code-editor/__tests__:11 个文件、103 个测试通过。修复前新增的 7 个交互回归失败,修复后通过。
  • cwd web/:bunx --no-install tsgo -b:通过。bun check -b 缺少 check 入口,使用已安装的 tsgo。
  • cwd 仓库根目录,设置 TEST_MYSQL_DSN、TEST_POSTGRES_DSN 后:
    go test ./controller ./model ./setting -run 'Test(AutoGroupsOptionPersistence|UpdateOption|ValidateOptionValue|UpdateMaxTokenAutoGroups|RetiredThemeOption)' -count=1 -v
    全部通过。真实 SQLite 3.50.4、MySQL 26.7.0、PostgreSQL 16.15 均执行,未跳过。覆盖非法值保留旧数据、批量拒绝、数据库失败回滚及有效数组保存。
  • 修改的前端文件通过定向 oxlint、保留版权头的格式检查;Go 文件经 gofmt,git diff --check 通过。
  • UI 无截图或录屏:验证使用真实表单、生产 schema 和编辑器的交互测试,未运行真实浏览器 E2E。
  • Not verified: Windows/Edge 实例、生产构建、最低数据库版本;无 schema 或迁移变更。

Risks

  • 非标量 option 值现在会被拒绝;JSON 配置须使用字符串传入。
  • UpdateOption 的通用数据库写入路径改为事务并传播数据库错误。
  • 不改变计费公式、额度计算或认证流程;历史异常值需管理员明确修正。
  • 已知遗留:历史 AutoGroups = {} 的可视化渲染错误不在本修复范围。

Scope check

  • Single focused change: yes,分组设置校验反馈和无效值持久化。
  • Secrets included: no
  • Out of scope: no

Summary by CodeRabbit

  • Bug Fixes
    • Invalid group settings are now rejected with clearer validation feedback, including guidance to correct JSON formatting. Invalid submissions no longer replace saved or current settings.
    • Settings are saved only when the update succeeds, preventing failed saves from changing the displayed values.
    • Option values now accept text, numbers, and booleans; unsupported value types are rejected.

…#8034)

Reveal invalid group settings in the existing JSON editor, focus the first invalid field, and share error handling across save and form submission. Preserve numeric-limit navigation and expose switch errors. Test with the production validation schema.

Reject missing/null and non-scalar option values. Validate AutoGroups before single and bulk persistence, preserve runtime groups on parse failure, and roll back failed option writes before publishing memory state. Keep historical malformed text available for explicit correction instead of silently replacing it.

Verification: frontend models and JSON editor suites passed (11 files, 103 tests); bunx --no-install tsgo -b passed (bun check -b is unavailable in this checkout); targeted oxlint, protected-header-safe formatting, gofmt and git diff --check passed.

Backend: go test ./controller ./model ./setting -run 'Test(AutoGroupsOptionPersistence|UpdateOption|ValidateOptionValue|UpdateMaxTokenAutoGroups|RetiredThemeOption)' -count=1 -v passed with real SQLite 3.50.4, MySQL 26.7.0 and PostgreSQL 16.15 test databases.
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f898867e-9ac4-4662-ac93-5e55fdd00692
Commits

Reviewing files that changed from the base of the PR and between b08ee86 and e1f3dcd.

Files selected for processing: 8
  • controller/option.go
  • controller/option_auto_group_test.go
  • model/option.go
  • setting/auto_group.go
  • web/src/features/system-settings/models/__tests__/group-settings.test.tsx
  • web/src/features/system-settings/models/group-ratio-form.tsx
  • web/src/features/system-settings/models/ratio-settings-card.tsx
  • web/src/features/system-settings/models/ratio-settings-schema.ts

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

Walkthrough

The changes validate AutoGroups values in backend option updates and group-pricing forms. Option writes now return database errors before updating in-memory settings. The form uses shared schemas and routes invalid submissions to visible validation feedback.

Changes

AutoGroups settings

Layer / File(s) Summary
Backend validation and persistence
setting/auto_group.go, model/option.go, controller/option.go, controller/option_auto_group_test.go
AutoGroups parsing rejects invalid JSON and arrays with non-string values. Option updates validate input and return database write errors before changing in-memory settings. Tests cover invalid inputs, write failures, and valid persistence.
Shared ratio settings schemas
web/src/features/system-settings/models/ratio-settings-schema.ts, web/src/features/system-settings/models/ratio-settings-card.tsx, web/src/features/system-settings/models/__tests__/group-settings.test.tsx
Model and group validation schemas move into a shared module. The schemas validate JSON settings and field types, and the card and tests use them.
Form error routing and feedback
web/src/features/system-settings/models/group-ratio-form.tsx, web/src/features/system-settings/models/__tests__/group-settings.test.tsx
Invalid submissions route to the relevant editor view and focus the first invalid field. The default-auto-group switches display validation messages. Tests cover invalid JSON and field values.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • QuantumNous/new-api#8035: It changes the group-pricing form validation path that this PR extends with shared schemas, error routing, and backend persistence handling.

Suggested reviewers: calcium-ion

Merge Risk: Minimal · up to e1f3d

No actionable issue identified in the reviewed changes; the PR is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title accurately summarizes the main changes: surfacing group-pricing validation errors and rejecting invalid nil options.
Linked Issues check Passed Issue #8034 is directly linked and requires visible feedback when group-pricing validation blocks saving. The frontend now applies one invalid-submit handler to the save button and native form submiss…
Out of Scope Changes check Passed The changed files remain connected to issue #8034. Schema extraction and shared error handling support the group-pricing validation fix. Backend type rejection, AutoGroups validation, transactional …
Full details: Linked Issues check

Explanation

Issue #8034 is directly linked and requires visible feedback when group-pricing validation blocks saving. The frontend now applies one invalid-submit handler to the save button and native form submission. The handler opens JSON mode for malformed JSON, selects the Auto section for the numeric limit case, and focuses the first invalid field. Both switch fields render validation messages. The shared group schema validates all listed JSON fields and requires AutoGroups to be a string array. Tests cover invalid values in six fields, invalid switch data, combined errors, focus, correction, and successful save. The backend validates AutoGroups before persistence and the targeted Go tests cover rejected malformed values and valid saves. The reported verification also records 103 frontend tests and the targeted Go tests on SQLite, MySQL, and PostgreSQL passing.

Full details: Out of Scope Changes check

Explanation

The changed files remain connected to issue #8034. Schema extraction and shared error handling support the group-pricing validation fix. Backend type rejection, AutoGroups validation, transactional writes, and rollback tests prevent invalid option persistence and stale in-memory state. No billing formula, relay, migration, or unrelated service changes are present. Historical &amp;lt;nil&amp;gt; values remain unchanged until an administrator corrects them, as stated in the current PR scope.

Full details: Docstring Coverage

Explanation

Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 8 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · 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

A rabbit checks the JSON rows,
And finds the fields that need a fix.
It hops to where the errors show,
Then waits for writes to safely stick.
The groups return in tidy strings,
While carrots cheer the saved settings.

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

soulteary added a commit to soulteary/yunqi that referenced this pull request Nov 22, 2026
Resolve SQLite source paths before constructing file URIs. Resolve directory
identities before sorting and acquiring locks so config aliases do not cause
self-conflicts. Add relative backup/verify/restore and alias-lock regressions.

Refs: QuantumNous/new-api#8076 (PR #8076)
Refs: QuantumNous/new-api#8034 (issue #8034)
soulteary added a commit to soulteary/yunqi that referenced this pull request Nov 22, 2026
Use complete logical-channel transaction snapshots so central persistence rollback
cannot be followed by an incremental undo that panics or removes existing data.
Reject audit cursors when any portion of the original retained interval expires.
Synchronize test writers after a second manager persists migration defaults,
without weakening pending external-edit protection.

Regression coverage includes first/existing logical creation, deletion and update
failures, partial/full cursor eviction, and repeated single-writer mutations.

Follow-up to soulteary/yunqi PR #105 review.
Refs: QuantumNous/new-api #8076 QuantumNous/new-api#8076
Refs: QuantumNous/new-api #8034 QuantumNous/new-api#8034
Refs: QuantumNous/new-api #6673 QuantumNous/new-api#6673
soulteary added a commit to soulteary/yunqi that referenced this pull request Nov 22, 2026
Refs: QuantumNous/new-api #7953 QuantumNous/new-api#7953
Refs: QuantumNous/new-api #7951 QuantumNous/new-api#7951
Refs: QuantumNous/new-api #8076 QuantumNous/new-api#8076
Refs: QuantumNous/new-api #8034 QuantumNous/new-api#8034
soulteary added a commit to soulteary/yunqi that referenced this pull request Nov 22, 2026
Carry explicit management context through policy, preview, approval and removal
into the atomic config persistence boundary. Retain compatible system wrappers
and the variadic discovery revision guard. Correlate policy/approval domain
history with the management operation ID.

Add transaction rollback and human/background actor regressions plus real HTTP
coverage of all four management mutation phases.

Refs: QuantumNous/new-api #7953 QuantumNous/new-api#7953
Refs: QuantumNous/new-api #7951 QuantumNous/new-api#7951
Refs: QuantumNous/new-api #8076 QuantumNous/new-api#8076
Refs: QuantumNous/new-api #8034 QuantumNous/new-api#8034
soulteary added a commit to soulteary/yunqi that referenced this pull request Nov 22, 2026
Refs: QuantumNous/new-api #7953 QuantumNous/new-api#7953
Refs: QuantumNous/new-api #7951 QuantumNous/new-api#7951
Refs: QuantumNous/new-api #8076 QuantumNous/new-api#8076
Refs: QuantumNous/new-api #8034 QuantumNous/new-api#8034
soulteary added a commit to soulteary/yunqi that referenced this pull request Nov 22, 2026
Forward HTTP management context to the locked account transaction while retaining a fresh system-context wrapper for automatic discovery. Verify both account and individual discovery writes remain isolated from human actors.

Refs: QuantumNous/new-api #7953 QuantumNous/new-api#7953
Refs: QuantumNous/new-api #7951 QuantumNous/new-api#7951
Refs: QuantumNous/new-api #8076 QuantumNous/new-api#8076
Refs: QuantumNous/new-api #8034 QuantumNous/new-api#8034
soulteary added a commit to soulteary/yunqi that referenced this pull request Nov 22, 2026
Commit configuration and bounded management audit atomically, retain explicit actor/operation identity through HTTP and domain transactions, and preserve separate system attribution for discovery. Regression tests, cross-review and full Verify CI passed, including retention/rollback fixes, model governance integration and isolated Redis readiness.

Refs: QuantumNous/new-api#8076 QuantumNous/new-api#8076
Refs: QuantumNous/new-api#8034 QuantumNous/new-api#8034
Refs: QuantumNous/new-api#6673 QuantumNous/new-api#6673
Refs: QuantumNous/new-api#7953 QuantumNous/new-api#7953
Refs: QuantumNous/new-api#7951 QuantumNous/new-api#7951
soulteary added a commit to soulteary/yunqi that referenced this pull request Nov 22, 2026
docs: finalize community improvement batches and validation

Document eight implemented capabilities, review fixes, exact commits, CI evidence and upstream correspondence. Preserve identity, Redis and evaluation boundaries, and provide the model governance lifecycle/API guide.

All functional PRs were reviewed and merged after successful regression tests and Verify CI. The running checkout and services were not changed.

Refs: QuantumNous/new-api issue #1730 QuantumNous/new-api#1730
Refs: QuantumNous/new-api issue #2841 QuantumNous/new-api#2841
Refs: QuantumNous/new-api issue #3240 QuantumNous/new-api#3240
Refs: QuantumNous/new-api PR #3345 QuantumNous/new-api#3345
Refs: QuantumNous/new-api issue #4328 QuantumNous/new-api#4328
Refs: QuantumNous/new-api PR #4329 QuantumNous/new-api#4329
Refs: QuantumNous/new-api PR #4492 QuantumNous/new-api#4492
Refs: QuantumNous/new-api PR #5431 QuantumNous/new-api#5431
Refs: QuantumNous/new-api PR #5791 QuantumNous/new-api#5791
Refs: QuantumNous/new-api PR #6264 QuantumNous/new-api#6264
Refs: QuantumNous/new-api PR #6583 QuantumNous/new-api#6583
Refs: QuantumNous/new-api PR #6620 QuantumNous/new-api#6620
Refs: QuantumNous/new-api PR #6673 QuantumNous/new-api#6673
Refs: QuantumNous/new-api issue #6972 QuantumNous/new-api#6972
Refs: QuantumNous/new-api PR #7028 QuantumNous/new-api#7028
Refs: QuantumNous/new-api issue #7951 QuantumNous/new-api#7951
Refs: QuantumNous/new-api issue #7952 QuantumNous/new-api#7952
Refs: QuantumNous/new-api PR #7953 QuantumNous/new-api#7953
Refs: QuantumNous/new-api PR #7955 QuantumNous/new-api#7955
Refs: QuantumNous/new-api issue #8034 QuantumNous/new-api#8034
Refs: QuantumNous/new-api PR #8076 QuantumNous/new-api#8076
Refs: QuantumNous/new-api issue #8123 QuantumNous/new-api#8123
Refs: QuantumNous/new-api PR #8124 QuantumNous/new-api#8124
Refs: QuantumNous/new-api issue #8232 QuantumNous/new-api#8232
Refs: QuantumNous/new-api PR #8233 QuantumNous/new-api#8233
Refs: QuantumNous/new-api issue #8295 QuantumNous/new-api#8295
Refs: QuantumNous/new-api PR #8296 QuantumNous/new-api#8296
Refs: QuantumNous/new-api PR #8350 QuantumNous/new-api#8350
Refs: QuantumNous/new-api PR #8357 QuantumNous/new-api#8357
Refs: QuantumNous/new-api PR #8363 QuantumNous/new-api#8363
Refs: #99 #99
Refs: #100 #100
Refs: #101 #101
Refs: #102 #102
Refs: #103 #103
Refs: #104 #104
Refs: #105 #105
Refs: #106 #106
Refs: #107 #107
Refs: #108 #108

Refs: #109 #109

Documentation Verify CI passed: https://github.com/soulteary/yunqi/actions/runs/45003986698

This branch has not been deployed

No deployments
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.

分组定价页保存静默失败:AutoGroups 值为 <nil> 时表单永久 invalid,onInvalid 只处理 MaxTokenAutoGroups

1 participant