Skip to content

chore: 合并上游 main (b388140ac) 到 fork-main - #46

Merged
AdoreJc merged 21 commits into
fork-mainfrom
sync/upstream-b388140ac
Nov 14, 2026
Merged

AdoreJc merged 21 commits into
fork-mainfrom
sync/upstream-b388140ac

Conversation

@AdoreJc

@AdoreJc AdoreJc commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

用户目标:先把 fork 同步到上游最新,再做后续功能与向上游贡献。

HQ-Task: T261113-16
本 PR 由 AI(Claude Code)生成。请用普通合并提交合并(不要 squash),以保留上游历史。

内容

冲突解法(28 个文件)

  • 两边各自追加、都保留:constant/api_type.go(fork 的 ClaudeOAuth 在前,值不变;上游 ProviderPlugin 在后,均不落库)、controller/channel_authz.go、i18n/keys.go、i18n/locales/{en,zh-CN,zh-TW}.yaml、common/log_text.zh-CN.json、main.go、model/system_task.go、setting/operation_setting/payment_setting.go、service/openai_chat_responses_mode.go、web/src/features/system-info/constants.ts、web/src/hooks/use-sidebar-data.ts
  • controller/channel.go:上游新的密钥更新流程 + fork 的自动重置配置保留与复制时清空成本字段
  • controller/codex_usage.go:保留 fork 重写的实现
  • service/codex_credential_refresh.go:fork 的持久化 + 上游的同步主题通知
  • model/channel.go:字段两边都留;Update/UpdateChannelStatus 用上游新签名并保留 fork 的冷却清除
  • model/channel_constraint.go:上游的插件中转判断 + fork 的 body_rewritten 过滤
  • model/option.go:上游易支付签名校验 + fork 的发信/审计选项校验;随上游移除敏感词选项
  • channel-mutate-drawer.tsx、model-price-cell.tsx:两边逻辑合并
  • 7 个前端语言文件:以上游文本为准,加回 fork 新增的 882 个 key;两边都新增且译文不同的少数 key 取上游

上游退役敏感词检查后的处理

上游退役了全局敏感词检查(启动时把词表迁到请求过滤插件实例并删除旧选项)。内容审计里名为 default 的关键词表原本直接读这份词表。提交 a8def85d9 在上游迁移之前先把原词表复制成一个名为 default 的普通存储词表,配置与审核策略规则里对它的引用不用改,升级前会命中的词升级后仍命中;default 之后可像其他词表一样编辑、删除。验证见评论。

验证

以下在 299e7f626 上运行,a8def85d9 上已全部复跑并通过(见评论)(macOS arm64 原生,Go 1.26.10,Bun 1.4.4):

  • make test:63 个包 ok、0 失败(根模块 + relaykit + tokenkit);relaykit、tokenkit 各自 GOWORK=off go build ./... 通过。
  • 前端:bun install --frozen-lockfile 通过;bun run typecheck 通过;bun run test 275 个文件 / 3095 个用例全过;bun run build 通过。
  • Windows 上 go test 有 controller、middleware、relay/channel 等包失败,属该环境已知问题,上面的 macOS 结果为准。
  • 端到端(测试容器,合并 + 适配后的 45a2e656b 构建):
    • 已做:全新 SQLite 启动,/api/status 200,启动日志无 error/panic;登录后渠道列表、插件列表(17 个)、插件市场源、插件运行状态、请求插件实例、提示词审计配置、审核策略、内容审计配置与关键词表、选项、用户、令牌接口均返回成功。
    • 已做:用 09cca3d97 构建在 SQLite、MySQL 8.4.13、PostgreSQL 17.12 上各起一个实例并建好数据(一个渠道、一个用户、一个令牌、敏感词与公告选项),启动日志无报错。
    • 未做:用合并后的构建接着这些数据升级(三库)、MySQL / PostgreSQL 全新库迁移、重复启动的幂等性、浏览器页面抽查(含 type 64 渠道表单)。测试环境暂不可用,恢复后补做,结果追加到评论。合并前需要补完。

seefs001 and others added 19 commits November 10, 2026 21:44
…ntumNous#8287)

DeepSeek Chat Completions rejects the developer role. Rewrite developer messages as system messages before sending them upstream; the Responses API accepts developer and is left unchanged.
* feat(payment): 易支付支持 RSA 签名方式

支付设置新增「签名方式」,可在 MD5 与 RSA 之间二选一。默认 MD5,已配置 MD5 的站点升级后行为不变。

- RSA 模式用商户私钥签名下单请求,跳转 /api/pay/submit;充值和订阅回调用平台公钥验签,MD5 签名的回调会被拒绝
- 保存时校验密钥:RSA 生效期间商户私钥和平台公钥必须能解析,切换到 RSA 前要先保存两把密钥;读取设置时不返回密钥
- 设置页选择 MD5 时只显示商户密钥,选择 RSA 时显示商户私钥和平台公钥;七种语言补齐文案
- go-epay 升级到 v0.0.6

* refactor(payment): 易支付签名设置改用 payment_setting 注册配置

签名方式、商户私钥、平台公钥改为 PaymentSetting 的字段,键名为 payment_setting.epay_sign_type、payment_setting.epay_merchant_private_key、payment_setting.epay_platform_public_key,由配置管理器统一加载和保存,不再在 option.go 里逐项初始化和赋值。

- 保存校验移到 operation_setting.ValidateEpaySignOption,规则不变
- 读取设置时不返回以 private_key 结尾的配置项;平台公钥可以正常显示和修改
* fix(channels): reset model redirect sync state when switching channels

* fix(channels): rebase batch redirect sync on current mappings and add regression tests
- moejs 迁到 github.com/MoeForge/moejs v0.1.0,Dockerfile、Electron 构建与发布流程的 PGO 路径同步更新;发布附带 THIRD-PARTY-LICENSES.md,并补充 moejs 附带的第三方声明。
- moego 升级到 v0.1.0-alpha.2:宿主 JSON 编解码经 common/kitutil 封装改用 moego/json,根模块和 relaykit 生产代码的 regexp 改用 moego/regexp。
- 内存中的请求体由校验器零拷贝解析;磁盘缓存的请求体经独立文件读取器解码,且只接受一个 JSON 值,尾随内容会被拒绝。
- 模型/分组提取与重复 model 键检测、渠道亲和 JSON 路径、任务协议 stream/background 标志、multipart 解析在磁盘模式下不再把整份请求体读进内存。图片透传直接转发已存储的请求体,并校验最终发往上游的 n。
- 出站请求体各自持有读取位置。此前透传重试共用存储游标,上一次尝试仍在发送时,下一次尝试可能发出残缺的请求体。收到响应头后不再提前关闭请求体,避免中断仍在发送的请求体。
- 表达式计费只在表达式使用 param() 时冻结请求体,其余情况不再读取并保留整份请求体。
…marketplace (QuantumNous#8271)

* feat(plugins): add provider plugins, request plugins and a community marketplace

- Provider plugins turn an upstream vendor into a channel type: routes,
  protocol conversion, models, static keys, sign-in flows with token
  refresh, balance queries, per-channel config and a scheduled hook.
- Request plugins run on requests and replies (ingress, request,
  outbound, egress, reply, report), with instances by scope, model
  ranges, dry runs and per-log records. Built-ins: request filter,
  request redaction, parameter override, auto reasoning effort, image
  compression and content moderation. Sensitive words move into a
  request filter instance on first start.
- Node sync: a system_sync_topics table lets every node reload settings,
  channels, plugins and other data within seconds, and the system info
  page shows each node's state.
- Marketplace: a community source next to the official one, lookup by
  plugin code for official and community plugins, key rules for
  community plugins, install counts and takedown warnings.

* docs(plugins): name request protocols and host-only members in the plugin API

- Protocol names: ctx.format and samples use relaykit's protocol names.
  The spec lists the client paths and body of each name, so every host
  passes the same names to plugins.
- Host-specific members: channel, group, user, token, channelTypes,
  channelOther and utils.paramOverride exist only on new-api. The types
  mark them optional.
- Relay routes: the spec now writes out the route keys and the converters
  each incoming path accepts. The schema lists the converter names.

* feat(plugins): show recommended plugins from the official list too

The site now marks official plugins as recommended in its index. The
built-in official and community lists both get a Recommended group;
lists added by the administrator still cannot recommend plugins.

* feat(plugins): fall back to www.newapi.pro when www.newapi.ai does not answer

Plugin lists, plugin files and logos from www.newapi.ai are downloaded
from www.newapi.pro, the mainland China site, when newapi.ai gives no
answer within 10 seconds; the browser remembers this for a day. The
marketplace toolbar has a download site picker: Auto, or Mainland China
to always use www.newapi.pro. Saved source addresses stay on newapi.ai,
and every file is still checked against its sha256.

Community install counts go to newapi.ai first and to newapi.pro when
newapi.ai cannot be reached.

* fix(plugins): leaving the page does not switch the plugin site to www.newapi.pro

Reloading or leaving the marketplace cancels requests still running.
That was read as www.newapi.ai not answering, so the browser moved to
www.newapi.pro for a day although newapi.ai was reachable. Requests
cut off by leaving the page are no longer counted.

* feat(plugins): choose the plugin download site by hand

The marketplace no longer switches between plugin sites by itself. The
toolbar menu lists the main site www.newapi.ai, the backup site
www.newapi.pro and the other plugin lists; picking an entry is the only
thing that changes where plugins are downloaded from, and the main site
can always be picked again.

A browser that the earlier automatic switch had moved to www.newapi.pro
opens on the main site again. The download site, the source choice and
managing sources now share one menu in the list header.

* feat(plugins): show plugin usage guides and require README and changelog

Every marketplace plugin version now ships a usage guide, README.md, and a
changelog, CHANGELOG.md, next to plugin.js. The install dialog shows the
guide in the reader's language when a translation is listed, falls back to
English, and links to the source file. A guide or changelog that breaks the
format is reported with its file, line and rule instead of being shown.

The plugin API document describes both formats, the translations they may
list, and the checks the community marketplace runs before it accepts a
version: readme_missing, readme_invalid, changelog_missing and
changelog_invalid. Versions accepted before these checks are not checked
again.

* fix(plugins): address review findings on plugin parts, limits and access

- Only the root user reads request plugin instance configs; an admin who
  may bind instances to channels gets them without configs.
- Outbound hooks that grow the body are held to MAX_REQUEST_BODY_MB, as
  ingress hooks are, and answer 413 without a retry.
- An admin who cannot read plugin options keeps the balance and model
  list actions on plugin channels; the server answers whether they work.
- Reading the parts of a plugin source gives up when the source does not
  parse or code elsewhere refers to meta, as the meta preview does.

* fix(plugins): address review findings on request processing, documents and node sync

- PDF checks resolve indirect parameters and bound every value the parser
  allocates or loops on: predictor columns, object stream counts, nested
  object streams, cross-reference streams and ToUnicode ranges. Font and
  CMap work checks the deadline.
- A WebP frame must match its declared canvas, and keyword search stops at
  its match limit.
- Request processing treats a body as JSON whenever the gateway parses it
  as JSON, keeps Gemini reply parts in place, scopes instances by the
  settled auto group, hides channel header overrides from plugin param
  overrides, and captures replies only for report instances in scope.
- Request processing no longer follows the plugin master switch, which now
  covers plugin tasks and channels only.
- json.patch copies stop at MAX_REQUEST_BODY_MB, and provider prepareRequest
  effects past it answer 413.
- Image billing reads the count from the final upstream body, including the
  count members of SiliconFlow, Imagen and Replicate and the Imagen default.
- Automatic channel status changes no longer reload every node's channel
  cache. A credential refresh holds no channel lock while it waits on the
  vendor. A key that needs login is disabled and the request can retry.
- Balance requests must go to the channel host or allowedHosts, and provider
  stream events a plugin drops keep the stream alive.
- Node sync: OAuth provider writes bump inside their transaction, a failed
  startup load is retried, and each node is judged by its own topics.
- request-filter checks the text the old sensitive-word check did,
  request-redact and content-moderation handle large inputs, and
  image-compress lossless mode leaves JPEG and WebP alone.

* fix(plugins): address the second review on balances, egress and routes

- Channel other_info writes (status changes, balance queries and manual
  multi-key actions) only land while other_info is still the value read,
  and retry otherwise, so a write on one node no longer overwrites another
  node's balance or status reason. They write only their own columns.
- On the Responses path egress reads the body after the channel finalizes
  it, which is the body sent upstream.
- The Vertex AI plugin picks the region by the model the client asked for,
  as the built-in Vertex AI channel does.
- /request-processing and /security are reserved route namespaces, and a
  test checks that every console page is reserved.
- The plugin API docs say what egress reads on a provider plugin channel.

* feat(channels): run the balance update as a system task with progress

"Update all balances" now queues a channel_balance system task instead of
starting a goroutine guarded by an in-process flag. The task row holds the
progress (enabled channels queried of total), so any node can answer it,
and its active key keeps one run at a time across nodes. The
CHANNEL_UPDATE_FREQUENCY schedule becomes the same task's schedule, so
manual and scheduled runs no longer overlap.

GET /api/channel/update_balance answers with the task id, and with the
running one when a run is already queued. GET
/api/channel/update_balance/task/:task_id, under the same channel
permission, returns the status, progress and failure of balance update
tasks only. The channel list follows the task, reloads as more channels
are queried and once more at the end, and reports how the run ended.

* feat(system): sync nodes through system tasks and clean up task history

Node sync no longer needs its own table. A write to synced data adds a
pending sync_<topic> system task. Every node polls the newest task of each
topic it keeps every 3 s and reloads when that task is newer than the one
it applied. Custom OAuth providers still add their task inside the write
transaction, and lock the newest task of the topic first, so tasks commit
in id order. The master marks a sync task succeeded once every online node
that keeps the topic has applied it. Until then the task shows how many
nodes have applied it and why the others have not. The
system_sync_topics table is gone.

A composite (type, id) index answers the newest task of a type from the
index. The latest-per-type and earliest-pending queries now read ids first,
because MySQL 5.7 scanned the whole table for them.

A daily system_task_cleanup task deletes finished system tasks older than
system_task_setting.retention_days (default 30, at least 1), in batches.
It never deletes active tasks or the newest task of any type. The
retention is set under Operations > Log maintenance.
The Vertex AI plugin now reads the channel deployment region (QuantumNous#8271), which the published 1.3.0 does not. Give that code its own version so the built-in plugin matches the marketplace again.
Upgrade frontend dependencies, keeping the newer of this branch's targets and main's versions.

- Notable upgrades: motion 13, nanoid 6, jsdom 30, @base-ui/react 1.7, lucide-react 1.34, @rsbuild/core 2.2, recharts 3.10.1, shadcn 4.19, react 19.2.8, react-hook-form 7.86, @hookform/resolvers 5.9.
- Kept main's pins: dompurify 3.4.17 and katex 0.18.2.
- oxlint stays on 1.74: 1.79 splits the React Compiler rule and reports 158 new errors on existing components.
- sonner 2.0.8 replays active toasts to a newly mounted Toaster, so the marketplace install dialog test now dismisses toasts between cases.
…#6928)

Show live password strength feedback that follows the account password policy (8–128 characters).

- Sign-up, change password, setup wizard and the admin user drawer show a strength meter, the length requirement and optional tips for a stronger password. Only the length blocks submission.
- Strength is rated mainly by length. Common passwords, one repeated character and straight runs such as 12345678 or qwertyui are marked as easy to guess, but only when they make up the whole password.
- The confirmation field says whether the passwords match, and a mismatch is shown only once.
- Password fields get a labelled show/hide button and link their hints for screen readers.
- Removed the unused 20-character limit and its translations.
…mNous#6955)

The notification settings restructure from this branch is already on main (QuantumNous#7868). What remains is a wording fix in the payment compliance notice.

- zh, zh-TW, ja, ru, vi and fr now say "super administrator" in the notice that locks payment, redemption codes, subscription plans and invitation rewards, matching the rest of the UI.
- fr: replaced the stray Chinese word in "codes de兑换" with "codes d’échange".
…mNous#8320)

react-router-devtools 1.167.1 ships router-devtools-core 1.168.1, which calls interpolatePath() with one object, but it resolved the top-level router-core 1.171.34, where interpolatePath takes positional arguments. In dev mode the devtools panel threw "path.endsWith is not a function" on every route change.

- Bump @tanstack/react-router to ^1.170.41 and @tanstack/react-router-devtools to ^1.167.2.
- The router, the devtools and the router plugin now share one router-core, 1.171.34.
- Production builds do not include the devtools.
…#8323)

A fieldset's default min-width is its content width, so a long line in
the plugin settings JSON editor widened the fieldset past the grid
column and pushed the plugin settings out of the channel drawer. Set
min-w-0 so the fieldset shrinks with its column and the editor scrolls
long lines itself.
…ntumNous#8322)

- rc.50 依赖的 moego v0.1.0-alpha.2 只按 AES-NI 选用 hashAES 内核,而该内核是 VEX 编码,需要 AVX。在有 AES-NI、没有 AVX 的 CPU(如 Celeron J4125)上,解析不少于 128 字节的请求 JSON 时进程因 SIGILL 退出,容器反复重启。
- alpha.3 在这类 CPU 上改用 SSE 编码的 AES 指令,结果与其他 CPU 相同。根模块和 relaykit 同步升级,THIRD-PARTY-LICENSES 中的版本号同步更新。

Fixes QuantumNous#8314
The plugin site's marketplace list shows meta.description on one line
and cuts longer summaries off with an ellipsis. Measured on the live
list at desktop width, the summary column is 572 px at 14 px: 40 Chinese
characters fit and 41 do not, and real summaries of up to 80 columns
(CJK and full-width punctuation counting as two) all fit.

Add a "Plugin summary length" section to the API reference recommending
at most 80 columns per locale, with guidance on what to leave to the
usage guide, and point the manifest table and the Meta type at it.
把上游 QuantumNous/new-api main(b388140ac,15 个提交)并入 fork-main,保留上游历史。
上游带来插件体系(provider plugins、request plugins、插件市场)、易支付 RSA 签名、
请求体按需流式读取、多节点同步主题等;fork 自有功能全部保留。

冲突 28 个文件:两边各自追加的内容都保留;语言文件以上游文本为准再加回 fork 新增的 key。

HQ-Task: T261113-16

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
上游把全局敏感词检查退役,启动时把词表迁到请求过滤插件实例并删除旧选项。
内容审计内置的 default 关键词表原本直接读这份全局词表,合并后已无数据来源:
该表现在为空、不再命中,自建关键词表不受影响。测试随之调整。

HQ-Task: T261113-16

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
上游易支付签名方式测试与 fork 支付网关开关测试各自构造表单默认值,
合并后表单同时要求两边新增的字段,补齐后类型检查与用例恢复通过。

HQ-Task: T261113-16

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
同步分支开工后 fork-main 又合入了 #42、#43,把它们并进来以免 PR 冲突。
冲突只有 7 个前端语言文件:保留同步分支的内容,再加回这两个 PR 新增的 key。

HQ-Task: T261113-16

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@AdoreJc

AdoreJc commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

端到端补充结果(HQ-Task: T261113-16)

用最终 head 299e7f626 构建的镜像,串行执行,每个场景都在同一份数据上启动两次(第二次为重启)。

场景 结果
SQLite 全新启动 /api/status 200;启动日志 0 条 error/panic/fatal/failed
SQLite 升级(数据由 09cca3d97 构建创建:1 渠道、2 用户、1 令牌、公告、敏感词选项) 两次启动均 200、日志无报错;渠道 1、用户 2、令牌 1、公告内容都在
MySQL 8.4.13 全新库 0 → 43 张表;两次启动均 200、日志无报错
MySQL 8.4.13 升级(同上数据) 两次启动均 200、日志无报错;数据都在;system_tasks 新增复合索引 idx_system_tasks_type_id(type,id)
PostgreSQL 17.12 全新库 0 → 43 张表;两次启动均 200、日志无报错
PostgreSQL 17.12 升级(同上数据) 两次启动均 200、日志无报错;数据都在;新增 idx_system_tasks_type_id

接口抽查(三库的全新实例上,管理员登录后):

  • 渠道列表、插件列表(17 个内置插件)、插件市场源、插件运行状态、请求插件实例、提示词审计配置、审核策略、内容审计配置与关键词表、选项(含支付开关与 payment_setting.epay_sign_type)、用户、令牌:全部返回成功。
  • 新建 type 64(Claude OAuth)渠道:合法 OAuth JSON 密钥创建成功;非 JSON 密钥被拒绝,提示需要含 access_token 的 JSON。
  • 前端路由 /、/channels、/task-plugins、/request-processing、/usage-logs/prompt-audit、/usage-logs/content-moderation、/system-settings/integrations 均返回 200 的应用外壳。

升级时观察到的两点:

  • 上游的敏感词迁移按预期执行:旧的 5 个敏感词选项被删除,词表进入一个名为“敏感词”的全局请求过滤实例(原先两个开关都开,所以实例为启用)。内容审计内置的 default 关键词表在升级前显示 2 个词,升级后为 0,与 PR 描述里“需要决定的行为变化”一致。
  • 升级后的库保留旧的单列索引 idx_system_tasks_type,全新库没有它;多一个冗余索引,不影响功能。

未做:在浏览器里登录后逐页点开(只做了接口与路由层面的抽查);带真实上游的中转流量。

测试容器、镜像与数据已清理。

@AdoreJc

AdoreJc commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

HQ-Review R1 @ 299e7f6: REQUEST_CHANGES

审查范围:只看合并本身(e2c79a519、299e7f626 的 remerge-diff,适配提交 45a2e656b、a19af8e7f),不审上游自身代码。

已核对、没有问题的部分:

  • 28 个冲突文件逐个看过 remerge-diff,两边内容都保留。codex_usage.go 保留 fork 实现,上游那段刷新后写回的逻辑已经在 fork 的 RefreshCodexChannelCredential 里,并且补上了 BumpSyncTopic。option.go 去掉的上游 Resend 校验已经被 fork 的 validateEmailDeliveryOption 覆盖。
  • 按文件集合核对:fork 相对合并基点改过的文件没有一个退回上游版本;上游改过的文件里,PR 与 fork 的差异只有两个适配提交。
  • 编号:渠道类型没有新增值(64 仍是 Claude OAuth)。APITypeProviderPlugin 排在 APITypeClaudeOAuth 之后,只在进程内使用,不落库。系统任务类型都是字符串,cost_backfill 与上游新增的值不冲突。
  • 数据库:model/main.go 与 fork-main 一致,AutoMigrate 列表没有丢表。上游只给 system_tasks 加了复合索引。
  • 语言文件:7 个前端语言文件加上 log_text.zh-CN.json、3 个后端 yaml,没有重复 key;上游 key 全部在、值未改;fork 新增 key 全部在;上游删掉的 70 个 key 在 web/src 里已无引用。
  • 请求体:上游改成流式读取后,BodyStorage.Bytes() 仍返回完整请求体(磁盘模式加锁读取),重放改为每次请求各自持有游标。提示词审计、内容审计读到的仍是完整请求体;它们在 ingress 插件之后、计费之前执行。provider plugin 渠道同样走 controller.Relay,不会绕开审核策略的挂点。

需要处理:

  1. [阻塞] 内容审计内置 default 词表被静默清空

    • 位置:service/contentmoderation/keyword.go:32、setting/content_moderation_setting/content_moderation.go:35-37,433、controller/content_moderation.go:196,212、web/src/features/system-settings/security/content-moderation/keyword-fields.tsx:138
    • 问题:适配后 default 永远不命中,但配置校验仍然允许选它,界面文案和接口报错也仍然写着“就是敏感词列表、去敏感词设置里改”,而那个设置已经不存在。
    • 失败场景:一个站点原本关闭了全局敏感词开关,只靠 keyword_only 模式加 default 词表做关键词审核。升级后,上游迁移把词表放进一个停用的请求过滤实例,default 变为 0 个词。这个站点的关键词审核从此不再生效,日志和界面都没有任何提示(e2e 已观察到 2 个词变成 0 个)。
    • 修法建议(任选其一):
      • 升级时把原词表复制成一个存储词表,并把内容审计配置和审核策略规则里对 default 的引用改过去;
      • 让 default 读取迁移后请求过滤实例里的词。
    • 至少要做到:不再允许选空的 default,或者在已选它时明确告警;同时修正失效的文案。
    • 适配后的测试 TestKeywordListsMatchCaseInsensitivelyAndFollowChanges 现在把“default 不命中”当作期望行为固定了下来,修复时一并调整。
  2. [非阻塞,后续跟进] 审核策略改路与插件渠道的交互缺一处过滤

    • 位置:model/channel_constraint.go:128-135
    • 细节已单独交主管,不在公开评论里展开。
  3. [非阻塞,后续跟进] fork 写 other_info 的函数仍是“读-改-写”盲写

    • 位置:model/channel.go:429-445 的 UpdateChannelOtherInfoEntry,调用方是 Claude 和 Codex 的被动用量采样。
    • 背景:上游这次把 other_info 的写入改成了比较后再写(UpdateChannelOtherInfo,model/channel.go:481),避免多节点之间互相覆盖。fork 这个函数仍只靠本节点的锁。
    • 失败场景:多节点部署时,A 节点刚写入的自动禁用原因 status_reason,可能被 B 节点的用量采样用旧快照覆盖。
    • 建议改用 UpdateChannelOtherInfo。
  4. [非阻塞,后续跟进] Claude OAuth 凭据刷新后没有触发节点同步

    • 位置:service/claude_credential_refresh.go:129
    • 问题:Codex 刷新已经补了 BumpSyncTopic(SyncTopicChannels),Claude 刷新还没有,其他节点要等 SYNC_FREQUENCY 的周期重载才能拿到新凭据。这个行为与合并前相同,不算回归;建议补齐,与 Codex 保持一致。

其他:

  • 合并前仍需补做:用浏览器登录后实际点开页面检查(PR 评论里写明未做)。
  • 本地(Windows)复核:go build ./... 通过;service/contentmoderation、service/auditpolicy、service/promptaudit、common、model 的测试通过(model 第一次运行失败过一次,带 -count=1 重跑两次都通过,判断是 Windows 环境的偶发问题)。

上游退役全局敏感词检查后,内容审计里名为 default 的关键词表失去了词表来源。
之前的适配让它恒不命中,只靠内容审计关键词模式做审核的站点升级后会静默失效。

现在升级时先把原敏感词复制成一个名为 default 的普通存储词表,再执行上游的迁移:
- 内容审计配置和审核策略规则里对 default 的引用无需改写,升级前会命中的词升级后仍命中,
  与旧的全局敏感词开关是否打开无关;
- 迁移幂等:旧选项被上游迁移删除后不再执行;已存在同名词表时不覆盖;
  复制失败时本次启动不执行上游迁移,词表留到下次启动;
- default 不再是内置表,可像其他词表一样编辑、删除;相应移除接口里的 builtin 字段、
  失效的报错与界面文案。

HQ-Task: T261113-16

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@AdoreJc

AdoreJc commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

HQ-Review R1 处理结果(HQ-Task: T261113-16)

新 head a8def85d9。

1. [阻塞] 内容审计 default 词表被清空 —— 已修。

做法:升级时把原全局敏感词复制成一个名为 default 的普通存储词表,在上游 MigrateSensitiveWords 删除旧选项之前执行。

  • 没有采用“另建词表并改写引用”:保留 default 这个名字后,内容审计配置和审核策略规则里的引用都不用改写,迁移只是一次插入,出错面更小。
  • 与旧的全局敏感词开关无关:只要旧词表非空就复制。
  • 幂等:旧选项被上游迁移删除后不再执行;已存在同名词表时不覆盖;复制失败时本次启动跳过上游迁移,词表留到下次启动。
  • 关键词表有长度和数量上限,超限的词不复制并写一条错误日志(原敏感词没有上限)。
  • default 不再是内置表:列表接口不再凭空返回它,去掉 builtin 字段,可像其他词表一样编辑、删除;删除了失效的接口报错、界面说明和过时注释,7 个语言文件同步。
  • 测试:TestKeywordListsMatchCaseInsensitivelyAndFollowChanges 改回断言 default 命中;新增 TestSensitiveWordsUpgradeKeepsDefaultListMatching(旧开关关闭 → 两个迁移按启动顺序各跑两次 → 只有一个词表、修订号不变、仍命中;已有同名词表不被覆盖);控制器测试改为 default 可编辑、列表里没有内置项。

2–4. 非阻塞项:按要求不在本 PR 处理。

验证(a8def85d9)

  • macOS 原生 make test:63 个包 ok、0 失败;relaykit、tokenkit 独立构建通过。
  • 前端:bun install --frozen-lockfile、bun run typecheck、bun run build 通过;bun run test 275 个文件 / 3095 个用例全过。
  • 端到端,三库各做一遍,串行执行。数据由 09cca3d97 构建创建:1 渠道、2 用户、1 令牌、公告、敏感词 2 个,全局敏感词两个开关都关,内容审计为 pre_block + keyword_only + default 词表。然后换成本分支构建在同一份数据上启动两次。
升级前(09cca3d97) 升级后第一次启动 第二次启动
含敏感词的请求 403 content_moderation_blocked,事件 keyword_block / default 同左 同左
不含敏感词的请求 通过审核,到达上游(测试渠道地址无效,500 do_request_failed) 同左 同左
default 词表 2 个词(内置) 2 个词(存储) 2 个词,未重复复制
渠道 / 用户 / 令牌 / 公告 1 / 2 / 1 / 有 不变 不变

SQLite、MySQL 8.4.13、PostgreSQL 17.12 结果一致。升级日志依次出现“复制 2 个敏感词到关键词表 default”和上游的“敏感词移到请求过滤实例”;上游迁出的那个过滤实例因旧开关关闭而处于停用状态,不影响上面的结果。启动日志里除这两次请求自身的错误外没有其他报错。

  • 全新 SQLite 库:启动 200、日志无报错;关键词表列表为空;新建名为 default 的词表成功。

未做:浏览器登录后的逐页检查;没有为词表列表界面新增前端用例(现有内容审计前端测试 13 个通过)。

测试容器、镜像与数据已清理。

fork-main 又合入了 #47,并进来以免 PR 冲突。
冲突只有 en、zh 两个前端语言文件:保留同步分支的内容,再加回 #47 新增的 key。

HQ-Task: T261113-16

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@AdoreJc

AdoreJc commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

补充(HQ-Task: T261113-16):fork-main 合入 #47 后与本分支在 en、zh 两个语言文件上冲突,已把 9682b8d8a 并入,新 head 849e0b607(保留本分支内容,加回 #47 新增的 13 个 key)。

在 849e0b607 上复跑(macOS 原生):make test 63 个包 ok、0 失败;relaykit、tokenkit 独立构建通过;bun install --frozen-lockfile、bun run typecheck、bun run build 通过;vitest 275 个文件 / 3097 个用例全过。上一条评论里的三库端到端是在 a8def85d9 上做的,这次合并只带入 #47 的前端改动,没有重做。

@AdoreJc

AdoreJc commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

HQ-Review R2 @ 849e0b6: APPROVE

本轮只审 R1 之后的两个提交:a8def85d9(default 词表迁移)与 849e0b607(并入 fork-main 9682b8d)。R1 已认可的上游合并不重审。

R1 第 1 项(升级后 default 词表变空、关键词审核静默失效):已修复。升级时把原敏感词复制成名为 default 的普通存储词表,执行顺序在上游 MigrateSensitiveWords 删除旧选项之前;原来引用 default 的内容审计配置和审核策略规则不用改,升级后照常命中,与旧的全局开关是否打开无关。

逐项核对(a8def85d9):

  • 顺序(main.go:379-388):只在主节点上跑,复制成功后才跑上游迁移。复制失败时本次启动跳过上游迁移、记错误日志,下次启动重试,不会死循环。代价是这一次启动期间旧检查已在代码里退役、新实例和词表也都没建,等于这一轮没有敏感词拦截。可以接受,见下面第 2 条。
  • 幂等与并发:旧选项删除后不会再复制;已有同名词表时不覆盖(升级前接口禁止保存名为 default 的词表,所以不会和用户已有的表冲突);旧词表为空时不创建。两个主节点同时启动时,name 上的唯一索引让后插入的那个报错,那个节点这次跳过上游迁移,下次启动发现表已存在就正常继续。不会出现重复行。
  • 三库兼容:只用了 GORM 结构体条件、lockForUpdate、Create,没有方言 SQL。
  • 缓存:迁移在内容审计服务启动之前完成,maintenanceLoop 第一次按版本号加载就能读到;其他节点约一分钟内会跟上。
  • 超出限制的词(单个超过 200 字、或超过 10000 个)不复制,记一条 SysError。这些词在上游的 request-filter 实例里仍是全量,可以接受。
  • 前端:builtin 字段已没有残留引用;被删掉的报错文案在前后端都没有孤立引用;新文案 7 种语言都换了;三条新日志都加进了 log_text.zh-CN.json。
  • 匹配语义:旧的 default 和新词表都是把文本和词转成小写再做 AC 匹配,大小写行为一致。

849e0b6(并入 fork-main):remerge-diff 只在 web/src/i18n/locales/{en,zh}.json 有冲突。我把三个提交的 7 种语言文件展开逐 key 对比:#47 新增的 13 个 key 都在、值和 fork-main 一样,同步分支的 key 和值一个没丢,也没有多出来的 key。其他文件和自动合并结果一致。

测试(本机 Windows,git archive 导出 849e0b6 的代码):go test ./service/contentmoderation/ ./model/ 全过。./controller -run ContentModeration 的断言都通过,只有已知的 Windows TempDir 清理失败。新测试断言的是用户能观察到的行为:升级后命中、重启后不重复复制、不覆盖已有表、default 可以编辑。在 299e7f6 上,[spam, default] 命中 default 这一例和 PUT default 的断言都会失败(推断:旧代码会跳过 default 并返回 400)。

不阻塞的意见:

  1. model/content_moderation.go(删除接口)和 keyword-fields.tsx:183("启用的词表"复选框):default 现在可以删了,但删除时不检查内容审计配置和审核策略规则有没有引用它。复选框只列出现存的词表,引用了已删除词表的勾选项在界面上看不到,而运行时找不到这个名字就当不命中。场景:管理员把 default 删了,配置仍是 keyword_gated_api 且只选了 default,结果所有请求都不再送 API 审核,界面上也看不出来。其他词表本来就有这个问题,这次 default 也加入了这一类。建议另开任务:删除时如果还有引用就拒绝或给出提示,或者在界面上显示"已引用但不存在"的词表。
  2. main.go:384-387:复制失败后跳过上游迁移的这条分支没有测试覆盖。持续失败(例如数据库权限问题)时,每次启动只打一条错误日志,站点会一直没有敏感词拦截。建议在运维说明里注明这条日志要处理。
  3. 边界情况:升级前已经存满 50 个存储词表的站点,迁移后会变成 51 个,之后新建词表会被拒绝,要先删一个才能建。很少见,记录一下即可。

结论:R1 的阻塞项已修复,两个新提交没有引入阻塞问题。本结论只适用于 849e0b6;按 B 级规则,合并需要用户批准。

@AdoreJc
AdoreJc merged commit 5d0ed1a into fork-main Nov 14, 2026
@AdoreJc
AdoreJc deleted the sync/upstream-b388140ac branch November 14, 2026 10:59
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.

6 participants