fix: 修正账号封禁分类与状态转换,支持webui配置日志等级/轮转配置等#453
Merged
chenyme merged 11 commits intochenyme:mainfrom Apr 12, 2026
Merged
Conversation
- classifier: 403 无凭证标记时回退为 FORBIDDEN 而非 AUTH_FAILURE - refresh: record_failure_async 403 改走状态机打击计数, 不再直接 DISABLED - state_machine: COOLING 恢复 ACTIVE 时清除 forbidden_strikes 残留 - feedback: 新增 SERVER_ERROR 健康度退化因子 (×0.75) - executor: TRANSPORT_ERR/UNKNOWN 映射到 SERVER_ERROR, 不再静默忽略 - xai_usage: 扩展无效凭证检测模式 (session not found/account suspended/token revoked/expired) - invalid_credentials: 优先检查 body 标记, 再按状态码分类
- headers: 移除完整 headers JSON dump, 仅记录 header_count - http: post_json 失败降级为 warning, 移除 body 输出 - chat: 移除逐帧 SSE debug 日志 (chat sse frame / stream adapter skipped)
- config.defaults.toml: 新增 [logging] 区段 (level/file_level/max_files) - logger: setup_logging/reload_logging 支持独立 file_level 参数 - admin: update_config 传递日志配置, reload_logging 热更新 - main: lifespan 启动时读取日志配置 - config.html: 系统配置新增「日志配置」分组 (控制台等级/文件等级/保留天数) - i18n: 6 语言新增 logging 相关翻译键 - README: 系统配置项表格补充 logging 分组
- FORBIDDEN 热路径不再直接 DISABLED,交由控制面打击计数决定
- config.update() 后调用 config.load() 刷新内存,避免读取过期值
- 删除 record_failure_async 中冗余的 record 二次查询
- exc.body → exc.details.get('body') 正确获取 UpstreamError 响应体
- apply_server_error 加入 feedback __all__ 导出列表
There was a problem hiding this comment.
Pull request overview
该 PR 主要修复账号封禁/反馈链路中 403 分类与状态机转换不合理的问题,引入 5xx/传输错误的健康度衰减,并对日志进行降噪,同时新增“文件日志等级/轮转保留数量”的可配置与 WebUI 支持。
Changes:
- 调整 403/无效凭证识别与反馈映射:将通用 403 从
AUTH_FAILURE改为FORBIDDEN,并补齐TRANSPORT_ERR/UNKNOWN→SERVER_ERROR的反馈映射与健康衰减。 - 新增账号健康因子
SERVER_ERROR(×0.75)以及 COOLING → ACTIVE 成功恢复时清除forbidden_strikes。 - 支持日志文件独立等级与按天轮转保留数量的配置(defaults + Admin 热更新 + WebUI schema + i18n/README),并移除部分高噪声日志输出。
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | 配置分组表新增 logging 相关键说明 |
| config.defaults.toml | 新增 [logging] file_level/max_files 默认配置 |
| app/statics/js/i18n.js | i18n 取值函数增强输入健壮性 |
| app/statics/i18n/zh.json | 新增日志配置分组与字段文案 |
| app/statics/i18n/en.json | 同上(英文) |
| app/statics/i18n/ja.json | 同上(日文) |
| app/statics/i18n/fr.json | 同上(法文) |
| app/statics/i18n/es.json | 同上(西语) |
| app/statics/i18n/de.json | 同上(德语) |
| app/statics/admin/config.html | WebUI 系统配置页新增日志配置分组(文件等级/保留数量)与 tr() 防御性处理 |
| app/products/web/admin/init.py | Admin 保存配置后加载快照并热更新文件日志 sink;增强代理配置清洗 |
| app/platform/logging/logger.py | 支持文件日志独立等级、文件 sink 热重载能力 |
| app/main.py | 启动后按配置加载并应用文件日志配置(level/max_files) |
| app/dataplane/reverse/classifier.py | 403 分类:优先识别无效/封禁标记,通用 403 走 FORBIDDEN |
| app/dataplane/reverse/executor.py | 增补 TRANSPORT_ERR/UNKNOWN → SERVER_ERROR 反馈映射 |
| app/dataplane/reverse/transport/http.py | post_json 失败降噪(warning、减少 body 输出)并整理参数格式 |
| app/dataplane/reverse/protocol/xai_usage.py | 扩展无效/封禁 body 匹配模式;quota-fetch 的 proxy feedback 映射整理 |
| app/dataplane/proxy/adapters/headers.py | 移除完整 headers JSON dump,降低日志噪声 |
| app/dataplane/account/feedback.py | 新增 apply_server_error 健康衰减逻辑 |
| app/dataplane/account/init.py | SERVER_ERROR 反馈在热路径中触发健康衰减 |
| app/control/account/state_machine.py | SUCCESS 恢复 ACTIVE 时清理 forbidden_strikes;整理状态机更新逻辑 |
| app/control/account/refresh.py | 主要为格式化/日志结构调整(不改变核心刷新流程) |
| app/control/account/invalid_credentials.py | 反馈类型映射优先识别“被封/无效账号”marker(含 403) |
| app/products/openai/chat.py | 移除 SSE 逐帧 debug 日志并整理调用/日志格式 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
修复账号封禁链路中多处分类与状态转换不合理的问题,削减日志噪声,并新增日志等级与轮转的 WebUI 可配置支持。
1. 账号封禁与反馈链路修复
classifier通用 403 回退为AUTH_FAILURE→ 账号被误标 EXPIREDFORBIDDEN→ 走 DISABLED 路径record_failure_async收到 403 直接写 DISABLED,绕过状态机的forbidden_strikes策略apply_feedback状态机,尊重打击计数阈值forbidden_strikes计数残留,下次 403 立即 DISABLEDforbidden_strikesSERVER_ERROR健康因子 (×0.75)TRANSPORT_ERR/UNKNOWN无反馈映射,网络超时/DNS 失败被静默忽略SERVER_ERROR参与健康衰减session not found等2. 日志降噪
headers.py完整 headers JSON dump(~54 MB/日)http.pypost_json 失败降级为 warning,移除 body 输出3. 日志轮转与等级可配置
[logging]区段:file_level/max_filesfile_level)Testing
get_errors零报错blocked-userbody →AUTH_FAILURE→UNAUTHORIZED→ EXPIRED ✓FORBIDDEN→ DISABLED ✓FORBIDDEN→ 状态机打击计数 → 达阈值后 DISABLED ✓SERVER_ERROR→ 健康度 ×0.75 衰减 ✓TRANSPORT_ERR→ 映射SERVER_ERROR→ 不再静默 ✓forbidden_strikes清零 ✓Related